// File: /workspace/github_c_makefile_star2_O3/smilingthax[P]libfontembed/sfnt.c
// Function: otf_load_glyf
int otf_load_glyf(OTF_FILE *otf) // {{{  - 0 on success
{
  assert(!is_CFF(otf)); // not for CFF
  int iA,len;
  // {{{ find glyf table
  iA=otf_find_table(otf,OTF_TAG('g','l','y','f'));
  if (iA==-1) {
    fprintf(stderr,"Unsupported OTF font / glyf table\n");
    return -1;
  }
  otf->glyfTable=otf->tables+iA;
  // }}}

  // {{{ read loca table
  char *loca=otf_get_table(otf,OTF_TAG('l','o','c','a'),&len);
  if ( (!loca)||
       (otf->indexToLocFormat>=2)||
       (otf_padded(len)!=otf_padded((otf->numGlyphs+1)*(otf->indexToLocFormat+1)*2)) ) {
    fprintf(stderr,"Unsupported OTF font / loca table\n");
    free(loca);
    return -1;
  }
  if (otf->glyphOffsets) {
    free(otf->glyphOffsets);
    assert(0);
  }
  otf->glyphOffsets=malloc((otf->numGlyphs+1)*sizeof(unsigned int));
  if (!otf->glyphOffsets) {
    fprintf(stderr,"Bad alloc: %s\n", strerror(errno));
    return -1;
  }
  if (otf->indexToLocFormat==0) {
    for (iA=0;iA<=otf->numGlyphs;iA++) {
      otf->glyphOffsets[iA]=get_USHORT(loca+iA*2)*2;
    }
  } else { // indexToLocFormat==1
    for (iA=0;iA<=otf->numGlyphs;iA++) {
      otf->glyphOffsets[iA]=get_ULONG(loca+iA*4);
    }
  }
  free(loca);
  if (otf->glyphOffsets[otf->numGlyphs]>otf->glyfTable->length) {
    fprintf(stderr,"Bad loca table\n");
    return -1;
  }
  // }}}

  if (otf->glyf) {
    free(otf->glyf);
    assert(0);
    otf->glyf=NULL;
  }
  if (otf->flags&OTF_F_CACHE_GLYF) {
    otf->glyf=otf_get_table(otf,OTF_TAG('g','l','y','f'),&len);
    if (!otf->glyf) {
      return -1;
    }

    if (otf->gly) {
      free(otf->gly);
      assert(0);
      otf->gly=NULL;
    }
    return 0;
  }

  // {{{ allocate otf->gly slot
  int maxGlyfLen=0;  // no single glyf takes more space
  for (iA=1;iA<=otf->numGlyphs;iA++) {
    const int glyfLen=otf->glyphOffsets[iA]-otf->glyphOffsets[iA-1];
    if (glyfLen<0) {
      fprintf(stderr,"Bad loca table: glyph len %d\n",glyfLen);
      return -1;
    }
    if (maxGlyfLen<glyfLen) {
      maxGlyfLen=glyfLen;
    }
  }
  if (otf->gly) {
    free(otf->gly);
    assert(0);
  }
  otf->gly=malloc(maxGlyfLen*sizeof(char));
  if (!otf->gly) {
    fprintf(stderr,"Bad alloc: %s\n", strerror(errno));
    return -1;
  }
  // }}}

  return 0;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
testb $0x1, 0xa(%rdi)
jne 0x4526
movq %rdi, %rbx
movl $0x676c7966, %esi       # imm = 0x676C7966
callq 0x41db
cmpl $-0x1, %eax
je 0x44e8
cltq
leaq (%rax,%rax,4), %rax
shlq $0x2, %rax
addq 0x40(%rbx), %rax
movq %rax, 0x88(%rbx)
leaq 0x4(%rsp), %rdx
movq %rbx, %rdi
movl $0x6c6f6361, %esi       # imm = 0x6C6F6361
callq 0x423c
movq %rax, %r14
testq %rax, %rax
je 0x44de
movzwl 0x4a(%rbx), %r12d
cmpl $0x1, %r12d
ja 0x44de
movl 0x4(%rsp), %ecx
addl $0x3, %ecx
andl $-0x4, %ecx
movzwl 0x4c(%rbx), %eax
leaq 0x1(%rax), %r15
leal 0x2(,%r12,2), %edx
imull %r15d, %edx
addl $0x3, %edx
andl $0x7ffffffc, %edx       # imm = 0x7FFFFFFC
cmpl %edx, %ecx
jne 0x44de
movq 0x50(%rbx), %rdi
testq %rdi, %rdi
jne 0x4545
leaq 0x4(,%rax,4), %rdi
callq 0x21c0
movq %rax, 0x50(%rbx)
testq %rax, %rax
je 0x44ef
xorl %ecx, %ecx
testl %r12d, %r12d
je 0x440a
movl (%r14,%rcx,4), %edx
bswapl %edx
movl %edx, (%rax,%rcx,4)
incq %rcx
cmpq %rcx, %r15
jne 0x43f7
jmp 0x4426
movzbl (%r14,%rcx,2), %edx
movzbl 0x1(%r14,%rcx,2), %esi
shll $0x9, %edx
leal (%rdx,%rsi,2), %edx
movl %edx, (%rax,%rcx,4)
incq %rcx
cmpq %rcx, %r15
jne 0x440a
movq %r14, %rdi
callq 0x21a0
movq 0x50(%rbx), %rax
movq 0x88(%rbx), %rdx
movzwl 0x4c(%rbx), %ecx
movl (%rax,%rcx,4), %esi
cmpl 0xc(%rdx), %esi
ja 0x44f6
movq 0x90(%rbx), %rdi
testq %rdi, %rdi
jne 0x4569
testb $0x1, 0x8(%rbx)
jne 0x44ac
xorl %edi, %edi
testq %rcx, %rcx
je 0x4484
xorl %esi, %esi
movl 0x4(%rax,%rsi,4), %edx
subl (%rax,%rsi,4), %edx
js 0x44fd
cmpl %edx, %edi
cmovlel %edx, %edi
incq %rsi
cmpq %rsi, %rcx
jne 0x4468
movl %edi, %edi
movq 0x80(%rbx), %rax
testq %rax, %rax
jne 0x458d
callq 0x21c0
movq %rax, 0x80(%rbx)
testq %rax, %rax
jne 0x44da
callq 0x26f3
jmp 0x4515
leaq 0x4(%rsp), %rdx
movq %rbx, %rdi
movl $0x676c7966, %esi       # imm = 0x676C7966
callq 0x423c
movq %rax, 0x90(%rbx)
testq %rax, %rax
je 0x4515
movq 0x80(%rbx), %rdi
testq %rdi, %rdi
jne 0x45b4
xorl %eax, %eax
jmp 0x451a
movq %r14, %rdi
callq 0x276f
jmp 0x4515
callq 0x2799
jmp 0x4515
callq 0x2742
jmp 0x4515
callq 0x2720
jmp 0x4515
movq 0xaadc(%rip), %rax      # 0xefe0
movq (%rax), %rdi
leaq 0x5f94(%rip), %rsi      # 0xa4a2
xorl %eax, %eax
callq 0x21d0
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
leaq 0x5ef4(%rip), %rdi      # 0xa421
leaq 0x651b(%rip), %rsi      # 0xaa4f
leaq 0x5ef3(%rip), %rcx      # 0xa42e
movl $0x245, %edx            # imm = 0x245
callq 0x20e0
callq 0x21a0
leaq 0x676f(%rip), %rdi      # 0xacc0
leaq 0x64f7(%rip), %rsi      # 0xaa4f
leaq 0x5ecf(%rip), %rcx      # 0xa42e
movl $0x25b, %edx            # imm = 0x25B
callq 0x20e0
callq 0x21a0
leaq 0x674b(%rip), %rdi      # 0xacc0
leaq 0x64d3(%rip), %rsi      # 0xaa4f
leaq 0x5eab(%rip), %rcx      # 0xa42e
movl $0x274, %edx            # imm = 0x274
callq 0x20e0
movq %rax, %rdi
callq 0x21a0
leaq 0x6724(%rip), %rdi      # 0xacc0
leaq 0x64ac(%rip), %rsi      # 0xaa4f
leaq 0x5e84(%rip), %rcx      # 0xa42e
movl $0x293, %edx            # imm = 0x293
callq 0x20e0
callq 0x21a0
leaq 0x6700(%rip), %rdi      # 0xacc0
leaq 0x6488(%rip), %rsi      # 0xaa4f
leaq 0x5e60(%rip), %rcx      # 0xa42e
movl $0x27f, %edx            # imm = 0x27F
callq 0x20e0