// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r8, %rbx
movl %ecx, 0x14(%rsp)
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %r12
movq (%r15), %r13
cmpq (%r14), %r13
je 0x8bd5
cmpl $0x45, (%r13)
jne 0x8bd5
movq %r13, %rdi
xorl %esi, %esi
callq 0x270e
cmpl 0x14(%rsp), %eax
ja 0x8bd5
movl %eax, %ebp
leaq 0x70(%r13), %rax
movq %rax, (%r15)
movq %r12, %rdi
movq %r13, %rsi
pushq $0x7e
popq %rdx
callq 0x87e0
movq %rax, 0x8(%rsp)
movq (%r15), %rax
cmpq (%r14), %rax
je 0x8be7
movq %r12, %rdi
leaq 0x8(%rsp), %r13
movq %r13, %rsi
callq 0xb4a6
leaq 0x70(%rax), %rdi
pushq $0x3
popq %rsi
callq 0xb51e
movq %r12, %rdi
movq %r13, %rsi
callq 0xb4a6
movq 0x70(%rax), %rax
movq %rbx, (%rax)
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
movl %ebp, %ecx
callq 0x895f
movq %rax, %rbx
movq %r12, %rdi
movq %r13, %rsi
callq 0xb4a6
movq 0x70(%rax), %rax
movq %rbx, 0x8(%rax)
movq (%r15), %rax
cmpq (%r14), %rax
je 0x8c1f
cmpl $0x46, (%rax)
jne 0x8c03
addq $0x70, %rax
movq %rax, (%r15)
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
movl %ebp, %ecx
callq 0x895f
movq %rax, %rbx
movq %r12, %rdi
leaq 0x8(%rsp), %rsi
callq 0xb4a6
movq 0x70(%rax), %rax
movq %rbx, 0x10(%rax)
movq 0x8(%rsp), %rbx
jmp 0x8ae4
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x10
popq %rdi
callq 0x20e0
movq %rax, %rbx
leaq 0x761b(%rip), %rsi      # 0x10214
movq %rax, %rdi
callq 0x23a0
jmp 0x8c39
pushq $0x10
popq %rdi
callq 0x20e0
movq %rax, %rbx
leaq 0x760e(%rip), %rsi      # 0x10223
movq %rax, %rdi
callq 0x23a0
jmp 0x8c39
pushq $0x10
popq %rdi
callq 0x20e0
movq %rax, %rbx
leaq 0x75f2(%rip), %rsi      # 0x10223
movq %rax, %rdi
callq 0x23a0
movq 0xf398(%rip), %rsi      # 0x17fd8
movq 0xf379(%rip), %rdx      # 0x17fc0
movq %rbx, %rdi
callq 0x2340
jmp 0x8c53
jmp 0x8c53
movq %rax, %r14
movq %rbx, %rdi
callq 0x2160
movq %r14, %rdi
callq 0x2370