// File: /workspace/github_c_makefile_star2_O1/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 0x13594
movq %rsi, %rbx
movq %rdi, %r15
leaq 0x8e3c(%rip), %rcx      # 0x1c1f4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x8(%r15), %rdi
movq %rbx, %rsi
callq 0x1338d
movq %rax, %r14
movq 0x10(%r15), %rdi
movq %rbx, %rsi
callq 0x1338d
movq %rax, %rbx
cmpl $0x0, (%r14)
je 0x13409
movq 0x8(%r14), %rax
cmpl $0x1, (%rax)
jne 0x13409
cmpl $0x0, (%rbx)
je 0x13409
movq 0x8(%rbx), %rax
cmpl $0x1, (%rax)
jne 0x13409
movq %r14, %rdi
callq 0x12e38
jmp 0x134ea
movl $0x10, %edi
callq 0x62ec
movq %rax, %r15
movabsq $0xa00000000, %rax      # imm = 0xA00000000
movq %rax, (%r15)
movl $0x50, %edi
callq 0x62ec
movq %rax, 0x8(%r15)
cmpl $0x0, (%r14)
jne 0x13443
movq 0x10(%r14), %rsi
movq %r15, %rdi
callq 0x11e43
cmpl $0x0, (%rbx)
jne 0x13454
movq 0x10(%rbx), %rsi
movq %r15, %rdi
callq 0x11e43
movq %r14, %rdi
callq 0x12e38
movq %rbx, %rdi
callq 0x12e38
movl $0x18, %edi
callq 0x62ec
movq %rax, %rbx
movl $0x0, (%rax)
movq $0x0, 0x8(%rax)
movq %r15, 0x10(%rax)
jmp 0x134ea
movl $0x8, %edi
callq 0x62ec
movq %rax, %r14
movl $0x1, %r15d
movl %r15d, (%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rax)
movl $0x18, %edi
callq 0x62ec
movq %rax, %rbx
movl %r15d, (%rax)
jmp 0x134de
movl 0x4(%r15), %esi
movq %rbx, %rdi
callq 0x10dfd
movq %rax, %rdi
callq 0x11ba7
movq %rax, %r14
movl $0x18, %edi
callq 0x62ec
movq %rax, %rbx
movl $0x1, (%rax)
movq %r14, 0x8(%rax)
movq $0x0, 0x10(%rax)
movq %rbx, %rax
addq $0x1f40, %rsp           # imm = 0x1F40
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x7b00(%rip), %rdi      # 0x1b004
leaq 0x8cfd(%rip), %rsi      # 0x1c208
leaq 0x8efc(%rip), %rcx      # 0x1c40e
movl $0xcf, %edx
xorl %eax, %eax
callq 0x6100
leaq 0x7b07(%rip), %rdi      # 0x1b02c
leaq 0x8ea0(%rip), %rsi      # 0x1c3cc
xorl %eax, %eax
callq 0x6100
leaq -0x1f60(%rbp), %rbx
movq %rbx, %rdi
movl $0x3e8, %esi            # imm = 0x3E8
callq 0x60e0
movl %eax, %r14d
movq %rbx, %rdi
movl %eax, %esi
callq 0x60b0
movq %rax, %rbx
leaq 0x7cb8(%rip), %rdi      # 0x1b216
callq 0x6070
testl %r14d, %r14d
jle 0x13622
movl %r14d, %r15d
leaq 0x7ab6(%rip), %r14      # 0x1b02c
xorl %r12d, %r12d
movq (%rbx,%r12,8), %rsi
movq %r14, %rdi
xorl %eax, %eax
callq 0x6100
incq %r12
cmpq %r12, %r15
jne 0x13579
jmp 0x13622
leaq 0x7a69(%rip), %rdi      # 0x1b004
leaq 0x8c66(%rip), %rsi      # 0x1c208
leaq 0x8e65(%rip), %rcx      # 0x1c40e
movl $0xce, %edx
xorl %eax, %eax
callq 0x6100
leaq 0x7a70(%rip), %rdi      # 0x1b02c
leaq 0x8e56(%rip), %rsi      # 0x1c419
xorl %eax, %eax
callq 0x6100
leaq -0x1f60(%rbp), %rbx
movq %rbx, %rdi
movl $0x3e8, %esi            # imm = 0x3E8
callq 0x60e0
movl %eax, %r14d
movq %rbx, %rdi
movl %eax, %esi
callq 0x60b0
movq %rax, %rbx
leaq 0x7c21(%rip), %rdi      # 0x1b216
callq 0x6070
testl %r14d, %r14d
jle 0x13622
movl %r14d, %r15d
leaq 0x7a23(%rip), %r14      # 0x1b02c
xorl %r12d, %r12d
movq (%rbx,%r12,8), %rsi
movq %r14, %rdi
xorl %eax, %eax
callq 0x6100
incq %r12
cmpq %r12, %r15
jne 0x1360c
movl $0x1, %edi
callq 0x61a0