// File: /workspace/github_cpp_makefile_star2_O3/Ciaxur[P]yagb-emu/include/imgui/imstb_truetype.h
// Function: stbtt_FindGlyphIndex(stbtt_fontinfo const*, int)
STBTT_DEF int stbtt_FindGlyphIndex(const stbtt_fontinfo *info, int unicode_codepoint)
{
   stbtt_uint8 *data = info->data;
   stbtt_uint32 index_map = info->index_map;

   stbtt_uint16 format = ttUSHORT(data + index_map + 0);
   if (format == 0) { // apple byte encoding
      stbtt_int32 bytes = ttUSHORT(data + index_map + 2);
      if (unicode_codepoint < bytes-6)
         return ttBYTE(data + index_map + 6 + unicode_codepoint);
      return 0;
   } else if (format == 6) {
      stbtt_uint32 first = ttUSHORT(data + index_map + 6);
      stbtt_uint32 count = ttUSHORT(data + index_map + 8);
      if ((stbtt_uint32) unicode_codepoint >= first && (stbtt_uint32) unicode_codepoint < first+count)
         return ttUSHORT(data + index_map + 10 + (unicode_codepoint - first)*2);
      return 0;
   } else if (format == 2) {
      STBTT_assert(0); // @TODO: high-byte mapping for japanese/chinese/korean
      return 0;
   } else if (format == 4) { // standard mapping for windows fonts: binary search collection of ranges
      stbtt_uint16 segcount = ttUSHORT(data+index_map+6) >> 1;
      stbtt_uint16 searchRange = ttUSHORT(data+index_map+8) >> 1;
      stbtt_uint16 entrySelector = ttUSHORT(data+index_map+10);
      stbtt_uint16 rangeShift = ttUSHORT(data+index_map+12) >> 1;

      // do a binary search of the segments
      stbtt_uint32 endCount = index_map + 14;
      stbtt_uint32 search = endCount;

      if (unicode_codepoint > 0xffff)
         return 0;

      // they lie from endCount .. endCount + segCount
      // but searchRange is the nearest power of two, so...
      if (unicode_codepoint >= ttUSHORT(data + search + rangeShift*2))
         search += rangeShift*2;

      // now decrement to bias correctly to find smallest
      search -= 2;
      while (entrySelector) {
         stbtt_uint16 end;
         searchRange >>= 1;
         end = ttUSHORT(data + search + searchRange*2);
         if (unicode_codepoint > end)
            search += searchRange*2;
         --entrySelector;
      }
      search += 2;

      {
         stbtt_uint16 offset, start;
         stbtt_uint16 item = (stbtt_uint16) ((search - endCount) >> 1);

         STBTT_assert(unicode_codepoint <= ttUSHORT(data + endCount + 2*item));
         start = ttUSHORT(data + index_map + 14 + segcount*2 + 2 + 2*item);
         if (unicode_codepoint < start)
            return 0;

         offset = ttUSHORT(data + index_map + 14 + segcount*6 + 2 + 2*item);
         if (offset == 0)
            return (stbtt_uint16) (unicode_codepoint + ttSHORT(data + index_map + 14 + segcount*4 + 2 + 2*item));

         return ttUSHORT(data + offset + (unicode_codepoint-start)*2 + index_map + 14 + segcount*6 + 2 + 2*item);
      }
   } else if (format == 12 || format == 13) {
      stbtt_uint32 ngroups = ttULONG(data+index_map+12);
      stbtt_int32 low,high;
      low = 0; high = (stbtt_int32)ngroups;
      // Binary search the right group.
      while (low < high) {
         stbtt_int32 mid = low + ((high-low) >> 1); // rounds down, so low <= mid < high
         stbtt_uint32 start_char = ttULONG(data+index_map+16+mid*12);
         stbtt_uint32 end_char = ttULONG(data+index_map+16+mid*12+4);
         if ((stbtt_uint32) unicode_codepoint < start_char)
            high = mid;
         else if ((stbtt_uint32) unicode_codepoint > end_char)
            low = mid+1;
         else {
            stbtt_uint32 start_glyph = ttULONG(data+index_map+16+mid*12+8);
            if (format == 12)
               return start_glyph + unicode_codepoint-start_char;
            else // format == 13
               return start_glyph;
         }
      }
      return 0; // not found
   }
   // @TODO
   STBTT_assert(0);
   return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
movl %esi, %eax
leaq (%rdi,%rax), %rcx
movzwl (%rdi,%rax), %r8d
rolw $0x8, %r8w
cmpw $0x6, %r8w
ja 0x7f889
movzwl %r8w, %r9d
leaq 0x47160(%rip), %r10     # 0xc69c0
movslq (%r10,%r9,4), %r9
addq %r10, %r9
jmpq *%r9
movzwl 0x2(%rcx), %eax
rolw $0x8, %ax
movzwl %ax, %eax
addl $-0x6, %eax
cmpl %edx, %eax
jle 0x7f8ee
movslq %edx, %rax
movzbl 0x6(%rcx,%rax), %eax
jmp 0x7fa99
movl %r8d, %eax
andl $0xfffe, %eax           # imm = 0xFFFE
cmpw $0xc, %ax
jne 0x7fa9e
movl 0xc(%rcx), %eax
bswapl %eax
testl %eax, %eax
jle 0x7f8ee
xorl %esi, %esi
movl %eax, %edi
subl %esi, %edi
sarl %edi
addl %esi, %edi
movslq %edi, %r9
shlq $0x2, %r9
leaq (%r9,%r9,2), %r9
movl 0x10(%rcx,%r9), %r11d
bswapl %r11d
movl %edx, %r10d
subl %r11d, %r10d
jae 0x7f8cd
movl %edi, %eax
jmp 0x7f8e0
movl 0x14(%rcx,%r9), %esi
bswapl %esi
cmpl %edx, %esi
jae 0x7f9c1
incl %edi
movl %edi, %esi
cmpl %eax, %esi
jl 0x7f8a6
jmp 0x7f8ee
cmpl $0xffff, %edx           # imm = 0xFFFF
jle 0x7f939
xorl %eax, %eax
jmp 0x7fa99
movzwl 0x6(%rcx), %eax
rolw $0x8, %ax
movzwl %ax, %edi
xorl %eax, %eax
movl %edx, %esi
subl %edi, %esi
jb 0x7fa99
movzwl 0x8(%rcx), %r8d
rolw $0x8, %r8w
movzwl %r8w, %r8d
addl %edi, %r8d
cmpl %edx, %r8d
jbe 0x7fa99
addl %esi, %esi
movzwl 0xa(%rcx,%rsi), %eax
rolw $0x8, %ax
movzwl %ax, %eax
jmp 0x7fa99
leal 0xe(%rsi), %r9d
movzbl 0xc(%rcx), %r8d
movzwl 0xa(%rcx), %r10d
rolw $0x8, %r10w
shll $0x8, %r8d
movzbl 0xd(%rcx), %r11d
andl $-0x2, %r11d
orq %r8, %r11
addq %rdi, %r9
movzwl (%r9,%r11), %r8d
rolw $0x8, %r8w
movzwl %r8w, %r8d
xorl %ebx, %ebx
cmpl %edx, %r8d
cmovgl %ebx, %r11d
addl %esi, %r11d
addl $0xc, %r11d
testw %r10w, %r10w
je 0x7f9da
movzwl 0x8(%rcx), %ebx
rolw $0x8, %bx
movzwl %bx, %ebx
shrl %ebx
movl %r11d, %r14d
addq %rdi, %r14
movl %ebx, %r8d
andl $-0x2, %r8d
movzwl (%r8,%r14), %r14d
rolw $0x8, %r14w
movzwl %r14w, %r14d
cmpl %edx, %r14d
jl 0x7f9b3
xorl %r8d, %r8d
addl %r11d, %r8d
movl %r8d, %r11d
decw %r10w
jne 0x7f98b
jmp 0x7f9dd
xorl %eax, %eax
cmpw $0xc, %r8w
movl 0x18(%rcx,%r9), %ecx
bswapl %ecx
cmovel %r10d, %eax
addl %ecx, %eax
jmp 0x7fa99
movl %r11d, %r8d
subl %esi, %r8d
addl $0x1fff4, %r8d          # imm = 0x1FFF4
andl $0x1fffe, %r8d          # imm = 0x1FFFE
movzwl (%r9,%r8), %esi
rolw $0x8, %si
movzwl %si, %esi
cmpl %edx, %esi
jl 0x7fadc
movzwl 0x6(%rcx), %esi
rolw $0x8, %si
movzwl %si, %esi
movl %esi, %r9d
andl $-0x2, %r9d
addq %rcx, %r9
addq $0xe, %r9
movzwl 0x2(%r8,%r9), %r9d
rolw $0x8, %r9w
movzwl %r9w, %r11d
xorl %r10d, %r10d
movl %edx, %r9d
subl %r11d, %r9d
jl 0x7fa95
shrl %esi
addq $0xe, %rcx
leal (%rsi,%rsi), %r10d
leaq (%r10,%r10,2), %r10
leaq (%rcx,%r10), %r11
movzwl 0x2(%r8,%r11), %r11d
rolw $0x8, %r11w
testw %r11w, %r11w
je 0x7fa7e
movzwl %r11w, %ecx
addq %rcx, %rdi
addl %r9d, %r9d
movslq %r9d, %rcx
addq %rax, %rdi
addq %r10, %rdi
addq %rcx, %rdi
movzwl 0x10(%r8,%rdi), %eax
rolw $0x8, %ax
movzwl %ax, %r10d
jmp 0x7fa95
movl %esi, %eax
leaq (%rcx,%rax,4), %rax
movzwl 0x2(%r8,%rax), %eax
rolw $0x8, %ax
movzwl %ax, %r10d
addl %edx, %r10d
movzwl %r10w, %eax
popq %rbx
popq %r14
popq %rbp
retq
leaq 0x38647(%rip), %rdi     # 0xb80ec
leaq 0x4e446(%rip), %rsi     # 0xcdef2
leaq 0x4e595(%rip), %rcx     # 0xce048
movl $0x60e, %edx            # imm = 0x60E
callq 0xc140
leaq 0x38628(%rip), %rdi     # 0xb80ec
leaq 0x4e427(%rip), %rsi     # 0xcdef2
leaq 0x4e576(%rip), %rcx     # 0xce048
movl $0x5c7, %edx            # imm = 0x5C7
callq 0xc140
leaq 0x4e59b(%rip), %rdi     # 0xce07e
leaq 0x4e408(%rip), %rsi     # 0xcdef2
leaq 0x4e557(%rip), %rcx     # 0xce048
movl $0x5eb, %edx            # imm = 0x5EB
callq 0xc140