// File: /workspace/github_c_makefile_star2_O2/alexj136[P]minijit/src/typecheck.c
// Function: check_Expr
TypeCheckResult *check_Expr(Expr *expr, TypeVector *symbol_table) {
    if(Expr_isInt(expr)) {
        return TypeCheckSuccess_init(IntType_init());
    }
    else if(Expr_isAdd(expr) || Expr_isSub(expr)) {
        TypeCheckResult *lhs_res = check_Expr(Add_lhs(expr), symbol_table);
        TypeCheckResult *rhs_res = check_Expr(Add_rhs(expr), symbol_table);

        // Success case
        if(TypeCheckResult_isTypeForm(lhs_res, typeInt) &&
                TypeCheckResult_isTypeForm(rhs_res, typeInt)) {

            TypeCheckResult_free(lhs_res);
            return rhs_res;
        }

        // Fail case
        TypeErrorVector *errors = TypeErrorVector_init();
        if(!(lhs_res->success)) {
            TypeErrorVector_append_all(errors, lhs_res->errors);
        }
        if(!(rhs_res->success)) {
            TypeErrorVector_append_all(errors, rhs_res->errors);
        }

        TypeCheckResult_free(lhs_res);
        TypeCheckResult_free(rhs_res);
        return TypeCheckFail_init(errors);
    }
    else if(Expr_isCall(expr)) {}
    else if(Expr_isVar(expr)) {
        return TypeCheckSuccess_init(
                Type_copy(TypeVector_get(symbol_table, Var_name(expr))));
    }
    else { ERROR("Unrecognised Expr type"); }
    NOT_IMPLEMENTED;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x1f40, %rsp           # imm = 0x1F40
movl (%rdi), %eax
cmpq $0x4, %rax
ja 0x129a2
movq %rsi, %r14
movq %rdi, %r15
leaq 0x89e7(%rip), %rcx      # 0x1b214
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x8(%r15), %rdi
movq %r14, %rsi
callq 0x12802
movq %rax, %rbx
movq 0x10(%r15), %rdi
movq %r14, %rsi
callq 0x12802
movq %rax, %r14
cmpl $0x0, (%rbx)
je 0x1288c
movq 0x8(%rbx), %rax
cmpl $0x1, (%rax)
jne 0x1288c
cmpl $0x0, (%r14)
je 0x1288c
movq 0x8(%r14), %rax
cmpl $0x1, (%rax)
jne 0x1288c
movq %rbx, %rdi
callq 0x122cc
movq %r14, %rax
addq $0x1f40, %rsp           # imm = 0x1F40
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
callq 0x111b5
movq %rax, %r15
cmpl $0x0, (%rbx)
jne 0x128a5
movq 0x10(%rbx), %rsi
movq %r15, %rdi
callq 0x11384
cmpl $0x0, (%r14)
jne 0x128b7
movq 0x10(%r14), %rsi
movq %r15, %rdi
callq 0x11384
movq %rbx, %rdi
callq 0x122cc
movq %r14, %rdi
callq 0x122cc
movq %r15, %rdi
addq $0x1f40, %rsp           # imm = 0x1F40
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x1228f
callq 0x11104
jmp 0x128f9
movl 0x4(%r15), %esi
movq %r14, %rdi
callq 0x10438
movq %rax, %rdi
callq 0x11127
movq %rax, %rdi
addq $0x1f40, %rsp           # imm = 0x1F40
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x12268
leaq 0x76ed(%rip), %rdi      # 0x1a004
leaq 0x890a(%rip), %rsi      # 0x1b228
leaq 0x8b09(%rip), %rcx      # 0x1b42e
xorl %r12d, %r12d
movl $0xcf, %edx
xorl %eax, %eax
callq 0x6100
leaq 0x76f1(%rip), %rbx      # 0x1a02c
leaq 0x8aaa(%rip), %rsi      # 0x1b3ec
movq %rbx, %rdi
xorl %eax, %eax
callq 0x6100
leaq -0x1f60(%rbp), %r15
movq %r15, %rdi
movl $0x3e8, %esi            # imm = 0x3E8
callq 0x60e0
movl %eax, %r14d
movq %r15, %rdi
movl %eax, %esi
callq 0x60b0
movq %rax, %r15
leaq 0x789f(%rip), %rdi      # 0x1a216
callq 0x6070
testl %r14d, %r14d
cmovlel %r12d, %r14d
xorl %r12d, %r12d
cmpq %r12, %r14
je 0x12a30
movq (%r15,%r12,8), %rsi
movq %rbx, %rdi
xorl %eax, %eax
callq 0x6100
incq %r12
jmp 0x12986
leaq 0x765b(%rip), %rdi      # 0x1a004
leaq 0x8878(%rip), %rsi      # 0x1b228
leaq 0x8a77(%rip), %rcx      # 0x1b42e
xorl %r12d, %r12d
movl $0xce, %edx
xorl %eax, %eax
callq 0x6100
leaq 0x765f(%rip), %rbx      # 0x1a02c
leaq 0x8a65(%rip), %rsi      # 0x1b439
movq %rbx, %rdi
xorl %eax, %eax
callq 0x6100
leaq -0x1f60(%rbp), %r15
movq %r15, %rdi
movl $0x3e8, %esi            # imm = 0x3E8
callq 0x60e0
movl %eax, %r14d
movq %r15, %rdi
movl %eax, %esi
callq 0x60b0
movq %rax, %r15
leaq 0x780d(%rip), %rdi      # 0x1a216
callq 0x6070
testl %r14d, %r14d
cmovlel %r12d, %r14d
xorl %r12d, %r12d
cmpq %r12, %r14
je 0x12a30
movq (%r15,%r12,8), %rsi
movq %rbx, %rdi
xorl %eax, %eax
callq 0x6100
incq %r12
jmp 0x12a18
pushq $0x1
popq %rdi
callq 0x61a0