// File: /workspace/github_c_makefile_star2_O3/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, 0x9259(%rip)      # 0xe0d0
jne 0x500e
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movb $0x1, 0x9241(%rip)      # 0xe0d0
xorl %r15d, %r15d
leaq 0x7277(%rip), %r14      # 0xc110
leaq (%r15,%r14), %rdx
addq $0x18, %rdx
movq -0x10(%rdx), %rdi
leaq (%r15,%r14), %rbx
addq $0x1a, %rbx
movl $0x69, %esi
movq %rbx, %rcx
callq 0x500f
movq -0x12(%rbx), %rdi
leaq (%r15,%r14), %rdx
addq $0x1c, %rdx
leaq (%r15,%r14), %rbx
addq $0x1e, %rbx
movl $0x64, %esi
movq %rbx, %rcx
callq 0x500f
movq -0x16(%rbx), %rdi
leaq (%r15,%r14), %rdx
addq $0x20, %rdx
leaq (%r15,%r14), %rbx
addq $0x22, %rbx
movl $0x6d, %esi
movq %rbx, %rcx
callq 0x500f
movq -0x1a(%rbx), %rdi
leaq (%r15,%r14), %rdx
addq $0x24, %rdx
leaq (%r15,%r14), %rbx
addq $0x26, %rbx
movl $0x6e, %esi
movq %rbx, %rcx
callq 0x500f
movq -0x1e(%rbx), %rdi
leaq (%r15,%r14), %rdx
addq $0x28, %rdx
xorl %esi, %esi
xorl %ecx, %ecx
callq 0x500f
addq $0x30, %r15
cmpq $0x1fb0, %r15           # imm = 0x1FB0
jne 0x4e99
leaq 0x9196(%rip), %rbx      # 0xe0e0
xorl %r15d, %r15d
movl $0x7fff8, %edx          # imm = 0x7FFF8
movq %rbx, %rdi
xorl %esi, %esi
callq 0x30f0
xorl %eax, %eax
movq %rax, %rcx
orq %r15, %rcx
xorl %edx, %edx
movq %rcx, %rsi
orq %rdx, %rsi
xorl %edi, %edi
movq %rsi, %r8
orq %rdi, %r8
xorl %r9d, %r9d
movzwl 0x1c(%r9,%r14), %r10d
orw 0x18(%r9,%r14), %r10w
movzwl %r10w, %r10d
movzwl 0x20(%r9,%r14), %r11d
movzwl 0x24(%r9,%r14), %r12d
orl %r11d, %r12d
orl %r10d, %r12d
notl %r12d
andl %r8d, %r12d
movzwl 0x28(%r9,%r14), %r10d
cmpl %r10d, %r12d
je 0x4fb9
addq $0x30, %r9
cmpq $0x1fb0, %r9            # imm = 0x1FB0
jne 0x4f77
jmp 0x4fc0
addq %r14, %r9
movq %r9, (%rbx,%r8,8)
incq %rdi
cmpq $0x10, %rdi
jne 0x4f6e
leaq 0x10(%rdx), %rsi
cmpq $0xf0, %rdx
movq %rsi, %rdx
jb 0x4f66
leaq 0x100(%rax), %rcx
cmpq $0xf00, %rax            # imm = 0xF00
movq %rcx, %rax
jb 0x4f5e
leaq 0x1000(%r15), %rax
cmpq $0xf000, %r15           # imm = 0xF000
movq %rax, %r15
jb 0x4f5c
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq