// File: /workspace/github_c_makefile_star2_O2/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 0x2267(%rip), %rdi      # 0x6a38
pushq $0x14
popq %rsi
pushq $0x1
popq %r15
movq %r15, %rdx
movq %r14, %rcx
callq 0x11c0
leaq 0x2263(%rip), %rdi      # 0x6a4d
pushq $0x6
popq %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x11c0
leaq 0x2171(%rip), %r15      # 0x6970
pushq $0x9
popq %rbp
xorl %r12d, %r12d
movq (%rbx), %rdi
callq 0x29db
cmpq %rax, %r12
jae 0x49e0
movq (%rbx), %rdi
movq %r12, %rsi
callq 0x29c6
movq %rax, %r13
movl (%rax), %eax
cmpq $0x6, %rax
ja 0x48e5
movslq (%r15,%rax,4), %rax
addq %r15, %rax
jmpq *%rax
movl %ebp, %edi
movq %r14, %rsi
callq 0x10f0
movq 0x8(%r13), %rdx
movq %r14, %rdi
leaq 0x2203(%rip), %rsi      # 0x6a54
jmp 0x48de
movl %ebp, %edi
movq %r14, %rsi
callq 0x10f0
movq 0x8(%r13), %rdx
movq 0x10(%r13), %rcx
movq %r14, %rdi
leaq 0x2208(%rip), %rsi      # 0x6a7a
xorl %eax, %eax
callq 0x1120
jmp 0x48e5
movl %ebp, %edi
movq %r14, %rsi
callq 0x10f0
leaq 0x21c1(%rip), %rdi      # 0x6a4d
pushq $0x6
popq %rsi
pushq $0x1
popq %rdx
movq %r14, %rcx
callq 0x11c0
jmp 0x48e5
movl %ebp, %edi
movq %r14, %rsi
callq 0x10f0
movq 0x8(%r13), %rdx
movq %r14, %rdi
leaq 0x21bb(%rip), %rsi      # 0x6a6f
jmp 0x48de
movl %ebp, %edi
movq %r14, %rsi
callq 0x10f0
movq 0x8(%r13), %rdx
movq %r14, %rdi
leaq 0x2193(%rip), %rsi      # 0x6a61
jmp 0x48de
movq 0x8(%r13), %rdx
movq %r14, %rdi
leaq 0x1c34(%rip), %rsi      # 0x6512
xorl %eax, %eax
callq 0x1120
incq %r12
jmp 0x4805
movl %ebp, %edi
movq %r14, %rsi
callq 0x10f0
movl 0x8(%r13), %eax
cmpq $0xb, %rax
ja 0x49ef
leaq 0x10(%r13), %r8
leaq 0x207c(%rip), %rcx      # 0x698c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %r14, %rdi
leaq 0x2165(%rip), %rsi      # 0x6a88
jmp 0x49ce
movq %r14, %rdi
leaq 0x2182(%rip), %rsi      # 0x6ab4
jmp 0x49ce
movq %r14, %rdi
leaq 0x2176(%rip), %rsi      # 0x6ab7
xorl %edx, %edx
xorl %eax, %eax
callq 0x4a0e
jmp 0x48e5
movq %r14, %rdi
leaq 0x215a(%rip), %rsi      # 0x6ab0
jmp 0x49ce
addq $0x28, %r13
movq %r14, %rdi
leaq 0x2137(%rip), %rsi      # 0x6a9d
jmp 0x49a6
addq $0x28, %r13
movq %r14, %rdi
leaq 0x212c(%rip), %rsi      # 0x6aa2
jmp 0x49a6
addq $0x28, %r13
movq %r14, %rdi
leaq 0x210d(%rip), %rsi      # 0x6a93
jmp 0x49a6
addq $0x28, %r13
movq %r14, %rdi
leaq 0x2116(%rip), %rsi      # 0x6aac
jmp 0x49a6
addq $0x28, %r13
movq %r14, %rdi
leaq 0x20f2(%rip), %rsi      # 0x6a98
pushq $0x2
popq %rdx
movq %r13, %rcx
xorl %eax, %eax
callq 0x4a0e
jmp 0x48e5
movq %r14, %rdi
leaq 0x20cc(%rip), %rsi      # 0x6a8e
jmp 0x49ce
movq %r14, %rdi
leaq 0x20d9(%rip), %rsi      # 0x6aa7
pushq $0x1
popq %rdx
movq %r8, %rcx
xorl %eax, %eax
callq 0x4a0e
jmp 0x48e5
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1e48(%rip), %rdi      # 0x683e
leaq 0x20be(%rip), %rsi      # 0x6abb
leaq 0x20c4(%rip), %rcx      # 0x6ac8
movl $0x14b, %edx            # imm = 0x14B
callq 0x10d0