// File: joncampbell123[P]haxcc/haxpp.cpp
// Function: parse_expr_rtl_ternary(expression&, __gnu_cxx::__normal_iterator<token*, std::vector<token, std::allocator<token>>>&, __gnu_cxx::__normal_iterator<token*, std::vector<token, std::allocator<token>>> const&, unsigned int, unsigned long)
expression::node::node_t parse_expr_rtl_ternary(expression &expr,token_string::iterator &ti,const token_string::iterator &tie,unsigned int min_prec,expression::node::node_t headnode) {
    unsigned int prec;

    while (ti != tie && (*ti).tval == token::QUESTIONMARK && (prec=token::precedence(*ti,false)) <= min_prec) {
        const expression::node::node_t opnode = expr.newnode(*(ti++),token::TERNARY);

        if (ti != tie) {
            expr.getnode(opnode).children.resize(3);
            expr.getnode(opnode).children[0] = headnode;
            expr.getnode(opnode).children[1] = parse_expr(expr,ti,tie,prec);

            if (ti == tie)
                throw invalid_argument("Ternary ? expected :");
            if ((*ti).tval != token::COLON)
                throw invalid_argument("Ternary ? expected :");
            ti++;

            expr.getnode(opnode).children[2] = parse_expr(expr,ti,tie,prec);
            headnode = opnode;
        }
        else {
            throw invalid_argument("missing rvalue");
        }
    }

    return headnode;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq %r8, -0x28(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x16580
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x59(%rbp)
jne 0x10f19
jmp 0x10f4e
movq -0x10(%rbp), %rdi
callq 0x16600
movq %rax, %rcx
xorl %eax, %eax
cmpl $0x45, (%rcx)
movb %al, -0x59(%rbp)
jne 0x10f4e
movq -0x10(%rbp), %rdi
callq 0x16600
movq %rax, %rdi
xorl %esi, %esi
callq 0x3a50
movl %eax, -0x2c(%rbp)
cmpl -0x1c(%rbp), %eax
setbe %al
movb %al, -0x59(%rbp)
movb -0x59(%rbp), %al
testb $0x1, %al
jne 0x10f5a
jmp 0x111b6
movq -0x8(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x165c0
movq %rax, -0x40(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x16600
movq -0x68(%rbp), %rdi
movq %rax, %rsi
movl $0x7e, %edx
callq 0x10a50
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x16580
testb $0x1, %al
jne 0x10fa5
jmp 0x11158
movq -0x8(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x16810
movq %rax, %rdi
addq $0x70, %rdi
movl $0x3, %esi
callq 0x168c0
movq -0x28(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x16810
movq %rax, %rdi
addq $0x70, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x16950
movq -0x78(%rbp), %rcx
movq %rcx, (%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movl -0x2c(%rbp), %ecx
callq 0x10cd0
movq %rax, -0x70(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x16810
movq %rax, %rdi
addq $0x70, %rdi
movl $0x1, %esi
callq 0x16950
movq -0x70(%rbp), %rcx
movq %rcx, (%rax)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x16970
testb $0x1, %al
jne 0x1103f
jmp 0x11092
movl $0x10, %edi
callq 0x3130
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x80(%rbp)
leaq 0x14499(%rip), %rsi     # 0x254f3
callq 0x3530
jmp 0x11061
movq -0x80(%rbp), %rdi
movq 0x21f6c(%rip), %rsi     # 0x32fd8
movq 0x21f4d(%rip), %rdx     # 0x32fc0
callq 0x34b0
movq -0x80(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
callq 0x31f0
jmp 0x111c3
movq -0x10(%rbp), %rdi
callq 0x16600
cmpl $0x46, (%rax)
je 0x110fc
movl $0x10, %edi
callq 0x3130
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x88(%rbp)
leaq 0x14435(%rip), %rsi     # 0x254f3
callq 0x3530
jmp 0x110c5
movq -0x88(%rbp), %rdi
movq 0x21f05(%rip), %rsi     # 0x32fd8
movq 0x21ee6(%rip), %rdx     # 0x32fc0
callq 0x34b0
movq -0x88(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
callq 0x31f0
jmp 0x111c3
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x165c0
movq %rax, -0x58(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movl -0x2c(%rbp), %ecx
callq 0x10cd0
movq %rax, -0x90(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x16810
movq %rax, %rdi
addq $0x70, %rdi
movl $0x2, %esi
callq 0x16950
movq -0x90(%rbp), %rcx
movq %rcx, (%rax)
movq -0x38(%rbp), %rax
movq %rax, -0x28(%rbp)
jmp 0x111b1
movl $0x10, %edi
callq 0x3130
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x98(%rbp)
leaq 0x1436e(%rip), %rsi     # 0x254e4
callq 0x3530
jmp 0x1117d
movq -0x98(%rbp), %rdi
movq 0x21e4d(%rip), %rsi     # 0x32fd8
movq 0x21e2e(%rip), %rdx     # 0x32fc0
callq 0x34b0
movq -0x98(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
callq 0x31f0
jmp 0x111c3
jmp 0x10efe
movq -0x28(%rbp), %rax
addq $0xa0, %rsp
popq %rbp
retq
movq -0x48(%rbp), %rdi
callq 0x34e0
nopl (%rax)