// File: /workspace/github_c_makefile_star2_O2/inolen[P]gdb_server/./sh4.h
// Function: sh4_init_tables
void INIT_TABLES() {
  static int initialized = 0;

  if (initialized) {
    return;
  }

  initialized = 1;

  // extract argument encoding information from signature
  for (int i = 0; i < NUM_OPCODES; i++) {
    INSTR_TYPE_T *type = &instr_type[i];
    ARG_MASK(type->sig, 'i', &type->imm_mask, &type->imm_shift);
    ARG_MASK(type->sig, 'd', &type->disp_mask, &type->disp_shift);
    ARG_MASK(type->sig, 'm', &type->rm_mask, &type->rm_shift);
    ARG_MASK(type->sig, 'n', &type->rn_mask, &type->rn_shift);
    ARG_MASK(type->sig, 0, &type->opcode_mask, NULL);
  }

  // initialize lookup table
  memset(instr_lookup, 0, sizeof(instr_lookup));

  for (int w = 0; w < 0x10000; w += 0x1000) {
    for (int x = 0; x < 0x1000; x += 0x100) {
      for (int y = 0; y < 0x100; y += 0x10) {
        for (int z = 0; z < 0x10; z++) {
          uint16_t value = w + x + y + z;

          for (int i = 0; i < NUM_OPCODES; i++) {
            INSTR_TYPE_T *type = &instr_type[i];
            uint16_t arg_mask = type->imm_mask | type->disp_mask |
                                type->rm_mask | type->rn_mask;

            if ((value & ~arg_mask) == type->opcode_mask) {
              instr_lookup[value] = type;
              break;
            }
          }
        }
      }
    }
  }
}

// Assembly:
cmpb $0x0, 0x926b(%rip)      # 0xe0d0
jne 0x5013
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movb $0x1, 0x9250(%rip)      # 0xe0d0
xorl %ebx, %ebx
leaq 0x7287(%rip), %r14      # 0xc110
pushq $0x6d
popq %r15
pushq $0x6e
popq %r12
cmpq $0x1fb0, %rbx           # imm = 0x1FB0
je 0x4f32
leaq (%rbx,%r14), %rdx
addq $0x18, %rdx
movq -0x10(%rdx), %rdi
leaq 0x1a(%rbx,%r14), %r13
pushq $0x69
popq %rsi
movq %r13, %rcx
callq 0x5014
movq -0x12(%r13), %rdi
leaq (%rbx,%r14), %rdx
addq $0x1c, %rdx
leaq 0x1e(%rbx,%r14), %r13
pushq $0x64
popq %rsi
movq %r13, %rcx
callq 0x5014
movq -0x16(%r13), %rdi
leaq (%rbx,%r14), %rdx
addq $0x20, %rdx
leaq (%rbx,%r14), %r13
addq $0x22, %r13
movl %r15d, %esi
movq %r13, %rcx
callq 0x5014
movq -0x1a(%r13), %rdi
leaq (%rbx,%r14), %rdx
addq $0x24, %rdx
leaq (%rbx,%r14), %r13
addq $0x26, %r13
movl %r12d, %esi
movq %r13, %rcx
callq 0x5014
movq -0x1e(%r13), %rdi
leaq (%rbx,%r14), %rdx
addq $0x28, %rdx
xorl %esi, %esi
xorl %ecx, %ecx
callq 0x5014
addq $0x30, %rbx
jmp 0x4e91
leaq 0x91a7(%rip), %rbx      # 0xe0e0
movl $0x7fff8, %edx          # imm = 0x7FFF8
movq %rbx, %rdi
xorl %esi, %esi
callq 0x30f0
xorl %esi, %esi
leaq 0x718f(%rip), %rax      # 0xc0e0
cmpq $0xffff, %rsi           # imm = 0xFFFF
ja 0x5005
xorl %ecx, %ecx
movq %rsi, -0x30(%rbp)
cmpq $0xfff, %rcx            # imm = 0xFFF
ja 0x4ff9
movq %rcx, %rdx
orq %rsi, %rdx
xorl %esi, %esi
cmpq $0xff, %rsi
ja 0x4fe9
movq %rdx, %rdi
orq %rsi, %rdi
xorl %r8d, %r8d
cmpq $0x10, %r8
je 0x4fe3
movq %rdi, %r9
orq %r8, %r9
movl $0xaa, %r10d
movq %rax, %r11
decq %r10
je 0x4fde
leaq 0x30(%r11), %r15
movzwl 0x4c(%r11), %r12d
orw 0x48(%r11), %r12w
movzwl %r12w, %r12d
movzwl 0x50(%r11), %r13d
movzwl 0x54(%r11), %r14d
orl %r13d, %r14d
orl %r12d, %r14d
notl %r14d
andl %r9d, %r14d
movzwl 0x58(%r11), %r12d
movq %r15, %r11
cmpl %r12d, %r14d
jne 0x4fa0
movq %r15, (%rbx,%r9,8)
incq %r8
jmp 0x4f8b
addq $0x10, %rsi
jmp 0x4f79
addq $0x100, %rcx            # imm = 0x100
movq -0x30(%rbp), %rsi
jmp 0x4f64
addq $0x1000, %rsi           # imm = 0x1000
jmp 0x4f51
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq