// File: /workspace/github_c_makefile_star2_O3/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 0x13593
movq %rsi, %rbx
movq %rdi, %r15
leaq 0x8e2d(%rip), %rcx      # 0x1c1e4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x8(%r15), %rdi
movq %rbx, %rsi
callq 0x1338c
movq %rax, %r14
movq 0x10(%r15), %rdi
movq %rbx, %rsi
callq 0x1338c
movq %rax, %rbx
cmpl $0x0, (%r14)
je 0x13408
movq 0x8(%r14), %rax
cmpl $0x1, (%rax)
jne 0x13408
cmpl $0x0, (%rbx)
je 0x13408
movq 0x8(%rbx), %rax
cmpl $0x1, (%rax)
jne 0x13408
movq %r14, %rdi
callq 0x12e37
jmp 0x134e9
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 0x13442
movq 0x10(%r14), %rsi
movq %r15, %rdi
callq 0x11e2d
cmpl $0x0, (%rbx)
jne 0x13453
movq 0x10(%rbx), %rsi
movq %r15, %rdi
callq 0x11e2d
movq %r14, %rdi
callq 0x12e37
movq %rbx, %rdi
callq 0x12e37
movl $0x18, %edi
callq 0x62ec
movq %rax, %rbx
movl $0x0, (%rax)
movq $0x0, 0x8(%rax)
movq %r15, 0x10(%rax)
jmp 0x134e9
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 0x134dd
movl 0x4(%r15), %esi
movq %rbx, %rdi
callq 0x10dd7
movq %rax, %rdi
callq 0x11b8f
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 0x7b01(%rip), %rdi      # 0x1b004
leaq 0x8cee(%rip), %rsi      # 0x1c1f8
leaq 0x8eed(%rip), %rcx      # 0x1c3fe
movl $0xcf, %edx
xorl %eax, %eax
callq 0x6100
leaq 0x7b08(%rip), %rdi      # 0x1b02c
leaq 0x8e91(%rip), %rsi      # 0x1c3bc
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 0x7cb9(%rip), %rdi      # 0x1b216
callq 0x6070
testl %r14d, %r14d
jle 0x13621
movl %r14d, %r15d
leaq 0x7ab7(%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 0x13578
jmp 0x13621
leaq 0x7a6a(%rip), %rdi      # 0x1b004
leaq 0x8c57(%rip), %rsi      # 0x1c1f8
leaq 0x8e56(%rip), %rcx      # 0x1c3fe
movl $0xce, %edx
xorl %eax, %eax
callq 0x6100
leaq 0x7a71(%rip), %rdi      # 0x1b02c
leaq 0x8e47(%rip), %rsi      # 0x1c409
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 0x7c22(%rip), %rdi      # 0x1b216
callq 0x6070
testl %r14d, %r14d
jle 0x13621
movl %r14d, %r15d
leaq 0x7a24(%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 0x1360b
movl $0x1, %edi
callq 0x61a0
nop