// File: /workspace/github_c_makefile_star2_O2/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
movl 0xc(%rdx), %r9d
leaq 0x63ac(%rip), %r8       # 0x1b94c
movslq %r9d, %r10
imulq $0xc, %r10, %r10
movl (%rax,%r10,4), %r11d
cmpq $0xb, %r11
ja 0x15675
movslq (%r8,%r11,4), %r11
addq %r8, %r11
jmpq *%r11
movslq 0x4(%rax,%r10,4), %r9
movl (%rdx,%r9,4), %r9d
jmp 0x15627
movslq 0x4(%rax,%r10,4), %r9
movslq 0x8(%rax,%r10,4), %r10
movl (%rdx,%r10,4), %r10d
addl %r10d, (%rdx,%r9,4)
jmp 0x15630
incl %r9d
movl %r9d, 0x8(%rdx)
jmp 0x15650
movslq 0x4(%rax,%r10,4), %r9
movslq (%rdx,%r9,4), %r9
movl (%rcx,%r9,4), %r9d
jmp 0x15627
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 0x15630
movslq 0x4(%rax,%r10,4), %r9
movslq 0x8(%rax,%r10,4), %r10
movl (%rdx,%r10,4), %r10d
subl %r10d, (%rdx,%r9,4)
jmp 0x15630
movl 0x4(%rax,%r10,4), %r9d
movslq 0x8(%rax,%r10,4), %r10
movl %r9d, (%rdx,%r10,4)
movl 0xc(%rdx), %r9d
incl %r9d
jmp 0x1565c
movslq 0x4(%rax,%r10,4), %r9
movl (%rdx,%r9,4), %r9d
jmp 0x1565c
movslq 0x8(%rax,%r10,4), %r11
cmpl $0x0, (%rdx,%r11,4)
jg 0x15634
movslq 0x4(%rax,%r10,4), %r9
subq %rdi, %r9
movl (%rsi,%r9,4), %r9d
movl %r9d, 0xc(%rdx)
jmp 0x155a0
addq $0x1f40, %rsp           # imm = 0x1F40
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4988(%rip), %rdi      # 0x1a004
leaq 0x62f9(%rip), %rsi      # 0x1b97c
leaq 0x630b(%rip), %rcx      # 0x1b995
xorl %r12d, %r12d
pushq $0x70
popq %rdx
xorl %eax, %eax
callq 0x6100
leaq 0x498e(%rip), %rbx      # 0x1a02c
leaq 0x630b(%rip), %rsi      # 0x1b9b0
movq %rbx, %rdi
xorl %eax, %eax
callq 0x6100
leaq -0x1f60(%rbp), %r15
movq %r15, %rdi
movl $0x3e8, %esi            # imm = 0x3E8
callq 0x60e0
movl %eax, %r14d
movq %r15, %rdi
movl %eax, %esi
callq 0x60b0
movq %rax, %r15
leaq 0x4b3c(%rip), %rdi      # 0x1a216
callq 0x6070
testl %r14d, %r14d
cmovlel %r12d, %r14d
xorl %r12d, %r12d
cmpq %r12, %r14
je 0x15701
movq (%r15,%r12,8), %rsi
movq %rbx, %rdi
xorl %eax, %eax
callq 0x6100
incq %r12
jmp 0x156e9
pushq $0x1
popq %rdi
callq 0x61a0