// File: /workspace/github_c_makefile_star2_O3/hamsternz[P]emulate-risc-v/riscv.c
// Function: riscv_run
int riscv_run(void) {
  ///////////////////////////////////////
  // Update counters 
  ////////////////////////////////////
  csr[CSR_RDCYCLE]++;
  if(csr[CSR_RDCYCLE] == 0)
    csr[CSR_RDCYCLEH]++;
  csr[CSR_MCYCLE] = csr[CSR_RDCYCLE];

  if(do_op()) {
    csr[CSR_RDTIME]++;
    if(csr[CSR_RDTIME] == 0)
      csr[CSR_RDTIMEH]++;
    return 1;
  } else {
    char buffer[100];
    sprintf(buffer,"Instruction : %08x",current_instr);
    display_log(buffer);
  }
  return 0;
}

// Assembly:
movl 0xca79(%rip), %eax      # 0xfa20
incl %eax
movl %eax, 0xca71(%rip)      # 0xfa20
jne 0x2fb7
incl 0xcc75(%rip)            # 0xfc2c
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %eax, 0xc655(%rip)      # 0xf620
movl 0x9a3f(%rip), %edi      # 0xca10
testb $0x3, %dil
je 0x3018
leaq 0x4d7c(%rip), %rdi      # 0x7d5a
callq 0x4d36
movl 0xdac7(%rip), %edx      # 0x10ab0
leaq 0x48dd(%rip), %rsi      # 0x78cd
xorl %ebx, %ebx
movq %rsp, %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x2210
movq %r14, %rdi
callq 0x4d36
movl %ebx, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpb $0x0, 0xdaa9(%rip)      # 0x10ac8
jne 0x3161
cmpb $0x0, 0xdac8(%rip)      # 0x10af4
je 0x31c2
callq 0x6072
testl %eax, %eax
jne 0x3161
xorl %eax, %eax
movb %al, 0xdaad(%rip)       # 0x10af4
callq 0x60c9
movl %eax, 0xda5e(%rip)      # 0x10ab0
movl %eax, %ebx
notl %ebx
movl %eax, %r9d
shrl $0x14, %r9d
movl %eax, %edx
shrl $0xf, %edx
movl %edx, %esi
andb $0x1f, %sil
movl %r9d, %edi
movl %r9d, %r8d
movl %r9d, %r10d
movl %r9d, 0xda68(%rip)      # 0x10ae0
movl %r9d, %r11d
andb $0x1f, %r11b
movl %eax, %r9d
shrl $0x7, %r9d
movl %r9d, %ebp
andb $0x1f, %bpl
andl $0x1f, %edx
andl $0x1f, %edi
movl $0xfffff000, %r15d      # imm = 0xFFFFF000
movl %eax, %r14d
andl %r15d, %r14d
movl %eax, %r12d
sarl $0xb, %r12d
andl $0xfff00000, %r12d      # imm = 0xFFF00000
movl %eax, %r13d
andl $0xff000, %r13d         # imm = 0xFF000
orl %r12d, %r13d
movl %eax, %r12d
shrl $0x9, %r12d
movl $0x800, %ecx            # imm = 0x800
andl %ecx, %r12d
orl %r13d, %r12d
movl %eax, %r13d
sarl $0x14, %r13d
andl $0x7fe, %r8d            # imm = 0x7FE
orl %r12d, %r8d
movl %eax, %r12d
sarl $0x13, %r12d
andl %r15d, %r12d
shll $0x4, %eax
andl %ecx, %eax
orl %r12d, %eax
andl $0x7e0, %r10d           # imm = 0x7E0
orl %eax, %r10d
movl %r9d, %eax
andl $0x1e, %eax
orl %r10d, %eax
movl %r13d, 0xd9cf(%rip)     # 0x10ad8
andl $-0x20, %r13d
andl $0x1f, %r9d
orl %r13d, %r9d
movb %sil, 0xd9b9(%rip)      # 0x10ad4
movb %r11b, 0xd9ba(%rip)     # 0x10adc
movb %bpl, 0xd997(%rip)      # 0x10ac0
movl %edx, 0xd9b5(%rip)      # 0x10ae4
movl %edi, 0xd9bb(%rip)      # 0x10af0
movl %r14d, 0xd988(%rip)     # 0x10ac4
movl %r8d, 0xd98d(%rip)      # 0x10ad0
movl %eax, 0xd983(%rip)      # 0x10acc
movl %r9d, 0xd998(%rip)      # 0x10ae8
xorl %eax, %eax
movb %al, 0xd994(%rip)       # 0x10aec
testb $0x3, %bl
jne 0x2fe3
movb 0xd98d(%rip), %al       # 0x10af4
movb 0xd95b(%rip), %cl       # 0x10ac8
orb %al, %cl
testb $0x1, %cl
je 0x317e
incl 0xd8a6(%rip)            # 0x10a20
testb $0x1, %al
jne 0x31d8
movl 0xd92c(%rip), %edx      # 0x10ab0
xorl %eax, %eax
leaq 0x8fb3(%rip), %rcx      # 0xc140
movl 0x24(%rax,%rcx), %esi
andl %edx, %esi
cmpl 0x20(%rax,%rcx), %esi
je 0x31aa
addq $0x28, %rax
cmpq $0x8c0, %rax            # imm = 0x8C0
jne 0x318d
jmp 0x2fe3
leaq (%rcx,%rax), %rdx
movq %rdx, 0xd903(%rip)      # 0x10ab8
callq *0x8(%rax,%rcx)
testl %eax, %eax
jne 0x31d8
jmp 0x2fe3
callq 0x6024
testl %eax, %eax
je 0x31f4
movb $0x1, 0xd922(%rip)      # 0x10af4
incl 0xd848(%rip)            # 0x10a20
movl $0x1, %ebx
incl 0xc841(%rip)            # 0xfa24
jne 0x3007
incl 0xca35(%rip)            # 0xfc24
jmp 0x3007
leaq 0x4b81(%rip), %rdi      # 0x7d7c
jmp 0x2fde