// File: /workspace/github_cpp_makefile_star2_O1/cphinton42[P]hinton-language/src/check.cpp
// Function: typecheck_all(Pool_Allocator*, Array<Decl_AST*>)
bool typecheck_all(Pool_Allocator *ast_pool, Array<Decl_AST*> decls)
{
    Dynamic_Array<Job> job_arrays[2] = {0};
    auto current = &job_arrays[0];
    auto next = &job_arrays[1];
    
    Context ctx;
    ctx.ast_pool = ast_pool;
    ctx.waiting_jobs = next;
    ctx.success = true;
    
    for(u64 i = 0; i < decls.count; ++i)
    {
        auto job = make_typecheck_job(nullptr, decls[i]);
        do_typecheck_job(&ctx, job);
    }
    
    if(!ctx.success)
    {
        print_err("Success flag was unset (1)\n");
        return false;
    }
    
    while(true)
    {
        auto tmp = current;
        current = next;
        next = tmp;
        
        if(current->count == 0)
        {
            return true;
        }
        next->count = 0;
        ctx.waiting_jobs = next;
        
        bool change = false;
        for(u64 i = 0; i < current->count; ++i)
        {
            if(do_typecheck_job(&ctx, (*current)[i]))
            {
                change = true;
            }
        }
        
        if(!ctx.success)
        {
            print_err("Success flag was unset (2)\n");
            return false;
        }
        else if(!change)
        {
            // TODO: detect error
            print_err("Error: no progress (%lu waiting jobs)\n", next->count);
            print_jobs(next->array);
            return false;
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
xorps %xmm0, %xmm0
leaq 0x78(%rsp), %rbx
movaps %xmm0, 0x8(%rbx)
movaps %xmm0, -0x8(%rbx)
movaps %xmm0, -0x18(%rbx)
movq %rdi, 0x20(%rsp)
movq %rbx, 0x28(%rsp)
movb $0x1, 0x30(%rsp)
testq %rsi, %rsi
je 0x725b
movq %rdx, %r12
movq %rsi, %r14
xorl %r13d, %r13d
leaq 0x20(%rsp), %r15
movq (%r12,%r13,8), %rax
movaps %xmm0, 0x40(%rsp)
movq %rax, 0x50(%rsp)
movq %rax, 0x10(%rsp)
movaps 0x40(%rsp), %xmm0
movups %xmm0, (%rsp)
movq %r15, %rdi
callq 0x43a6
xorps %xmm0, %xmm0
incq %r13
cmpq %r13, %r14
jne 0x722c
cmpb $0x1, 0x30(%rsp)
jne 0x733d
leaq 0x60(%rsp), %r12
leaq 0x20(%rsp), %r15
movl $0x1, %r13d
movq %r12, %r14
movq %rbx, %r12
cmpq $0x0, (%rbx)
je 0x72e5
movq $0x0, (%r14)
movq %r14, 0x28(%rsp)
cmpq $0x0, (%r12)
je 0x72eb
movl %eax, 0x1c(%rsp)
movq %r14, 0x38(%rsp)
xorl %ebp, %ebp
xorl %r14d, %r14d
xorl %ebx, %ebx
movq 0x8(%r12), %rax
movq 0x10(%rax,%rbp), %rcx
movq %rcx, 0x10(%rsp)
movups (%rax,%rbp), %xmm0
movups %xmm0, (%rsp)
movq %r15, %rdi
callq 0x43a6
movzbl %bl, %ebx
testb %al, %al
cmovnel %r13d, %ebx
incq %r14
addq $0x18, %rbp
cmpq (%r12), %r14
jb 0x72a5
movq 0x38(%rsp), %r14
movl 0x1c(%rsp), %eax
jmp 0x72ed
movb $0x1, %al
xorl %ebp, %ebp
jmp 0x732f
xorl %ebx, %ebx
cmpb $0x0, 0x30(%rsp)
je 0x731d
movb $0x1, %bpl
testb $0x1, %bl
jne 0x732f
movq (%r14), %rsi
xorl %ebp, %ebp
leaq 0x9dfc(%rip), %rdi      # 0x11104
xorl %eax, %eax
callq 0x4261
movq (%r14), %rdi
movq 0x8(%r14), %rsi
callq 0x7184
jmp 0x732d
xorl %ebp, %ebp
leaq 0x9dc2(%rip), %rdi      # 0x110e8
xorl %eax, %eax
callq 0x4261
xorl %eax, %eax
movq %r14, %rbx
testb %bpl, %bpl
jne 0x7276
jmp 0x734d
leaq 0x9d88(%rip), %rdi      # 0x110cc
xorl %eax, %eax
callq 0x4261
xorl %eax, %eax
andb $0x1, %al
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq