// File: /workspace/github_c_makefile_star2_O1/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 $0x48, %rsp
movl %ecx, -0x3c(%rbp)
movl %edx, -0x4c(%rbp)
movq %rdi, %r13
addl 0x18(%rsi), %r8d
movl %r8d, -0x2c(%rbp)
movl 0x4(%rsi), %eax
leal 0x1(%rax), %ecx
movl %ecx, 0x4(%rsi)
cmpl $0xc8, %eax
jle 0x1af12
leaq 0x1214a(%rip), %rsi     # 0x2d020
movq %r13, %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x7516
movq %rax, %r14
incl 0x10(%rax)
movq (%r13), %rsi
movl 0x10(%rsi), %eax
leal -0x1(%rax), %ecx
movl %ecx, 0x10(%rsi)
cmpl $0x1, %eax
jg 0x1af03
movq %r13, %rdi
callq 0x759a
movq %r14, (%r13)
movl $0x1, %r12d
jmp 0x1b4f5
movq %rsi, %r14
leaq 0x18(%rsi), %rax
movq %rax, -0x38(%rbp)
movq 0x8(%r14), %rbx
movl 0xc(%rbx), %eax
cmpl $0x7, %eax
je 0x1b4e3
leaq 0x18(%rbx), %rcx
movq %rcx, 0x8(%r14)
cmpq 0x10(%r14), %rbx
je 0x1af41
movl -0xc(%rbx), %r15d
jmp 0x1af44
xorl %r15d, %r15d
cmpl $0xc, %eax
jg 0x1af8c
cmpl $0xb, %eax
je 0x1b008
cmpl $0xc, %eax
jne 0x1afc4
testb $0x1, -0x3c(%rbp)
jne 0x1b0da
movl -0x2c(%rbp), %eax
movq -0x38(%rbp), %rcx
cmpl %eax, (%rcx)
jne 0x1af79
movl 0x4(%r14), %eax
cmpl $0x2, %eax
jge 0x1b16b
movq 0x28(%r14), %rdx
movq %r13, %rdi
leaq 0x120e1(%rip), %rsi     # 0x2d068
jmp 0x1b04e
cmpl $0xd, %eax
je 0x1b027
cmpl $0x29, %eax
jne 0x1afc4
testb $0x4, -0x3c(%rbp)
jne 0x1b0f7
movl 0x4(%r14), %eax
cmpl $0x1, %eax
jne 0x1b16b
movq 0x28(%r14), %rdx
movq %r13, %rdi
leaq 0x12127(%rip), %rsi     # 0x2d0e6
jmp 0x1b04e
cmpl $0x14, %eax
jl 0x1b065
cmpl $0x13, %r15d
jg 0x1afec
cmpl $0xd, %r15d
ja 0x1b18a
movl $0x2801, %ecx           # imm = 0x2801
btl %r15d, %ecx
jae 0x1b18a
cmpl $0x17, %eax
je 0x1b182
cmpl $0x18, %eax
jne 0x1b18a
movl $0x36, %eax
jmp 0x1b187
movl -0x2c(%rbp), %eax
movq -0x38(%rbp), %rcx
cmpl %eax, (%rcx)
jne 0x1b113
movq 0x28(%r14), %rdx
movq %r13, %rdi
leaq 0x12012(%rip), %rsi     # 0x2d037
jmp 0x1b04e
movq -0x38(%rbp), %rax
movl (%rax), %eax
testb $0x2, -0x3c(%rbp)
jne 0x1b149
cmpl -0x2c(%rbp), %eax
je 0x1b109
movq 0x28(%r14), %rdx
movq %r13, %rdi
leaq 0x1204e(%rip), %rsi     # 0x2d09c
xorl %eax, %eax
callq 0x692d
movl $0x1, %ebx
movl $0x1, %r12d
jmp 0x1b40b
cmpl $0x13, %r15d
jg 0x1b084
cmpl $0xd, %r15d
ja 0x1b347
movl $0x2801, %ecx           # imm = 0x2801
btl %r15d, %ecx
jae 0x1b347
movl %eax, %ecx
andl $-0x2, %ecx
cmpl $0xe, %ecx
movq %r13, -0x58(%rbp)
jne 0x1b255
movq (%rbx), %rdi
leaq -0x68(%rbp), %rsi
cmpl $0xe, %eax
jne 0x1b209
callq 0xd4a4
movq %rax, -0x48(%rbp)
movq %r13, %rdi
callq 0xae58
movq %rax, %r13
leaq 0x1b21f(%rip), %rax     # 0x362e0
movq %rax, 0x8(%r13)
movq $0x0, (%r13)
movq -0x48(%rbp), %rax
movq %rax, 0x18(%r13)
jmp 0x1b23c
decl (%r14)
movl $0x5, %ebx
movl %r12d, %ecx
movl -0x2c(%rbp), %eax
cmpl %eax, 0x18(%r14)
jne 0x1b406
jmp 0x1b40b
movl %r12d, %ecx
movl -0x2c(%rbp), %eax
movq -0x38(%rbp), %rdx
cmpl %eax, (%rdx)
jne 0x1b406
movq %rbx, 0x8(%r14)
decl 0x4(%r14)
jmp 0x1b175
incl (%r14)
movl $0x1, %ebx
movq %r13, %rdi
movq %r14, %rsi
xorl %edx, %edx
movl $0x1, %ecx
movl $0x1, %r8d
callq 0x1ae9d
movl %r12d, %ecx
movl $0x1, %r12d
testl %eax, %eax
jne 0x1b40b
jmp 0x1b406
movl %r12d, %ecx
cmpl -0x2c(%rbp), %eax
jle 0x1b406
movq %r13, %rdi
leaq 0x11f63(%rip), %rsi     # 0x2d0c2
xorl %eax, %eax
callq 0x692d
jmp 0x1b055
movq %rbx, 0x8(%r14)
decl %eax
movl %eax, 0x4(%r14)
xorl %r12d, %r12d
movl $0x1, %ebx
jmp 0x1b40b
movl $0x35, %eax
movl %eax, 0xc(%rbx)
movl 0xc(%rbx), %eax
leal -0x14(%rax), %ecx
cmpl $0x14, %eax
leaq (%rcx,%rcx,2), %rcx
leaq 0x1bca2(%rip), %rdx     # 0x36e40
leaq (%rdx,%rcx,8), %r15
leaq 0xd5ef(%rip), %rcx      # 0x28798
cmovlq %rcx, %r15
movzbl 0x10(%r15), %edx
cmpl -0x4c(%rbp), %edx
jl 0x1b1d0
movb 0x12(%r15), %cl
movl %ecx, %esi
andb $0x2, %sil
shrb %sil
cmpl -0x4c(%rbp), %edx
setne %dil
orb %sil, %dil
jne 0x1b1e1
movq %rbx, 0x8(%r14)
movl $0x5, %ebx
xorl %r15d, %r15d
jmp 0x1b3fe
testb $0x1, %cl
jne 0x1b315
movq %r13, %rdi
movq %r14, %rsi
cmpl $0x28, %eax
jne 0x1b367
movl $0x4, %ecx
movl $0x2, %r8d
jmp 0x1b36f
callq 0x6120
movsd %xmm0, -0x48(%rbp)
movq %r13, %rdi
callq 0xae58
movq %rax, %r13
leaq 0x1b10b(%rip), %rax     # 0x36330
movq %rax, 0x8(%r13)
movq $0x0, (%r13)
movsd -0x48(%rbp), %xmm0
movsd %xmm0, 0x18(%r13)
movslq 0x8(%rbx), %rax
addq (%rbx), %rax
cmpq %rax, -0x68(%rbp)
je 0x1b258
movq -0x58(%rbp), %rdi
movq %r13, %rsi
callq 0x759a
xorl %r13d, %r13d
testq %r13, %r13
jne 0x1b2bb
movq (%rbx), %rsi
movl 0x8(%rbx), %edx
movq -0x58(%rbp), %rdi
callq 0x7516
movq %rax, %r13
cmpl $0x5, 0xc(%rbx)
jne 0x1b2bb
movq 0x30(%r14), %rcx
movl 0x10(%rbx), %edx
movq 0x8(%r13), %rax
testq %rax, %rax
je 0x1b2a5
movq 0x8(%rax), %rax
testq %rax, %rax
je 0x1b2a5
movq -0x58(%rbp), %rdi
movq %r13, %rsi
movq %rcx, -0x48(%rbp)
movl %edx, -0x5c(%rbp)
callq *%rax
movl -0x5c(%rbp), %edx
movq -0x48(%rbp), %rcx
incl 0x10(%rcx)
movq %rcx, 0x18(%r13)
movl %edx, 0x20(%r13)
leaq 0x1af21(%rip), %rax     # 0x361d8
movq %rax, 0x8(%r13)
movq 0x40(%r14), %rsi
leaq 0x28(%rsi), %rax
movq %rax, 0x40(%r14)
movq %r13, 0x8(%rsi)
incl 0x10(%r13)
movl 0xc(%rbx), %eax
movl %eax, (%rsi)
movq -0x38(%rbp), %rdi
callq 0xad96
movq -0x58(%rbp), %r13
cmpl $0x13, %r15d
jle 0x1b2ef
movl %r12d, %ecx
jmp 0x1b406
movl $0x1, %ebx
cmpl $0xd, %r15d
ja 0x1b40b
movl $0x2801, %eax           # imm = 0x2801
btl %r15d, %eax
movl %r12d, %ecx
jb 0x1b406
jmp 0x1b40b
cmpl $0xb, 0x24(%rbx)
jne 0x1b3b8
leaq 0x30(%rbx), %rax
movq %rax, 0x8(%r14)
movzbl 0x11(%r15), %r8d
testl %r8d, %r8d
je 0x1b418
incl (%r14)
movq %r13, %rdi
movq %r14, %rsi
xorl %edx, %edx
movl $0x3, %ecx
jmp 0x1b36f
movq 0x28(%r14), %rdx
movq %r13, %rdi
leaq 0x11e26(%rip), %rsi     # 0x2d17b
xorl %eax, %eax
callq 0x692d
movl $0x1, %r12d
jmp 0x1b2e1
xorl %ecx, %ecx
movl $0x1, %r8d
callq 0x1ae9d
testl %eax, %eax
jne 0x1b3f0
movq 0x40(%r14), %rsi
leaq 0x28(%rsi), %rax
movq %rax, 0x40(%r14)
movl 0xc(%rbx), %eax
movl %eax, (%rsi)
movb 0x11(%r15), %al
cmpb $0x3, %al
jb 0x1b436
movq -0x38(%rbp), %rcx
movslq (%rcx), %rcx
testq %rcx, %rcx
je 0x1b42b
leaq -0x1(%rcx), %rdx
movl %edx, 0x18(%r14)
movq 0x20(%r14), %rdx
movq -0x8(%rdx,%rcx,8), %rcx
jmp 0x1b42d
movq %r13, %rdi
leaq 0x11d45(%rip), %rsi     # 0x2d107
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x7516
movq %rax, %r12
incl 0x10(%rax)
movq (%r13), %rsi
movl 0x10(%rsi), %eax
leal -0x1(%rax), %ecx
movl %ecx, 0x10(%rsi)
cmpl $0x1, %eax
jg 0x1b3ec
movq %r13, %rdi
callq 0x759a
movq %r12, (%r13)
movl $0x1, %ebx
xorl %r15d, %r15d
movl $0x1, %r12d
movl %r12d, %ecx
testb %r15b, %r15b
je 0x1b40b
xorl %ebx, %ebx
movl %ecx, %r12d
testl %ebx, %ebx
je 0x1af1d
jmp 0x1b4de
cmpl $0xc, 0x3c(%rbx)
jne 0x1b459
leaq 0x48(%rbx), %rax
movq %rax, 0x8(%r14)
jmp 0x1b378
xorl %ecx, %ecx
movq %rcx, 0x20(%rsi)
testq %rcx, %rcx
je 0x1b4b4
cmpb $0x2, %al
jb 0x1b473
movq -0x38(%rbp), %rcx
movslq (%rcx), %rcx
testq %rcx, %rcx
je 0x1b468
leaq -0x1(%rcx), %rdx
movl %edx, 0x18(%r14)
movq 0x20(%r14), %rdx
movq -0x8(%rdx,%rcx,8), %rcx
jmp 0x1b46a
movq %r13, %rdi
leaq 0x11cc8(%rip), %rsi     # 0x2d12b
jmp 0x1b3c2
xorl %ecx, %ecx
movq %rcx, 0x18(%rsi)
testq %rcx, %rcx
je 0x1b4b4
testb %al, %al
je 0x1b4a1
movq -0x38(%rbp), %rax
movslq (%rax), %rax
testq %rax, %rax
je 0x1b496
leaq -0x1(%rax), %rcx
movl %ecx, 0x18(%r14)
movq 0x20(%r14), %rcx
movq -0x8(%rcx,%rax,8), %rax
jmp 0x1b498
xorl %eax, %eax
movq %rax, 0x10(%rsi)
testq %rax, %rax
je 0x1b4b4
movq -0x38(%rbp), %rdi
callq 0xad96
xorl %ebx, %ebx
movb $0x1, %r15b
jmp 0x1b3fe
movq (%r15), %rdx
movq 0x28(%r14), %rcx
xorl %r15d, %r15d
movq %r13, %rdi
leaq 0x11c88(%rip), %rsi     # 0x2d150
xorl %eax, %eax
callq 0x692d
addq $-0x28, 0x40(%r14)
movl $0x1, %ebx
jmp 0x1b3f8
cmpl $0x5, %ebx
jne 0x1b4f5
movq -0x38(%rbp), %rax
movl (%rax), %eax
cmpl -0x2c(%rbp), %eax
jne 0x1b507
decl 0x4(%r14)
xorl %r12d, %r12d
movl %r12d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testb $0x2, -0x3c(%rbp)
jne 0x1b526
cmpl -0x2c(%rbp), %eax
jge 0x1b551
cmpl $0x0, 0x4(%r14)
je 0x1b55a
movq 0x28(%r14), %rdx
leaq 0x11ca9(%rip), %rsi     # 0x2d1cd
jmp 0x1b542
cmpl -0x2c(%rbp), %eax
leaq 0x11c94(%rip), %rax     # 0x2d1c4
leaq 0x11c91(%rip), %rdx     # 0x2d1c8
cmovlq %rax, %rdx
leaq 0x11c5f(%rip), %rsi     # 0x2d1a1
movq %r13, %rdi
xorl %eax, %eax
callq 0x692d
jmp 0x1af07
leaq 0x11cb3(%rip), %rsi     # 0x2d20b
jmp 0x1b561
leaq 0x11929(%rip), %rsi     # 0x2ce8a
movq %r13, %rdi
xorl %eax, %eax
callq 0x692d
jmp 0x1af07