// File: cphinton42[P]hinton-language/src/check.cpp
// Function: typecheck_bool(Context*, Expr_AST*, Bool_AST*)
internal
bool typecheck_bool(Context *ctx, Expr_AST *type, Bool_AST *bool_ast)
{
    if(type)
    {
        Expr_AST *reduced_ast;
        Status status = reduce_type(ctx, type, &reduced_ast);
        if(status == Status::good)
        {
            if(reduced_ast->type != AST_Type::primitive_ast)
            {
                report_error("Type mismatch: got bool", bool_ast);
                ctx->success = false;
                return false;
            }
            
            Primitive_AST *prim_ast = static_cast<Primitive_AST*>(reduced_ast);
            
            u64 prim = prim_ast->primitive;
            if(!(prim & PRIM_BOOLLIKE))
            {
                report_error("Type mismatch: got bool", bool_ast);
                ctx->success = false;
                return false;
            }
            
            u64 size = prim & PRIM_SIZE_MASK;
            
            switch(size)
            {
                case PRIM_NO_SIZE:
                case PRIM_SIZE1: {
                    set_resolved_type(bool_ast, &bool8_t_ast);
                } break;
                case PRIM_SIZE2: {
                    set_resolved_type(bool_ast, &bool16_t_ast);
                } break;
                case PRIM_SIZE4: {
                    set_resolved_type(bool_ast, &bool32_t_ast);
                } break;
                case PRIM_SIZE8: {
                    set_resolved_type(bool_ast, &bool64_t_ast);
                } break;
                default: {
                    assert(false);
                } break;
            }
            return true;
        }
    }
    else
    {
        set_resolved_type(bool_ast, &bool8_t_ast);
        return true;
    }
    
    auto job = make_typecheck_job(type, bool_ast);
    array_add(ctx->waiting_jobs, job);
    return false;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x8f95
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
leaq -0x28(%rbp), %rdx
callq 0x9040
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
jne 0x8f93
movq -0x28(%rbp), %rax
cmpw $0x11, (%rax)
je 0x8eab
movq -0x20(%rbp), %rsi
leaq 0x11ed2(%rip), %rdi     # 0x1ad67
callq 0x4950
movq -0x10(%rbp), %rax
movb $0x0, 0x10(%rax)
movb $0x0, -0x1(%rbp)
jmp 0x9028
movq -0x28(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
andq $0x80, %rax
cmpq $0x0, %rax
jne 0x8ef0
movq -0x20(%rbp), %rsi
leaq 0x11e8d(%rip), %rdi     # 0x1ad67
callq 0x4950
movq -0x10(%rbp), %rax
movb $0x0, 0x10(%rax)
movb $0x0, -0x1(%rbp)
jmp 0x9028
movq -0x40(%rbp), %rax
andl $0x7, %eax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x90(%rbp)
subq $0x4, %rax
ja 0x8f6b
movq -0x90(%rbp), %rax
leaq 0x10246(%rip), %rcx     # 0x19160
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x20(%rbp), %rdi
leaq 0x16eaa(%rip), %rsi     # 0x1fdd8
callq 0x3be0
jmp 0x8f8a
movq -0x20(%rbp), %rdi
leaq 0x16ec0(%rip), %rsi     # 0x1fe00
callq 0x3be0
jmp 0x8f8a
movq -0x20(%rbp), %rdi
leaq 0x16ed6(%rip), %rsi     # 0x1fe28
callq 0x3be0
jmp 0x8f8a
movq -0x20(%rbp), %rdi
leaq 0x16eec(%rip), %rsi     # 0x1fe50
callq 0x3be0
jmp 0x8f8a
leaq 0x10eb0(%rip), %rdi     # 0x19e22
leaq 0x10f73(%rip), %rsi     # 0x19eec
movl $0x638, %edx            # imm = 0x638
leaq 0x11dfa(%rip), %rcx     # 0x1ad7f
callq 0x3080
movb $0x1, -0x1(%rbp)
jmp 0x9028
jmp 0x8fab
movq -0x20(%rbp), %rdi
leaq 0x16e38(%rip), %rsi     # 0x1fdd8
callq 0x3be0
movb $0x1, -0x1(%rbp)
jmp 0x9028
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
leaq -0x60(%rbp), %rdi
xorl %ecx, %ecx
callq 0x4a80
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x60(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x68(%rbp)
movq 0x16c9b(%rip), %rax     # 0x1fc80
movq %rax, -0x88(%rbp)
movq 0x16c95(%rip), %rax     # 0x1fc88
movq %rax, -0x80(%rbp)
movq -0x88(%rbp), %rsi
movq -0x80(%rbp), %rdx
leaq -0x78(%rbp), %rax
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x10(%rsp)
callq 0x17c30
movb $0x0, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0xb0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)