// File: /workspace/github_c_makefile_star2_O0/hamsternz[P]emulate-risc-v/gpio.c
// Function: GPIO_get
int GPIO_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 0x00:
       break;
     case 0x04:
       break;
     case 0x08:
       break;
     case 0x0C:
       break;
     case 0x10:
       break;
     case 0x14:
       break;
     case 0x18:
       break;
     case 0x1C:
       break;
     case 0x20:
       break;
     case 0x24:
       break;
     case 0x28:
       break;
     case 0x2C:
       break;
     case 0x30:
       break;
     case 0x34:
       break;
     case 0x38:
       break;
     case 0x3C:
       break;
     case 0x40:
       break;
   }
   *value = v;
     
   sprintf(buffer,"GPIO Rd address 0x%08x: 0x%08x", address, v);
   display_log(buffer);

   return 1;
}

// Assembly:
subq $0x98, %rsp
movq %rdi, 0x88(%rsp)
movl %esi, 0x84(%rsp)
movq %rdx, 0x78(%rsp)
movl $0x0, 0x74(%rsp)
movl 0x84(%rsp), %eax
andl $0x3, %eax
cmpl $0x0, %eax
je 0x8a2c
movq 0x55ff(%rip), %rax      # 0xdff8
movq (%rax), %rdi
movq 0x88(%rsp), %rax
movl 0x8(%rax), %edx
addl 0x84(%rsp), %edx
leaq 0x2565(%rip), %rsi      # 0xaf7a
movb $0x0, %al
callq 0x2130
movl $0x0, 0x94(%rsp)
jmp 0x8b93
movl 0x84(%rsp), %eax
addl $0x4, %eax
movq 0x88(%rsp), %rcx
cmpl 0xc(%rcx), %eax
jbe 0x8a7d
movq 0x55ae(%rip), %rax      # 0xdff8
movq (%rax), %rdi
movq 0x88(%rsp), %rax
movl 0x8(%rax), %edx
addl 0x84(%rsp), %edx
leaq 0x24cb(%rip), %rsi      # 0xaf31
movb $0x0, %al
callq 0x2130
movl $0x0, 0x94(%rsp)
jmp 0x8b93
movq 0x88(%rsp), %rax
movq 0x38(%rax), %rax
movl 0x84(%rsp), %ecx
movzbl (%rax,%rcx), %eax
movl %eax, 0x74(%rsp)
movl 0x74(%rsp), %eax
movq 0x88(%rsp), %rcx
movq 0x38(%rcx), %rcx
movl 0x84(%rsp), %edx
incl %edx
movzbl (%rcx,%rdx), %ecx
shll $0x8, %ecx
addl %ecx, %eax
movl %eax, 0x74(%rsp)
movl 0x74(%rsp), %eax
movq 0x88(%rsp), %rcx
movq 0x38(%rcx), %rcx
movl 0x84(%rsp), %edx
addl $0x2, %edx
movzbl (%rcx,%rdx), %ecx
shll $0x10, %ecx
addl %ecx, %eax
movl %eax, 0x74(%rsp)
movl 0x74(%rsp), %eax
movq 0x88(%rsp), %rcx
movq 0x38(%rcx), %rcx
movl 0x84(%rsp), %edx
addl $0x3, %edx
movzbl (%rcx,%rdx), %ecx
shll $0x18, %ecx
addl %ecx, %eax
movl %eax, 0x74(%rsp)
movl 0x84(%rsp), %eax
movq %rax, 0x8(%rsp)
subq $0x40, %rax
ja 0x8b55
movq 0x8(%rsp), %rax
leaq 0x2d16(%rip), %rcx      # 0xb840
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
jmp 0x8b55
jmp 0x8b55
jmp 0x8b55
jmp 0x8b55
jmp 0x8b55
jmp 0x8b55
jmp 0x8b55
jmp 0x8b55
jmp 0x8b55
jmp 0x8b55
jmp 0x8b55
jmp 0x8b55
jmp 0x8b55
jmp 0x8b55
jmp 0x8b55
jmp 0x8b55
jmp 0x8b55
movl 0x74(%rsp), %ecx
movq 0x78(%rsp), %rax
movl %ecx, (%rax)
leaq 0x10(%rsp), %rdi
movl 0x84(%rsp), %edx
movl 0x74(%rsp), %ecx
leaq 0x2e18(%rip), %rsi      # 0xb98f
movb $0x0, %al
callq 0x21e0
leaq 0x10(%rsp), %rdi
callq 0x6b20
movl $0x1, 0x94(%rsp)
movl 0x94(%rsp), %eax
addq $0x98, %rsp
retq
nopw %cs:(%rax,%rax)