// File: /workspace/github_c_makefile_star2_O2/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 $0x28, %rsp
movl %r8d, %r12d
movq %rsi, %r15
movq %rdi, %r14
addl 0x18(%rsi), %r12d
movl 0x4(%rsi), %eax
leal 0x1(%rax), %esi
movl %esi, 0x4(%r15)
cmpl $0xc8, %eax
jle 0x184b3
leaq 0xfb95(%rip), %rsi      # 0x28012
pushq $-0x1
popq %rdx
movq %r14, %rdi
callq 0x7363
movq %rax, %rbx
incl 0x10(%rax)
movq (%r14), %rsi
movl 0x10(%rsi), %eax
leal -0x1(%rax), %ecx
movl %ecx, 0x10(%rsi)
cmpl $0x1, %eax
jg 0x184a7
movq %r14, %rdi
callq 0x73bf
movq %rbx, (%r14)
pushq $0x1
popq %r14
jmp 0x1897b
movl %edx, -0x44(%rbp)
movq %r14, -0x30(%rbp)
leaq 0x18(%r15), %rax
movq %rax, -0x38(%rbp)
pushq $0x1
popq %r14
leaq 0x19973(%rip), %rsi     # 0x31e40
movl %ecx, -0x3c(%rbp)
movq 0x8(%r15), %r13
movl 0xc(%r13), %eax
cmpl $0x7, %eax
je 0x188b8
leaq 0x18(%r13), %rdx
movq %rdx, 0x8(%r15)
cmpq 0x10(%r15), %r13
je 0x184f5
movl -0xc(%r13), %ebx
jmp 0x184f7
xorl %ebx, %ebx
cmpl $0x29, %eax
je 0x18582
cmpl $0xc, %eax
je 0x1854a
cmpl $0xd, %eax
je 0x18565
cmpl $0xb, %eax
jne 0x1859d
movq -0x38(%rbp), %rax
cmpl %r12d, (%rax)
je 0x188a4
incl (%r15)
movq -0x30(%rbp), %rdi
movq %r15, %rsi
xorl %edx, %edx
movl %r14d, %ecx
movl %r14d, %r8d
callq 0x18447
leaq 0x19902(%rip), %rsi     # 0x31e40
movl -0x3c(%rbp), %ecx
testl %eax, %eax
je 0x184d0
jmp 0x1897b
testb $0x1, %cl
je 0x1887e
decl (%r15)
cmpl %r12d, 0x18(%r15)
jne 0x184d0
jmp 0x188b8
movq -0x38(%rbp), %rax
movl (%rax), %eax
testb $0x2, %cl
je 0x18856
cmpl %r12d, %eax
jle 0x184d0
jmp 0x1890f
testb $0x4, %cl
je 0x18865
movq -0x38(%rbp), %rax
cmpl %r12d, (%rax)
jne 0x184d0
jmp 0x1885f
cmpl $0x14, %eax
jl 0x185d1
cmpl $0x13, %ebx
jg 0x185b6
cmpl $0xd, %ebx
ja 0x18622
movl $0x2801, %edx           # imm = 0x2801
btl %ebx, %edx
jae 0x18622
pushq $0x35
popq %rdx
cmpl $0x17, %eax
je 0x185c6
cmpl $0x18, %eax
jne 0x18622
pushq $0x36
popq %rdx
movl %edx, 0xc(%r13)
xorl %r9d, %r9d
movl %edx, %eax
jmp 0x18629
cmpl $0x13, %ebx
jg 0x185ed
cmpl $0xd, %ebx
ja 0x1881a
movl $0x2801, %ecx           # imm = 0x2801
btl %ebx, %ecx
jae 0x1881a
movl %eax, %ecx
andl $-0x2, %ecx
cmpl $0xe, %ecx
jne 0x18781
movq (%r13), %rdi
leaq -0x50(%rbp), %rsi
cmpl $0xe, %eax
jne 0x18752
callq 0xc7ef
movq -0x30(%rbp), %rdi
movq %rax, %rsi
callq 0x8212
jmp 0x18760
cmpl $0x28, %eax
sete %r9b
leal -0x14(%rax), %edx
imulq $0x18, %rdx, %rbx
movzbl 0x10(%rbx,%rsi), %edx
movl -0x44(%rbp), %r8d
cmpl %r8d, %edx
jl 0x188b4
addq %rsi, %rbx
movb 0x12(%rbx), %sil
movl %esi, %edi
andb $0x2, %dil
shrb %dil
cmpl %r8d, %edx
setne %r8b
orb %dil, %r8b
je 0x188b4
testb $0x1, %sil
jne 0x1867d
testb %r9b, %r9b
je 0x186af
movq -0x30(%rbp), %rdi
movq %r15, %rsi
pushq $0x4
popq %rcx
pushq $0x2
popq %r8
jmp 0x186bb
cmpl $0xb, 0x24(%r13)
jne 0x1898d
leaq 0x30(%r13), %rcx
movq %rcx, 0x8(%r15)
movzbl 0x11(%rbx), %r8d
testl %r8d, %r8d
je 0x187f6
incl (%r15)
movq -0x30(%rbp), %rdi
movq %r15, %rsi
xorl %edx, %edx
pushq $0x3
popq %rcx
jmp 0x186bb
movq -0x30(%rbp), %rdi
movq %r15, %rsi
xorl %ecx, %ecx
movl %r14d, %r8d
callq 0x18447
testl %eax, %eax
jne 0x1897b
movl 0xc(%r13), %eax
movb 0x11(%rbx), %cl
movq 0x40(%r15), %r14
leaq 0x28(%r14), %rdx
movq %rdx, 0x40(%r15)
movl %eax, (%r14)
cmpb $0x3, %cl
jb 0x186fc
movq -0x38(%rbp), %rdi
callq 0xa553
movq %rax, 0x20(%r14)
testq %rax, %rax
je 0x1892e
movb 0x11(%rbx), %cl
cmpb $0x2, %cl
jb 0x18717
movq -0x38(%rbp), %rdi
callq 0xa553
movq %rax, 0x18(%r14)
testq %rax, %rax
je 0x1892e
cmpb $0x0, 0x11(%rbx)
je 0x18733
movq -0x38(%rbp), %rdi
callq 0xa553
movq %rax, 0x10(%r14)
testq %rax, %rax
je 0x1892e
movq -0x38(%rbp), %rdi
movq %r14, %rsi
callq 0xa502
pushq $0x1
popq %r14
movl -0x3c(%rbp), %ecx
leaq 0x196f3(%rip), %rsi     # 0x31e40
jmp 0x184d0
callq 0x6120
movq -0x30(%rbp), %rdi
callq 0xd366
movq %rax, %r14
movslq 0x8(%r13), %rax
addq (%r13), %rax
cmpq %rax, -0x50(%rbp)
je 0x18810
movq -0x30(%rbp), %rdi
movq %r14, %rsi
callq 0x73bf
movl %r12d, -0x40(%rbp)
movq (%r13), %rsi
movl 0x8(%r13), %edx
movq -0x30(%rbp), %r12
movq %r12, %rdi
callq 0x7363
movq %rax, %r14
cmpl $0x5, 0xc(%r13)
jne 0x187b6
movq 0x30(%r15), %rdx
movl 0x10(%r13), %ecx
movq %r12, %rdi
movq %r14, %rsi
callq 0xb3cf
movl -0x40(%rbp), %r12d
movq 0x40(%r15), %rsi
leaq 0x28(%rsi), %rax
movq %rax, 0x40(%r15)
movq %r14, 0x8(%rsi)
incl 0x10(%r14)
movl 0xc(%r13), %eax
movl %eax, (%rsi)
movq -0x38(%rbp), %rdi
callq 0xa502
cmpl $0x13, %ebx
pushq $0x1
popq %r14
movl -0x3c(%rbp), %ecx
leaq 0x19652(%rip), %rsi     # 0x31e40
jg 0x184d0
jmp 0x1883a
cmpl $0xc, 0x3c(%r13)
jne 0x18996
addq $0x48, %r13
movq %r13, 0x8(%r15)
xorl %ecx, %ecx
jmp 0x186cf
testq %r14, %r14
jne 0x187ba
jmp 0x18781
movq 0x28(%r15), %rdx
movq -0x30(%rbp), %rdi
leaq 0xf944(%rip), %rsi      # 0x2816d
xorl %eax, %eax
callq 0x68a7
leaq 0x19609(%rip), %rsi     # 0x31e40
movl -0x3c(%rbp), %ecx
cmpl $0xd, %ebx
ja 0x1897b
movl $0x2801, %eax           # imm = 0x2801
btl %ebx, %eax
jb 0x184d0
jmp 0x1897b
cmpl %r12d, %eax
jne 0x18951
movq %r13, 0x8(%r15)
jmp 0x188c3
movl 0x4(%r15), %eax
cmpl $0x1, %eax
jne 0x18898
movq 0x28(%r15), %rdx
leaq 0xf85f(%rip), %rsi      # 0x280d8
jmp 0x1895c
movq -0x38(%rbp), %rax
cmpl %r12d, (%rax)
jne 0x18921
movl 0x4(%r15), %eax
cmpl $0x2, %eax
jl 0x18921
movq %r13, 0x8(%r15)
decl %eax
movl %eax, 0x4(%r15)
jmp 0x188c7
movq 0x28(%r15), %rdx
leaq 0xf77a(%rip), %rsi      # 0x28029
jmp 0x1895c
movq %r13, 0x8(%r15)
movq -0x38(%rbp), %rax
movl (%rax), %eax
cmpl %r12d, %eax
jne 0x188cf
decl 0x4(%r15)
xorl %r14d, %r14d
jmp 0x1897b
testb $0x2, %cl
jne 0x188f1
cmpl %r12d, %eax
jge 0x18918
cmpl $0x0, 0x4(%r15)
je 0x18969
movq 0x28(%r15), %rdx
leaq 0xf8d0(%rip), %rsi      # 0x281bf
jmp 0x1895c
cmpl %r12d, %eax
leaq 0xf8bb(%rip), %rax      # 0x281b6
leaq 0xf8b8(%rip), %rdx      # 0x281ba
cmovlq %rax, %rdx
leaq 0xf886(%rip), %rsi      # 0x28193
jmp 0x1895c
leaq 0xf79e(%rip), %rsi      # 0x280b4
jmp 0x18970
leaq 0xf8de(%rip), %rsi      # 0x281fd
jmp 0x18970
movq 0x28(%r15), %rdx
leaq 0xf72e(%rip), %rsi      # 0x2805a
jmp 0x1895c
movq (%rbx), %rdx
movq 0x28(%r15), %rcx
leaq 0xf806(%rip), %rsi      # 0x28142
movq -0x30(%rbp), %rdi
xorl %eax, %eax
callq 0x68a7
addq $-0x28, 0x40(%r15)
jmp 0x184aa
movq 0x28(%r15), %rdx
leaq 0xf732(%rip), %rsi      # 0x2808e
movq -0x30(%rbp), %rdi
xorl %eax, %eax
callq 0x68a7
jmp 0x1897b
leaq 0xf50c(%rip), %rsi      # 0x27e7c
movq -0x30(%rbp), %rdi
xorl %eax, %eax
callq 0x68a7
movl %r14d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xf765(%rip), %rsi      # 0x280f9
jmp 0x1899d
leaq 0xf780(%rip), %rsi      # 0x2811d
pushq $-0x1
popq %rdx
movq -0x30(%rbp), %r15
movq %r15, %rdi
callq 0x7363
movq %rax, %rbx
incl 0x10(%rax)
movq (%r15), %rsi
movl 0x10(%rsi), %eax
leal -0x1(%rax), %ecx
movl %ecx, 0x10(%rsi)
cmpl $0x1, %eax
jg 0x189cb
movq %r15, %rdi
callq 0x73bf
movq %rbx, (%r15)
jmp 0x1897b