// File: /workspace/github_c_makefile_star2_O0/jtuu[P]quesler/src/compiler.c
// Function: compile
bool compile(const char* source, Chunk* chunk) {
    init_scanner(source);

    Compiler compiler;
    init_compiler(&compiler);
    compiling_chunk = chunk;

    parser.had_error = false;
    parser.panic_mode = false;
    parser.entry_function_exists = false;
    parser.labels_count = 0;
    parser.functions = NULL;
    parser.functions_count = 0;
    parser.functions_capacity = 0;
    
    for (size_t i = 1; i < NUM_REGISTERS; i++) {
        parser.free_registers[i] = true;
    }

    emit_runtime();

    advance();
    
    while (!match(TOKEN_EOF)) {
        declaration();
    }

    end_compiler();

    if (!parser.entry_function_exists) {
        error("Missing entry function");
    }

    if (register_alloc_counter != 0) {
        fprintf(stderr, "%d unfreed register(s): [", register_alloc_counter);

        bool first = true;
        for (size_t i = 1; i < NUM_REGISTERS; i++) {
            if (!parser.free_registers[i]) {
                if (first) {
                    fprintf(stderr, "%lu", i);
                    first = false;
                } else {
                    fprintf(stderr, ", %lu", i);
                }
            }
        }

        fprintf(stderr, "]\n");
    }

    return !parser.had_error;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x3040, %rsp           # imm = 0x3040
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
callq 0x8ac0
leaq -0x3020(%rbp), %rdi
callq 0x5640
movq -0x10(%rbp), %rax
movq %rax, 0x1411d(%rip)     # 0x195a0
movb $0x0, 0x14196(%rip)     # 0x19620
movb $0x0, 0x14190(%rip)     # 0x19621
movb $0x0, 0x14298(%rip)     # 0x19730
movq $0x0, 0x14285(%rip) # 0x19728
movq $0x0, 0x1428a(%rip) # 0x19738
movq $0x0, 0x14287(%rip) # 0x19740
movq $0x0, 0x14284(%rip) # 0x19748
movq $0x1, -0x3028(%rbp)
cmpq $0x100, -0x3028(%rbp) # imm = 0x100
jae 0x5503
movq -0x3028(%rbp), %rcx
leaq 0x140be(%rip), %rax     # 0x195a8
movb $0x1, 0x7a(%rax,%rcx)
movq -0x3028(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x3028(%rbp)
jmp 0x54cf
callq 0x5680
callq 0x5690
movl $0x2a, %edi
callq 0x5710
xorb $-0x1, %al
testb $0x1, %al
jne 0x551f
jmp 0x5526
callq 0x5750
jmp 0x550d
callq 0x57a0
testb $0x1, 0x141fe(%rip)     # 0x19730
jne 0x5540
leaq 0x6b3a(%rip), %rdi      # 0xc075
callq 0x57b0
cmpl $0x0, 0x14051(%rip)     # 0x19598
je 0x5626
movq 0x13a9c(%rip), %rax     # 0x18ff0
movq (%rax), %rdi
movl 0x1403b(%rip), %edx     # 0x19598
leaq 0x6b28(%rip), %rsi      # 0xc08c
movb $0x0, %al
callq 0x40f0
movb $0x1, -0x3029(%rbp)
movq $0x1, -0x3038(%rbp)
cmpq $0x100, -0x3038(%rbp) # imm = 0x100
jae 0x560e
movq -0x3038(%rbp), %rcx
leaq 0x1400c(%rip), %rax     # 0x195a8
testb $0x1, 0x7a(%rax,%rcx)
jne 0x55f5
testb $0x1, -0x3029(%rbp)
je 0x55d4
movq 0x13a3d(%rip), %rax     # 0x18ff0
movq (%rax), %rdi
movq -0x3038(%rbp), %rdx
leaq 0x6ae4(%rip), %rsi      # 0xc0a8
movb $0x0, %al
callq 0x40f0
movb $0x0, -0x3029(%rbp)
jmp 0x55f3
movq 0x13a15(%rip), %rax     # 0x18ff0
movq (%rax), %rdi
movq -0x3038(%rbp), %rdx
leaq 0x6aba(%rip), %rsi      # 0xc0a6
movb $0x0, %al
callq 0x40f0
jmp 0x55f5
jmp 0x55f7
movq -0x3038(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x3038(%rbp)
jmp 0x557d
movq 0x139db(%rip), %rax     # 0x18ff0
movq (%rax), %rdi
leaq 0x6a8d(%rip), %rsi      # 0xc0ac
movb $0x0, %al
callq 0x40f0
movb 0x13ff4(%rip), %al      # 0x19620
xorb $-0x1, %al
andb $0x1, %al
addq $0x3040, %rsp           # imm = 0x3040
popq %rbp
retq
nopl (%rax)