LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_c_makefile_star2_O2/samtools[P]htslib/test/hfile.c
// Function: reopen
void reopen(const char *infname, const char *outfname)
{
    if (fin) { if (hclose(fin) != 0) fail("hclose(input)"); }
    if (fout) { if (hclose(fout) != 0) fail("hclose(output)"); }

    fin = hopen(infname, "r");
    if (fin == NULL) fail("hopen(\"%s\")", infname);

    fout = hopen(outfname, "w");
    if (fout == NULL) fail("hopen(\"%s\")", outfname);
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
movq 0x9388e(%rip), %rdi     # 0x99508
testq %rdi, %rdi
je 0x5c88
callq 0x7512
testl %eax, %eax
jne 0x5cfc
movq 0x93881(%rip), %rdi     # 0x99510
testq %rdi, %rdi
je 0x5c9d
callq 0x7512
testl %eax, %eax
jne 0x5d05
leaq 0x6ff43(%rip), %rsi     # 0x75be7
movq %r14, %rdi
xorl %eax, %eax
callq 0x7dbf
movq %rax, 0x93853(%rip)     # 0x99508
testq %rax, %rax
je 0x5cdf
leaq 0x6f140(%rip), %rsi     # 0x74e01
movq %rbx, %rdi
xorl %eax, %eax
callq 0x7dbf
movq %rax, 0x9383e(%rip)     # 0x99510
testq %rax, %rax
je 0x5ceb
addq $0x8, %rsp
popq %rbx
popq %r14
retq
leaq 0x6c3a8(%rip), %rdi     # 0x7208e
movq %r14, %rsi
jmp 0x5cf5
leaq 0x6c39c(%rip), %rdi     # 0x7208e
movq %rbx, %rsi
xorl %eax, %eax
callq 0x5a9c
leaq 0x6c36e(%rip), %rdi     # 0x72071
jmp 0x5d0c
leaq 0x6c373(%rip), %rdi     # 0x7207f
xorl %eax, %eax
callq 0x5a9c
// File: /workspace/github_c_makefile_star2_O2/morozov312[P]documentary/./src/main.c
// Function: main
int main(int argc, char** argv)
{
    char *start_dir, *dest_dir;
    int argc_flag = Check_argc(argc, argv);
    if (!argc_flag) {
        return 0;
    }
    int argv_flag = Check_argv(argc, argv, &start_dir, &dest_dir);
    if (!argv_flag) {
        return 0;
    }
    if (strcmp(start_dir, "") == 0) {
        printf("\x1b[31m Error! \x1b[0m\n");
        Print_help();
        return 0;
    }
    char** paths_array = (char**)calloc(MAX_COUNT_OF_FILES, sizeof(char*));
    for (int i = 0; i < MAX_COUNT_OF_FILES; i++) {
        paths_array[i] = (char*)calloc(MAX_PATH_LEN, sizeof(char));
    }
    int recursive_exit_flag = 0;
    int recursive_res = Search_files_recursive(
            start_dir, paths_array, &recursive_exit_flag);
    if (recursive_res == -1) {
        printf("%s\n",
               "\x1b[36mWarning!\x1b[0m limit of files for this "
               "folder "
               "overpassed!");
    }
    for (int i = 0; i < MAX_COUNT_OF_FILES; i++) {
        size_t len = strlen(paths_array[i]);
        if (len > 0) {
            Create_document(paths_array[i], dest_dir);
        }
    }
    for (int i = 0; i < MAX_COUNT_OF_FILES; i++) {
        free(paths_array[i]);
    }
    free(paths_array);
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x20, %rsp
movq %rsi, %rbx
movl %edi, %r14d
callq 0x172d
testl %eax, %eax
je 0x136f
leaq -0x30(%rbp), %rdx
leaq -0x28(%rbp), %rcx
movl %r14d, %edi
movq %rbx, %rsi
callq 0x17c9
testl %eax, %eax
je 0x136f
movq -0x30(%rbp), %r14
cmpb $0x0, (%r14)
je 0x135c
pushq $0x1e
popq %rdi
pushq $0x8
popq %rsi
callq 0x1110
movq %rax, %rbx
xorl %r12d, %r12d
pushq $0x1
popq %r15
cmpq $0x1e, %r12
je 0x12f8
movl $0xff, %edi
movq %r15, %rsi
callq 0x1110
movq %rax, (%rbx,%r12,8)
incq %r12
jmp 0x12dc
leaq -0x34(%rbp), %rdx
andl $0x0, (%rdx)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1495
cmpl $-0x1, %eax
jne 0x131b
leaq 0x1cee(%rip), %rdi      # 0x3004
callq 0x1060
xorl %r14d, %r14d
cmpq $0x1e, %r14
je 0x133b
movq (%rbx,%r14,8), %rdi
cmpb $0x0, (%rdi)
je 0x1336
movq -0x28(%rbp), %rsi
callq 0x209d
incq %r14
jmp 0x131e
xorl %r14d, %r14d
cmpq $0x1e, %r14
je 0x1352
movq (%rbx,%r14,8), %rdi
callq 0x1030
incq %r14
jmp 0x133e
movq %rbx, %rdi
callq 0x1030
jmp 0x136f
leaq 0x1cde(%rip), %rdi      # 0x3041
callq 0x1060
xorl %eax, %eax
callq 0x16ae
xorl %eax, %eax
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
nop
// File: /workspace/github_c_makefile_star2_O2/canboat[P]canboat/group-function/request.c
// Function: usage
void usage(char **argv, char **av)
{
  if (av)
  {
    fprintf(stderr, "Unknown or invalid argument %s\n", av[0]);
  }
  fprintf(stderr, "Usage: %s <dest> <prio> <pgn> <interval> <field>=<value> ...\n\n", argv[0]);
  fprintf(stderr, "       <field> is a decimal value\n");
  fprintf(stderr, "       <value> is a hexadecimal value; the length of the value defines how many bytes are encoded\n");
  fprintf(stderr, "       Maximum # of fields: %d\n\n", MAX_FIELDS);
  fprintf(stderr, "This program uses PGN 126208 to request a device to start reporting a PGN at the given interval.\n");
  fprintf(stderr, "The use of this is thus completely dependent on what the device allows.\n\n" COPYRIGHT);
  exit(1);
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
testq %rsi, %rsi
je 0x13b3
movq 0x4c59(%rip), %rax      # 0x5ff8
movq (%rax), %rdi
movq (%rsi), %rdx
leaq 0x1c58(%rip), %rsi      # 0x3004
xorl %eax, %eax
callq 0x1130
movq 0x4c3e(%rip), %r14      # 0x5ff8
movq (%r14), %rdi
movq (%rbx), %rdx
leaq 0x1c5d(%rip), %rsi      # 0x3024
xorl %eax, %eax
callq 0x1130
movq (%r14), %rcx
leaq 0x1c8b(%rip), %rdi      # 0x3063
pushq $0x22
popq %rsi
pushq $0x1
popq %rbx
movq %rbx, %rdx
callq 0x1210
movq (%r14), %rcx
leaq 0x1c96(%rip), %rdi      # 0x3086
pushq $0x62
popq %rsi
movq %rbx, %rdx
callq 0x1210
movq (%r14), %rdi
leaq 0x1ce4(%rip), %rsi      # 0x30e9
pushq $0x14
popq %rdx
xorl %eax, %eax
callq 0x1130
movq (%r14), %rcx
leaq 0x1cf1(%rip), %rdi      # 0x310a
pushq $0x61
popq %rsi
movq %rbx, %rdx
callq 0x1210
movq (%r14), %rcx
leaq 0x1d3e(%rip), %rdi      # 0x316c
movl $0x304, %esi            # imm = 0x304
movq %rbx, %rdx
callq 0x1210
pushq $0x1
popq %rdi
callq 0x11f0
// File: /workspace/github_c_makefile_star2_O2/hamsternz[P]emulate-risc-v/main.c
// Function: main
int main(int argc, char *argv[]) {
  int run = 1, quit = 0, trace = 1, reset = 0;

  if(!display_start()) {
    fprintf(stderr,"Unable to initialise display\n");
    return 0;
  }

  if(!memory_initialise()) {
    return 0;
  }
  display_log("Memory inisitalised");

  if(!riscv_initialise()) {
    return 0;
  }
  display_log("RISC-V initalised");
  riscv_reset();
  display_log("Press SPACE to run a sigle instruction, or 'r' to run. 'q' to quit");

  while(!quit) {
    if(run) {
       if(!memory_run())
         run = 0;
    }
    if(run) {
       if(!riscv_run() ||run == 1)
         run = 0;
    }
    display_update();
    display_process_input(&run, &quit, &trace, &reset);
    if(reset) {
      riscv_reset();
      reset = 0;
    }
  }
  riscv_dump();
  riscv_finish();
  display_log("RISC-V shutdown");
  memory_finish();
  display_log("Memory shutdown");
  display_update();
  display_end();
  
  return 0;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x18, %rsp
pushq $0x1
popq %rax
movl %eax, 0x8(%rsp)
andl $0x0, 0x10(%rsp)
movl %eax, 0x14(%rsp)
andl $0x0, 0xc(%rsp)
callq 0x4674
testl %eax, %eax
je 0x243e
callq 0x5d8c
testl %eax, %eax
je 0x2430
leaq 0x4cc5(%rip), %rdi      # 0x7022
callq 0x4b7e
callq 0x2d3c
testl %eax, %eax
je 0x2430
leaq 0x4cc0(%rip), %rdi      # 0x7036
callq 0x4b7e
callq 0x2cd4
leaq 0x4cc1(%rip), %rdi      # 0x7048
callq 0x4b7e
xorl %eax, %eax
leaq 0x8(%rsp), %rbx
leaq 0x10(%rsp), %r14
leaq 0x14(%rsp), %r15
leaq 0xc(%rsp), %r12
testl %eax, %eax
jne 0x23ff
cmpl $0x0, 0x8(%rsp)
je 0x23d2
callq 0x5f1c
testl %eax, %eax
je 0x23cd
cmpl $0x0, 0x8(%rsp)
je 0x23d2
callq 0x2dec
testl %eax, %eax
je 0x23cd
cmpl $0x1, 0x8(%rsp)
jne 0x23d2
andl $0x0, 0x8(%rsp)
callq 0x4882
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
movq %r12, %rcx
callq 0x4cc5
cmpl $0x0, 0xc(%rsp)
je 0x23f9
callq 0x2cd4
andl $0x0, 0xc(%rsp)
movl 0x10(%rsp), %eax
jmp 0x23a2
callq 0x3042
callq 0x3043
leaq 0x4c7b(%rip), %rdi      # 0x708b
callq 0x4b7e
callq 0x6066
leaq 0x4c7a(%rip), %rdi      # 0x709b
callq 0x4b7e
callq 0x4882
callq 0x4e02
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movq 0x9bb3(%rip), %rax      # 0xbff8
movq (%rax), %rcx
leaq 0x4bb5(%rip), %rdi      # 0x7004
pushq $0x1d
popq %rsi
pushq $0x1
popq %rdx
callq 0x2200
jmp 0x2430
// File: /workspace/github_c_makefile_star2_O2/hamsternz[P]emulate-risc-v/riscv.c
// Function: riscv_reset
void riscv_reset(void) {
  memory_reset();
  memset(regs,0xFF,sizeof(regs));
  regs[0] = 0;
  pc = 0x20400000;
  display_log("RISC-V reset");
}

// Assembly:
pushq %rax
callq 0x5d44
pcmpeqd %xmm0, %xmm0
movdqa %xmm0, 0xdd3a(%rip)     # 0x10a20
movdqa %xmm0, 0xdda2(%rip)     # 0x10a90
movdqa %xmm0, 0xdd8a(%rip)     # 0x10a80
movdqa %xmm0, 0xdd72(%rip)     # 0x10a70
movdqa %xmm0, 0xdd5a(%rip)     # 0x10a60
movdqa %xmm0, 0xdd42(%rip)     # 0x10a50
movdqa %xmm0, 0xdd2a(%rip)     # 0x10a40
andl $0x0, 0xdd03(%rip)      # 0x10a20
movdqa %xmm0, 0xdd0b(%rip)     # 0x10a30
movl $0x20400000, 0x9cd1(%rip) # imm = 0x20400000
leaq 0x4b6e(%rip), %rdi      # 0x78a4
popq %rax
jmp 0x4b7e
// File: /workspace/github_c_makefile_star2_O2/hamsternz[P]emulate-risc-v/riscv.c
// Function: riscv_initialise
int riscv_initialise(void) {
  int i;
  for(i = 0; i < sizeof(opcodes)/sizeof(struct opcode_entry); i++) {
     int j;
     if(strlen(opcodes[i].spec) != 32) {
       return 0;
     }
     opcodes[i].mask = 0;
     opcodes[i].value = 0;
     for(j = 0; j < 32; j++) {
       opcodes[i].value <<= 1;
       opcodes[i].mask  <<= 1;

       /* Change the string specifiers into masks */
       switch(opcodes[i].spec[j]) {
          case '0':
             opcodes[i].mask  |= 1;
             break;
          case '1':
             opcodes[i].mask  |= 1;
             opcodes[i].value |= 1;
             break;
          case '-':
             break;
          default:
	     display_log("Unknown character in opcode");
	     return 0;
        }
     }
  }
  return 1;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
xorl %r15d, %r15d
pushq $0x1
popq %rbx
leaq 0x93de(%rip), %r12      # 0xc130
cmpq $0x38, %r15
je 0x2dd2
imulq $0x28, %r15, %r13
movq (%r13,%r12), %r14
movq %r14, %rdi
callq 0x20a0
cmpq $0x20, %rax
jne 0x2dd0
addq %r12, %r13
andq $0x0, 0x20(%r13)
xorl %eax, %eax
xorl %ecx, %ecx
xorl %edx, %edx
cmpq $0x20, %rax
je 0x2dbf
addl %edx, %edx
movl %edx, 0x20(%r13)
addl %ecx, %ecx
movl %ecx, 0x24(%r13)
movzbl (%r14,%rax), %esi
cmpl $0x2d, %esi
je 0x2dba
cmpl $0x31, %esi
je 0x2dac
cmpl $0x30, %esi
jne 0x2dc4
orl $0x1, %ecx
movl %ecx, 0x24(%r13)
jmp 0x2dba
orl $0x1, %ecx
movl %ecx, 0x24(%r13)
orl $0x1, %edx
movl %edx, 0x20(%r13)
incq %rax
jmp 0x2d7d
incq %r15
jmp 0x2d52
leaq 0x4ae6(%rip), %rdi      # 0x78b1
callq 0x4b7e
xorl %ebx, %ebx
movl %ebx, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O2/hamsternz[P]emulate-risc-v/riscv.c
// Function: trace
static void trace(char *fmt, uint32_t a, uint32_t b, uint32_t c) {
  char buffer[128];
  if(!trace_active)
    return;
  sprintf(buffer,"%08X:%c",pc, stalled ? '*' : ' ');
  sprintf(buffer+10, fmt, a, b, c);
  display_trace(buffer);
}

// Assembly:
cmpl $0x0, 0x90d5(%rip)      # 0xc120
je 0x30be
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x80, %rsp
movl %ecx, %ebx
movl %edx, %ebp
movl %esi, %r14d
movq %rdi, %r15
movl 0x9994(%rip), %edx      # 0xca00
cmpb $0x0, 0xda45(%rip)      # 0x10ab8
pushq $0x2a
popq %rax
pushq $0x20
popq %rcx
cmovnel %eax, %ecx
leaq 0x486f(%rip), %rsi      # 0x78f2
movq %rsp, %r12
movq %r12, %rdi
xorl %eax, %eax
callq 0x21f0
leaq 0xa(%rsp), %rdi
movq %r15, %rsi
movl %r14d, %edx
movl %ebp, %ecx
movl %ebx, %r8d
xorl %eax, %eax
callq 0x21f0
movq %r12, %rdi
callq 0x4c37
addq $0x80, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/hamsternz[P]emulate-risc-v/riscv.c
// Function: exception
static void exception( char *reason) {
  char buffer[200];
  if(strlen(reason) < 100)
    sprintf(buffer, "EXCEPTION: %s : instruction 0x%08x", reason, current_instr);
  else
    sprintf(buffer, "EXCEPTION: [reason too long] : instruction 0x%08x", current_instr);
  display_log(reason);
}

// Assembly:
pushq %rbx
subq $0xd0, %rsp
movl 0xd532(%rip), %ecx      # 0x10aa0
leaq 0x46bf(%rip), %rsi      # 0x7c34
leaq 0x469f(%rip), %rbx      # 0x7c1b
movq %rsp, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x21f0
movq %rbx, %rdi
addq $0xd0, %rsp
popq %rbx
jmp 0x4b7e
nopl (%rax)
// File: /workspace/github_c_makefile_star2_O2/hamsternz[P]emulate-risc-v/memorymap.c
// Function: memorymap_aligned_read
int memorymap_aligned_read(uint32_t address, uint32_t *value) {
   struct region *r = first_region;

   /* Find the region */
   while(r != NULL) {
     if(address >= r->base && address < r->base+r->size)
       break;
     r = r->next;
   }

   /* If no region found then exit */
   if(r == NULL) {
     char buffer[128];
     sprintf(buffer, "Read of invalid address %08X",address);
     display_log(buffer);
     return 0;
   }

   /* Trap a currently unhandled error */
   if(address+4 > r->base + r->size) {
     display_log("Need to split the read of address as it crosses boundary");
     return 0;
   }
   return r->get(r, address-r->base, value);
}

// Assembly:
pushq %rbx
subq $0x80, %rsp
movq %rsi, %rax
movl %edi, %edx
leaq 0xd538(%rip), %rdi      # 0x10ae8
movq (%rdi), %rdi
testq %rdi, %rdi
je 0x35d8
movl 0x8(%rdi), %ecx
movl %edx, %esi
subl %ecx, %esi
jb 0x35b0
addl 0xc(%rdi), %ecx
cmpl %edx, %ecx
jbe 0x35b0
addl $0x4, %edx
cmpl %ecx, %edx
jbe 0x35ff
leaq 0x485f(%rip), %rdi      # 0x7e35
jmp 0x35ef
leaq 0x4839(%rip), %rsi      # 0x7e18
movq %rsp, %rbx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x21f0
movq %rbx, %rdi
callq 0x4b7e
xorl %eax, %eax
addq $0x80, %rsp
popq %rbx
retq
movq 0x20(%rdi), %rcx
movq %rax, %rdx
addq $0x80, %rsp
popq %rbx
jmpq *%rcx
// File: /workspace/github_c_makefile_star2_O2/hamsternz[P]emulate-risc-v/memorymap.c
// Function: memorymap_aligned_write
int memorymap_aligned_write(uint32_t address, uint8_t mask, uint32_t value) {
   struct region *r = first_region;

   /* Find the region */
   while(r != NULL) {
     if(address >= r->base && address < r->base+r->size)
       break;
     r = r->next;
   }

   /* If no region found then exit */
   if(r == NULL) {
     char buffer[128];
     sprintf(buffer, "Write of invalid address %08X",address);
     display_log(buffer);
     return 0;
   }

   /* Trap a currently unhandled error */
   if(address+4 > r->base + r->size) {
     display_log("Write to split the read of address as it crosses boundary");
     return 0;
   }
   return r->set(r, address-r->base, mask, value);
}

// Assembly:
pushq %rbx
subq $0x80, %rsp
movl %edx, %ecx
movl %edi, %edx
leaq 0xd4c5(%rip), %rdi      # 0x10ae8
movq (%rdi), %rdi
testq %rdi, %rdi
je 0x3650
movl 0x8(%rdi), %r8d
movl %edx, %eax
subl %r8d, %eax
jb 0x3623
addl 0xc(%rdi), %r8d
cmpl %edx, %r8d
jbe 0x3623
addl $0x4, %edx
cmpl %r8d, %edx
jbe 0x3677
leaq 0x483e(%rip), %rdi      # 0x7e8c
jmp 0x3667
leaq 0x4817(%rip), %rsi      # 0x7e6e
movq %rsp, %rbx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x21f0
movq %rbx, %rdi
callq 0x4b7e
xorl %eax, %eax
addq $0x80, %rsp
popq %rbx
retq
movq 0x18(%rdi), %r8
movzbl %sil, %edx
movl %eax, %esi
addq $0x80, %rsp
popq %rbx
jmpq *%r8
// File: /workspace/github_c_makefile_star2_O2/hamsternz[P]emulate-risc-v/memorymap.c
// Function: add_region
static int add_region(uint32_t base, uint32_t size, 
  int  (*init)(struct region *r),
  int (*get)(struct region *r, uint32_t address, uint32_t *value),
  int (*set)(struct region *r, uint32_t address, uint8_t mask, uint32_t value),
  void (*free)(struct region *r),
  void (*dump)(struct region *r)) {
  struct region *r = NULL;

  /* Allocate space */
  r = malloc(sizeof(struct region));
  if(r == NULL) {
    return 0;
  }

  /* Initialise it */
  memset(r,0,sizeof(struct region));
  r->base = base;
  r->size = size;
  r->init = init;
  r->get  = get;
  r->set  = set;
  r->free = free;
  r->dump = dump;

  /* Add to list */
  if(first_region == NULL) {
    first_region = r;
    r->next = NULL;
  } else {
    struct region *c = first_region;
    while(c->next != NULL)
      c = c->next;
    c->next = r;
    r->next = NULL;
  }
  return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %r9, %rbx
movq %r8, %r14
movq %rcx, %r15
movq %rdx, %r12
movl %esi, %ebp
movl %edi, %r13d
pushq $0x1
popq %rdi
pushq $0x40
popq %rsi
callq 0x2130
testq %rax, %rax
je 0x3936
movq 0x40(%rsp), %rcx
movl %r13d, 0x8(%rax)
movl %ebp, 0xc(%rax)
movq %r12, 0x10(%rax)
movq %r15, 0x20(%rax)
movq %r14, 0x18(%rax)
movq %rbx, 0x28(%rax)
movq %rcx, 0x30(%rax)
movq 0xd1c4(%rip), %rcx      # 0x10ae8
testq %rcx, %rcx
je 0x393a
movq %rcx, %rdx
movq (%rcx), %rcx
testq %rcx, %rcx
jne 0x3929
jmp 0x3941
xorl %eax, %eax
jmp 0x394b
leaq 0xd1a7(%rip), %rdx      # 0x10ae8
movq %rax, (%rdx)
andq $0x0, (%rax)
pushq $0x1
popq %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/hamsternz[P]emulate-risc-v/memorymap.c
// Function: memorymap_read
int memorymap_read(uint32_t address, uint8_t width, uint32_t *value) {
   uint32_t v, v1, mask;

   /* Mask out data we don't want */
   switch(width) {
     case 1:
       mask = 0xFF;
       break; 
     case 2:
       mask = 0xFFFF;
       break; 
     case 4:
       mask = 0xFFFFFFFF;
       break; 
     default:
       display_log("Invalid read width at address 0x%08x");
       return 0;
   }

   /* Read the memory region */
   switch(address & 3) {
     case 0:
       if(!memorymap_aligned_read(address+0, &v))  return 0;
       break;
     case 1:
       if(!memorymap_aligned_read(address-1, &v))  return 0;
       if(!memorymap_aligned_read(address+3, &v1)) return 0;
       v = (v>>8) | (v1 <<24);
       break;
     case 2:
       if(!memorymap_aligned_read(address-2, &v))  return 0;
       if(!memorymap_aligned_read(address+2, &v1)) return 0;
       v = (v>>16) | (v1 <<16);
       break;
     default:
       if(!memorymap_aligned_read(address-3, &v))  return 0;
       if(!memorymap_aligned_read(address+1, &v1)) return 0;
       v = (v>>24) | (v1 <<8);
       break;
   }
   /* Set the return value */
   *value = v & mask;
   return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdx, %rbx
movl %edi, %r14d
leaq 0x442a(%rip), %rax      # 0x7d98
cmpl $0x1, %esi
je 0x39a5
cmpl $0x4, %esi
je 0x3992
cmpl $0x2, %esi
jne 0x39d1
movl $0xffff, %r15d          # imm = 0xFFFF
movl %r14d, %ecx
andl $0x3, %ecx
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
pushq $-0x1
popq %r15
movl %r14d, %ecx
andl $0x3, %ecx
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movl $0xff, %r15d
movl %r14d, %ecx
andl $0x3, %ecx
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movq %rsp, %rsi
movl %r14d, %edi
callq 0x359c
testl %eax, %eax
je 0x39dd
movl (%rsp), %eax
jmp 0x3a81
leaq 0x453f(%rip), %rdi      # 0x7f17
callq 0x4b7e
xorl %ebp, %ebp
jmp 0x3a8a
leal -0x2(%r14), %edi
movq %rsp, %rsi
callq 0x359c
xorl %ebp, %ebp
testl %eax, %eax
je 0x3a8a
addl $0x2, %r14d
leaq 0x4(%rsp), %rsi
movl %r14d, %edi
callq 0x359c
testl %eax, %eax
je 0x3a8a
movl (%rsp), %ecx
movl 0x4(%rsp), %eax
shldl $0x10, %ecx, %eax
jmp 0x3a81
leal -0x3(%r14), %edi
movq %rsp, %rsi
callq 0x359c
xorl %ebp, %ebp
testl %eax, %eax
je 0x3a8a
incl %r14d
leaq 0x4(%rsp), %rsi
movl %r14d, %edi
callq 0x359c
testl %eax, %eax
je 0x3a8a
movl (%rsp), %ecx
movl 0x4(%rsp), %eax
shldl $0x8, %ecx, %eax
jmp 0x3a81
leal -0x1(%r14), %edi
movq %rsp, %rsi
callq 0x359c
xorl %ebp, %ebp
testl %eax, %eax
je 0x3a8a
addl $0x3, %r14d
leaq 0x4(%rsp), %rsi
movl %r14d, %edi
callq 0x359c
testl %eax, %eax
je 0x3a8a
movl (%rsp), %ecx
movl 0x4(%rsp), %eax
shldl $0x18, %ecx, %eax
andl %eax, %r15d
movl %r15d, (%rbx)
pushq $0x1
popq %rbp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/hamsternz[P]emulate-risc-v/memorymap.c
// Function: memorymap_finish
void memorymap_finish(void) {
   while(first_region != NULL) {
      struct region *r = first_region;
      first_region = first_region->next;
      r->free(r);
      free(r);
   }
}

// Assembly:
pushq %rbx
movq 0xce54(%rip), %rbx      # 0x10ae8
testq %rbx, %rbx
je 0x3cb3
movq (%rbx), %rax
movq %rax, 0xce45(%rip)      # 0x10ae8
movq %rbx, %rdi
callq *0x28(%rbx)
movq %rbx, %rdi
callq 0x2040
jmp 0x3c8d
popq %rbx
retq
nopl (%rax)
// File: /workspace/github_c_makefile_star2_O2/hamsternz[P]emulate-risc-v/ram.c
// Function: RAM_init
int RAM_init(struct region *r) {
  uint32_t *data;

  if(r->data != NULL) {
    display_log("RAM 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
pushq %rax
cmpq $0x0, 0x38(%rdi)
je 0x3cdd
leaq 0x42a1(%rip), %rdi      # 0x7f72
callq 0x4b7e
xorl %eax, %eax
jmp 0x3e71
movq %rdi, %rbx
movl 0xc(%rdi), %esi
pushq $0x1
popq %rdi
callq 0x2130
testq %rax, %rax
je 0x3cd6
movq %rax, %r14
movq %rax, 0x38(%rbx)
movl 0x8(%rbx), %edx
leaq 0x4343(%rip), %rsi      # 0x8044
movq %rsp, %rdi
xorl %eax, %eax
callq 0x21a0
testl %eax, %eax
jle 0x3e32
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x3e56
leaq 0x437e(%rip), %rsi      # 0x80a5
callq 0x21b0
testq %rax, %rax
je 0x3e80
movq %rax, %r15
movq (%rsp), %rdi
callq 0x2040
xorl %r12d, %r12d
pushq $0x7
popq %rbp
movq %r15, %rdi
callq 0x2100
cmpl $0xa, %eax
je 0x3d47
cmpl $0xd, %eax
je 0x3d47
cmpl $-0x1, %eax
je 0x3e3b
leal -0x30(%rax), %r13d
cmpl $0x9, %r13d
jbe 0x3d94
leal -0x41(%rax), %ecx
cmpl $0x5, %ecx
ja 0x3d7a
leal -0x37(%rax), %r13d
jmp 0x3d94
leal -0x61(%rax), %ecx
cmpl $0x5, %ecx
ja 0x3d88
leal -0x57(%rax), %r13d
jmp 0x3d94
xorl %r13d, %r13d
cmpl $0x20, %eax
jne 0x3eb9
subl $0x1, %ebp
jb 0x3e0c
movq %r15, %rdi
callq 0x2100
leal -0x30(%rax), %ecx
cmpl $0x9, %ecx
ja 0x3db2
shll $0x4, %r13d
orl %ecx, %r13d
jmp 0x3d94
leal -0x41(%rax), %ecx
cmpl $0x5, %ecx
ja 0x3dc7
shll $0x4, %r13d
addl %eax, %r13d
addl $-0x37, %r13d
jmp 0x3d94
leal -0x61(%rax), %ecx
cmpl $0x5, %ecx
ja 0x3ddc
shll $0x4, %r13d
addl %eax, %r13d
addl $-0x57, %r13d
jmp 0x3d94
cmpl $0x20, %eax
ja 0x3eb0
movl %eax, %ecx
movabsq $0x100000600, %rdx      # imm = 0x100000600
btq %rcx, %rdx
jae 0x3eb0
leal 0x3(,%r12,4), %ecx
cmpl 0xc(%rbx), %ecx
jae 0x3ea7
movl %r13d, (%r14,%r12,4)
incq %r12
pushq $0x7
popq %rbp
cmpl $-0x1, %eax
je 0x3d47
cmpl $0xa, %eax
je 0x3d47
movq %r15, %rdi
callq 0x2100
jmp 0x3e16
leaq 0x4218(%rip), %rdi      # 0x8051
jmp 0x3e5d
leaq 0x427d(%rip), %rdi      # 0x80bf
movl %r12d, %esi
xorl %eax, %eax
callq 0x20c0
movq %r15, %rdi
callq 0x2090
jmp 0x3e62
leaq 0x421f(%rip), %rdi      # 0x807c
callq 0x4b7e
leaq 0x4121(%rip), %rdi      # 0x7f8a
callq 0x4b7e
pushq $0x1
popq %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8171(%rip), %rax      # 0xbff8
movq (%rax), %rdi
movq (%rsp), %rdx
leaq 0x4213(%rip), %rsi      # 0x80a8
xorl %eax, %eax
callq 0x2140
movq (%rsp), %rdi
callq 0x2040
jmp 0x3e62
leaq 0x424b(%rip), %rdi      # 0x80f9
jmp 0x3e5d
leaq 0x4262(%rip), %rdi      # 0x8119
jmp 0x3e5d
movq 0x8138(%rip), %rax      # 0xbff8
movq (%rax), %rcx
leaq 0x4210(%rip), %rdi      # 0x80da
pushq $0x1e
popq %rsi
pushq $0x1
popq %rdx
callq 0x2200
jmp 0x3e62
// File: /workspace/github_c_makefile_star2_O2/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 0x3f5a
movl %ecx, %r12d
movl %edx, %ebp
testb $0x3, %bl
jne 0x3f7d
testb $0x1, %bpl
je 0x3f0c
movq 0x38(%r14), %rax
movl %ebx, %ecx
movl %r12d, %edx
movb %dl, (%rax,%rcx)
testb $0x2, %bpl
je 0x3f1f
movq 0x38(%r14), %rax
leal 0x1(%rbx), %ecx
movl %r12d, %edx
movb %dh, (%rax,%rcx)
testb $0x4, %bpl
je 0x3f35
movl %r12d, %eax
shrl $0x10, %eax
movq 0x38(%r14), %rcx
leal 0x2(%rbx), %edx
movb %al, (%rcx,%rdx)
pushq $0x1
popq %r15
testb $0x8, %bpl
je 0x3f4e
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 0x8097(%rip), %rax      # 0xbff8
movq (%rax), %rdi
addl 0x8(%r14), %ebx
leaq 0x4030(%rip), %rsi      # 0x7f9f
xorl %r15d, %r15d
movl %ebx, %edx
xorl %eax, %eax
callq 0x2140
jmp 0x3f4e
movq 0x8074(%rip), %rax      # 0xbff8
movq (%rax), %rdi
movl 0x8(%r14), %edx
addl %ebx, %edx
leaq 0x4035(%rip), %rsi      # 0x7fc9
xorl %eax, %eax
callq 0x2140
jmp 0x3efa
// File: /workspace/github_c_makefile_star2_O2/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 0x3fc1
leal 0x4(%rax), %ecx
cmpl 0xc(%rdi), %ecx
ja 0x3fd7
movq 0x38(%rdi), %rcx
movl %eax, %eax
movl (%rcx,%rax), %eax
movl %eax, (%rdx)
pushq $0x1
popq %rbx
movl %ebx, %eax
popq %rbx
retq
movq 0x8030(%rip), %rcx      # 0xbff8
movq (%rcx), %rcx
addl 0x8(%rdi), %eax
leaq 0x4013(%rip), %rsi      # 0x7fe8
jmp 0x3feb
movq 0x801a(%rip), %rcx      # 0xbff8
movq (%rcx), %rcx
addl 0x8(%rdi), %eax
leaq 0x3fb4(%rip), %rsi      # 0x7f9f
xorl %ebx, %ebx
movq %rcx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0x2140
jmp 0x3fbd
// File: /workspace/github_c_makefile_star2_O2/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 %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movl 0x8(%rdi), %esi
movl 0xc(%rdi), %edx
leaq 0x3ff0(%rip), %rdi      # 0x8006
xorl %eax, %eax
callq 0x20c0
leaq 0x3ffc(%rip), %r14      # 0x8020
leaq 0x3ffb(%rip), %r15      # 0x8026
pushq $0xa
popq %rbp
xorl %r12d, %r12d
cmpq $0xfff, %r12            # imm = 0xFFF
ja 0x4080
movl 0xc(%rbx), %eax
cmpq %rax, %r12
jae 0x4080
movl %r12d, %r13d
andl $0x1f, %r13d
jne 0x405b
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, %r13d
jne 0x407b
movl %ebp, %edi
callq 0x2050
incq %r12
jmp 0x4031
testb $0x1f, %r12b
je 0x409c
pushq $0xa
popq %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2050
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/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 0x3f6d(%rip), %rsi      # 0x802c
movq %rsp, %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x21f0
movq %r14, %rdi
callq 0x4b7e
movq 0x38(%rbx), %rdi
callq 0x2040
addq $0x68, %rsp
popq %rbx
popq %r14
retq
nopl (%rax)
// File: /workspace/github_c_makefile_star2_O2/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 0x40fb
xorl %ebx, %ebx
leaq 0x4077(%rip), %rdi      # 0x8170
jmp 0x4120
movq %rdi, %rbx
pushq $0x1
popq %rdi
pushq $0x22
popq %rsi
callq 0x2130
testq %rax, %rax
je 0x4129
orw $-0x1, (%rax)
movq %rax, 0x38(%rbx)
pushq $0x1
popq %rbx
leaq 0x4069(%rip), %rdi      # 0x8189
callq 0x4b7e
movl %ebx, %eax
popq %rbx
retq
xorl %ebx, %ebx
jmp 0x4125
// File: /workspace/github_c_makefile_star2_O2/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 0x439c
cmpb $0x7, 0x17(%rax)
ja 0x43ab
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 0x43de
leaq 0x3f21(%rip), %rax      # 0x82bb
jmp 0x43b8
cmpb $0x0, 0x21(%rax)
je 0x43de
leaq 0x3f5a(%rip), %rax      # 0x8303
jmp 0x43b8
cmpb $0x0, 0x21(%rax)
je 0x43de
leaq 0x3f26(%rip), %rax      # 0x82de
pushq %rbx
subq $0x70, %rsp
movzbl %sil, %edx
movq %rsp, %rbx
movq %rbx, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0x21f0
movq %rbx, %rdi
callq 0x4b7e
addq $0x70, %rsp
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O2/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 0x3e33(%rip), %rsi      # 0x847f
movq %rsp, %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x21f0
movq %r14, %rdi
callq 0x4b7e
movq 0x38(%rbx), %rdi
callq 0x2040
addq $0x68, %rsp
popq %rbx
popq %r14
retq
nop
// File: /workspace/github_c_makefile_star2_O2/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 %rbx
pushq %rax
movq %rdi, %rbx
movq 0xbf65(%rip), %rdi      # 0x10af0
testq %rdi, %rdi
je 0x4ba1
leaq 0x39b9(%rip), %rsi      # 0x8550
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2140
movl 0xc07d(%rip), %ebp      # 0x10c24
cmpl $0x6, %ebp
jne 0x4bf2
movq 0xc07d(%rip), %rdi      # 0x10c30
callq 0x2040
pushq $0x1
popq %rax
leaq 0xc06e(%rip), %rcx      # 0x10c30
cmpq $0x6, %rax
je 0x4bd6
movq (%rcx,%rax,8), %rdx
movq %rdx, -0x8(%rcx,%rax,8)
incq %rax
jmp 0x4bc2
andq $0x0, 0xc07a(%rip)      # 0x10c58
movl $0x5, 0xc03c(%rip)      # 0x10c24
movb $0x0, 0xc029(%rip)      # 0x10c18
pushq $0x5
popq %rbp
movq %rbx, %rdi
callq 0x20a0
leaq 0x1(%rax), %rdi
callq 0x2190
movslq %ebp, %rcx
leaq 0xc023(%rip), %rdx      # 0x10c30
movq %rax, (%rdx,%rcx,8)
testq %rax, %rax
je 0x4c30
movb $0x0, 0xbffb(%rip)      # 0x10c18
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2070
incl %ebp
movl %ebp, 0xbff4(%rip)      # 0x10c24
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/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:
movb $0x0, 0xbfde(%rip)      # 0x10c1c
movslq 0xc01b(%rip), %rcx      # 0x10c60
cmpq $0x11, %rcx
jne 0x4c6f
movq 0xbeae(%rip), %rax      # 0x10b00
xorl %ecx, %ecx
leaq 0xbea5(%rip), %rdx      # 0x10b00
cmpq $0x10, %rcx
je 0x4c7e
movq 0x8(%rdx,%rcx,8), %rsi
movq %rsi, (%rdx,%rcx,8)
incq %rcx
jmp 0x4c5b
leaq 0xbe8a(%rip), %rax      # 0x10b00
movq (%rax,%rcx,8), %rax
incl %ecx
jmp 0x4c92
movq %rax, 0xbefb(%rip)      # 0x10b80
movl $0x10, 0xbfd1(%rip)     # 0x10c60
pushq $0x11
popq %rcx
testq %rax, %rax
je 0x4cc4
xorl %edx, %edx
cmpq $0x33, %rdx
ja 0x4cb8
movb (%rdi,%rdx), %sil
testb %sil, %sil
je 0x4cb8
movb %sil, (%rax,%rdx)
incq %rdx
jmp 0x4c99
movb $0x20, (%rax,%rdx)
incq %rdx
cmpq $0x34, %rdx
jne 0x4cb1
movl %ecx, 0xbf9c(%rip)      # 0x10c60
retq
// File: /workspace/github_c_makefile_star2_O2/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, %r14
movq %rdx, %r12
movq %rsi, %r15
movq %rdi, %rbx
movq 0x72f8(%rip), %rax      # 0xbfd8
movq (%rax), %rdi
callq 0x2080
cmpl $0x20, %eax
je 0x4d36
cmpl $0x74, %eax
je 0x4d0a
cmpl $0x71, %eax
je 0x4d28
cmpl $0x72, %eax
je 0x4d1a
cmpl $0x52, %eax
jne 0x4d3c
movl $0x1, (%r14)
jmp 0x4d3c
xorl %eax, %eax
cmpl $0x0, (%r12)
sete %al
movl %eax, (%r12)
jmp 0x4d3c
xorl %eax, %eax
cmpl $0x0, (%rbx)
sete %al
addl %eax, %eax
movl %eax, (%rbx)
jmp 0x4d3c
xorl %eax, %eax
cmpl $0x0, (%r15)
sete %al
movl %eax, (%r15)
jmp 0x4d3c
movl $0x1, (%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O2/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), %ecx
leaq 0xbe3e(%rip), %rax      # 0x10b90
cmpb $0x62, %cl
ja 0x4d78
movslq 0xbf06(%rip), %rcx      # 0x10c64
movq (%rax,%rcx,8), %rcx
movslq 0xbeff(%rip), %rdx      # 0x10c68
movb %dil, (%rcx,%rdx)
leal 0x1(%rdx), %ecx
movl %ecx, 0xbef2(%rip)      # 0x10c68
jmp 0x4d8f
cmpb $0xd, %dil
jne 0x4d89
andl $0x0, 0xbee3(%rip)      # 0x10c68
xorl %ecx, %ecx
jmp 0x4d8f
movl 0xbed9(%rip), %ecx      # 0x10c68
cmpb $0xa, %dil
je 0x4d9a
cmpl $0x50, %ecx
jne 0x4dfa
movl 0xbec4(%rip), %ecx      # 0x10c64
leal 0x1(%rcx), %edx
movl %edx, 0xbebb(%rip)      # 0x10c64
andl $0x0, 0xbeb8(%rip)      # 0x10c68
cmpl $0x6, %edx
jne 0x4dfa
pushq $0x1
popq %rsi
movq 0xbdd1(%rip), %rdx      # 0x10b90
cmpq $0x6, %rsi
je 0x4dd3
movq (%rax,%rsi,8), %rdi
movq %rdi, -0x8(%rax,%rsi,8)
incq %rsi
jmp 0x4dbf
movq %rdx, 0xbdde(%rip)      # 0x10bb8
movaps 0x36bf(%rip), %xmm0     # 0x84a0
movups %xmm0, 0x40(%rdx)
movups %xmm0, 0x30(%rdx)
movups %xmm0, 0x20(%rdx)
movups %xmm0, 0x10(%rdx)
movups %xmm0, (%rdx)
movl %ecx, 0xbe6a(%rip)      # 0x10c64
movb $0x0, 0xbe1f(%rip)      # 0x10c20
retq
// File: /workspace/github_c_makefile_star2_O2/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 0xbce3(%rip), %rdi      # 0x10af0
testq %rdi, %rdi
je 0x4e1f
callq 0x2090
andq $0x0, 0xbcd1(%rip)      # 0x10af0
xorl %ebx, %ebx
leaq 0xbcd8(%rip), %r14      # 0x10b00
cmpq $0x88, %rbx
je 0x4e40
movq (%rbx,%r14), %rdi
callq 0x2040
addq $0x8, %rbx
jmp 0x4e28
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x2210
// File: /workspace/github_c_makefile_star2_O2/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 %rbx
cmpq $0x0, 0x38(%rdi)
je 0x4e5f
xorl %ebx, %ebx
leaq 0x3762(%rip), %rdi      # 0x85bf
jmp 0x4e80
movq %rdi, %rbx
movl 0xc(%rdi), %esi
pushq $0x1
popq %rdi
callq 0x2130
testq %rax, %rax
je 0x4e89
movq %rax, 0x38(%rbx)
pushq $0x1
popq %rbx
leaq 0x3758(%rip), %rdi      # 0x85d8
callq 0x4b7e
movl %ebx, %eax
popq %rbx
retq
xorl %ebx, %ebx
jmp 0x4e85
// File: /workspace/github_c_makefile_star2_O2/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 0x4f3d
movl %ecx, %r12d
movl %edx, %ebp
testb $0x3, %bl
jne 0x4f60
leaq 0x372c(%rip), %rsi      # 0x85eb
movq %rsp, %r15
movq %r15, %rdi
movl %ebx, %edx
movl %r12d, %ecx
xorl %eax, %eax
callq 0x21f0
movq %r15, %rdi
callq 0x4b7e
testb $0x1, %bpl
je 0x4eeb
movq 0x38(%r14), %rax
movl %ebx, %ecx
movl %r12d, %edx
movb %dl, (%rax,%rcx)
testb $0x2, %bpl
je 0x4efe
movq 0x38(%r14), %rax
leal 0x1(%rbx), %ecx
movl %r12d, %edx
movb %dh, (%rax,%rcx)
testb $0x4, %bpl
je 0x4f14
movl %r12d, %eax
shrl $0x10, %eax
movq 0x38(%r14), %rcx
leal 0x2(%rbx), %edx
movb %al, (%rcx,%rdx)
pushq $0x1
popq %r15
testb $0x8, %bpl
je 0x4f2d
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 0x70b4(%rip), %rax      # 0xbff8
movq (%rax), %rdi
addl 0x8(%r14), %ebx
leaq 0x304d(%rip), %rsi      # 0x7f9f
xorl %r15d, %r15d
movl %ebx, %edx
xorl %eax, %eax
callq 0x2140
jmp 0x4f2d
movq 0x7091(%rip), %rax      # 0xbff8
movq (%rax), %rdi
movl 0x8(%r14), %edx
addl %ebx, %edx
leaq 0x3052(%rip), %rsi      # 0x7fc9
xorl %eax, %eax
callq 0x2140
jmp 0x4eb8
// File: /workspace/github_c_makefile_star2_O2/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 0x4fdb
leal 0x4(%rdx), %ecx
cmpl 0xc(%rdi), %ecx
ja 0x4ff1
movq 0x38(%rdi), %rcx
movl %edx, %esi
movl (%rcx,%rsi), %ecx
cmpl $0x8, %edx
je 0x4fac
testl %edx, %edx
jne 0x4fb2
orl $0x80000000, %ecx       # imm = 0x80000000
movl %ecx, (%rax)
leaq 0x364f(%rip), %rsi      # 0x860a
movq %rsp, %rbx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x21f0
movq %rbx, %rdi
callq 0x4b7e
pushq $0x1
popq %rbx
movl %ebx, %eax
addq $0x70, %rsp
popq %rbx
retq
movq 0x7016(%rip), %rax      # 0xbff8
movq (%rax), %rax
addl 0x8(%rdi), %edx
leaq 0x2ff9(%rip), %rsi      # 0x7fe8
jmp 0x5005
movq 0x7000(%rip), %rax      # 0xbff8
movq (%rax), %rax
addl 0x8(%rdi), %edx
leaq 0x2f9a(%rip), %rsi      # 0x7f9f
xorl %ebx, %ebx
movq %rax, %rdi
xorl %eax, %eax
callq 0x2140
jmp 0x4fd3
// File: /workspace/github_c_makefile_star2_O2/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 0x356d(%rip), %rsi      # 0x8644
movq %rsp, %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x21f0
movq %r14, %rdi
callq 0x4b7e
movq 0x38(%rbx), %rdi
callq 0x2040
addq $0x68, %rsp
popq %rbx
popq %r14
retq
nopl (%rax)
// File: /workspace/github_c_makefile_star2_O2/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 0x5128
leaq 0x3541(%rip), %rdi      # 0x865d
callq 0x4b7e
xorl %eax, %eax
jmp 0x52c0
movq %rdi, %rbx
movl 0xc(%rdi), %esi
pushq $0x1
popq %rdi
callq 0x2130
testq %rax, %rax
je 0x5121
movq %rax, %r14
movq %rax, 0x38(%rbx)
movl 0x8(%rbx), %edx
leaq 0x3574(%rip), %rsi      # 0x86c0
leaq 0x8(%rsp), %rdi
xorl %eax, %eax
callq 0x21a0
testl %eax, %eax
jle 0x5281
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x52a5
leaq 0x2f30(%rip), %rsi      # 0x80a5
callq 0x21b0
testq %rax, %rax
je 0x52cf
movq %rax, %r15
movq 0x8(%rsp), %rdi
callq 0x2040
xorl %r12d, %r12d
pushq $0x7
popq %rbp
movq %r15, %rdi
callq 0x2100
cmpl $0xa, %eax
je 0x5196
cmpl $0xd, %eax
je 0x5196
cmpl $-0x1, %eax
je 0x528a
leal -0x30(%rax), %r13d
cmpl $0x9, %r13d
jbe 0x51e3
leal -0x41(%rax), %ecx
cmpl $0x5, %ecx
ja 0x51c9
leal -0x37(%rax), %r13d
jmp 0x51e3
leal -0x61(%rax), %ecx
cmpl $0x5, %ecx
ja 0x51d7
leal -0x57(%rax), %r13d
jmp 0x51e3
xorl %r13d, %r13d
cmpl $0x20, %eax
jne 0x5310
subl $0x1, %ebp
jb 0x525b
movq %r15, %rdi
callq 0x2100
leal -0x30(%rax), %ecx
cmpl $0x9, %ecx
ja 0x5201
shll $0x4, %r13d
orl %ecx, %r13d
jmp 0x51e3
leal -0x41(%rax), %ecx
cmpl $0x5, %ecx
ja 0x5216
shll $0x4, %r13d
addl %eax, %r13d
addl $-0x37, %r13d
jmp 0x51e3
leal -0x61(%rax), %ecx
cmpl $0x5, %ecx
ja 0x522b
shll $0x4, %r13d
addl %eax, %r13d
addl $-0x57, %r13d
jmp 0x51e3
cmpl $0x20, %eax
ja 0x5307
movl %eax, %ecx
movabsq $0x100000600, %rdx      # imm = 0x100000600
btq %rcx, %rdx
jae 0x5307
leal 0x3(,%r12,4), %ecx
cmpl 0xc(%rbx), %ecx
jae 0x52fe
movl %r13d, (%r14,%r12,4)
incq %r12
pushq $0x7
popq %rbp
cmpl $-0x1, %eax
je 0x5196
cmpl $0xa, %eax
je 0x5196
movq %r15, %rdi
callq 0x2100
jmp 0x5265
leaq 0x2dc9(%rip), %rdi      # 0x8051
jmp 0x52ac
leaq 0x2e2e(%rip), %rdi      # 0x80bf
movl %r12d, %esi
xorl %eax, %eax
callq 0x20c0
movq %r15, %rdi
callq 0x2090
jmp 0x52b1
leaq 0x2dd0(%rip), %rdi      # 0x807c
callq 0x4b7e
leaq 0x2cd2(%rip), %rdi      # 0x7f8a
callq 0x4b7e
pushq $0x1
popq %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%rsp), %rdx
leaq 0x2dcd(%rip), %rsi      # 0x80a8
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x21f0
movq %rbx, %rdi
callq 0x4b7e
movq 0x8(%rsp), %rdi
callq 0x2040
jmp 0x52b1
leaq 0x2df4(%rip), %rdi      # 0x80f9
jmp 0x52ac
leaq 0x2e0b(%rip), %rdi      # 0x8119
jmp 0x52ac
movq 0x6ce1(%rip), %rax      # 0xbff8
movq (%rax), %rcx
leaq 0x2db9(%rip), %rdi      # 0x80da
pushq $0x1e
popq %rsi
pushq $0x1
popq %rdx
callq 0x2200
jmp 0x52b1
// File: /workspace/github_c_makefile_star2_O2/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 0x5351
testb $0x3, %dl
jne 0x5373
leaq 0x3330(%rip), %rdi      # 0x8675
callq 0x4b7e
pushq $0x1
popq %rbx
movl %ebx, %eax
popq %rbx
retq
movq 0x6ca0(%rip), %rax      # 0xbff8
movq (%rax), %rax
addl 0x8(%rdi), %edx
leaq 0x2c3a(%rip), %rsi      # 0x7f9f
xorl %ebx, %ebx
movq %rax, %rdi
xorl %eax, %eax
callq 0x2140
jmp 0x534d
movq 0x6c7e(%rip), %rax      # 0xbff8
movq (%rax), %rax
addl 0x8(%rdi), %edx
leaq 0x2c42(%rip), %rsi      # 0x7fc9
movq %rax, %rdi
xorl %eax, %eax
callq 0x2140
jmp 0x533e
// File: /workspace/github_c_makefile_star2_O2/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 0x31f6(%rip), %rsi      # 0x86a8
movq %rsp, %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x21f0
movq %r14, %rdi
callq 0x4b7e
movq 0x38(%rbx), %rdi
callq 0x2040
addq $0x68, %rsp
popq %rbx
popq %r14
retq