// File: /workspace/github_c_makefile_star2_O0/alexj136[P]minijit/src/ncodegen.c
// Function: ncode_gen
NCodeLinkable *ncode_gen(ICodeOperationVector *ops) {

    // Allocate space to store the generated ncode. Allocate enough space such
    // that if every instruction were the longest type, there would be exactly
    // enough space for the generated code.
    int ncode_buf_size = sizeof(byte) * ((ICodeOperationVector_size(ops) *
            JUMPLINK_x86_64_size) + x86_64_preamble_size);
    byte *ncode_buf = challoc(ncode_buf_size);
    int ncode_buf_alloc_idx = 0;
    int icode_idx;
    LinkTargetVector *link_targets = LinkTargetVector_init();
    IntRefVector *label_map = IntRefVector_init();

    // Include the preamble
    write_x86_64_preamble(ncode_buf + ncode_buf_alloc_idx, NULL, NULL);
    ncode_buf_alloc_idx += x86_64_preamble_size;

    // Loop writes the instructions in place and records the link locations to
    // be filled in later
    for(icode_idx = 0; icode_idx < ICodeOperationVector_size(ops);
            icode_idx++) {

        ICodeOperation *cur_instr = ICodeOperationVector_get(ops, icode_idx);
        int opc = cur_instr->opc;
        int arg1 = cur_instr->arg1;
        int arg2 = cur_instr->arg2;

        if(opc == MOVE) {
            write_x86_64_MOVE(ncode_buf + ncode_buf_alloc_idx, arg1, arg2);
            ncode_buf_alloc_idx += MOVE_x86_64_size;
        }
        else if(opc == LOAD) {
            write_x86_64_LOAD(ncode_buf + ncode_buf_alloc_idx, arg1, arg2);
            ncode_buf_alloc_idx += LOAD_x86_64_size;
        }
        else if(opc == STORE) {
            write_x86_64_STORE(ncode_buf + ncode_buf_alloc_idx, arg1, arg2);
            ncode_buf_alloc_idx += STORE_x86_64_size;
        }
        else if(opc == ADD) {
            write_x86_64_ADD(ncode_buf + ncode_buf_alloc_idx, arg1, arg2);
            ncode_buf_alloc_idx += ADD_x86_64_size;
        }
        else if(opc == SUB) {
            write_x86_64_SUB(ncode_buf + ncode_buf_alloc_idx, arg1, arg2);
            ncode_buf_alloc_idx += SUB_x86_64_size;
        }
        else if(opc == LOADIMM) {
            write_x86_64_LOADIMM(ncode_buf + ncode_buf_alloc_idx, arg1, arg2);
            ncode_buf_alloc_idx += LOADIMM_x86_64_size;
        }
        else if(opc == JUMP) {
            write_x86_64_JUMP(ncode_buf + ncode_buf_alloc_idx, NULL);
            LinkTargetVector_append(link_targets, LinkTarget_init(
                    ncode_buf_alloc_idx + JUMP_x86_64_address_offset, arg1));
            ncode_buf_alloc_idx += JUMP_x86_64_size;
        }
        else if(opc == JUMPCOND) {
            write_x86_64_JUMPCOND(ncode_buf + ncode_buf_alloc_idx, NULL, arg2);
            LinkTargetVector_append(link_targets, LinkTarget_init(
                    ncode_buf_alloc_idx + JUMPCOND_x86_64_address_offset,
                    arg1));
            ncode_buf_alloc_idx += JUMPCOND_x86_64_size;
        }
        else if(opc == JUMPLINK) {
            write_x86_64_JUMPLINK(ncode_buf + ncode_buf_alloc_idx, NULL);
            LinkTargetVector_append(link_targets, LinkTarget_init(
                    ncode_buf_alloc_idx + JUMPLINK_x86_64_address_offset,
                    arg1));
            ncode_buf_alloc_idx += JUMPLINK_x86_64_size;
        }
        else if(opc == JUMPADDR) {
            write_x86_64_JUMPADDR(ncode_buf + ncode_buf_alloc_idx, arg1);
            ncode_buf_alloc_idx += JUMPADDR_x86_64_size;
        }
        else if(opc == LABEL) {
            IntRefVector_append(label_map, IntRef_init(ncode_buf_alloc_idx));
        }
        else if(opc == HALT) {
            write_x86_64_HALT(ncode_buf + ncode_buf_alloc_idx);
            ncode_buf_alloc_idx += HALT_x86_64_size;
        }
    }

    return NCodeLinkable_init(ncode_buf, ncode_buf_size, link_targets,
            label_map);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
callq 0x1a540
imull $0x16, %eax, %eax
addl $0x2e, %eax
cltq
shlq $0x0, %rax
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %edi
callq 0x62f0
movq %rax, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
callq 0x1f340
movq %rax, -0x28(%rbp)
movb $0x0, %al
callq 0x7dd0
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rdi
movslq -0x1c(%rbp), %rax
addq %rax, %rdi
xorl %eax, %eax
movl %eax, %edx
movq %rdx, %rsi
callq 0x1eb20
movl -0x1c(%rbp), %eax
addl $0x2e, %eax
movl %eax, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
movl %eax, -0x48(%rbp)
movq -0x8(%rbp), %rdi
callq 0x1a540
movl %eax, %ecx
movl -0x48(%rbp), %eax
cmpl %ecx, %eax
jge 0x20c62
movq -0x8(%rbp), %rdi
movl -0x20(%rbp), %esi
callq 0x1a900
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x3c(%rbp)
movq -0x38(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x40(%rbp)
movq -0x38(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x3c(%rbp)
jne 0x20a25
movq -0x18(%rbp), %rdi
movslq -0x1c(%rbp), %rax
addq %rax, %rdi
movl -0x40(%rbp), %esi
movl -0x44(%rbp), %edx
callq 0x1edb0
movl -0x1c(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x1c(%rbp)
jmp 0x20c52
cmpl $0x1, -0x3c(%rbp)
jne 0x20a4f
movq -0x18(%rbp), %rdi
movslq -0x1c(%rbp), %rax
addq %rax, %rdi
movl -0x40(%rbp), %esi
movl -0x44(%rbp), %edx
callq 0x1ee70
movl -0x1c(%rbp), %eax
addl $0x3, %eax
movl %eax, -0x1c(%rbp)
jmp 0x20c50
cmpl $0x2, -0x3c(%rbp)
jne 0x20a79
movq -0x18(%rbp), %rdi
movslq -0x1c(%rbp), %rax
addq %rax, %rdi
movl -0x40(%rbp), %esi
movl -0x44(%rbp), %edx
callq 0x1eeb0
movl -0x1c(%rbp), %eax
addl $0x3, %eax
movl %eax, -0x1c(%rbp)
jmp 0x20c4e
cmpl $0x3, -0x3c(%rbp)
jne 0x20aa3
movq -0x18(%rbp), %rdi
movslq -0x1c(%rbp), %rax
addq %rax, %rdi
movl -0x40(%rbp), %esi
movl -0x44(%rbp), %edx
callq 0x1edf0
movl -0x1c(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x1c(%rbp)
jmp 0x20c4c
cmpl $0x4, -0x3c(%rbp)
jne 0x20acd
movq -0x18(%rbp), %rdi
movslq -0x1c(%rbp), %rax
addq %rax, %rdi
movl -0x40(%rbp), %esi
movl -0x44(%rbp), %edx
callq 0x1ee30
movl -0x1c(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x1c(%rbp)
jmp 0x20c4a
cmpl $0x5, -0x3c(%rbp)
jne 0x20af7
movq -0x18(%rbp), %rdi
movslq -0x1c(%rbp), %rax
addq %rax, %rdi
movl -0x40(%rbp), %esi
movl -0x44(%rbp), %edx
callq 0x1ed40
movl -0x1c(%rbp), %eax
addl $0x5, %eax
movl %eax, -0x1c(%rbp)
jmp 0x20c48
cmpl $0x6, -0x3c(%rbp)
jne 0x20b41
movq -0x18(%rbp), %rdi
movslq -0x1c(%rbp), %rax
addq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1eef0
movq -0x28(%rbp), %rax
movq %rax, -0x50(%rbp)
movl -0x1c(%rbp), %edi
addl $0x2, %edi
movl -0x40(%rbp), %esi
callq 0x20900
movq -0x50(%rbp), %rdi
movq %rax, %rsi
callq 0x1f490
movl -0x1c(%rbp), %eax
addl $0xc, %eax
movl %eax, -0x1c(%rbp)
jmp 0x20c46
cmpl $0x7, -0x3c(%rbp)
jne 0x20b8e
movq -0x18(%rbp), %rdi
movslq -0x1c(%rbp), %rax
addq %rax, %rdi
movl -0x44(%rbp), %edx
xorl %eax, %eax
movl %eax, %esi
callq 0x1efd0
movq -0x28(%rbp), %rax
movq %rax, -0x58(%rbp)
movl -0x1c(%rbp), %edi
addl $0xb, %edi
movl -0x40(%rbp), %esi
callq 0x20900
movq -0x58(%rbp), %rdi
movq %rax, %rsi
callq 0x1f490
movl -0x1c(%rbp), %eax
addl $0x15, %eax
movl %eax, -0x1c(%rbp)
jmp 0x20c44
cmpl $0x8, -0x3c(%rbp)
jne 0x20bd5
movq -0x18(%rbp), %rdi
movslq -0x1c(%rbp), %rax
addq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1f0f0
movq -0x28(%rbp), %rax
movq %rax, -0x60(%rbp)
movl -0x1c(%rbp), %edi
addl $0xc, %edi
movl -0x40(%rbp), %esi
callq 0x20900
movq -0x60(%rbp), %rdi
movq %rax, %rsi
callq 0x1f490
movl -0x1c(%rbp), %eax
addl $0x16, %eax
movl %eax, -0x1c(%rbp)
jmp 0x20c42
cmpl $0x9, -0x3c(%rbp)
jne 0x20bf9
movq -0x18(%rbp), %rdi
movslq -0x1c(%rbp), %rax
addq %rax, %rdi
movl -0x40(%rbp), %esi
callq 0x1f210
movl -0x1c(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x1c(%rbp)
jmp 0x20c40
cmpl $0xa, -0x3c(%rbp)
jne 0x20c1d
movq -0x30(%rbp), %rax
movq %rax, -0x68(%rbp)
movl -0x1c(%rbp), %edi
callq 0x67b0
movq -0x68(%rbp), %rdi
movq %rax, %rsi
callq 0x7f20
jmp 0x20c3e
cmpl $0xb, -0x3c(%rbp)
jne 0x20c3c
movq -0x18(%rbp), %rdi
movslq -0x1c(%rbp), %rax
addq %rax, %rdi
callq 0x1f240
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x20c3e
jmp 0x20c40
jmp 0x20c42
jmp 0x20c44
jmp 0x20c46
jmp 0x20c48
jmp 0x20c4a
jmp 0x20c4c
jmp 0x20c4e
jmp 0x20c50
jmp 0x20c52
jmp 0x20c54
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x209b2
movq -0x18(%rbp), %rdi
movl -0xc(%rbp), %esi
movq -0x28(%rbp), %rdx
movq -0x30(%rbp), %rcx
callq 0x1f2e0
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax)