presto-main/src/main/java/io/prestosql/sql/gen/NullIfCodeGenerator.java/NullIfCodeGenerator/generateExpression
class NullIfCodeGenerator:    @Override
    public BytecodeNode generateExpression(ResolvedFunction resolvedFunction, BytecodeGeneratorContext generatorContext, Type returnType, List<RowExpression> arguments)
    {
        Scope scope = generatorContext.getScope();

        RowExpression first = arguments.get(0);
        RowExpression second = arguments.get(1);

        LabelNode notMatch = new LabelNode("notMatch");

        // push first arg on the stack
        Variable firstValue = scope.createTempVariable(first.getType().getJavaType());
        BytecodeBlock block = new BytecodeBlock()
                .comment("check if first arg is null")
                .append(generatorContext.generate(first))
                .append(ifWasNullPopAndGoto(scope, notMatch, void.class))
                .dup(first.getType().getJavaType())
                .putVariable(firstValue);

        Type firstType = first.getType();
        Type secondType = second.getType();

        // if (equal(cast(first as <common type>), cast(second as <common type>))
        Metadata metadata = generatorContext.getMetadata();
        ResolvedFunction resolvedEqualsFunction = metadata.resolveOperator(OperatorType.EQUAL, ImmutableList.of(firstType, secondType));
        ScalarFunctionImplementation equalsFunction = metadata.getScalarFunctionImplementation(resolvedEqualsFunction);
        Type firstRequiredType = metadata.getType(resolvedEqualsFunction.getSignature().getArgumentTypes().get(0));
        Type secondRequiredType = metadata.getType(resolvedEqualsFunction.getSignature().getArgumentTypes().get(1));
        BytecodeNode equalsCall = generatorContext.generateCall(
                resolvedEqualsFunction.getSignature().getName(),
                equalsFunction,
                ImmutableList.of(
                        cast(generatorContext, firstValue, firstType, firstRequiredType),
                        cast(generatorContext, generatorContext.generate(second), secondType, secondRequiredType)));

        BytecodeBlock conditionBlock = new BytecodeBlock()
                .append(equalsCall)
                .append(BytecodeUtils.ifWasNullClearPopAndGoto(scope, notMatch, void.class, boolean.class));

        // if first and second are equal, return null
        BytecodeBlock trueBlock = new BytecodeBlock()
                .append(generatorContext.wasNull().set(constantTrue()))
                .pop(first.getType().getJavaType())
                .pushJavaDefault(first.getType().getJavaType());

        // else return first (which is still on the stack
        block.append(new IfStatement()
                .condition(conditionBlock)
                .ifTrue(trueBlock)
                .ifFalse(notMatch));

        return block;
    }