// File: /workspace/github_cpp_makefile_star2_O2/joncampbell123[P]haxcc/haxpp.cpp
// Function: pp_if_eval(expression&, unsigned long)
signed long long pp_if_eval(expression &expr,expression::node::node_t node) {
    if (node == expression::node::none)
        throw invalid_argument("expression tree with no root");

    const auto &n = expr.getnode(node);
    switch (n.tval.tval) {
        case token::INTEGER:
            return n.tval.i.s;
        case token::FLOAT:
            throw invalid_argument("Floating point not allowed in expressions at preprocessor level");
        case token::STRING:
            throw invalid_argument("Strings not allowed in expressions at preprocessor level");
        case token::ASSIGNMENT:
            throw invalid_argument("Assignment not permitted in macro preprocessor");
        case token::POSTINCREMENT:
        case token::POSTDECREMENT:
        case token::PREINCREMENT:
        case token::PREDECREMENT:
            throw invalid_argument("increment/decrement not allowed in macro preprocessor");
        case token::DEREFERENCE:
        case token::STRUCTREF:
        case token::ADDRESSOF:
            throw invalid_argument("struct/pointer ref not allowed in macro preprocessor");
        case token::SIZEOF:
            throw invalid_argument("sizeof not allowed in macro preprocessor");
        case token::COMMA:
            return pp_if_eval(expr,n.children.at(1)); /* a,b -> b */
        case token::PLUS:
            if (n.children.size() == 2)
                return pp_if_eval(expr,n.children.at(0)) + pp_if_eval(expr,n.children.at(1));
            else if (n.children.size() == 1)
                return pp_if_eval(expr,n.children.at(0)); /* +a -> a */
        case token::NEGATE:
            return -pp_if_eval(expr,n.children.at(0));
        case token::MINUS:
            return pp_if_eval(expr,n.children.at(0)) - pp_if_eval(expr,n.children.at(1));
        case token::NOT:
            return (pp_if_eval(expr,n.children.at(0)) == 0) ? 1 : 0;
        case token::COMPLEMENT:
            return ~pp_if_eval(expr,n.children.at(0));
        case token::MULTIPLY:
            return pp_if_eval(expr,n.children.at(0)) * pp_if_eval(expr,n.children.at(1));
        case token::DIVISION:
            return pp_if_eval(expr,n.children.at(0)) / pp_if_eval(expr,n.children.at(1));
        case token::MODULUS:
            return pp_if_eval(expr,n.children.at(0)) % pp_if_eval(expr,n.children.at(1));
        case token::LOGICAL_AND:
            return ((pp_if_eval(expr,n.children.at(0)) != 0ll) && (pp_if_eval(expr,n.children.at(1)) != 0ll)) ? 1 : 0;
        case token::LOGICAL_OR:
            return ((pp_if_eval(expr,n.children.at(0)) != 0ll) || (pp_if_eval(expr,n.children.at(1)) != 0ll)) ? 1 : 0;
        case token::BINARY_AND:
            return pp_if_eval(expr,n.children.at(0)) & pp_if_eval(expr,n.children.at(1));
        case token::BINARY_XOR:
            return pp_if_eval(expr,n.children.at(0)) ^ pp_if_eval(expr,n.children.at(1));
        case token::BINARY_OR:
            return pp_if_eval(expr,n.children.at(0)) | pp_if_eval(expr,n.children.at(1));
        case token::EQUALS:
            return (pp_if_eval(expr,n.children.at(0)) == pp_if_eval(expr,n.children.at(1))) ? 1 : 0;
        case token::NOT_EQUALS:
            return (pp_if_eval(expr,n.children.at(0)) != pp_if_eval(expr,n.children.at(1))) ? 1 : 0;
        case token::LESS_THAN:
            return (pp_if_eval(expr,n.children.at(0)) < pp_if_eval(expr,n.children.at(1))) ? 1 : 0;
        case token::LESS_THAN_OR_EQUAL:
            return (pp_if_eval(expr,n.children.at(0)) <= pp_if_eval(expr,n.children.at(1))) ? 1 : 0;
        case token::GREATER_THAN:
            return (pp_if_eval(expr,n.children.at(0)) > pp_if_eval(expr,n.children.at(1))) ? 1 : 0;
        case token::GREATER_THAN_OR_EQUAL:
            return (pp_if_eval(expr,n.children.at(0)) >= pp_if_eval(expr,n.children.at(1))) ? 1 : 0;
        case token::TERNARY:
            return (pp_if_eval(expr,n.children.at(0)) != 0ll) ?
                    pp_if_eval(expr,n.children.at(1)) :
                    pp_if_eval(expr,n.children.at(2));
        case token::IDENTIFIER:
            return 0ll; /* if the macro expansion did not replace the identifier with a value then it is zero */
        case token::DEFINED:
            {
                const auto &c = expr.getnode(n.children.at(0));
                if (c.tval.tval == token::IDENTIFIER)
                    return is_macro(c.tval.sval) ? 1 : 0;
                else
                    throw invalid_argument("defined() used with a non-identifier");
            }
        case token::TYPECAST: /* .at(0)=type tokens .at(1)=expression to typecast */
            fprintf(stderr,"WARNING: Typecasts are ignored by the macro processor\n");
            return pp_if_eval(expr,n.children.at(n.children.size()-size_t(1)));
        default:
            break;
    };

    throw invalid_argument(string("unsupported expression in preprocessor level, token ")+to_string(n.tval));
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x70, %rsp
movq %rsi, 0x8(%rsp)
cmpq $-0x1, %rsi
je 0x9bdb
movq %rdi, %rbx
leaq 0x8(%rsp), %rsi
callq 0xb4a6
movq %rax, %r14
movl (%rax), %eax
leal -0x5(%rax), %ecx
cmpl $0x3f, %ecx
ja 0x9689
leaq 0x5e0c(%rip), %rax      # 0xf484
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
xorl %r15d, %r15d
jmp 0x9b8a
cmpl $0x63, %eax
je 0x9b58
cmpl $0x7e, %eax
jne 0x9c43
addq $0x70, %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0xb5c8
movq (%rax), %rsi
movq %rbx, %rdi
callq 0x963c
testq %rax, %rax
jne 0x9a1b
pushq $0x2
jmp 0x9a1d
addq $0x70, %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0xb5c8
movq (%rax), %rsi
movq %rbx, %rdi
callq 0x963c
movq %rax, %r12
pushq $0x1
popq %rsi
movq %r14, %rdi
callq 0xb5c8
movq (%rax), %rsi
movq %rbx, %rdi
callq 0x963c
movq %rax, %r15
andq %r12, %r15
jmp 0x9b8a
addq $0x70, %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0xb5c8
movq (%rax), %rsi
movq %rbx, %rdi
callq 0x963c
movq %rax, %r12
pushq $0x1
popq %rsi
movq %r14, %rdi
callq 0xb5c8
movq (%rax), %rsi
movq %rbx, %rdi
callq 0x963c
movq %rax, %r15
orq %r12, %r15
jmp 0x9b8a
addq $0x70, %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0xb5c8
movq (%rax), %rsi
movq %rbx, %rdi
callq 0x963c
movq %rax, %r12
pushq $0x1
popq %rsi
movq %r14, %rdi
callq 0xb5c8
movq (%rax), %rsi
movq %rbx, %rdi
callq 0x963c
xorl %r15d, %r15d
cmpq %rax, %r12
jmp 0x9a0e
addq $0x70, %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0xb5c8
movq (%rax), %rsi
movq %rbx, %rdi
callq 0x963c
movq %rax, %r12
pushq $0x1
popq %rsi
movq %r14, %rdi
callq 0xb5c8
movq (%rax), %rsi
movq %rbx, %rdi
callq 0x963c
xorl %r15d, %r15d
cmpq %rax, %r12
jmp 0x9ad5
addq $0x70, %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0xb5c8
movq (%rax), %rsi
movq %rbx, %rdi
callq 0x963c
movq %rax, %r12
pushq $0x1
popq %rsi
movq %r14, %rdi
callq 0xb5c8
movq (%rax), %rsi
movq %rbx, %rdi
callq 0x963c
xorl %r15d, %r15d
cmpq %rax, %r12
setl %r15b
jmp 0x9b8a
addq $0x70, %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0xb5c8
movq (%rax), %rsi
movq %rbx, %rdi
callq 0x963c
movq %rax, %r12
pushq $0x1
popq %rsi
movq %r14, %rdi
callq 0xb5c8
movq (%rax), %rsi
movq %rbx, %rdi
callq 0x963c
xorl %r15d, %r15d
cmpq %rax, %r12
setg %r15b
jmp 0x9b8a
addq $0x70, %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0xb5c8
movq (%rax), %rsi
movq %rbx, %rdi
callq 0x963c
movq %rax, %r12
pushq $0x1
popq %rsi
movq %r14, %rdi
callq 0xb5c8
movq (%rax), %rsi
movq %rbx, %rdi
callq 0x963c
movq %rax, %r15
imulq %r12, %r15
jmp 0x9b8a
addq $0x70, %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0xb5c8
movq (%rax), %rsi
movq %rbx, %rdi
callq 0x963c
movq %rax, %r12
pushq $0x1
popq %rsi
movq %r14, %rdi
callq 0xb5c8
movq (%rax), %rsi
movq %rbx, %rdi
callq 0x963c
xorl %r15d, %r15d
cmpq %rax, %r12
setge %r15b
jmp 0x9b8a
addq $0x70, %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0xb5c8
movq (%rax), %rsi
movq %rbx, %rdi
callq 0x963c
movq %rax, %r15
pushq $0x1
popq %rsi
movq %r14, %rdi
callq 0xb5c8
movq (%rax), %rsi
movq %rbx, %rdi
callq 0x963c
movq %rax, %rcx
movq %r15, %rax
cqto
idivq %rcx
movq %rdx, %r15
jmp 0x9b8a
addq $0x70, %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0xb5c8
movq (%rax), %rsi
movq %rbx, %rdi
callq 0x963c
movq %rax, %r12
pushq $0x1
popq %rsi
movq %r14, %rdi
callq 0xb5c8
movq (%rax), %rsi
movq %rbx, %rdi
callq 0x963c
xorl %r15d, %r15d
cmpq %rax, %r12
setle %r15b
jmp 0x9b8a
addq $0x70, %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0xb5c8
movq (%rax), %rsi
movq %rbx, %rdi
callq 0x963c
movq %rax, %r15
pushq $0x1
popq %rsi
movq %r14, %rdi
callq 0xb5c8
movq (%rax), %rsi
movq %rbx, %rdi
callq 0x963c
movq %rax, %rcx
movq %r15, %rax
cqto
idivq %rcx
jmp 0x9a31
addq $0x70, %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0xb5c8
movq (%rax), %rsi
movq %rbx, %rdi
callq 0x963c
movq %rax, %r15
notq %r15
jmp 0x9b8a
addq $0x70, %r14
xorl %r15d, %r15d
movq %r14, %rdi
xorl %esi, %esi
callq 0xb5c8
movq (%rax), %rsi
movq %rbx, %rdi
callq 0x963c
testq %rax, %rax
jne 0x99f2
jmp 0x9b8a
addq $0x70, %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0xb5c8
movq (%rax), %rsi
movq %rbx, %rdi
callq 0x963c
testq %rax, %rax
je 0x99f2
pushq $0x1
popq %r15
jmp 0x9b8a
pushq $0x1
popq %rsi
movq %r14, %rdi
callq 0xb5c8
movq (%rax), %rsi
movq %rbx, %rdi
callq 0x963c
xorl %r15d, %r15d
testq %rax, %rax
setne %r15b
jmp 0x9b8a
addq $0x70, %r14
pushq $0x1
popq %rsi
movq %r14, %rdi
callq 0xb5c8
movq (%rax), %rsi
movq %rbx, %rdi
callq 0x963c
movq %rax, %r15
jmp 0x9b8a
leaq 0x70(%r14), %r15
movq 0x78(%r14), %rax
subq 0x70(%r14), %rax
sarq $0x3, %rax
cmpq $0x1, %rax
je 0x9b9a
cmpq $0x2, %rax
jne 0x9a92
movq %r15, %rdi
xorl %esi, %esi
callq 0xb5c8
movq (%rax), %rsi
movq %rbx, %rdi
callq 0x963c
movq %rax, %r14
pushq $0x1
popq %rsi
movq %r15, %rdi
callq 0xb5c8
movq (%rax), %rsi
movq %rbx, %rdi
callq 0x963c
movq %rax, %r15
addq %r14, %r15
jmp 0x9b8a
addq $0x70, %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0xb5c8
movq (%rax), %rsi
movq %rbx, %rdi
callq 0x963c
movq %rax, %r15
negq %r15
jmp 0x9b8a
addq $0x70, %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0xb5c8
movq (%rax), %rsi
movq %rbx, %rdi
callq 0x963c
xorl %r15d, %r15d
testq %rax, %rax
sete %r15b
jmp 0x9b8a
movq 0x8(%r14), %r15
jmp 0x9b8a
addq $0x70, %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0xb5c8
movq (%rax), %rsi
movq %rbx, %rdi
callq 0x963c
movq %rax, %r15
pushq $0x1
popq %rsi
movq %r14, %rdi
callq 0xb5c8
movq (%rax), %rsi
movq %rbx, %rdi
callq 0x963c
subq %rax, %r15
jmp 0x9b8a
addq $0x70, %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0xb5c8
movq (%rax), %rsi
movq %rbx, %rdi
callq 0x963c
movq %rax, %r12
pushq $0x1
popq %rsi
movq %r14, %rdi
callq 0xb5c8
movq (%rax), %rsi
movq %rbx, %rdi
callq 0x963c
movq %rax, %r15
xorq %r12, %r15
jmp 0x9b8a
addq $0x70, %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0xb5c8
movq %rbx, %rdi
movq %rax, %rsi
callq 0xb4a6
cmpl $0x5, (%rax)
jne 0x9d0a
addq $0x48, %rax
movq %rax, %rdi
callq 0x3639
movzbl %al, %r15d
movq %r15, %rax
addq $0x70, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %r15, %rdi
xorl %esi, %esi
jmp 0x9a21
movq 0xe40d(%rip), %rax      # 0x17fb8
movq (%rax), %rcx
leaq 0x686f(%rip), %rdi      # 0x10424
pushq $0x36
popq %rsi
pushq $0x1
popq %rdx
callq 0x23d0
movq %r14, %rdi
addq $0x70, %rdi
movq 0x78(%r14), %rsi
subq 0x70(%r14), %rsi
sarq $0x3, %rsi
decq %rsi
jmp 0x9a21
pushq $0x10
popq %rdi
callq 0x20e0
movq %rax, %rbx
leaq 0x66b9(%rip), %rsi      # 0x102a6
movq %rax, %rdi
callq 0x23a0
movq 0xe3dc(%rip), %rsi      # 0x17fd8
movq 0xe3bd(%rip), %rdx      # 0x17fc0
movq %rbx, %rdi
callq 0x2340
pushq $0x10
popq %rdi
callq 0x20e0
movq %rax, %rbx
leaq 0x674e(%rip), %rsi      # 0x1036b
movq %rax, %rdi
callq 0x23a0
jmp 0x9bf5
pushq $0x10
popq %rdi
callq 0x20e0
movq %rax, %rbx
leaq 0x6768(%rip), %rsi      # 0x103a1
movq %rax, %rdi
callq 0x23a0
jmp 0x9bf5
pushq $0x10
popq %rdi
callq 0x20e0
movq %rax, %rbx
leaq 0x6806(%rip), %rsi      # 0x1045b
leaq 0x30(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0xb1b8
leaq 0x10(%rsp), %rdi
movq %r14, %rsi
callq 0x47a7
leaq 0x50(%rsp), %rdi
leaq 0x30(%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq 0xb282
movb $0x1, %bpl
leaq 0x50(%rsp), %rsi
movq %rbx, %rdi
callq 0x2360
xorl %ebp, %ebp
movq 0xe33a(%rip), %rsi      # 0x17fd8
movq 0xe31b(%rip), %rdx      # 0x17fc0
movq %rbx, %rdi
callq 0x2340
pushq $0x10
popq %rdi
callq 0x20e0
movq %rax, %rbx
leaq 0x667d(%rip), %rsi      # 0x1033c
movq %rax, %rdi
callq 0x23a0
jmp 0x9bf5
pushq $0x10
popq %rdi
callq 0x20e0
movq %rax, %rbx
leaq 0x6625(%rip), %rsi      # 0x10303
movq %rax, %rdi
callq 0x23a0
jmp 0x9bf5
pushq $0x10
popq %rdi
callq 0x20e0
movq %rax, %rbx
leaq 0x65c6(%rip), %rsi      # 0x102c3
movq %rax, %rdi
callq 0x23a0
jmp 0x9bf5
pushq $0x10
popq %rdi
callq 0x20e0
movq %rax, %rbx
leaq 0x66e3(%rip), %rsi      # 0x103ff
movq %rax, %rdi
callq 0x23a0
jmp 0x9bf5
pushq $0x10
popq %rdi
callq 0x20e0
movq %rax, %rbx
leaq 0x669b(%rip), %rsi      # 0x103d6
movq %rax, %rdi
callq 0x23a0
jmp 0x9bf5
movq %rax, %r14
leaq 0x50(%rsp), %rdi
callq 0x2408
jmp 0x9d5d
movq %rax, %r14
movb $0x1, %bpl
leaq 0x10(%rsp), %rdi
callq 0x2408
jmp 0x9d6f
movq %rax, %r14
movb $0x1, %bpl
leaq 0x30(%rsp), %rdi
callq 0x2408
testb %bpl, %bpl
jne 0x9d93
jmp 0x9d9b
jmp 0x9d90
jmp 0x9d90
jmp 0x9d90
jmp 0x9d90
jmp 0x9d90
jmp 0x9d90
jmp 0x9d90
jmp 0x9d90
movq %rax, %r14
movq %rbx, %rdi
callq 0x2160
movq %r14, %rdi
callq 0x2370