// File: /workspace/github_c_makefile_star2_O3/msteveb[P]autosetup/./jimsh0.c
// Function: ExprTreeBuildTree
static int ExprTreeBuildTree(Jim_Interp *interp, struct ExprBuilder *builder, int precedence, int flags, int exp_numterms) {
    int rc;
    struct JimExprNode *node;

    int exp_stacklen = builder->stack.len + exp_numterms;

    if (builder->level++ > 200) {
        Jim_SetResultString(interp, "Expression too complex", -1);
        return JIM_ERR;
    }

    while (builder->token->type != JIM_TT_EOL) {
        ParseToken *t = builder->token++;
        int prevtt;

        if (t == builder->first_token) {
            prevtt = JIM_TT_NONE;
        }
        else {
            prevtt = t[-1].type;
        }

        if (t->type == JIM_TT_SUBEXPR_START) {
            if (builder->stack.len == exp_stacklen) {
                Jim_SetResultFormatted(interp, "unexpected open parenthesis in expression: \"%#s\"", builder->exprObjPtr);
                return JIM_ERR;
            }
            builder->parencount++;
            rc = ExprTreeBuildTree(interp, builder, 0, EXPR_UNTIL_CLOSE, 1);
            if (rc != JIM_OK) {
                return rc;
            }

        }
        else if (t->type == JIM_TT_SUBEXPR_END) {
            if (!(flags & EXPR_UNTIL_CLOSE)) {
                if (builder->stack.len == exp_stacklen && builder->level > 1) {
                    builder->token--;
                    builder->level--;
                    return JIM_OK;
                }
                Jim_SetResultFormatted(interp, "unexpected closing parenthesis in expression: \"%#s\"", builder->exprObjPtr);
                return JIM_ERR;
            }
            builder->parencount--;
            if (builder->stack.len == exp_stacklen) {

                break;
            }
        }
        else if (t->type == JIM_TT_SUBEXPR_COMMA) {
            if (!(flags & EXPR_FUNC_ARGS)) {
                if (builder->stack.len == exp_stacklen) {

                    builder->token--;
                    builder->level--;
                    return JIM_OK;
                }
                Jim_SetResultFormatted(interp, "unexpected comma in expression: \"%#s\"", builder->exprObjPtr);
                return JIM_ERR;
            }
            else {

                if (builder->stack.len > exp_stacklen) {
                    Jim_SetResultFormatted(interp, "too many arguments to math function");
                    return JIM_ERR;
                }
            }

        }
        else if (t->type == JIM_EXPROP_COLON) {
            if (!(flags & EXPR_TERNARY)) {
                if (builder->level != 1) {

                    builder->token--;
                    builder->level--;
                    return JIM_OK;
                }
                Jim_SetResultFormatted(interp, ": without ? in expression: \"%#s\"", builder->exprObjPtr);
                return JIM_ERR;
            }
            if (builder->stack.len == exp_stacklen) {

                builder->token--;
                builder->level--;
                return JIM_OK;
            }

        }
        else if (TOKEN_IS_EXPR_OP(t->type)) {
            const struct Jim_ExprOperator *op;


            if (TOKEN_IS_EXPR_OP(prevtt) || TOKEN_IS_EXPR_START(prevtt)) {
                if (t->type == JIM_EXPROP_SUB) {
                    t->type = JIM_EXPROP_UNARYMINUS;
                }
                else if (t->type == JIM_EXPROP_ADD) {
                    t->type = JIM_EXPROP_UNARYPLUS;
                }
            }

            op = JimExprOperatorInfoByOpcode(t->type);

            if (op->precedence < precedence || (!(op->attr & OP_RIGHT_ASSOC) && op->precedence == precedence)) {

                builder->token--;
                break;
            }

            if (op->attr & OP_FUNC) {
                if (builder->token->type != JIM_TT_SUBEXPR_START) {
                    Jim_SetResultString(interp, "missing arguments for math function", -1);
                    return JIM_ERR;
                }
                builder->token++;
                if (op->arity == 0) {
                    if (builder->token->type != JIM_TT_SUBEXPR_END) {
                        Jim_SetResultString(interp, "too many arguments for math function", -1);
                        return JIM_ERR;
                    }
                    builder->token++;
                    goto noargs;
                }
                builder->parencount++;


                rc = ExprTreeBuildTree(interp, builder, 0, EXPR_FUNC_ARGS | EXPR_UNTIL_CLOSE, op->arity);
            }
            else if (t->type == JIM_EXPROP_TERNARY) {

                rc = ExprTreeBuildTree(interp, builder, op->precedence, EXPR_TERNARY, 2);
            }
            else {
                rc = ExprTreeBuildTree(interp, builder, op->precedence, 0, 1);
            }

            if (rc != JIM_OK) {
                return rc;
            }

noargs:
            node = builder->next++;
            node->type = t->type;

            if (op->arity >= 3) {
                node->ternary = Jim_StackPop(&builder->stack);
                if (node->ternary == NULL) {
                    goto missingoperand;
                }
            }
            if (op->arity >= 2) {
                node->right = Jim_StackPop(&builder->stack);
                if (node->right == NULL) {
                    goto missingoperand;
                }
            }
            if (op->arity >= 1) {
                node->left = Jim_StackPop(&builder->stack);
                if (node->left == NULL) {
missingoperand:
                    Jim_SetResultFormatted(interp, "missing operand to %s in expression: \"%#s\"", op->name, builder->exprObjPtr);
                    builder->next--;
                    return JIM_ERR;

                }
            }


            Jim_StackPush(&builder->stack, node);
        }
        else {
            Jim_Obj *objPtr = NULL;




            if (!TOKEN_IS_EXPR_START(prevtt) && !TOKEN_IS_EXPR_OP(prevtt)) {
                Jim_SetResultFormatted(interp, "missing operator in expression: \"%#s\"", builder->exprObjPtr);
                return JIM_ERR;
            }


            if (t->type == JIM_TT_EXPR_INT || t->type == JIM_TT_EXPR_DOUBLE) {
                char *endptr;
                if (t->type == JIM_TT_EXPR_INT) {
                    objPtr = Jim_NewIntObj(interp, jim_strtoull(t->token, &endptr));
                }
                else {
                    objPtr = Jim_NewDoubleObj(interp, strtod(t->token, &endptr));
                }
                if (endptr != t->token + t->len) {

                    Jim_FreeNewObj(interp, objPtr);
                    objPtr = NULL;
                }
            }

            if (!objPtr) {

                objPtr = Jim_NewStringObj(interp, t->token, t->len);
                if (t->type == JIM_TT_CMD) {

                    Jim_SetSourceInfo(interp, objPtr, builder->fileNameObj, t->line);
                }
            }


            node = builder->next++;
            node->objPtr = objPtr;
            Jim_IncrRefCount(node->objPtr);
            node->type = t->type;
            Jim_StackPush(&builder->stack, node);
        }
    }

    if (builder->stack.len == exp_stacklen) {
        builder->level--;
        return JIM_OK;
    }

    if ((flags & EXPR_FUNC_ARGS)) {
        Jim_SetResultFormatted(interp, "too %s arguments for math function", (builder->stack.len < exp_stacklen) ? "few" : "many");
    }
    else {
        if (builder->stack.len < exp_stacklen) {
            if (builder->level == 0) {
                Jim_SetResultFormatted(interp, "empty expression");
            }
            else {
                Jim_SetResultFormatted(interp, "syntax error in expression \"%#s\": premature end of expression", builder->exprObjPtr);
            }
        }
        else {
            Jim_SetResultFormatted(interp, "extra terms after expression");
        }
    }

    return JIM_ERR;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %r14
movq %rdi, %rbx
addl 0x18(%rsi), %r8d
movl 0x4(%rsi), %eax
leal 0x1(%rax), %esi
movl %esi, 0x4(%r14)
cmpl $0xc8, %eax
jle 0x1a967
leaq 0x1168f(%rip), %rsi     # 0x2bfc2
movq %rbx, %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x7508
movq %rax, %r14
incl 0x10(%rax)
movq (%rbx), %rsi
movl 0x10(%rsi), %eax
leal -0x1(%rax), %ecx
movl %ecx, 0x10(%rsi)
cmpl $0x1, %eax
jg 0x1a95f
movq %rbx, %rdi
callq 0x758c
movq %r14, (%rbx)
jmp 0x1aed9
movl %edx, -0x4c(%rbp)
movq %rbx, -0x30(%rbp)
leaq 0x18(%r14), %rdi
movq 0x8(%r14), %r13
movl 0xc(%r13), %eax
cmpl $0x7, %eax
je 0x1ae01
leaq 0xc(%r13), %rbx
movl %r8d, -0x40(%rbp)
movl %ecx, -0x3c(%rbp)
movq %rdi, -0x38(%rbp)
leaq 0x18(%r13), %rdx
movq %rdx, 0x8(%r14)
movl $0x0, %r15d
cmpq 0x10(%r14), %r13
je 0x1a9aa
movl -0xc(%r13), %r15d
cmpl $0xc, %eax
jg 0x1a9d8
cmpl $0xb, %eax
je 0x1aa4c
cmpl $0xc, %eax
jne 0x1a9fd
testb $0x1, %cl
je 0x1ae80
decl (%r14)
cmpl %r8d, 0x18(%r14)
jne 0x1adec
jmp 0x1ae01
cmpl $0xd, %eax
je 0x1aa8f
cmpl $0x29, %eax
jne 0x1a9fd
testb $0x4, %cl
je 0x1aea8
cmpl %r8d, (%rdi)
jne 0x1adec
jmp 0x1ae7a
cmpl $0x14, %eax
jl 0x1aaa8
cmpl $0x13, %r15d
movl -0x4c(%rbp), %r9d
leaq 0x1b42b(%rip), %r11     # 0x35e40
jg 0x1aa30
cmpl $0xd, %r15d
ja 0x1ab1d
movl $0x2801, %edx           # imm = 0x2801
btl %r15d, %edx
jae 0x1ab1d
cmpl $0x17, %eax
je 0x1ab26
cmpl $0x18, %eax
jne 0x1ab1d
movl $0x36, %eax
jmp 0x1ab2b
cmpl %r8d, (%rdi)
je 0x1ae9b
incl (%r14)
movl $0x1, %r12d
movq -0x30(%rbp), %rdi
movq %r14, %rsi
xorl %edx, %edx
movl $0x1, %ecx
movl $0x1, %r8d
callq 0x1a900
movq -0x38(%rbp), %rdi
movl -0x3c(%rbp), %ecx
movl -0x40(%rbp), %r8d
testl %eax, %eax
je 0x1adec
jmp 0x1aedf
movl (%rdi), %eax
testb $0x2, %cl
je 0x1ae71
cmpl %r8d, %eax
jle 0x1adec
jmp 0x1aec7
cmpl $0x13, %r15d
jg 0x1aac7
cmpl $0xd, %r15d
ja 0x1adac
movl $0x2801, %ecx           # imm = 0x2801
btl %r15d, %ecx
jae 0x1adac
movl %eax, %ecx
andl $-0x2, %ecx
cmpl $0xe, %ecx
jne 0x1acdc
movq (%r13), %rdi
leaq -0x58(%rbp), %rsi
cmpl $0xe, %eax
jne 0x1ac8c
callq 0xd4a0
movq %rax, -0x48(%rbp)
movq -0x30(%rbp), %rdi
callq 0xae38
movq %rax, %r12
leaq 0x1a7ee(%rip), %rax     # 0x352f0
movq %rax, 0x8(%r12)
movq $0x0, (%r12)
movq -0x48(%rbp), %rax
movq %rax, 0x18(%r12)
jmp 0x1acc2
cmpl $0x28, %eax
sete %r10b
jmp 0x1ab30
movl $0x35, %eax
movl %eax, (%rbx)
xorl %r10d, %r10d
leal -0x14(%rax), %edx
leaq (%rdx,%rdx,2), %rsi
movzbl 0x10(%r11,%rsi,8), %edx
cmpl %r9d, %edx
jl 0x1aebe
leaq (%r11,%rsi,8), %r15
movb 0x12(%r15), %sil
movl %esi, %r11d
andb $0x2, %r11b
shrb %r11b
cmpl %r9d, %edx
setne %r9b
orb %r11b, %r9b
je 0x1aebe
testb $0x1, %sil
jne 0x1ab87
testb %r10b, %r10b
je 0x1abbb
movq -0x30(%rbp), %rdi
movq %r14, %rsi
movl $0x4, %ecx
movl $0x2, %r8d
jmp 0x1abca
cmpl $0xb, 0x24(%r13)
jne 0x1af17
leaq 0x30(%r13), %rcx
movq %rcx, 0x8(%r14)
movzbl 0x11(%r15), %r8d
testl %r8d, %r8d
je 0x1ad79
incl (%r14)
movq -0x30(%rbp), %rdi
movq %r14, %rsi
xorl %edx, %edx
movl $0x3, %ecx
jmp 0x1abca
movq -0x30(%rbp), %rdi
movq %r14, %rsi
xorl %ecx, %ecx
movl $0x1, %r8d
callq 0x1a900
movl $0x1, %r12d
testl %eax, %eax
movq -0x38(%rbp), %rdi
jne 0x1aedf
movl (%rbx), %ecx
movzbl 0x11(%r15), %eax
movq 0x40(%r14), %rsi
leaq 0x28(%rsi), %rdx
movq %rdx, 0x40(%r14)
movl %ecx, (%rsi)
cmpl $0x3, %eax
jb 0x1ac26
movslq (%rdi), %rax
testq %rax, %rax
je 0x1af27
leaq -0x1(%rax), %rcx
movl %ecx, 0x18(%r14)
movq 0x20(%r14), %rcx
movq -0x8(%rcx,%rax,8), %rax
movq %rax, 0x20(%rsi)
testq %rax, %rax
jne 0x1ac33
jmp 0x1af34
testl %eax, %eax
je 0x1ad9a
cmpl $0x2, %eax
jne 0x1ac5d
movslq (%rdi), %rax
testq %rax, %rax
je 0x1af20
leaq -0x1(%rax), %rcx
movl %ecx, 0x18(%r14)
movq 0x20(%r14), %rcx
movq -0x8(%rcx,%rax,8), %rax
movq %rax, 0x18(%rsi)
testq %rax, %rax
je 0x1af34
movslq (%rdi), %rax
testq %rax, %rax
je 0x1af10
leaq -0x1(%rax), %rcx
movl %ecx, 0x18(%r14)
movq 0x20(%r14), %rcx
movq -0x8(%rcx,%rax,8), %rax
movq %rax, 0x10(%rsi)
testq %rax, %rax
jne 0x1ad9a
jmp 0x1af34
callq 0x6120
movsd %xmm0, -0x48(%rbp)
movq -0x30(%rbp), %rdi
callq 0xae38
movq %rax, %r12
leaq 0x1a697(%rip), %rax     # 0x35340
movq %rax, 0x8(%r12)
movq $0x0, (%r12)
movsd -0x48(%rbp), %xmm0
movsd %xmm0, 0x18(%r12)
movslq 0x8(%r13), %rax
addq (%r13), %rax
cmpq %rax, -0x58(%rbp)
je 0x1ad44
movq -0x30(%rbp), %rdi
movq %r12, %rsi
callq 0x758c
movq (%r13), %rsi
movl 0x8(%r13), %edx
movq -0x30(%rbp), %rdi
callq 0x7508
movq %rax, %r12
cmpl $0x5, (%rbx)
jne 0x1ad44
movq 0x30(%r14), %rcx
movl 0x10(%r13), %r13d
movq 0x8(%r12), %rax
testq %rax, %rax
movq -0x38(%rbp), %rdi
je 0x1ad29
movq 0x8(%rax), %rax
testq %rax, %rax
je 0x1ad29
movq -0x30(%rbp), %rdi
movq %r12, %rsi
movq %rcx, -0x48(%rbp)
callq *%rax
movq -0x48(%rbp), %rcx
movq -0x38(%rbp), %rdi
incl 0x10(%rcx)
movq %rcx, 0x18(%r12)
movl %r13d, 0x20(%r12)
leaq 0x1a4ab(%rip), %rax     # 0x351e8
movq %rax, 0x8(%r12)
jmp 0x1ad48
movq -0x38(%rbp), %rdi
movq 0x40(%r14), %rsi
leaq 0x28(%rsi), %rax
movq %rax, 0x40(%r14)
movq %r12, 0x8(%rsi)
incl 0x10(%r12)
movl (%rbx), %eax
movl %eax, (%rsi)
callq 0xad73
movq -0x38(%rbp), %rdi
cmpl $0x13, %r15d
movl -0x40(%rbp), %r8d
movl -0x3c(%rbp), %ecx
jle 0x1adcd
jmp 0x1adec
cmpl $0xc, 0x3c(%r13)
jne 0x1af54
addq $0x48, %r13
movq %r13, 0x8(%r14)
movq 0x40(%r14), %rsi
leaq 0x28(%rsi), %rcx
movq %rcx, 0x40(%r14)
movl %eax, (%rsi)
callq 0xad73
movq -0x38(%rbp), %rdi
movl -0x40(%rbp), %r8d
movl -0x3c(%rbp), %ecx
jmp 0x1adec
movq 0x28(%r14), %rdx
movq -0x30(%rbp), %rdi
leaq 0x11362(%rip), %rsi     # 0x2c11d
xorl %eax, %eax
callq 0x6923
movl -0x40(%rbp), %r8d
movl -0x3c(%rbp), %ecx
movq -0x38(%rbp), %rdi
movl $0x1, %r12d
cmpl $0xd, %r15d
ja 0x1aedf
movl $0x2801, %eax           # imm = 0x2801
btl %r15d, %eax
jae 0x1aedf
movq 0x8(%r14), %r13
leaq 0xc(%r13), %rbx
movl 0xc(%r13), %eax
cmpl $0x7, %eax
jne 0x1a992
movl (%rdi), %eax
cmpl %r8d, %eax
jne 0x1ae14
decl 0x4(%r14)
xorl %r12d, %r12d
jmp 0x1aedf
testb $0x2, %cl
jne 0x1ae36
cmpl %r8d, %eax
movq -0x30(%rbp), %rdi
jge 0x1ae5f
cmpl $0x0, 0x4(%r14)
je 0x1ae68
movq 0x28(%r14), %rdx
leaq 0x1133b(%rip), %rsi     # 0x2c16f
jmp 0x1ae56
cmpl %r8d, %eax
leaq 0x11326(%rip), %rax     # 0x2c166
leaq 0x11323(%rip), %rdx     # 0x2c16a
cmovlq %rax, %rdx
leaq 0x112f1(%rip), %rsi     # 0x2c143
movq -0x30(%rbp), %rdi
xorl %eax, %eax
callq 0x6923
jmp 0x1aed9
leaq 0x11347(%rip), %rsi     # 0x2c1ad
jmp 0x1aed2
leaq 0x10fbd(%rip), %rsi     # 0x2be2c
jmp 0x1aed2
cmpl %r8d, %eax
jne 0x1af00
movq %r13, 0x8(%r14)
jmp 0x1ae08
cmpl %r8d, (%rdi)
jne 0x1ae8e
movl 0x4(%r14), %eax
cmpl $0x2, %eax
jge 0x1aef1
movq 0x28(%r14), %rdx
leaq 0x11171(%rip), %rsi     # 0x2c00a
jmp 0x1ae52
movq 0x28(%r14), %rdx
leaq 0x11133(%rip), %rsi     # 0x2bfd9
jmp 0x1ae52
movl 0x4(%r14), %eax
cmpl $0x1, %eax
jne 0x1aef1
movq 0x28(%r14), %rdx
leaq 0x111cc(%rip), %rsi     # 0x2c088
jmp 0x1ae52
movq %r13, 0x8(%r14)
jmp 0x1ae01
leaq 0x11196(%rip), %rsi     # 0x2c064
movq -0x30(%rbp), %rdi
xorl %eax, %eax
callq 0x6923
movl $0x1, %r12d
movl %r12d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r13, 0x8(%r14)
decl %eax
movl %eax, 0x4(%r14)
jmp 0x1ae0c
movq 0x28(%r14), %rdx
leaq 0x11133(%rip), %rsi     # 0x2c03e
jmp 0x1ae52
movl $0x10, %eax
jmp 0x1af2c
leaq 0x1118b(%rip), %rsi     # 0x2c0a9
jmp 0x1af5b
movl $0x18, %eax
jmp 0x1af2c
movl $0x20, %eax
movq $0x0, (%rsi,%rax)
movq (%r15), %rdx
movq 0x28(%r14), %rcx
leaq 0x111b0(%rip), %rsi     # 0x2c0f2
movq -0x30(%rbp), %rdi
xorl %eax, %eax
callq 0x6923
addq $-0x28, 0x40(%r14)
jmp 0x1aedf
leaq 0x11172(%rip), %rsi     # 0x2c0cd
movq -0x30(%rbp), %rbx
jmp 0x1a933