// File: /workspace/github_c_makefile_star2_O3/endeav0r[P]hvm/src/instruction.c
// Function: ins_str
int ins_str (const struct _instruction * ins, char * buf, size_t buf_size)
{
    const char * opcode    = ins_opcode_str(ins->opcode);
    const char * operand_0 = ins_reg_str(ins->operand_0);
    const char * operand_1 = ins_reg_str(ins->operand_1);
    const char * operand_2 = ins_reg_str(ins->operand_2);
    char lval[8];

    if (opcode == NULL)
        return -1;

    switch (ins->opcode) {
    case OP_ADD :
    case OP_SUB :
    case OP_MUL :
    case OP_DIV :
    case OP_MOD :
    case OP_AND :
    case OP_OR  :
    case OP_XOR :
        if ((operand_0 == NULL) || (operand_1 == NULL) || (operand_2 == NULL))
            return -1;
        return snprintf(buf, buf_size, "%s %s, %s, %s",
                        opcode, operand_0, operand_1, operand_2);

    case OP_ADDLVAL :
    case OP_SUBLVAL :
    case OP_MULLVAL :
    case OP_DIVLVAL :
    case OP_MODLVAL :
    case OP_ANDLVAL :
    case OP_ORLVAL  :
    case OP_XORLVAL :
        if (operand_0 == NULL)
            return -1;
        snprintf(lval, 8, "%04x", ntohs(ins->lval));
        return snprintf(buf, buf_size, "%s %s, %s", opcode, operand_0, lval);

    case OP_MOV    :
    case OP_CMP    :
    case OP_LOADR  :
    case OP_STORR  :
    case OP_LOADBR :
    case OP_STORBR :
        if ((operand_0 == NULL) || (operand_1 == NULL))
            return -1;
        return snprintf(buf, buf_size, "%s %s, %s", opcode, operand_0, operand_1);

    case OP_JMP      :
    case OP_JE       :
    case OP_JNE      :
    case OP_JL       :
    case OP_JLE      :
    case OP_JG       :
    case OP_JGE      :
    case OP_CALL     :
    case OP_PUSHLVAL :
        snprintf(lval, 8, "%x", ntohs(ins->lval));
        return snprintf(buf, buf_size, "%s %s", opcode, lval);

    case OP_LOAD    :
    case OP_STOR    :
    case OP_LOADB   :
    case OP_STORB   :
    case OP_MOVLVAL :
    case OP_CMPLVAL :
        if (operand_0 == NULL)
            return -1;
        snprintf(lval, 8, "%04x", ntohs(ins->lval));
        if (ins->opcode == OP_STOR) 
            return snprintf(buf, buf_size, "%s %s, %s", opcode, lval, operand_0);
        else
            return snprintf(buf, buf_size, "%s %s, %s", opcode, operand_0, lval);

    case OP_CALLR :
    case OP_IN    :
    case OP_OUT   :
    case OP_PUSH  :
    case OP_POP   :
        if (operand_0 == NULL)
            return -1;
        return snprintf(buf, buf_size, "%s %s", opcode, operand_0);

    case OP_RET     :
    case OP_HLT     :
    case OP_SYSCALL :
    case OP_NOP     :
        return snprintf(buf, buf_size, "%s", opcode);
    }

    return -1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %r13
movzbl (%rdi), %ebp
movl %ebp, %edi
callq 0x2a48
movq %rax, %rbx
movzbl 0x1(%r13), %eax
leaq 0x38e9(%rip), %rcx      # 0x6478
cmpq $0xa, %rax
ja 0x2ddc
leaq 0x36e0(%rip), %rdx      # 0x6280
movslq (%rdx,%rax,4), %rax
addq %rdx, %rax
jmpq *%rax
xorl %edx, %edx
movq %rcx, %r12
jmp 0x2c0a
leaq 0x38cd(%rip), %r12      # 0x6484
jmp 0x2c08
leaq 0x38d0(%rip), %r12      # 0x6490
jmp 0x2c08
leaq 0x38b5(%rip), %r12      # 0x647e
jmp 0x2c08
leaq 0x38af(%rip), %r12      # 0x6481
jmp 0x2c08
leaq 0x38bd(%rip), %r12      # 0x6498
jmp 0x2c08
leaq 0x3897(%rip), %r12      # 0x647b
jmp 0x2c08
leaq 0x389a(%rip), %r12      # 0x6487
jmp 0x2c08
leaq 0x3894(%rip), %r12      # 0x648a
jmp 0x2c08
leaq 0x388e(%rip), %r12      # 0x648d
jmp 0x2c08
leaq 0x388c(%rip), %r12      # 0x6494
xorl %edx, %edx
movzbl 0x2(%r13), %eax
cmpq $0xa, %rax
ja 0x2de6
leaq 0x368c(%rip), %rsi      # 0x62ac
movslq (%rsi,%rax,4), %rax
addq %rsi, %rax
jmpq *%rax
xorl %esi, %esi
movq %rcx, %r9
jmp 0x2c8a
leaq 0x384d(%rip), %r9       # 0x6484
jmp 0x2c88
leaq 0x3850(%rip), %r9       # 0x6490
jmp 0x2c88
leaq 0x3835(%rip), %r9       # 0x647e
jmp 0x2c88
leaq 0x382f(%rip), %r9       # 0x6481
jmp 0x2c88
leaq 0x383d(%rip), %r9       # 0x6498
jmp 0x2c88
leaq 0x3817(%rip), %r9       # 0x647b
jmp 0x2c88
leaq 0x381a(%rip), %r9       # 0x6487
jmp 0x2c88
leaq 0x3814(%rip), %r9       # 0x648a
jmp 0x2c88
leaq 0x380e(%rip), %r9       # 0x648d
jmp 0x2c88
leaq 0x380c(%rip), %r9       # 0x6494
xorl %esi, %esi
movzbl 0x3(%r13), %eax
cmpq $0xa, %rax
ja 0x2df1
leaq 0x3638(%rip), %rdi      # 0x62d8
movslq (%rdi,%rax,4), %rax
addq %rdi, %rax
jmpq *%rax
leaq 0x37cb(%rip), %rcx      # 0x647b
jmp 0x2d01
leaq 0x37cb(%rip), %rcx      # 0x6484
jmp 0x2d01
leaq 0x37ce(%rip), %rcx      # 0x6490
jmp 0x2d01
leaq 0x37b3(%rip), %rcx      # 0x647e
jmp 0x2d01
leaq 0x37ad(%rip), %rcx      # 0x6481
jmp 0x2d01
leaq 0x37bb(%rip), %rcx      # 0x6498
jmp 0x2d01
leaq 0x37a1(%rip), %rcx      # 0x6487
jmp 0x2d01
leaq 0x379b(%rip), %rcx      # 0x648a
jmp 0x2d01
leaq 0x3795(%rip), %rcx      # 0x648d
jmp 0x2d01
leaq 0x3793(%rip), %rcx      # 0x6494
xorl %edi, %edi
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testq %rbx, %rbx
je 0x2ec0
leal -0x10(%rbp), %r8d
cmpl $0x51, %r8d
ja 0x2ecf
leaq 0x35de(%rip), %r10      # 0x6304
movslq (%r10,%r8,4), %r8
addq %r10, %r8
jmpq *%r8
movzwl 0x2(%r13), %eax
rolw $0x8, %ax
movzwl %ax, %ecx
leaq 0x37ed(%rip), %rdx      # 0x6530
leaq 0x10(%rsp), %r12
movl $0x8, %esi
movq %r12, %rdi
xorl %eax, %eax
callq 0x2140
leaq 0x37d5(%rip), %rdx      # 0x6533
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rcx
movq %r12, %r8
xorl %eax, %eax
callq 0x2140
jmp 0x2ec0
orb %dil, %sil
orb %sil, %dl
jne 0x2ec0
movq %rcx, (%rsp)
leaq 0x3786(%rip), %rdx      # 0x6513
jmp 0x2ead
testb %dl, %dl
jne 0x2ec0
movzwl 0x2(%r13), %eax
rolw $0x8, %ax
movzwl %ax, %ecx
leaq 0x3774(%rip), %rdx      # 0x6521
leaq 0x10(%rsp), %r13
movl $0x8, %esi
movq %r13, %rdi
xorl %eax, %eax
callq 0x2140
leaq 0x375e(%rip), %rdx      # 0x6526
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rcx
movq %r12, %r8
movq %r13, %r9
jmp 0x2eb9
movb $0x1, %dl
xorl %r12d, %r12d
jmp 0x2c0a
movb $0x1, %sil
xorl %r9d, %r9d
jmp 0x2c8a
movb $0x1, %dil
xorl %ecx, %ecx
jmp 0x2d03
testb %dl, %dl
jne 0x2ec0
movzwl 0x2(%r13), %eax
rolw $0x8, %ax
movzwl %ax, %ecx
leaq 0x370b(%rip), %rdx      # 0x6521
leaq 0x10(%rsp), %rdi
movl $0x8, %esi
xorl %eax, %eax
callq 0x2140
cmpb $0x34, (%r13)
jne 0x2ea1
leaq 0x36f1(%rip), %rdx      # 0x6526
leaq 0x10(%rsp), %r8
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rcx
movq %r12, %r9
jmp 0x2eb9
orb %sil, %dl
jne 0x2ec0
leaq 0x36d2(%rip), %rdx      # 0x6526
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rcx
movq %r12, %r8
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2140
testb %dl, %dl
jne 0x2ec0
leaq 0x36b3(%rip), %rdx      # 0x6533
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rcx
movq %r12, %r8
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2140
leaq 0x367e(%rip), %rdx      # 0x6526
leaq 0x10(%rsp), %r9
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rcx
movq %r12, %r8
xorl %eax, %eax
callq 0x2140
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x90, %ebp
jne 0x2ec0
leaq 0x3640(%rip), %rdx      # 0x651e
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rcx
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2140