// File: /workspace/github_c_makefile_star2_O1/alexj136[P]minijit/src/vmcode_interpreter.c
// Function: VMCodeInterpreterState_run
void VMCodeInterpreterState_run(VMCodeInterpreterState *state) {

    // Copy the pointers in the VMCodeInterpreterState to minimise indirection
    int *code      = state->code;
    int *stack     = state->stack;
    int *registers = state->registers;
    int *labels    = state->labels;
    int min_label  = state->min_label;

    while(true) {
        if(OPC == MOVE) {
            registers[ARG2] = registers[ARG1];
            registers[PROGRAM_COUNTER]++;
        }
        else if(OPC == LOAD) {
            registers[ARG2] = stack[registers[ARG1]];
            registers[PROGRAM_COUNTER]++;
        }
        else if(OPC == STORE) {
            stack[registers[ARG2]] = registers[ARG1];
            registers[PROGRAM_COUNTER]++;
        }
        else if(OPC == ADD) {
            registers[ARG1] = registers[ARG1] + registers[ARG2];
            registers[PROGRAM_COUNTER]++;
        }
        else if(OPC == SUB) {
            registers[ARG1] = registers[ARG1] - registers[ARG2];
            registers[PROGRAM_COUNTER]++;
        }
        else if(OPC == LOADIMM) {
            registers[ARG2] = ARG1;
            registers[PROGRAM_COUNTER]++;
        }
        else if(OPC == JUMP) {
            registers[PROGRAM_COUNTER] =
                    VMCodeInterpreterState_lookup_label_address(ARG1);
        }
        else if(OPC == JUMPCOND) {
            if(registers[ARG2] < 1) {
                registers[PROGRAM_COUNTER] =
                        VMCodeInterpreterState_lookup_label_address(ARG1);
            }
            else {
                registers[PROGRAM_COUNTER]++;
            }
        }
        else if(OPC == JUMPLINK) {
            registers[RETURN_ADDRESS] = registers[PROGRAM_COUNTER] + 1;
            registers[PROGRAM_COUNTER] =
                    VMCodeInterpreterState_lookup_label_address(ARG1);
        }
        else if(OPC == JUMPADDR) {
            registers[PROGRAM_COUNTER] = registers[ARG1];
        }
        else if(OPC == LABEL) {
            registers[PROGRAM_COUNTER]++;
        }
        else if(OPC == HALT) {
            break;
        }
        else {
            ERROR("Unrecognised Opcode");
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x1f40, %rsp           # imm = 0x1F40
movq (%rdi), %rax
movq 0x8(%rdi), %rcx
movq 0x10(%rdi), %rdx
movq 0x18(%rdi), %rsi
movslq 0x20(%rdi), %rdi
leaq 0x6432(%rip), %r8       # 0x1c91c
movslq 0xc(%rdx), %r9
leaq (,%r9,4), %r10
leaq (%r10,%r10,2), %r10
movl (%rax,%r10,4), %r11d
cmpq $0xb, %r11
ja 0x165c8
movslq (%r8,%r11,4), %r11
addq %r8, %r11
jmpq *%r11
movslq 0x4(%rax,%r10,4), %r9
movl (%rdx,%r9,4), %r9d
jmp 0x1657a
movslq 0x4(%rax,%r10,4), %r9
movslq 0x8(%rax,%r10,4), %r10
movl (%rdx,%r10,4), %r10d
addl %r10d, (%rdx,%r9,4)
jmp 0x16583
incl %r9d
movl %r9d, 0x8(%rdx)
jmp 0x165a3
movslq 0x4(%rax,%r10,4), %r9
movslq (%rdx,%r9,4), %r9
movl (%rcx,%r9,4), %r9d
jmp 0x1657a
movslq 0x4(%rax,%r10,4), %r9
movl (%rdx,%r9,4), %r9d
movslq 0x8(%rax,%r10,4), %r10
movslq (%rdx,%r10,4), %r10
movl %r9d, (%rcx,%r10,4)
jmp 0x16583
movslq 0x4(%rax,%r10,4), %r9
movslq 0x8(%rax,%r10,4), %r10
movl (%rdx,%r10,4), %r10d
subl %r10d, (%rdx,%r9,4)
jmp 0x16583
movl 0x4(%rax,%r10,4), %r9d
movslq 0x8(%rax,%r10,4), %r10
movl %r9d, (%rdx,%r10,4)
movl 0xc(%rdx), %r9d
incl %r9d
jmp 0x165af
movslq 0x4(%rax,%r10,4), %r9
movl (%rdx,%r9,4), %r9d
jmp 0x165af
movslq 0x8(%rax,%r10,4), %r11
cmpl $0x0, (%rdx,%r11,4)
jg 0x16587
movslq 0x4(%rax,%r10,4), %r9
subq %rdi, %r9
movl (%rsi,%r9,4), %r9d
movl %r9d, 0xc(%rdx)
jmp 0x164ea
addq $0x1f40, %rsp           # imm = 0x1F40
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4a35(%rip), %rdi      # 0x1b004
leaq 0x6376(%rip), %rsi      # 0x1c94c
leaq 0x6388(%rip), %rcx      # 0x1c965
movl $0x70, %edx
xorl %eax, %eax
callq 0x6100
leaq 0x4a3c(%rip), %rdi      # 0x1b02c
leaq 0x6389(%rip), %rsi      # 0x1c980
xorl %eax, %eax
callq 0x6100
leaq -0x1f60(%rbp), %rbx
movq %rbx, %rdi
movl $0x3e8, %esi            # imm = 0x3E8
callq 0x60e0
movl %eax, %r14d
movq %rbx, %rdi
movl %eax, %esi
callq 0x60b0
movq %rax, %rbx
leaq 0x4bed(%rip), %rdi      # 0x1b216
callq 0x6070
testl %r14d, %r14d
jle 0x16656
movl %r14d, %r15d
leaq 0x49ef(%rip), %r14      # 0x1b02c
xorl %r12d, %r12d
movq (%rbx,%r12,8), %rsi
movq %r14, %rdi
xorl %eax, %eax
callq 0x6100
incq %r12
cmpq %r12, %r15
jne 0x16640
movl $0x1, %edi
callq 0x61a0