LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_c_makefile_star2_O1/hamsternz[P]emulate-risc-v/ram.c
// Function: RAM_set
int RAM_set(struct region *r, uint32_t address, uint8_t mask, uint32_t value) {

   if(address+4 > r->size) {
     fprintf(stderr,"Memory region boundary crossed at 0x%08x\n", r->base+address);
     return 0;
   }

   if((address & 3) != 0) {
     fprintf(stderr,"Unaligned memory write 0x%08x\n", r->base+address);
   }
#if 0
   fprintf(stderr, "Write %08x %x, 0x%08x\n", address, mask, value);
#endif
   if(mask & 1) {
      ((unsigned char *)r->data)[address+0] = value; 
   }
   if(mask & 2) {
      ((unsigned char *)r->data)[address+1] = value>>8; 
   }
   if(mask & 4) {
      ((unsigned char *)r->data)[address+2] = value>>16; 
   }
   if(mask & 8) {
      ((unsigned char *)r->data)[address+3] = value>>24; 
   }
   return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl %esi, %ebx
movq %rdi, %r14
leal 0x4(%rbx), %eax
cmpl 0xc(%rdi), %eax
ja 0x417c
movl %ecx, %r12d
movl %edx, %ebp
testb $0x3, %bl
jne 0x419f
testb $0x1, %bpl
je 0x412c
movq 0x38(%r14), %rax
movl %ebx, %ecx
movl %r12d, %edx
movb %dl, (%rax,%rcx)
testb $0x2, %bpl
je 0x413f
movq 0x38(%r14), %rax
leal 0x1(%rbx), %ecx
movl %r12d, %edx
movb %dh, (%rax,%rcx)
testb $0x4, %bpl
je 0x4155
movl %r12d, %eax
shrl $0x10, %eax
movq 0x38(%r14), %rcx
leal 0x2(%rbx), %edx
movb %al, (%rcx,%rdx)
movl $0x1, %r15d
testb $0x8, %bpl
je 0x4170
shrl $0x18, %r12d
movq 0x38(%r14), %rax
addl $0x3, %ebx
movb %r12b, (%rax,%rbx)
movl %r15d, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq 0x7e75(%rip), %rax      # 0xbff8
movq (%rax), %rdi
addl 0x8(%r14), %ebx
leaq 0x3e0e(%rip), %rsi      # 0x7f9f
xorl %r15d, %r15d
movl %ebx, %edx
xorl %eax, %eax
callq 0x2140
jmp 0x4170
movq 0x7e52(%rip), %rax      # 0xbff8
movq (%rax), %rdi
movl 0x8(%r14), %edx
addl %ebx, %edx
leaq 0x3e13(%rip), %rsi      # 0x7fc9
xorl %eax, %eax
callq 0x2140
jmp 0x411a
// File: /workspace/github_c_makefile_star2_O1/hamsternz[P]emulate-risc-v/ram.c
// Function: RAM_get
int RAM_get(struct region *r, uint32_t address, uint32_t *value) {
   uint32_t v = 0;
   if((address & 3) != 0) {
     fprintf(stderr,"Unaligned memory read 0x%08x\n", r->base+address);
     return 0;
   }

   if(address+4 > r->size) {
     fprintf(stderr,"Memory region boundary crossed at 0x%08x\n", r->base+address);
     return 0;
   }

   v = ((unsigned char *)r->data)[address++]; 
   v = v + (((unsigned char *)r->data)[address++] << 8); 
   v = v + (((unsigned char *)r->data)[address++] << 16); 
   v = v + (((unsigned char *)r->data)[address++] << 24); 
   *value = v;
   return 1;
}

// Assembly:
pushq %rbx
movl %esi, %eax
testb $0x3, %al
jne 0x41e5
leal 0x4(%rax), %ecx
cmpl 0xc(%rdi), %ecx
ja 0x41fb
movq 0x38(%rdi), %rcx
movl %eax, %eax
movl (%rcx,%rax), %eax
movl %eax, (%rdx)
movl $0x1, %ebx
movl %ebx, %eax
popq %rbx
retq
movq 0x7e0c(%rip), %rcx      # 0xbff8
movq (%rcx), %rcx
addl 0x8(%rdi), %eax
leaq 0x3def(%rip), %rsi      # 0x7fe8
jmp 0x420f
movq 0x7df6(%rip), %rcx      # 0xbff8
movq (%rcx), %rcx
addl 0x8(%rdi), %eax
leaq 0x3d90(%rip), %rsi      # 0x7f9f
xorl %ebx, %ebx
movq %rcx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0x2140
jmp 0x41e1
// File: /workspace/github_c_makefile_star2_O1/hamsternz[P]emulate-risc-v/ram.c
// Function: RAM_dump
void RAM_dump(struct region *r) {
   int i;

   printf("RAM 0x%08x length 0x%08x\n", r->base, r->size);
   for(i = 0; i < r->size && i < 4096; i++) {
      if(i%32 == 0) {
	 printf("%08x:", r->base+i);
      }
      printf(" %02x", ((unsigned char *)(r->data))[i]);
      if(i%32 == 31)
	 printf("\n");
   }
   if(i%32 != 0)
     printf("\n");
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rdi, %rbx
movl 0x8(%rdi), %esi
movl 0xc(%rdi), %edx
leaq 0x3dcf(%rip), %rdi      # 0x8006
xorl %eax, %eax
callq 0x20c0
cmpl $0x0, 0xc(%rbx)
je 0x42be
leaq 0x3dd5(%rip), %r14      # 0x8020
leaq 0x3dd4(%rip), %r15      # 0x8026
xorl %r12d, %r12d
movl %r12d, %ebp
andl $0x1f, %ebp
jne 0x426d
movl 0x8(%rbx), %esi
addl %r12d, %esi
movq %r14, %rdi
xorl %eax, %eax
callq 0x20c0
movq 0x38(%rbx), %rax
movzbl (%rax,%r12), %esi
movq %r15, %rdi
xorl %eax, %eax
callq 0x20c0
cmpl $0x1f, %ebp
jne 0x428f
movl $0xa, %edi
callq 0x2050
leaq 0x1(%r12), %rax
cmpq $0xffe, %r12            # imm = 0xFFE
ja 0x42a8
movl 0xc(%rbx), %ecx
movq %rax, %r12
cmpq %rcx, %rax
jb 0x4255
testb $0x1f, %al
je 0x42be
movl $0xa, %edi
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x2050
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/hamsternz[P]emulate-risc-v/ram.c
// Function: RAM_free
void RAM_free(struct region *r) {
   char buffer[100];
   sprintf(buffer, "Releasing RAM at 0x%08x", r->base);
   display_log(buffer);
   if(r->data != NULL) 
     free(r->data);
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x68, %rsp
movq %rdi, %rbx
movl 0x8(%rdi), %edx
leaq 0x3d51(%rip), %rsi      # 0x802c
movq %rsp, %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x2200
movq %r14, %rdi
callq 0x4d86
movq 0x38(%rbx), %rdi
testq %rdi, %rdi
je 0x42fe
callq 0x2040
addq $0x68, %rsp
popq %rbx
popq %r14
retq
nop
// File: /workspace/github_c_makefile_star2_O1/hamsternz[P]emulate-risc-v/uart.c
// Function: UART_init
int UART_init(struct region *r) {
  struct uart_data *data;

  if(r->data != NULL) {
    display_log("UART already initialized");
    return 0;
  }
 
  data = malloc(sizeof(struct uart_data));
  if(data == NULL){
    return 0;
  }

  memset(data, 0, sizeof(struct uart_data));
  data->divisor = 0xffff;
  data->debug   = UART_DEBUG;
  r->data = (void *)data;

  display_log("Set up UART region");
  return 1;
}

// Assembly:
pushq %rbx
cmpq $0x0, 0x38(%rdi)
je 0x431b
xorl %ebx, %ebx
leaq 0x3e57(%rip), %rdi      # 0x8170
jmp 0x4356
movq %rdi, %rbx
movl $0x22, %edi
callq 0x2190
testq %rax, %rax
je 0x435f
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movups %xmm0, 0x10(%rax)
movw $0x0, 0x20(%rax)
movw $0xffff, (%rax)         # imm = 0xFFFF
movb $0x0, 0x21(%rax)
movq %rax, 0x38(%rbx)
movl $0x1, %ebx
leaq 0x3e33(%rip), %rdi      # 0x8189
callq 0x4d86
movl %ebx, %eax
popq %rbx
retq
xorl %ebx, %ebx
jmp 0x435b
// File: /workspace/github_c_makefile_star2_O1/hamsternz[P]emulate-risc-v/uart.c
// Function: UART_rx_enqueue
void UART_rx_enqueue(struct region *r, uint8_t c) {
  char buffer[100];
  struct uart_data *data = r->data;
  if(data->rx_enable) {
    if(data->rx_count < UART_QUEUE_DEPTH) {
      data->rx_fifo[data->tx_write_ptr] = c;
      data->rx_count++;
      data->tx_write_ptr = (data->tx_write_ptr == UART_FIFO_SIZE-1) ? 0 : data->tx_write_ptr+1;
      if(data->debug) {
        sprintf(buffer,"UART data added to rx queue 0x%02x", c);
        display_log(buffer);
      }
    } else {
      if(data->debug) {
        sprintf(buffer,"UART rx queue overflow adding 0x%02x", c);
        display_log(buffer);
      }
    }
  } else {
    if(data->debug) {
      sprintf(buffer,"UART rx disabled while adding 0x%02x", c);
      display_log(buffer);
    }
  }
}

// Assembly:
movq 0x38(%rdi), %rax
cmpb $0x0, 0x1b(%rax)
je 0x45ce
cmpb $0x7, 0x17(%rax)
ja 0x45dd
movzbl 0xb(%rax), %ecx
movb %sil, 0xd(%rax,%rcx)
incb 0x17(%rax)
leal 0x1(%rcx), %edx
xorl %edi, %edi
cmpq $0x7, %rcx
movzbl %dl, %ecx
cmovel %edi, %ecx
movb %cl, 0xb(%rax)
cmpb $0x0, 0x21(%rax)
je 0x4610
leaq 0x3cef(%rip), %rax      # 0x82bb
jmp 0x45ea
cmpb $0x0, 0x21(%rax)
je 0x4610
leaq 0x3d28(%rip), %rax      # 0x8303
jmp 0x45ea
cmpb $0x0, 0x21(%rax)
je 0x4610
leaq 0x3cf4(%rip), %rax      # 0x82de
pushq %rbx
subq $0x70, %rsp
movzbl %sil, %edx
movq %rsp, %rbx
movq %rbx, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0x2200
movq %rbx, %rdi
callq 0x4d86
addq $0x70, %rsp
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O1/hamsternz[P]emulate-risc-v/uart.c
// Function: UART_free
void UART_free(struct region *r) {
   char buffer[100];
   sprintf(buffer, "Releasing UART at 0x%08x", r->base);
   display_log(buffer);
   if(r->data != NULL) 
     free(r->data);
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x68, %rsp
movq %rdi, %rbx
movl 0x8(%rdi), %edx
leaq 0x3bff(%rip), %rsi      # 0x847f
movq %rsp, %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x2200
movq %r14, %rdi
callq 0x4d86
movq 0x38(%rbx), %rdi
testq %rdi, %rdi
je 0x48a3
callq 0x2040
addq $0x68, %rsp
popq %rbx
popq %r14
retq
nop
// File: /workspace/github_c_makefile_star2_O1/hamsternz[P]emulate-risc-v/display.c
// Function: display_log
void display_log(char *str) {
  if(log_file != NULL) {
    fprintf(log_file,"%s\n",str);
  }
  if(log_index == N_LOG) {
    ////////////////////
    // Free up a line 
    ////////////////////
    int i;
    if(log_lines[0] != NULL)
      free(log_lines[0]);
    for(i = 1; i < N_LOG; i++) {
      log_lines[i-1] = log_lines[i];
    }	    
    log_lines[N_LOG-1] = NULL;
    log_index--;
    log_changed = 1;
  }  

  log_lines[log_index] = malloc(strlen(str)+1);

  if(log_lines[log_index] == NULL)
    return;

  log_changed = 1;
  strcpy(log_lines[log_index],str);
  log_index++;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
movq %rdi, %rbx
movq 0xbd6c(%rip), %rdi      # 0x10b00
testq %rdi, %rdi
je 0x4daa
leaq 0x37b0(%rip), %rsi      # 0x8550
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2140
movl 0xbe84(%rip), %ebp      # 0x10c34
cmpl $0x6, %ebp
jne 0x4e0a
movq 0xbe84(%rip), %rdi      # 0x10c40
testq %rdi, %rdi
je 0x4dc6
callq 0x2040
movups 0xbe7b(%rip), %xmm0     # 0x10c48
movaps %xmm0, 0xbe6c(%rip)     # 0x10c40
movups 0xbe7d(%rip), %xmm0     # 0x10c58
movaps %xmm0, 0xbe6e(%rip)     # 0x10c50
movq 0xbe7f(%rip), %rax      # 0x10c68
movq %rax, 0xbe70(%rip)      # 0x10c60
movq $0x0, 0xbe6d(%rip) # 0x10c68
decl %ebp
movl %ebp, 0xbe31(%rip)      # 0x10c34
movb $0x0, 0xbe1e(%rip)      # 0x10c28
movq %rbx, %rdi
callq 0x20a0
leaq 0x1(%rax), %rdi
callq 0x2190
movslq 0xbe12(%rip), %r14      # 0x10c34
leaq 0xbe17(%rip), %rcx      # 0x10c40
movq %rax, (%rcx,%r14,8)
testq %rax, %rax
je 0x4e4e
movb $0x0, 0xbdef(%rip)      # 0x10c28
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2070
incl %r14d
movl %r14d, 0xbde6(%rip)     # 0x10c34
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/hamsternz[P]emulate-risc-v/display.c
// Function: display_trace
void display_trace(char *str) {
  int i; 
  trace_changed = 1;

  if(trace_index == N_TRACE) {
    char *temp;
    ////////////////////
    // Move top line to the bottom (to be overwritten)
    ////////////////////
    temp = trace_lines[0];
    for(i = 1; i < N_TRACE; i++) {
      trace_lines[i-1] = trace_lines[i];
    }
    trace_lines[N_TRACE-1] = temp;
    trace_index--;
  } 

  if(trace_lines[trace_index] == NULL)
    return;

  for(i = 0; str[i] != '\0' && i < TRACE_WIDTH; i++){
    trace_lines[trace_index][i] = str[i];
  }

  for(; i < TRACE_WIDTH; i++) {
    trace_lines[trace_index][i] = ' ';
  }

  trace_index++;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
movq %rdi, %rbx
movb $0x0, 0xbdcb(%rip)      # 0x10c2c
movl 0xbe09(%rip), %ebp      # 0x10c70
cmpl $0x11, %ebp
jne 0x4e9a
movq 0xbc9d(%rip), %r14      # 0x10b10
leaq 0xbc96(%rip), %rdi      # 0x10b10
leaq 0xbc97(%rip), %rsi      # 0x10b18
movl $0x80, %edx
callq 0x21b0
movq %r14, 0xbcfe(%rip)      # 0x10b90
decl %ebp
movl %ebp, 0xbdd6(%rip)      # 0x10c70
movslq 0xbdcf(%rip), %r14      # 0x10c70
leaq 0xbc68(%rip), %rax      # 0x10b10
movq (%rax,%r14,8), %rdi
testq %rdi, %rdi
je 0x4efd
movb (%rbx), %dl
testb %dl, %dl
je 0x4ed3
xorl %ecx, %ecx
movb %dl, (%rdi,%rcx)
leaq 0x1(%rcx), %rax
cmpq $0x32, %rcx
ja 0x4ed5
movb 0x1(%rbx,%rcx), %dl
movq %rax, %rcx
testb %dl, %dl
jne 0x4eb9
jmp 0x4ed5
xorl %eax, %eax
cmpl $0x33, %eax
ja 0x4ef3
movl %eax, %ecx
addq %rcx, %rdi
movl $0x33, %edx
subl %eax, %edx
incq %rdx
movl $0x20, %esi
callq 0x20f0
incl %r14d
movl %r14d, 0xbd73(%rip)     # 0x10c70
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/hamsternz[P]emulate-risc-v/display.c
// Function: display_process_input
void display_process_input(int *run, int *quit, int *trace, int *reset) {
  int key = getch();
  switch(key) {
    case 'R':
       *reset = 1;
       break;
    case 'r':
       *run = *run ? 0 : 2;
       break;
    case 't':
       *trace = !*trace;
       break;
    case 'q':
       *quit = !*quit;
       break;
    case ' ':
       *run = 1;
       break;
  }
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rcx, %r15
movq %rdx, %r14
movq %rsi, %r12
movq %rdi, %rbx
movq 0x70bb(%rip), %rax      # 0xbfd8
movq (%rax), %rdi
callq 0x2080
cmpl $0x70, %eax
jle 0x4f47
cmpl $0x71, %eax
je 0x4f5a
cmpl $0x72, %eax
je 0x4f6a
cmpl $0x74, %eax
jne 0x4f7e
xorl %eax, %eax
cmpl $0x0, (%r14)
sete %al
movl %eax, (%r14)
jmp 0x4f7e
cmpl $0x20, %eax
je 0x4f78
cmpl $0x52, %eax
jne 0x4f7e
movl $0x1, (%r15)
jmp 0x4f7e
xorl %eax, %eax
cmpl $0x0, (%r12)
sete %al
movl %eax, (%r12)
jmp 0x4f7e
xorl %eax, %eax
cmpl $0x0, (%rbx)
sete %al
addl %eax, %eax
movl %eax, (%rbx)
jmp 0x4f7e
movl $0x1, (%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O1/hamsternz[P]emulate-risc-v/display.c
// Function: display_uart_write
void display_uart_write(char c) {

  /* Only display printable characters */
  if(c > 27 && c < 127) {
    uart_lines[uart_cursor_y][uart_cursor_x] = c;
    uart_cursor_x++;
  }

  /* Caridge return brings the cursor to the left */
  if(c == '\r') {
    uart_cursor_x = 0;
  }

  /* Do we need to move to the next line? */
  if(c == '\n' || uart_cursor_x == UART_WIDTH) {
    uart_cursor_y++;
    uart_cursor_x = 0;
    /* Have we run out of lines */
    if(uart_cursor_y == N_UART) {
      /* shuffle the lines up, moving the first line to the end */
      int i;
      char *t = uart_lines[0];
      for(i = 1; i < N_UART; i++) {
	uart_lines[i-1] = uart_lines[i];
      }
      uart_lines[N_UART-1] = t;

      /* Empty out the first line */
      memset(uart_lines[N_UART-1],' ', UART_WIDTH);
      uart_cursor_y--;
    }
  }
  uart_changed = 1;
}

// Assembly:
leal -0x1c(%rdi), %eax
cmpb $0x62, %al
ja 0x4fb7
movslq 0xbcdc(%rip), %rax      # 0x10c74
leaq 0xbc01(%rip), %rcx      # 0x10ba0
movq (%rcx,%rax,8), %rax
movslq 0xbcce(%rip), %rcx      # 0x10c78
movb %dil, (%rax,%rcx)
leal 0x1(%rcx), %eax
movl %eax, 0xbcc1(%rip)      # 0x10c78
cmpb $0xd, %dil
jne 0x4fc7
movl $0x0, 0xbcb1(%rip)      # 0x10c78
cmpb $0xa, %dil
je 0x4fd6
cmpl $0x50, 0xbca4(%rip)     # 0x10c78
jne 0x504c
movl 0xbc98(%rip), %eax      # 0x10c74
leal 0x1(%rax), %ecx
movl %ecx, 0xbc8f(%rip)      # 0x10c74
movl $0x0, 0xbc89(%rip)      # 0x10c78
cmpl $0x6, %ecx
jne 0x504c
movq 0xbba5(%rip), %rcx      # 0x10ba0
movups 0xbba6(%rip), %xmm0     # 0x10ba8
movups 0xbbaf(%rip), %xmm1     # 0x10bb8
movaps %xmm1, 0xbba0(%rip)     # 0x10bb0
movq 0xbbb1(%rip), %rdx      # 0x10bc8
movq %rdx, 0xbba2(%rip)      # 0x10bc0
movaps %xmm0, 0xbb7b(%rip)     # 0x10ba0
movq %rcx, 0xbb9c(%rip)      # 0x10bc8
movaps 0x346d(%rip), %xmm0     # 0x84a0
movups %xmm0, 0x40(%rcx)
movups %xmm0, 0x30(%rcx)
movups %xmm0, 0x20(%rcx)
movups %xmm0, 0x10(%rcx)
movups %xmm0, (%rcx)
movl %eax, 0xbc28(%rip)      # 0x10c74
movb $0x0, 0xbbdd(%rip)      # 0x10c30
retq
// File: /workspace/github_c_makefile_star2_O1/hamsternz[P]emulate-risc-v/display.c
// Function: display_end
void display_end(void) {
  int i;
  if(log_file != NULL) {
    fclose(log_file);
    log_file = NULL;
  }
  for(i = 0; i < N_TRACE; i++) {
    if(trace_lines[i] != NULL)
      free(trace_lines[i]);
  }
  endwin();
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq 0xbaa1(%rip), %rdi      # 0x10b00
testq %rdi, %rdi
je 0x5074
callq 0x2090
movq $0x0, 0xba8c(%rip) # 0x10b00
xorl %ebx, %ebx
leaq 0xba93(%rip), %r14      # 0x10b10
movq (%rbx,%r14), %rdi
testq %rdi, %rdi
je 0x508b
callq 0x2040
addq $0x8, %rbx
cmpq $0x88, %rbx
jne 0x507d
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x2220
// File: /workspace/github_c_makefile_star2_O1/hamsternz[P]emulate-risc-v/prci.c
// Function: PRCI_init
int PRCI_init(struct region *r) {
  uint32_t *data;

  if(r->data != NULL) {
    display_log("PRCI already initialized");
    return 0;
  }
 
  data = malloc(r->size);
  if(data == NULL){
    return 0;
  }
  r->data = (void *)data;
  memset(r->data, 0, r->size);
  display_log("Set up PRCI region");
  return 1;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
cmpq $0x0, 0x38(%rdi)
je 0x50ba
xorl %ebx, %ebx
leaq 0x3507(%rip), %rdi      # 0x85bf
jmp 0x50ea
movq %rdi, %r14
movl 0xc(%rdi), %ebx
movq %rbx, %rdi
callq 0x2190
testq %rax, %rax
je 0x50f9
movq %rax, 0x38(%r14)
movq %rax, %rdi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x20f0
movl $0x1, %ebx
leaq 0x34ee(%rip), %rdi      # 0x85d8
callq 0x4d86
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
xorl %ebx, %ebx
jmp 0x50ef
// File: /workspace/github_c_makefile_star2_O1/hamsternz[P]emulate-risc-v/prci.c
// Function: PRCI_set
int PRCI_set(struct region *r, uint32_t address, uint8_t mask, uint32_t value) {
   char buffer[100];
   if(address+4 > r->size) {
     fprintf(stderr,"Memory region boundary crossed at 0x%08x\n", r->base+address);
     return 0;
   }

   if((address & 3) != 0) {
     fprintf(stderr,"Unaligned memory write 0x%08x\n", r->base+address);
   }
   sprintf(buffer,"PRCI Wr address 0x%08x: 0x%08x", address, value);
   display_log(buffer);

   if(mask & 1) {
      ((unsigned char *)r->data)[address+0] = value; 
   }
   if(mask & 2) {
      ((unsigned char *)r->data)[address+1] = value>>8; 
   }
   if(mask & 4) {
      ((unsigned char *)r->data)[address+2] = value>>16; 
   }
   if(mask & 8) {
      ((unsigned char *)r->data)[address+3] = value>>24; 
   }
   return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x70, %rsp
movl %esi, %ebx
movq %rdi, %r14
leal 0x4(%rbx), %eax
cmpl 0xc(%rdi), %eax
ja 0x51af
movl %ecx, %r12d
movl %edx, %ebp
testb $0x3, %bl
jne 0x51d2
leaq 0x34bc(%rip), %rsi      # 0x85eb
movq %rsp, %r15
movq %r15, %rdi
movl %ebx, %edx
movl %r12d, %ecx
xorl %eax, %eax
callq 0x2200
movq %r15, %rdi
callq 0x4d86
testb $0x1, %bpl
je 0x515b
movq 0x38(%r14), %rax
movl %ebx, %ecx
movl %r12d, %edx
movb %dl, (%rax,%rcx)
testb $0x2, %bpl
je 0x516e
movq 0x38(%r14), %rax
leal 0x1(%rbx), %ecx
movl %r12d, %edx
movb %dh, (%rax,%rcx)
testb $0x4, %bpl
je 0x5184
movl %r12d, %eax
shrl $0x10, %eax
movq 0x38(%r14), %rcx
leal 0x2(%rbx), %edx
movb %al, (%rcx,%rdx)
movl $0x1, %r15d
testb $0x8, %bpl
je 0x519f
shrl $0x18, %r12d
movq 0x38(%r14), %rax
addl $0x3, %ebx
movb %r12b, (%rax,%rbx)
movl %r15d, %eax
addq $0x70, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq 0x6e42(%rip), %rax      # 0xbff8
movq (%rax), %rdi
addl 0x8(%r14), %ebx
leaq 0x2ddb(%rip), %rsi      # 0x7f9f
xorl %r15d, %r15d
movl %ebx, %edx
xorl %eax, %eax
callq 0x2140
jmp 0x519f
movq 0x6e1f(%rip), %rax      # 0xbff8
movq (%rax), %rdi
movl 0x8(%r14), %edx
addl %ebx, %edx
leaq 0x2de0(%rip), %rsi      # 0x7fc9
xorl %eax, %eax
callq 0x2140
jmp 0x5128
// File: /workspace/github_c_makefile_star2_O1/hamsternz[P]emulate-risc-v/prci.c
// Function: PRCI_get
int PRCI_get(struct region *r, uint32_t address, uint32_t *value) {
   uint32_t v = 0;
   char buffer[100];
   if((address & 3) != 0) {
     fprintf(stderr,"Unaligned memory read 0x%08x\n", r->base+address);
     return 0;
   }

   if(address+4 > r->size) {
     fprintf(stderr,"Memory region boundary crossed at 0x%08x\n", r->base+address);
     return 0;
   }

   v = ((unsigned char *)r->data)[address]; 
   v = v + (((unsigned char *)r->data)[address+1] << 8); 
   v = v + (((unsigned char *)r->data)[address+2] << 16); 
   v = v + (((unsigned char *)r->data)[address+3] << 24); 

   switch(address) {
     case 0:
       v |= 1<<31; // HF Lock flag
       break;
     case 8:
       v |= 1<<31; // PLL Lock flag
       break;    
   }
   *value = v;
     
   sprintf(buffer,"PRCI Rd address 0x%08x: 0x%08x", address, v);
   display_log(buffer);

   return 1;
}

// Assembly:
pushq %rbx
subq $0x70, %rsp
movq %rdx, %rax
movl %esi, %edx
testb $0x3, %dl
jne 0x524f
leal 0x4(%rdx), %ecx
cmpl 0xc(%rdi), %ecx
ja 0x5265
movq 0x38(%rdi), %rcx
movl %edx, %esi
movl (%rcx,%rsi), %ecx
cmpl $0x8, %edx
je 0x521e
testl %edx, %edx
jne 0x5224
orl $0x80000000, %ecx       # imm = 0x80000000
movl %ecx, (%rax)
leaq 0x33dd(%rip), %rsi      # 0x860a
movq %rsp, %rbx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x2200
movq %rbx, %rdi
callq 0x4d86
movl $0x1, %ebx
movl %ebx, %eax
addq $0x70, %rsp
popq %rbx
retq
movq 0x6da2(%rip), %rax      # 0xbff8
movq (%rax), %rax
addl 0x8(%rdi), %edx
leaq 0x2d85(%rip), %rsi      # 0x7fe8
jmp 0x5279
movq 0x6d8c(%rip), %rax      # 0xbff8
movq (%rax), %rax
addl 0x8(%rdi), %edx
leaq 0x2d26(%rip), %rsi      # 0x7f9f
xorl %ebx, %ebx
movq %rax, %rdi
xorl %eax, %eax
callq 0x2140
jmp 0x5247
// File: /workspace/github_c_makefile_star2_O1/hamsternz[P]emulate-risc-v/prci.c
// Function: PRCI_free
void PRCI_free(struct region *r) {
   char buffer[100];
   sprintf(buffer, "Releasing PRCI at 0x%08x", r->base);
   display_log(buffer);
   if(r->data != NULL) 
     free(r->data);
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x68, %rsp
movq %rdi, %rbx
movl 0x8(%rdi), %edx
leaq 0x3301(%rip), %rsi      # 0x8644
movq %rsp, %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x2200
movq %r14, %rdi
callq 0x4d86
movq 0x38(%rbx), %rdi
testq %rdi, %rdi
je 0x5366
callq 0x2040
addq $0x68, %rsp
popq %rbx
popq %r14
retq
nop
// File: /workspace/github_c_makefile_star2_O1/hamsternz[P]emulate-risc-v/rom.c
// Function: ROM_init
int ROM_init(struct region *r) {
  uint32_t *data;

  if(r->data != NULL) {
    display_log("ROM already initialized");
    return 0;
  }
 
  data = malloc(r->size);
  if(data == NULL){
    return 0;
  }
  r->data = (void *)data;
  memset(r->data, 0, r->size);
  attempt_to_read(r);
  display_log("Set up memory region");
  return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
cmpq $0x0, 0x38(%rdi)
je 0x5393
xorl %ebx, %ebx
leaq 0x32cf(%rip), %rdi      # 0x865d
jmp 0x555a
movq %rdi, %rbx
movl 0xc(%rdi), %r15d
movq %r15, %rdi
callq 0x2190
testq %rax, %rax
je 0x5526
movq %rax, %r14
movq %rax, 0x38(%rbx)
movq %rax, %rdi
xorl %esi, %esi
movq %r15, %rdx
callq 0x20f0
movl 0x8(%rbx), %edx
leaq 0x32f7(%rip), %rsi      # 0x86c0
leaq 0x8(%rsp), %rdi
xorl %eax, %eax
callq 0x21a0
testl %eax, %eax
jle 0x552a
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x5542
leaq 0x2cb3(%rip), %rsi      # 0x80a5
callq 0x21c0
testq %rax, %rax
je 0x5570
movq %rax, %r15
movq 0x8(%rsp), %rdi
callq 0x2040
xorl %r13d, %r13d
movq %r15, %rdi
callq 0x2110
cmpl $0xa, %eax
je 0x5410
cmpl $0xd, %eax
je 0x5410
cmpl $-0x1, %eax
jne 0x5442
leaq 0x2c91(%rip), %rdi      # 0x80bf
movl %r13d, %esi
xorl %eax, %eax
callq 0x20c0
movl $0x3, %eax
jmp 0x54d5
leal -0x30(%rax), %ebp
cmpl $0x9, %ebp
jbe 0x5471
leal -0x41(%rax), %ecx
cmpl $0x5, %ecx
ja 0x5457
addl $-0x37, %eax
jmp 0x5462
leal -0x61(%rax), %ecx
cmpl $0x5, %ecx
ja 0x5466
addl $-0x57, %eax
movl %eax, %ebp
jmp 0x5471
xorl %ebp, %ebp
cmpl $0x20, %eax
jne 0x551f
movl $0x7, %r12d
movq %r15, %rdi
callq 0x2110
leal -0x30(%rax), %ecx
cmpl $0x9, %ecx
ja 0x548e
shll $0x4, %ebp
orl %ecx, %ebp
jmp 0x54b0
leal -0x41(%rax), %ecx
cmpl $0x5, %ecx
ja 0x54a0
shll $0x4, %ebp
addl %eax, %ebp
addl $-0x37, %ebp
jmp 0x54b0
leal -0x61(%rax), %ecx
cmpl $0x5, %ecx
ja 0x54df
shll $0x4, %ebp
addl %eax, %ebp
addl $-0x57, %ebp
decl %r12d
jne 0x5477
movslq %r13d, %rcx
movl %ebp, (%r14,%rcx,4)
incl %r13d
cmpl $-0x1, %eax
je 0x54d3
cmpl $0xa, %eax
je 0x54d3
movq %r15, %rdi
callq 0x2110
jmp 0x54bf
xorl %eax, %eax
testl %eax, %eax
je 0x5410
jmp 0x5533
cmpl $0x20, %eax
ja 0x550c
movl %eax, %ecx
movabsq $0x100000600, %rdx      # imm = 0x100000600
btq %rcx, %rdx
jae 0x550c
leal 0x3(,%r13,4), %ecx
cmpl 0xc(%rbx), %ecx
jb 0x54b5
leaq 0x2bef(%rip), %rdi      # 0x80f9
jmp 0x5513
leaq 0x2c06(%rip), %rdi      # 0x8119
callq 0x4d86
movl $0x1, %eax
jmp 0x54d5
callq 0x2320
jmp 0x5518
xorl %ebx, %ebx
jmp 0x555f
leaq 0x2b20(%rip), %rdi      # 0x8051
jmp 0x5549
cmpl $0x3, %eax
jne 0x554e
movq %r15, %rdi
callq 0x2090
jmp 0x554e
leaq 0x2b33(%rip), %rdi      # 0x807c
callq 0x4d86
movl $0x1, %ebx
leaq 0x2a30(%rip), %rdi      # 0x7f8a
callq 0x4d86
movl %ebx, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%rsp), %rdx
leaq 0x2b2c(%rip), %rsi      # 0x80a8
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x2200
movq %rbx, %rdi
callq 0x4d86
movq 0x8(%rsp), %rdi
callq 0x2040
jmp 0x554e
// File: /workspace/github_c_makefile_star2_O1/hamsternz[P]emulate-risc-v/rom.c
// Function: ROM_set
int ROM_set(struct region *r, uint32_t address, uint8_t mask, uint32_t value) {

   if(address+4 > r->size) {
     fprintf(stderr,"Memory region boundary crossed at 0x%08x\n", r->base+address);
     return 0;
   }

   if((address & 3) != 0) {
     fprintf(stderr,"Unaligned memory write 0x%08x\n", r->base+address);
   }
   display_log("Attempt to write to ROM\n");
   return 1;
}

// Assembly:
pushq %rbx
movl %esi, %edx
leal 0x4(%rdx), %eax
cmpl 0xc(%rdi), %eax
ja 0x55c4
testb $0x3, %dl
jne 0x55e6
leaq 0x30bf(%rip), %rdi      # 0x8675
callq 0x4d86
movl $0x1, %ebx
movl %ebx, %eax
popq %rbx
retq
movq 0x6a2d(%rip), %rax      # 0xbff8
movq (%rax), %rax
addl 0x8(%rdi), %edx
leaq 0x29c7(%rip), %rsi      # 0x7f9f
xorl %ebx, %ebx
movq %rax, %rdi
xorl %eax, %eax
callq 0x2140
jmp 0x55c0
movq 0x6a0b(%rip), %rax      # 0xbff8
movq (%rax), %rax
addl 0x8(%rdi), %edx
leaq 0x29cf(%rip), %rsi      # 0x7fc9
movq %rax, %rdi
xorl %eax, %eax
callq 0x2140
jmp 0x55af
// File: /workspace/github_c_makefile_star2_O1/hamsternz[P]emulate-risc-v/rom.c
// Function: ROM_free
void ROM_free(struct region *r) {
   char buffer[100];
   sprintf(buffer, "Releasing ROM at 0x%08x", r->base);
   display_log(buffer);
   if(r->data != NULL) 
     free(r->data);
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x68, %rsp
movq %rdi, %rbx
movl 0x8(%rdi), %edx
leaq 0x2f89(%rip), %rsi      # 0x86a8
movq %rsp, %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x2200
movq %r14, %rdi
callq 0x4d86
movq 0x38(%rbx), %rdi
testq %rdi, %rdi
je 0x5742
callq 0x2040
addq $0x68, %rsp
popq %rbx
popq %r14
retq
nop
// File: /workspace/github_c_makefile_star2_O1/hamsternz[P]emulate-risc-v/spi.c
// Function: SPI_init
int SPI_init(struct region *r) {
  uint32_t *data;

  if(r->data != NULL) {
    display_log("SPI already initialized");
    return 0;
  }
 
  data = malloc(r->size);
  if(data == NULL){
    return 0;
  }
  r->data = (void *)data;
  memset(r->data, 0, r->size);
  display_log("Set up SPI region");
  return 1;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
cmpq $0x0, 0x38(%rdi)
je 0x5762
xorl %ebx, %ebx
leaq 0x2f6d(%rip), %rdi      # 0x86cd
jmp 0x5792
movq %rdi, %r14
movl 0xc(%rdi), %ebx
movq %rbx, %rdi
callq 0x2190
testq %rax, %rax
je 0x57a1
movq %rax, 0x38(%r14)
movq %rax, %rdi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x20f0
movl $0x1, %ebx
leaq 0x2f53(%rip), %rdi      # 0x86e5
callq 0x4d86
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
xorl %ebx, %ebx
jmp 0x5797
// File: /workspace/github_c_makefile_star2_O1/hamsternz[P]emulate-risc-v/spi.c
// Function: SPI_get
int SPI_get(struct region *r, uint32_t address, uint32_t *value) {
   uint32_t v = 0;
   char buffer[100];
   if((address & 3) != 0) {
     fprintf(stderr,"Unaligned memory read 0x%08x\n", r->base+address);
     return 0;
   }

   if(address+4 > r->size) {
     fprintf(stderr,"Memory region boundary crossed at 0x%08x\n", r->base+address);
     return 0;
   }

   v = ((unsigned char *)r->data)[address]; 
   v = v + (((unsigned char *)r->data)[address+1] << 8); 
   v = v + (((unsigned char *)r->data)[address+2] << 16); 
   v = v + (((unsigned char *)r->data)[address+3] << 24); 

   if(address == 0)
     v |= 1<<31;
   *value = v;
     
   sprintf(buffer,"SPI Rd address 0x%08x: 0x%08x", address, v);
   display_log(buffer);

   return 1;
}

// Assembly:
pushq %rbx
subq $0x70, %rsp
movq %rdx, %rax
movl %esi, %edx
testb $0x3, %dl
jne 0x58f5
leal 0x4(%rdx), %ecx
cmpl 0xc(%rdi), %ecx
ja 0x590b
movq 0x38(%rdi), %rcx
movl %edx, %esi
movl (%rcx,%rsi), %esi
movl %esi, %ecx
orl $0x80000000, %ecx       # imm = 0x80000000
testl %edx, %edx
cmovnel %esi, %ecx
movl %ecx, (%rax)
leaq 0x2e42(%rip), %rsi      # 0x8715
movq %rsp, %rbx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x2200
movq %rbx, %rdi
callq 0x4d86
movl $0x1, %ebx
movl %ebx, %eax
addq $0x70, %rsp
popq %rbx
retq
movq 0x66fc(%rip), %rax      # 0xbff8
movq (%rax), %rax
addl 0x8(%rdi), %edx
leaq 0x26df(%rip), %rsi      # 0x7fe8
jmp 0x591f
movq 0x66e6(%rip), %rax      # 0xbff8
movq (%rax), %rax
addl 0x8(%rdi), %edx
leaq 0x2680(%rip), %rsi      # 0x7f9f
xorl %ebx, %ebx
movq %rax, %rdi
xorl %eax, %eax
callq 0x2140
jmp 0x58ed
// File: /workspace/github_c_makefile_star2_O1/hamsternz[P]emulate-risc-v/spi.c
// Function: SPI_free
void SPI_free(struct region *r) {
   char buffer[100];
   sprintf(buffer, "Releasing SPI at 0x%08x", r->base);
   display_log(buffer);
   if(r->data != NULL) 
     free(r->data);
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x68, %rsp
movq %rdi, %rbx
movl 0x8(%rdi), %edx
leaq 0x2d64(%rip), %rsi      # 0x874d
movq %rsp, %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x2200
movq %r14, %rdi
callq 0x4d86
movq 0x38(%rbx), %rdi
testq %rdi, %rdi
je 0x5a0c
callq 0x2040
addq $0x68, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O1/hamsternz[P]emulate-risc-v/clint.c
// Function: CLINT_init
int CLINT_init(struct region *r) {
  uint32_t *data;

  if(r->data != NULL) {
    display_log("CLINT already initialized");
    return 0;
  }
 
  data = malloc(r->size);
  if(data == NULL){
    return 0;
  }
  r->data = (void *)data;
  memset(r->data, 0, r->size);
  display_log("Set up CLINT region");
  return 1;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
cmpq $0x0, 0x38(%rdi)
je 0x5a2a
xorl %ebx, %ebx
leaq 0x2d3d(%rip), %rdi      # 0x8765
jmp 0x5a5a
movq %rdi, %r14
movl 0xc(%rdi), %ebx
movq %rbx, %rdi
callq 0x2190
testq %rax, %rax
je 0x5a69
movq %rax, 0x38(%r14)
movq %rax, %rdi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x20f0
movl $0x1, %ebx
leaq 0x2d25(%rip), %rdi      # 0x877f
callq 0x4d86
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
xorl %ebx, %ebx
jmp 0x5a5f
// File: /workspace/github_c_makefile_star2_O1/hamsternz[P]emulate-risc-v/clint.c
// Function: CLINT_get
int CLINT_get(struct region *r, uint32_t address, uint32_t *value) {
   uint32_t v = 0;
   char buffer[100];
   if((address & 3) != 0) {
     fprintf(stderr,"Unaligned memory read 0x%08x\n", r->base+address);
     return 0;
   }

   if(address+4 > r->size) {
     fprintf(stderr,"Memory region boundary crossed at 0x%08x\n", r->base+address);
     return 0;
   }

   v = ((unsigned char *)r->data)[address]; 
   v = v + (((unsigned char *)r->data)[address+1] << 8); 
   v = v + (((unsigned char *)r->data)[address+2] << 16); 
   v = v + (((unsigned char *)r->data)[address+3] << 24); 

   switch(address) {
     case 0x0000: // MSIP regs
        *value = v;
	break;
     case 0x4000: // Timer Compare Reg
        *value = v;
	break;
     case 0x4004:
        *value = v;
	break;
     case 0xBFF8:   // Cycle count
        *value = riscv_cycle_count_l();
	break;
     case 0xBFFC:
        *value = riscv_cycle_count_h();
	break;
     default:
        sprintf(buffer,"CLINT Rd of non-register address 0x%08x", address);
        display_log(buffer);
	*value = 0;
	return 1;
   }
     
   sprintf(buffer,"CLINT Rd address 0x%08x: 0x%08x", address, v);
   display_log(buffer);

   return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x68, %rsp
movl %esi, %ebx
testb $0x3, %bl
jne 0x5c2a
leal 0x4(%rbx), %eax
cmpl 0xc(%rdi), %eax
ja 0x5c40
movq %rdx, %r14
movq 0x38(%rdi), %rax
movl %ebx, %ecx
movl (%rax,%rcx), %ebp
movl %ebp, %eax
cmpl $0x4003, %ebx           # imm = 0x4003
jle 0x5bbb
cmpl $0x4004, %ebx           # imm = 0x4004
je 0x5bf5
cmpl $0xbffc, %ebx           # imm = 0xBFFC
je 0x5bf0
cmpl $0xbff8, %ebx           # imm = 0xBFF8
jne 0x5bc9
callq 0x2f93
jmp 0x5bf5
testl %ebx, %ebx
je 0x5bf5
movl %ebp, %eax
cmpl $0x4000, %ebx           # imm = 0x4000
je 0x5bf5
leaq 0x2be3(%rip), %rsi      # 0x87b3
movq %rsp, %r15
movq %r15, %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0x2200
movq %r15, %rdi
callq 0x4d86
movl $0x0, (%r14)
jmp 0x5c18
callq 0x2f9a
movl %eax, (%r14)
leaq 0x2bdc(%rip), %rsi      # 0x87db
movq %rsp, %r14
movq %r14, %rdi
movl %ebx, %edx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x2200
movq %r14, %rdi
callq 0x4d86
movl $0x1, %ebp
movl %ebp, %eax
addq $0x68, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq 0x63c7(%rip), %rax      # 0xbff8
movq (%rax), %rax
addl 0x8(%rdi), %ebx
leaq 0x23aa(%rip), %rsi      # 0x7fe8
jmp 0x5c54
movq 0x63b1(%rip), %rax      # 0xbff8
movq (%rax), %rax
addl 0x8(%rdi), %ebx
leaq 0x234b(%rip), %rsi      # 0x7f9f
xorl %ebp, %ebp
movq %rax, %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0x2140
jmp 0x5c1d
// File: /workspace/github_c_makefile_star2_O1/hamsternz[P]emulate-risc-v/clint.c
// Function: CLINT_free
void CLINT_free(struct region *r) {
   char buffer[100];
   sprintf(buffer, "Releasing CLINT at 0x%08x", r->base);
   display_log(buffer);
   if(r->data != NULL) 
     free(r->data);
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x68, %rsp
movq %rdi, %rbx
movl 0x8(%rdi), %edx
leaq 0x2af7(%rip), %rsi      # 0x8817
movq %rsp, %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x2200
movq %r14, %rdi
callq 0x4d86
movq 0x38(%rbx), %rdi
testq %rdi, %rdi
je 0x5d43
callq 0x2040
addq $0x68, %rsp
popq %rbx
popq %r14
retq
nop
// File: /workspace/github_c_makefile_star2_O1/hamsternz[P]emulate-risc-v/gpio.c
// Function: GPIO_init
int GPIO_init(struct region *r) {
  uint32_t *data;

  if(r->data != NULL) {
    display_log("GPIO already initialized");
    return 0;
  }
 
  data = malloc(r->size);
  if(data == NULL){
    return 0;
  }
  r->data = (void *)data;
  memset(r->data, 0, r->size);
  display_log("Set up GPIO region");
  return 1;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
cmpq $0x0, 0x38(%rdi)
je 0x5d62
xorl %ebx, %ebx
leaq 0x2ad1(%rip), %rdi      # 0x8831
jmp 0x5d92
movq %rdi, %r14
movl 0xc(%rdi), %ebx
movq %rbx, %rdi
callq 0x2190
testq %rax, %rax
je 0x5da1
movq %rax, 0x38(%r14)
movq %rax, %rdi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x20f0
movl $0x1, %ebx
leaq 0x2ab8(%rip), %rdi      # 0x884a
callq 0x4d86
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
xorl %ebx, %ebx
jmp 0x5d97
// File: /workspace/github_c_makefile_star2_O1/hamsternz[P]emulate-risc-v/gpio.c
// Function: GPIO_free
void GPIO_free(struct region *r) {
   char buffer[100];
   sprintf(buffer, "Releasing GPIO at 0x%08x", r->base);
   display_log(buffer);
   if(r->data != NULL) 
     free(r->data);
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x68, %rsp
movq %rdi, %rbx
movl 0x8(%rdi), %edx
leaq 0x28da(%rip), %rsi      # 0x88b6
movq %rsp, %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x2200
movq %r14, %rdi
callq 0x4d86
movq 0x38(%rbx), %rdi
testq %rdi, %rdi
je 0x5fff
callq 0x2040
addq $0x68, %rsp
popq %rbx
popq %r14
retq
nop
// File: /workspace/github_c_makefile_star2_O1/hamsternz[P]emulate-risc-v/memory.c
// Function: memory_read_request
uint32_t memory_read_request(uint32_t address) {
  if(read_request_fifo.count == FIFO_SIZE)
    return 0;
  read_request_fifo.address[read_request_fifo.write_ptr] = address;
  read_request_fifo.count++;
  read_request_fifo.write_ptr = (read_request_fifo.write_ptr == FIFO_SIZE-1) ? 0 : read_request_fifo.write_ptr+1;
  return 1;
}

// Assembly:
movl 0xacaf(%rip), %ecx      # 0x10d48
xorl %eax, %eax
cmpl $0x8, %ecx
je 0x60d3
movl 0xac9e(%rip), %eax      # 0x10d44
leaq 0xac93(%rip), %rdx      # 0x10d40
incl %ecx
leal 0x1(%rax), %esi
xorl %r8d, %r8d
cmpq $0x7, %rax
movl %edi, 0xc(%rdx,%rax,4)
movl %ecx, 0xac85(%rip)      # 0x10d48
cmovnel %esi, %r8d
movl %r8d, 0xac76(%rip)      # 0x10d44
movl $0x1, %eax
retq
// File: /workspace/github_c_makefile_star2_O1/hamsternz[P]emulate-risc-v/memory.c
// Function: memory_fetch_request
uint32_t memory_fetch_request(uint32_t address) {
  if(fetch_request_fifo.count == FIFO_SIZE)
    return 0;

  fetch_request_fifo.address[fetch_request_fifo.write_ptr] = address;
  fetch_request_fifo.count++;
  fetch_request_fifo.write_ptr = (fetch_request_fifo.write_ptr == FIFO_SIZE-1) ? 0 : fetch_request_fifo.write_ptr+1;

  return 1;
}

// Assembly:
movl 0xac9a(%rip), %ecx      # 0x10d74
xorl %eax, %eax
cmpl $0x8, %ecx
je 0x6114
movl 0xac89(%rip), %eax      # 0x10d70
leaq 0xac7e(%rip), %rdx      # 0x10d6c
incl %ecx
leal 0x1(%rax), %esi
xorl %r8d, %r8d
cmpq $0x7, %rax
movl %edi, 0xc(%rdx,%rax,4)
movl %ecx, 0xac70(%rip)      # 0x10d74
cmovnel %esi, %r8d
movl %r8d, 0xac61(%rip)      # 0x10d70
movl $0x1, %eax
retq
// File: /workspace/github_c_makefile_star2_O1/hamsternz[P]emulate-risc-v/memory.c
// Function: memory_read_data
uint32_t memory_read_data(void) {
  uint32_t rtn;
  if(read_data_fifo.count == 0) {
    display_log("Attempt to read empty FIFO read_data");
    return 0;
  }

  rtn = read_data_fifo.data[read_data_fifo.read_ptr];
  read_data_fifo.count--;
  read_data_fifo.read_ptr = (read_data_fifo.read_ptr == FIFO_SIZE-1) ? 0 : read_data_fifo.read_ptr+1; 
  return rtn;
}

// Assembly:
movl 0xab4f(%rip), %ecx      # 0x10c84
testl %ecx, %ecx
je 0x6165
movl 0xab3d(%rip), %eax      # 0x10c7c
leaq 0xab36(%rip), %rdx      # 0x10c7c
decl %ecx
leal 0x1(%rax), %esi
xorl %edi, %edi
cmpq $0x7, %rax
movl 0xc(%rdx,%rax,4), %eax
movl %ecx, 0xab29(%rip)      # 0x10c84
cmovnel %esi, %edi
movl %edi, 0xab18(%rip)      # 0x10c7c
retq
pushq %rax
leaq 0x276f(%rip), %rdi      # 0x88dc
callq 0x4d86
xorl %eax, %eax
addq $0x8, %rsp
retq
// File: /workspace/github_c_makefile_star2_O1/hamsternz[P]emulate-risc-v/memory.c
// Function: memory_fetch_data
uint32_t memory_fetch_data(void) {
  uint32_t rtn;
  if(fetch_data_fifo.count == 0) {
    display_log("Attempt to read empty FIFO fetch_data");
    return 0;
  }

  rtn = fetch_data_fifo.data[fetch_data_fifo.read_ptr];
  fetch_data_fifo.count--;
  fetch_data_fifo.read_ptr = (fetch_data_fifo.read_ptr == FIFO_SIZE-1) ? 0 : fetch_data_fifo.read_ptr+1;
  return rtn;
}

// Assembly:
movl 0xab31(%rip), %ecx      # 0x10cb0
testl %ecx, %ecx
je 0x61af
movl 0xab1f(%rip), %eax      # 0x10ca8
leaq 0xab18(%rip), %rdx      # 0x10ca8
decl %ecx
leal 0x1(%rax), %esi
xorl %edi, %edi
cmpq $0x7, %rax
movl 0xc(%rdx,%rax,4), %eax
movl %ecx, 0xab0b(%rip)      # 0x10cb0
cmovnel %esi, %edi
movl %edi, 0xaafa(%rip)      # 0x10ca8
retq
pushq %rax
leaq 0x274a(%rip), %rdi      # 0x8901
callq 0x4d86
xorl %eax, %eax
addq $0x8, %rsp
retq
// File: /workspace/github_c_makefile_star2_O1/hamsternz[P]emulate-risc-v/memory.c
// Function: memory_write_request
int      memory_write_request(uint32_t address, uint32_t mask, uint32_t value) {
  if(write_request_fifo.count == FIFO_SIZE) {
    return 0;
  }
  write_request_fifo.address[write_request_fifo.write_ptr] = address;
  write_request_fifo.mask[write_request_fifo.write_ptr]    = mask;
  write_request_fifo.data[write_request_fifo.write_ptr]    = value;
  write_request_fifo.count++;
  write_request_fifo.write_ptr = (write_request_fifo.write_ptr == FIFO_SIZE-1) ? 0 : write_request_fifo.write_ptr+1;
  return 1; 
}

// Assembly:
movl 0xab06(%rip), %ecx      # 0x10cdc
xorl %eax, %eax
cmpl $0x8, %ecx
je 0x621c
movl 0xaaf5(%rip), %eax      # 0x10cd8
leaq 0xaaea(%rip), %r8       # 0x10cd4
incl %ecx
leal 0x1(%rax), %r9d
xorl %r10d, %r10d
cmpq $0x7, %rax
movl %edi, 0xc(%r8,%rax,4)
movl %esi, 0x2c(%r8,%rax,4)
movl %edx, 0x4c(%r8,%rax,4)
movl %ecx, 0xaad0(%rip)      # 0x10cdc
cmovnel %r9d, %r10d
movl %r10d, 0xaac1(%rip)     # 0x10cd8
movl $0x1, %eax
retq
// File: /workspace/github_c_makefile_star2_O1/FredTheDino[P]Fog/src/rain/editor_main.cpp
// Function: read_with_default(char const*, char const*, char*, unsigned int)
void read_with_default(const char *prompt, const char *def, char *val, u32 length) {
    s32 input_length;
    do {
        printf("%s", prompt);
        if (def)
            printf(" [%s]", def);
        printf(": ");

        fgets(val, length, stdin);
        input_length = strlen(val);
        if (val[MAX(input_length - 1, 0)] == '\n') {
            break;
        }

        printf("You passed in a too long string, max length is %d.\n", length);
        do {
            fgets(val, length, stdin);
            input_length = strlen(val);
        } while (val[MAX(input_length - 1, 0)] != '\n');
    } while (true);

    if (input_length == 2)
        memcpy((void *) def, (void *) val, strlen(def));
    else
        val[input_length - 1] = '\0';

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %ecx, %r15d
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, -0x30(%rbp)
movq 0x4c7eb(%rip), %r13     # 0x4efe8
movl $0x1, %r12d
leaq 0x2eab1(%rip), %rdi     # 0x312bb
movq -0x30(%rbp), %rsi
xorl %eax, %eax
callq 0x2080
testq %r14, %r14
je 0x282b
leaq 0x2d88f(%rip), %rdi     # 0x300b0
movq %r14, %rsi
xorl %eax, %eax
callq 0x2080
leaq 0x2e716(%rip), %rdi     # 0x30f48
xorl %eax, %eax
callq 0x2080
movq (%r13), %rdx
movq %rbx, %rdi
movl %r15d, %esi
callq 0x22f0
movq %rbx, %rdi
callq 0x2250
movslq %eax, %rcx
decq %rcx
testl %ecx, %ecx
movl $0x0, %edx
cmovgl %ecx, %edx
cmpb $0xa, (%rbx,%rdx)
je 0x28a1
leaq 0x2d849(%rip), %rdi     # 0x300b6
movl %r15d, %esi
xorl %eax, %eax
callq 0x2080
movq (%r13), %rdx
movq %rbx, %rdi
movl %r15d, %esi
callq 0x22f0
movq %rbx, %rdi
callq 0x2250
cmpl $0x2, %eax
cmovll %r12d, %eax
cmpb $0xa, -0x1(%rbx,%rax)
jne 0x2877
jmp 0x2803
cmpl $0x2, %eax
jne 0x28ca
movq %r14, %rdi
callq 0x2250
movq %r14, %rdi
movq %rbx, %rsi
movq %rax, %rdx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2090
movb $0x0, (%rbx,%rcx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/FredTheDino[P]Fog/src/rain/editor_main.cpp
// Function: write_sprite_to_file(EditableSprite, _IO_FILE*)
void write_sprite_to_file(EditableSprite sprite, FILE *file) {
    fprintf(file, "%s:#%llu:%d:", sprite.name,
            fog_asset_hash(sprite.sheet), sprite.points.size());

    Vec2 center = fog_V2(0, 0);
    for (u32 i = 0; i < sprite.points.size(); i++) {
        center += sprite.points[i];
    }
    center /= sprite.points.size();
    for (u32 i = 0; i < sprite.points.size(); i++) {
        Vec2 p = sprite.points[i];
        fprintf(file, "(%f %f %f %f)",
            p.x - center.x, p.y - center.y,
            p.x, p.y);
    }
    fprintf(file, "\n");
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x20, %rsp
movq %rsi, %rbx
movq %rdi, %r14
leaq 0x20(%rdi), %r15
movq 0x18(%rdi), %rdi
callq 0x2861a
movq 0x8(%r14), %r8
subq (%r14), %r8
sarq $0x3, %r8
leaq 0x2d7d9(%rip), %rsi     # 0x300ea
movq %rbx, %rdi
movq %r15, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x2170
xorps %xmm0, %xmm0
xorps %xmm1, %xmm1
callq 0x2899d
movaps %xmm0, %xmm4
movq (%r14), %rcx
movq 0x8(%r14), %rdx
movq %rdx, %rax
subq %rcx, %rax
sarq $0x3, %rax
cmpq %rcx, %rdx
je 0x2959
xorl %edx, %edx
movsd (%rcx,%rdx,8), %xmm0
addps %xmm0, %xmm4
incq %rdx
movl %edx, %esi
cmpq %rsi, %rax
ja 0x2947
testq %rax, %rax
js 0x2968
xorps %xmm0, %xmm0
cvtsi2ss %rax, %xmm0
jmp 0x2980
movq %rax, %rcx
shrq %rcx
andl $0x1, %eax
orq %rcx, %rax
xorps %xmm0, %xmm0
cvtsi2ss %rax, %xmm0
addss %xmm0, %xmm0
movq (%r14), %rax
cmpq %rax, 0x8(%r14)
je 0x2a13
movss 0x2d66f(%rip), %xmm1    # 0x30004
divss %xmm0, %xmm1
movaps %xmm4, %xmm0
mulss %xmm1, %xmm0
movaps %xmm0, -0x30(%rbp)
shufps $0x55, %xmm4, %xmm4     # xmm4 = xmm4[1,1,1,1]
mulss %xmm1, %xmm4
movl $0x1, %r12d
xorl %ecx, %ecx
leaq 0x2d73c(%rip), %r15     # 0x300f7
movaps %xmm4, -0x40(%rbp)
movss (%rax,%rcx,8), %xmm0
movss 0x4(%rax,%rcx,8), %xmm1
xorps %xmm2, %xmm2
cvtss2sd %xmm0, %xmm2
subss -0x30(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
xorps %xmm3, %xmm3
cvtss2sd %xmm1, %xmm3
subss %xmm4, %xmm1
cvtss2sd %xmm1, %xmm1
movq %rbx, %rdi
movq %r15, %rsi
movb $0x4, %al
callq 0x2170
movaps -0x40(%rbp), %xmm4
movl %r12d, %ecx
movq (%r14), %rax
movq 0x8(%r14), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
incl %r12d
cmpq %rcx, %rdx
ja 0x29bf
movl $0xa, %edi
movq %rbx, %rsi
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x2400
// File: /workspace/github_c_makefile_star2_O1/FredTheDino[P]Fog/src/rain/editor_main.cpp
// Function: find_next_sheet(unsigned long long, int)
AssetID find_next_sheet(AssetID start=0, int dir=1) {
    for (s32 i = 1; i < (s32) fog_asset_num(); i++) {
        AssetID curr = (start + i * dir + fog_asset_num()) % fog_asset_num();
        if (fog_asset_is(curr, Type::TEXTURE))
            return curr;
    }
    return -1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %esi, %r15d
movq %rdi, %r14
callq 0x28609
movq $-0x1, %rbx
cmpl $0x2, %eax
jl 0x2aa9
movslq %r15d, %r12
addq %r12, %r14
movl $0x1, %r13d
callq 0x28609
movq %rax, %r15
addq %r14, %r15
callq 0x28609
movq %rax, %rcx
movq %r15, %rax
xorl %edx, %edx
divq %rcx
movq %rdx, %r15
movq %rdx, %rdi
movl $0x1, %esi
callq 0x285dd
testb %al, %al
cmovneq %r15, %rbx
jne 0x2aa9
incq %r13
callq 0x28609
cltq
addq %r12, %r14
cmpq %rax, %r13
jl 0x2a5d
movq $-0x1, %rbx
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/FredTheDino[P]Fog/src/rain/editor_main.cpp
// Function: create_new_sprite()
void create_new_sprite() {
    EditableSprite new_sprite = {
        std::vector<Vec2>(0),
        find_next_sheet(0, 1),
    };
    read_with_default("sprite name",
            nullptr,
            new_sprite.name,
            MAX_TEXT_LENGTH);

    global_editor.current_sprite = global_editor.sprites.size();
    global_editor.sprites.push_back(new_sprite);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
subq $0x38, %rsp
xorps %xmm0, %xmm0
movaps %xmm0, -0x40(%rbp)
movq $0x0, -0x30(%rbp)
xorl %edi, %edi
movl $0x1, %esi
callq 0x2a2c
leaq -0x20(%rbp), %rdx
movq %rax, -0x8(%rdx)
xorps %xmm0, %xmm0
movaps %xmm0, (%rdx)
leaq 0x2d5b5(%rip), %rdi     # 0x30105
xorl %esi, %esi
movl $0x10, %ecx
callq 0x27db
movq 0x4d235(%rip), %rax     # 0x4fd98
subq 0x4d226(%rip), %rax     # 0x4fd90
leaq 0x4d21f(%rip), %rdi     # 0x4fd90
shrq $0x4, %rax
imull $0xaaaaaaab, %eax, %eax # imm = 0xAAAAAAAB
movl %eax, 0x4d207(%rip)     # 0x4fd88
leaq -0x40(%rbp), %rsi
callq 0x4498
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x2b9f
movq -0x30(%rbp), %rsi
subq %rdi, %rsi
callq 0x20e0
addq $0x38, %rsp
popq %rbx
popq %rbp
retq
jmp 0x2ba8
movq %rax, %rbx
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x2bc0
movq -0x30(%rbp), %rsi
subq %rdi, %rsi
callq 0x20e0
movq %rbx, %rdi
callq 0x2310
// File: /workspace/github_c_makefile_star2_O1/FredTheDino[P]Fog/src/rain/editor_main.cpp
// Function: main
int main(int argc, char *argv[]) {
    fog_input_request_name((u32) In::EDIT_NUM_BINDINGS);
    fog_init(argc, argv);
    setup(argc, argv);

    fog_run(sprite_editor_update, sprite_editor_draw);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
movq %rsi, %rbx
movl %edi, %r14d
movl $0x12, %edi
callq 0x291e2
movl %r14d, %edi
movq %rbx, %rsi
callq 0x2866d
movl %r14d, %edi
movq %rbx, %rsi
callq 0x2bc8
leaq -0xf73(%rip), %rdi      # 0x3471
leaq -0x458(%rip), %rsi      # 0x3f93
callq 0x28684
xorl %eax, %eax
popq %rbx
popq %r14
popq %rbp
retq
nop
// File: /workspace/github_c_makefile_star2_O1/FredTheDino[P]Fog/src/engine/util/printf.c
// Function: fctprintf
int fctprintf(void (*out)(char character, void* arg), void* arg, const char* format, ...)
{
  va_list va;
  va_start(va, format);
  const out_fct_wrap_type out_fct_wrap = { out, arg };
  const int ret = _vsnprintf(_out_fct, (char*)(uintptr_t)&out_fct_wrap, (size_t)-1, format, va);
  va_end(va);
  return ret;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdx, %r10
leaq -0xe0(%rbp), %rdx
movq %rcx, 0x18(%rdx)
movq %r8, 0x20(%rdx)
movq %r9, 0x28(%rdx)
testb %al, %al
je 0x70bc
movaps %xmm0, -0xb0(%rbp)
movaps %xmm1, -0xa0(%rbp)
movaps %xmm2, -0x90(%rbp)
movaps %xmm3, -0x80(%rbp)
movaps %xmm4, -0x70(%rbp)
movaps %xmm5, -0x60(%rbp)
movaps %xmm6, -0x50(%rbp)
movaps %xmm7, -0x40(%rbp)
leaq -0x30(%rbp), %r8
movq %rdx, 0x10(%r8)
leaq 0x10(%rbp), %rax
movq %rax, 0x8(%r8)
movabsq $0x3000000018, %rax     # imm = 0x3000000018
movq %rax, (%r8)
leaq -0x10(%rbp), %rax
movq %rdi, (%rax)
movq %rsi, 0x8(%rax)
leaq 0x1b(%rip), %rdi        # 0x7106
movq %rax, %rsi
movq $-0x1, %rdx
movq %r10, %rcx
callq 0x6586
addq $0xe0, %rsp
popq %rbp
retq