// File: /workspace/github_c_makefile_star2_O2/johnvtan[P]ccccc/asm.c
// Function: gen_asm
list_t *gen_asm(program_t *prog) {
    if (!prog || !prog->fn_defs) {
        UNREACHABLE("gen_asm: malformed program\n");
    }
    debug("=====================Generating ASM=====================\n");
    list_t *output = list_new();

    pair_t *fn_pair;
    map_for_each(prog->fn_defs, fn_pair) {
        fn_def_t *fn_def = fn_pair->value;
        if (!fn_def->stmts)
            continue;
        list_t *fn_instrs = fn_def_to_asm(fn_def);
        if (!fn_instrs) {
            UNREACHABLE("gen_asm: null fn_instrs\n");
        }
        list_concat(output, fn_instrs);
    }
    debug("length: %d\n", output->len);
    return output;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
testq %rdi, %rdi
je 0x1611
movq %rdi, %r14
cmpq $0x0, (%rdi)
je 0x1611
callq 0x2c34
movq %rax, 0x20(%rsp)
movq (%r14), %rax
movq (%rax), %rdi
movq (%rdi), %rax
movq 0x8(%rax), %rax
movq %rax, 0x10(%rdi)
movq %r14, 0x28(%rsp)
addq $0x10, %rdi
leaq 0x30(%rsp), %rsi
callq 0x2dfe
testb %al, %al
je 0x15b8
movq 0x30(%rsp), %rax
movq 0x8(%rax), %rbx
cmpq $0x0, 0x10(%rbx)
je 0x15ad
cmpq $0x0, (%rbx)
je 0x15cc
callq 0x2c34
movq %rax, %r12
movq (%rbx), %rdi
pushq $0x1
popq %r14
movl %r14d, %esi
callq 0x162d
movq %r12, %rdi
movq %rax, %rsi
callq 0x2c7e
callq 0x2c34
movq %rax, %r15
pushq $0x8
popq %r13
movl %r13d, %edi
pushq $0x5
popq %rbp
movl %ebp, %esi
callq 0x1d33
movq %r15, %rdi
movq %rax, %rsi
callq 0x2c7e
movl %r14d, %edi
pushq $0x6
popq %r14
movl %r14d, %esi
movl %ebp, %edx
callq 0x1dc7
movq %r15, %rdi
movq %rax, %rsi
callq 0x2c7e
movq 0x28(%rbx), %rsi
pushq $0x2
popq %rbp
movl %ebp, %edi
movl %r14d, %edx
callq 0x1e60
movq %r15, %rdi
movq %rax, %rsi
callq 0x2c7e
movl %r13d, %edi
movl %ebp, %esi
callq 0x1d33
movq %r15, %rdi
movq %rax, %rsi
callq 0x2c7e
movq 0x18(%rbx), %rdi
testq %rdi, %rdi
leaq 0x38(%rsp), %r13
je 0x14aa
cmpl $0x0, 0x18(%rdi)
je 0x14aa
movq (%rdi), %rax
movq 0x8(%rax), %rax
movq %rax, 0x10(%rdi)
leaq 0x3c5b(%rip), %r14      # 0x50c0
addq $0x10, %rdi
movq %r13, %rsi
callq 0x2dfe
testb %al, %al
je 0x14aa
movq 0x20(%rbx), %rax
movq (%rax), %rdi
movq 0x38(%rsp), %rsi
callq 0x2ed9
movl (%r14), %edi
movl 0x8(%rax), %esi
movq 0x10(%rax), %rdx
callq 0x1eff
movq %r15, %rdi
movq %rax, %rsi
callq 0x2c7e
movq 0x18(%rbx), %rdi
addq $0x4, %r14
jmp 0x1465
movq %r12, %rdi
movq %r15, %rsi
callq 0x2cbd
leaq 0x3d0e(%rip), %rdi      # 0x51ca
callq 0x1653
movq %rax, %r14
movq %rax, %rdi
xorl %esi, %esi
callq 0x162d
movq %rax, %r15
movq %r14, 0x38(%rsp)
leaq 0x40(%rsp), %rax
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq 0x20(%rbx), %rax
movq %rax, 0x50(%rsp)
movq 0x28(%rsp), %r14
movq 0x10(%rbx), %rdi
callq 0x2d0a
testq %rax, %rax
je 0x1525
movups 0x38(%rsp), %xmm0
movups 0x48(%rsp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %rax, %rdi
callq 0x16ce
movq %r12, %rdi
movq %rax, %rsi
callq 0x2cbd
jmp 0x14ef
movq %r12, %rdi
movq %r15, %rsi
callq 0x2c7e
callq 0x2c34
movq %rax, %r15
pushq $0x8
popq %rdi
movl %ebp, %esi
callq 0x1d33
movq %r15, %rdi
movq %rax, %rsi
callq 0x2c7e
pushq $0x1
popq %rdi
pushq $0x5
popq %rbx
movl %ebx, %esi
pushq $0x6
popq %rdx
callq 0x1dc7
movq %r15, %rdi
movq %rax, %rsi
callq 0x2c7e
pushq $0x9
popq %rdi
movl %ebx, %esi
callq 0x1d33
movq %r15, %rdi
movq %rax, %rsi
callq 0x2c7e
movq %r12, %rdi
movq %r15, %rsi
callq 0x2cbd
pushq $0x3
popq %rdi
callq 0x1cb1
movq %r12, %rdi
movq %rax, %rsi
callq 0x2c7e
testq %r12, %r12
je 0x15e8
movq 0x20(%rsp), %rdi
movq %r12, %rsi
callq 0x2cbd
movq (%r14), %rax
movq (%rax), %rdi
jmp 0x1378
movq 0x20(%rsp), %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3b61(%rip), %rdi      # 0x5134
leaq 0x3b94(%rip), %rsi      # 0x516e
leaq 0x3bc8(%rip), %rcx      # 0x51a9
movl $0x32d, %edx            # imm = 0x32D
jmp 0x1602
leaq 0x3b45(%rip), %rdi      # 0x5134
leaq 0x3b78(%rip), %rsi      # 0x516e
leaq 0x3b93(%rip), %rcx      # 0x5190
movl $0x360, %edx            # imm = 0x360
xorl %eax, %eax
callq 0x1080
pushq $-0x1
popq %rdi
callq 0x1110
leaq 0x3b1c(%rip), %rdi      # 0x5134
leaq 0x3b4f(%rip), %rsi      # 0x516e
leaq 0x3b4e(%rip), %rcx      # 0x5174
movl $0x354, %edx            # imm = 0x354
jmp 0x1602