// File: /workspace/github_c_makefile_star2_O3/yutopp[P]cc/asm_x86_64.c
// Function: asm_x86_64_fprint
void asm_x86_64_fprint(FILE* fp, ASM_X86_64* a) {
	fprintf(fp, ".file	\"simple_00.c\"\n"); // TODO
	fprintf(fp, ".text\n");                  // TODO

    for(size_t i=0; i<vector_len(a->insts); ++i) {
        ASM_X86_64_Inst* inst = vector_at(a->insts, i);
        switch(inst->kind) {
        case ASM_X86_64_INST_KIND_SECTION:
            fprintf(fp, "\t");
            fprintf(fp, ".section\t%s\n", inst->value.section.name);
            break;

        case ASM_X86_64_INST_KIND_STRING:
            fprintf(fp, "\t");
            fprintf(fp, ".string\t\"%s\"\n", inst->value.string.s);
            break;

        case ASM_X86_64_INST_KIND_TEXT:
            fprintf(fp, "\t");
            fprintf(fp, ".text\n");
            break;

        case ASM_X86_64_INST_KIND_GLOBAL:
            fprintf(fp, "\t");
            fprintf(fp, ".globl\t%s\n", inst->value.global.name);
            break;

        case ASM_X86_64_INST_KIND_TYPE:
            fprintf(fp, "\t");
            fprintf(fp, ".type\t%s, %s\n", inst->value.type.name, inst->value.type.type);
            break;

        case ASM_X86_64_INST_KIND_LABEL:
            fprintf(fp, "%s:\n", inst->value.label.name);
            break;

        case ASM_X86_64_INST_KIND_OP:
        {
            fprintf(fp, "\t");
            ASM_X86_64_Value* args = inst->value.op.args;
            switch(inst->value.op.op) {
            case ASM_X86_64_OP_PUSHQ:
                fprint_inst_op(fp, "pushq", 1, &args[0]);
                break;

            case ASM_X86_64_OP_POPQ:
                fprint_inst_op(fp, "popq", 1, &args[0]);
                break;

            case ASM_X86_64_OP_MOVQ:
                fprint_inst_op(fp, "movq", 2, &args[1], &args[0]);
                break;

            case ASM_X86_64_OP_ADDQ:
                fprint_inst_op(fp, "addq", 2, &args[1], &args[0]);
                break;

            case ASM_X86_64_OP_SUBQ:
                fprint_inst_op(fp, "subq", 2, &args[1], &args[0]);
                break;

            case ASM_X86_64_OP_LEAQ:
                fprint_inst_op(fp, "leaq", 2, &args[1], &args[0]);
                break;

            case ASM_X86_64_OP_CALL:
                fprint_inst_op(fp, "call", 1, &args[0]);
                break;

            case ASM_X86_64_OP_CMPQ:
                fprint_inst_op(fp, "cmp", 2, &args[1], &args[0]);
                break;

            case ASM_X86_64_OP_JMP:
                fprint_inst_op(fp, "jmp", 1, &args[0]);
                break;

            case ASM_X86_64_OP_JE:
                fprint_inst_op(fp, "je", 1, &args[0]);
                break;

            case ASM_X86_64_OP_RET:
                fprint_inst_op(fp, "ret", 0);
                break;

            default:
                assert(0); // TODO: error handling...
            }
            break;
        }
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
leaq 0x2c0e(%rip), %rdi      # 0x7a38
movl $0x14, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x11c0
leaq 0x2c0a(%rip), %rdi      # 0x7a4d
movl $0x6, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x11c0
movq (%rbx), %rdi
callq 0x2f0b
testq %rax, %rax
je 0x5064
leaq 0x2b03(%rip), %r15      # 0x7970
leaq 0x2b18(%rip), %r12      # 0x798c
xorl %r13d, %r13d
movq (%rbx), %rdi
movq %r13, %rsi
callq 0x2ef6
movq %rax, %rbp
movl (%rax), %eax
cmpq $0x6, %rax
ja 0x4f59
movslq (%r15,%rax,4), %rax
addq %r15, %rax
jmpq *%rax
movl $0x9, %edi
movq %r14, %rsi
callq 0x10f0
movq 0x8(%rbp), %rdx
movq %r14, %rdi
leaq 0x2b9f(%rip), %rsi      # 0x7a54
jmp 0x4f52
movl $0x9, %edi
movq %r14, %rsi
callq 0x10f0
movq 0x8(%rbp), %rdx
movq 0x10(%rbp), %rcx
movq %r14, %rdi
leaq 0x2ba1(%rip), %rsi      # 0x7a7a
xorl %eax, %eax
callq 0x1120
jmp 0x4f59
movl $0x9, %edi
movq %r14, %rsi
callq 0x10f0
movl $0x6, %esi
movl $0x1, %edx
leaq 0x2b4d(%rip), %rdi      # 0x7a4d
movq %r14, %rcx
callq 0x11c0
jmp 0x4f59
movl $0x9, %edi
movq %r14, %rsi
callq 0x10f0
movq 0x8(%rbp), %rdx
movq %r14, %rdi
leaq 0x2b4a(%rip), %rsi      # 0x7a6f
jmp 0x4f52
movl $0x9, %edi
movq %r14, %rsi
callq 0x10f0
movq 0x8(%rbp), %rdx
movq %r14, %rdi
leaq 0x2b1f(%rip), %rsi      # 0x7a61
jmp 0x4f52
movq 0x8(%rbp), %rdx
movq %r14, %rdi
leaq 0x25c0(%rip), %rsi      # 0x7512
xorl %eax, %eax
callq 0x1120
incq %r13
movq (%rbx), %rdi
callq 0x2f0b
cmpq %rax, %r13
jb 0x4e77
jmp 0x5064
movl $0x9, %edi
movq %r14, %rsi
callq 0x10f0
movl 0x8(%rbp), %eax
cmpq $0xb, %rax
ja 0x5073
leaq 0x10(%rbp), %r8
movslq (%r12,%rax,4), %rax
addq %r12, %rax
jmpq *%rax
movq %r14, %rdi
leaq 0x2ae5(%rip), %rsi      # 0x7a88
jmp 0x5050
movq %r14, %rdi
leaq 0x2b02(%rip), %rsi      # 0x7ab4
jmp 0x5050
movq %r14, %rdi
leaq 0x2af6(%rip), %rsi      # 0x7ab7
xorl %edx, %edx
xorl %eax, %eax
callq 0x5092
jmp 0x4f59
movq %r14, %rdi
leaq 0x2ada(%rip), %rsi      # 0x7ab0
jmp 0x5050
addq $0x28, %rbp
movq %r14, %rdi
leaq 0x2ab7(%rip), %rsi      # 0x7a9d
jmp 0x5026
addq $0x28, %rbp
movq %r14, %rdi
leaq 0x2aac(%rip), %rsi      # 0x7aa2
jmp 0x5026
addq $0x28, %rbp
movq %r14, %rdi
leaq 0x2a8d(%rip), %rsi      # 0x7a93
jmp 0x5026
addq $0x28, %rbp
movq %r14, %rdi
leaq 0x2a96(%rip), %rsi      # 0x7aac
jmp 0x5026
addq $0x28, %rbp
movq %r14, %rdi
leaq 0x2a72(%rip), %rsi      # 0x7a98
movl $0x2, %edx
movq %rbp, %rcx
xorl %eax, %eax
callq 0x5092
jmp 0x4f59
movq %r14, %rdi
leaq 0x2a4a(%rip), %rsi      # 0x7a8e
jmp 0x5050
movq %r14, %rdi
leaq 0x2a57(%rip), %rsi      # 0x7aa7
movl $0x1, %edx
movq %r8, %rcx
xorl %eax, %eax
callq 0x5092
jmp 0x4f59
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x27c4(%rip), %rdi      # 0x783e
leaq 0x2a3a(%rip), %rsi      # 0x7abb
leaq 0x2a40(%rip), %rcx      # 0x7ac8
movl $0x14b, %edx            # imm = 0x14B
callq 0x10d0