// File: donfreiday[P]gb/./imgui/stb_truetype.h
// Function: stbtt_InitFont(stbtt_fontinfo*, unsigned char const*, int)
STBTT_DEF int stbtt_InitFont(stbtt_fontinfo *info, const unsigned char *data2, int fontstart)
{
   stbtt_uint8 *data = (stbtt_uint8 *) data2;
   stbtt_uint32 cmap, t;
   stbtt_int32 i,numTables;

   info->data = data;
   info->fontstart = fontstart;

   cmap = stbtt__find_table(data, fontstart, "cmap");       // required
   info->loca = stbtt__find_table(data, fontstart, "loca"); // required
   info->head = stbtt__find_table(data, fontstart, "head"); // required
   info->glyf = stbtt__find_table(data, fontstart, "glyf"); // required
   info->hhea = stbtt__find_table(data, fontstart, "hhea"); // required
   info->hmtx = stbtt__find_table(data, fontstart, "hmtx"); // required
   info->kern = stbtt__find_table(data, fontstart, "kern"); // not required
   if (!cmap || !info->loca || !info->head || !info->glyf || !info->hhea || !info->hmtx)
      return 0;

   t = stbtt__find_table(data, fontstart, "maxp");
   if (t)
      info->numGlyphs = ttUSHORT(data+t+4);
   else
      info->numGlyphs = 0xffff;

   // find a cmap encoding table we understand *now* to avoid searching
   // later. (todo: could make this installable)
   // the same regardless of glyph.
   numTables = ttUSHORT(data + cmap + 2);
   info->index_map = 0;
   for (i=0; i < numTables; ++i) {
      stbtt_uint32 encoding_record = cmap + 4 + 8 * i;
      // find an encoding we understand:
      switch(ttUSHORT(data+encoding_record)) {
         case STBTT_PLATFORM_ID_MICROSOFT:
            switch (ttUSHORT(data+encoding_record+2)) {
               case STBTT_MS_EID_UNICODE_BMP:
               case STBTT_MS_EID_UNICODE_FULL:
                  // MS/Unicode
                  info->index_map = cmap + ttULONG(data+encoding_record+4);
                  break;
            }
            break;
        case STBTT_PLATFORM_ID_UNICODE:
            // Mac/iOS has these
            // all the encodingIDs are unicode, so we don't bother to check it
            info->index_map = cmap + ttULONG(data+encoding_record+4);
            break;
      }
   }
   if (info->index_map == 0)
      return 0;

   info->indexToLocFormat = ttUSHORT(data+info->head + 50);
   return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movl -0x1c(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x28(%rbp), %rdi
movl -0x1c(%rbp), %esi
leaq 0x20d2a(%rip), %rdx     # 0x64999
callq 0x46410
movl %eax, -0x2c(%rbp)
movq -0x28(%rbp), %rdi
movl -0x1c(%rbp), %esi
leaq 0x20d19(%rip), %rdx     # 0x6499e
callq 0x46410
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x18(%rax)
movq -0x28(%rbp), %rdi
movl -0x1c(%rbp), %esi
leaq 0x20d02(%rip), %rdx     # 0x649a3
callq 0x46410
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x1c(%rax)
movq -0x28(%rbp), %rdi
movl -0x1c(%rbp), %esi
leaq 0x20ceb(%rip), %rdx     # 0x649a8
callq 0x46410
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x20(%rax)
movq -0x28(%rbp), %rdi
movl -0x1c(%rbp), %esi
leaq 0x20cd4(%rip), %rdx     # 0x649ad
callq 0x46410
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x24(%rax)
movq -0x28(%rbp), %rdi
movl -0x1c(%rbp), %esi
leaq 0x20cbd(%rip), %rdx     # 0x649b2
callq 0x46410
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x28(%rax)
movq -0x28(%rbp), %rdi
movl -0x1c(%rbp), %esi
leaq 0x20ca6(%rip), %rdx     # 0x649b7
callq 0x46410
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x2c(%rax)
cmpl $0x0, -0x2c(%rbp)
je 0x43d57
movq -0x10(%rbp), %rax
cmpl $0x0, 0x18(%rax)
je 0x43d57
movq -0x10(%rbp), %rax
cmpl $0x0, 0x1c(%rax)
je 0x43d57
movq -0x10(%rbp), %rax
cmpl $0x0, 0x20(%rax)
je 0x43d57
movq -0x10(%rbp), %rax
cmpl $0x0, 0x24(%rax)
je 0x43d57
movq -0x10(%rbp), %rax
cmpl $0x0, 0x28(%rax)
jne 0x43d63
movl $0x0, -0x4(%rbp)
jmp 0x43ed8
movq -0x28(%rbp), %rdi
movl -0x1c(%rbp), %esi
leaq 0x20c4b(%rip), %rdx     # 0x649bc
callq 0x46410
movl %eax, -0x30(%rbp)
cmpl $0x0, -0x30(%rbp)
je 0x43d9e
movq -0x28(%rbp), %rdi
movl -0x30(%rbp), %eax
addq %rax, %rdi
addq $0x4, %rdi
callq 0x46500
movzwl %ax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x14(%rax)
jmp 0x43da9
movq -0x10(%rbp), %rax
movl $0xffff, 0x14(%rax)     # imm = 0xFFFF
movq -0x28(%rbp), %rdi
movl -0x2c(%rbp), %eax
addq %rax, %rdi
addq $0x2, %rdi
callq 0x46500
movzwl %ax, %eax
movl %eax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movl $0x0, 0x30(%rax)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x38(%rbp), %eax
jge 0x43e9c
movl -0x2c(%rbp), %edx
movl -0x34(%rbp), %eax
movl %eax, %ecx
movl %edx, %eax
leal 0x4(%rax,%rcx,8), %eax
movl %eax, -0x3c(%rbp)
movq -0x28(%rbp), %rdi
movl -0x3c(%rbp), %eax
addq %rax, %rdi
callq 0x46500
movzwl %ax, %ecx
movl %ecx, -0x40(%rbp)
testw %ax, %ax
je 0x43e67
jmp 0x43e0d
movl -0x40(%rbp), %eax
subl $0x3, %eax
jne 0x43e8c
jmp 0x43e17
movq -0x28(%rbp), %rax
movl -0x3c(%rbp), %ecx
leaq 0x2(%rax,%rcx), %rdi
callq 0x46500
movzwl %ax, %ecx
movl %ecx, -0x44(%rbp)
subw $0x1, %ax
je 0x43e40
jmp 0x43e36
movl -0x44(%rbp), %eax
subl $0xa, %eax
jne 0x43e65
jmp 0x43e40
movl -0x2c(%rbp), %eax
movl %eax, -0x48(%rbp)
movq -0x28(%rbp), %rdi
movl -0x3c(%rbp), %eax
addq %rax, %rdi
addq $0x4, %rdi
callq 0x46390
movl -0x48(%rbp), %ecx
addl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x30(%rax)
jmp 0x43e8c
movl -0x2c(%rbp), %eax
movl %eax, -0x4c(%rbp)
movq -0x28(%rbp), %rdi
movl -0x3c(%rbp), %eax
addq %rax, %rdi
addq $0x4, %rdi
callq 0x46390
movl -0x4c(%rbp), %ecx
addl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x30(%rax)
jmp 0x43e8e
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x43dd4
movq -0x10(%rbp), %rax
cmpl $0x0, 0x30(%rax)
jne 0x43eaf
movl $0x0, -0x4(%rbp)
jmp 0x43ed8
movq -0x28(%rbp), %rdi
movq -0x10(%rbp), %rax
movslq 0x1c(%rax), %rax
addq %rax, %rdi
addq $0x32, %rdi
callq 0x46500
movzwl %ax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x34(%rax)
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)