// File: /workspace/github_c_makefile_star2_O0/smilingthax[P]libfontembed/sfnt.c
// Function: otf_do_load
static int otf_do_load(OTF_FILE *otf,int pos) // {{{
{
  int iA;

  // {{{ check version
  if (otf->version==0x00010000) { // 1.0 truetype
  } else if (otf->version==OTF_TAG('O','T','T','O')) { // OTF(CFF)
    otf->flags|=OTF_F_FMT_CFF;
  } else if (otf->version==OTF_TAG('t','r','u','e')) { // (old mac)
  } else if (otf->version==OTF_TAG('t','y','p','1')) { // sfnt wrapped type1
    fprintf(stderr,"Unsupported ttf font (typ1)\n");
    return -1;
  } else {
    fprintf(stderr,"Not a ttf font (unknown version)\n");
    return -1;
  }
  // }}}

  // {{{ read directory
  otf->tables=malloc(sizeof(OTF_DIRENT)*otf->numTables);
  if (!otf->tables) {
    fprintf(stderr,"Bad alloc: %s\n", strerror(errno));
    return -1;
  }
  if (otf->flags&OTF_F_WOFF) {
    pos=otf_load_woff_directory(otf,pos);
  } else {
    pos=otf_load_directory(otf,pos);
  }
  if (pos==-1) {
    return -1;
  }

  // check that opentype and truetype is not mixed
  for (iA=0;iA<otf->numTables;iA++) {
    if ( (otf->tables[iA].tag==OTF_TAG('C','F','F',' '))&&
         (!is_CFF(otf)) ) {
      fprintf(stderr,"Wrong magic\n");
      return -1;
    } else if ( (otf->tables[iA].tag==OTF_TAG('g','l','y','p'))&&
                (is_CFF(otf)) ) {
      fprintf(stderr,"Wrong magic\n");
      return -1;
    }
  }
  // }}}

//  otf->flags|=OTF_F_CACHE_GLYF; // i.e. always?
//  otf->flags|=OTF_F_DO_CHECKSUM;
  // {{{ check head table
  int len=0;
  char *head=otf_get_table(otf,OTF_TAG('h','e','a','d'),&len);
  if ( (!head)||
       (get_ULONG(head+0)!=0x00010000)||  // version
       (len!=54)||
       (get_ULONG(head+12)!=0x5F0F3CF5)|| // magic
       (get_SHORT(head+52)!=0x0000) ) {   // glyphDataFormat
    fprintf(stderr,"Unsupported OTF font / head table\n");
    free(head);
    return -1;
  }
  // }}}
  otf->unitsPerEm=get_USHORT(head+18);
  otf->indexToLocFormat=get_SHORT(head+50);

  // {{{ checksum whole file -- not for WOFF: checksum has to be calculated on UNCOMPRESSED content
  if ( (otf->flags&OTF_F_DO_CHECKSUM)&&((otf->flags&OTF_F_WOFF)==0) ) {
    unsigned int csum=0;
    char tmp[1024];
    rewind(otf->f);
    while (!feof(otf->f)) {
      len=fread(tmp,1,1024,otf->f);
      if (len&3) { // zero padding reqd.
        memset(tmp+len,0,4-(len&3));
      }
      csum+=otf_checksum(tmp,len);
    }
    if (csum!=0xb1b0afba) {
      fprintf(stderr,"Wrong global checksum\n");
      free(head);
      return -1;
    }
  }
  // }}}
  free(head);

  // {{{ read maxp table / numGlyphs
  char *maxp=otf_get_table(otf,OTF_TAG('m','a','x','p'),&len);
  if (maxp) {
    const unsigned int maxp_version=get_ULONG(maxp);
    if ( (maxp_version==0x00005000)&&(len==6)&&
         (is_CFF(otf)) ) { // version 0.5, only CFF
      otf->numGlyphs=get_USHORT(maxp+4);
    } else if ( (maxp_version==0x00010000)&&(len==32)&&
                (!is_CFF(otf)) ) { // version 1.0, only TTF
      otf->numGlyphs=get_USHORT(maxp+4);
    } else {
      fprintf(stderr,"Unsupported OTF font / maxp table\n");
      free(maxp);
      return -1;
    }
    free(maxp);
  }
  // }}}

  return pos;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x450, %rsp            # imm = 0x450
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x10000, 0x14(%rax)    # imm = 0x10000
jne 0x38d4
jmp 0x395b
movq -0x10(%rbp), %rax
cmpl $0x4f54544f, 0x14(%rax) # imm = 0x4F54544F
jne 0x38f3
movq -0x10(%rbp), %rax
movl 0x8(%rax), %ecx
orl $0x10000, %ecx          # imm = 0x10000
movl %ecx, 0x8(%rax)
jmp 0x3959
movq -0x10(%rbp), %rax
cmpl $0x74727565, 0x14(%rax) # imm = 0x74727565
jne 0x3902
jmp 0x3957
movq -0x10(%rbp), %rax
cmpl $0x74797031, 0x14(%rax) # imm = 0x74797031
jne 0x3933
movq 0xf6ca(%rip), %rax      # 0x12fe0
movq (%rax), %rdi
leaq 0xaf00(%rip), %rsi      # 0xe820
movb $0x0, %al
callq 0x21e0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3d80
movq 0xf6a6(%rip), %rax      # 0x12fe0
movq (%rax), %rdi
leaq 0xaef9(%rip), %rsi      # 0xe83d
movb $0x0, %al
callq 0x21e0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3d80
jmp 0x3959
jmp 0x395b
movq -0x10(%rbp), %rax
movzwl 0x38(%rax), %eax
imulq $0x14, %rax, %rdi
callq 0x21d0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x40(%rax)
jne 0x39c3
movq 0xf657(%rip), %rax      # 0x12fe0
movq (%rax), %rax
movq %rax, -0x448(%rbp)
callq 0x2040
movl (%rax), %edi
callq 0x2070
movq -0x448(%rbp), %rdi
movq %rax, %rdx
leaq 0xa9ac(%rip), %rsi      # 0xe35c
movb $0x0, %al
callq 0x21e0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3d80
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
andl $0x8000, %eax           # imm = 0x8000
cmpl $0x0, %eax
je 0x39e5
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x56a0
movl %eax, -0x14(%rbp)
jmp 0x39f4
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x57d0
movl %eax, -0x14(%rbp)
cmpl $-0x1, -0x14(%rbp)
jne 0x3a06
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3d80
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
movq -0x10(%rbp), %rcx
movzwl 0x38(%rcx), %ecx
cmpl %ecx, %eax
jge 0x3acc
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movslq -0x18(%rbp), %rcx
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
cmpl $0x43464620, (%rax)     # imm = 0x43464620
jne 0x3a6d
movq -0x10(%rbp), %rdi
callq 0x46c0
cmpl $0x0, %eax
jne 0x3a6d
movq 0xf590(%rip), %rax      # 0x12fe0
movq (%rax), %rdi
leaq 0xae05(%rip), %rsi      # 0xe85f
movb $0x0, %al
callq 0x21e0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3d80
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movslq -0x18(%rbp), %rcx
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
cmpl $0x676c7970, (%rax)     # imm = 0x676C7970
jne 0x3aba
movq -0x10(%rbp), %rdi
callq 0x46c0
cmpl $0x0, %eax
je 0x3aba
movq 0xf543(%rip), %rax      # 0x12fe0
movq (%rax), %rdi
leaq 0xadb8(%rip), %rsi      # 0xe85f
movb $0x0, %al
callq 0x21e0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3d80
jmp 0x3abc
jmp 0x3abe
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x3a0d
movl $0x0, -0x1c(%rbp)
movq -0x10(%rbp), %rdi
movl $0x68656164, %esi       # imm = 0x68656164
leaq -0x1c(%rbp), %rdx
callq 0x4000
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x3b2d
movq -0x28(%rbp), %rdi
callq 0x3540
cmpl $0x10000, %eax          # imm = 0x10000
jne 0x3b2d
cmpl $0x36, -0x1c(%rbp)
jne 0x3b2d
movq -0x28(%rbp), %rdi
addq $0xc, %rdi
callq 0x3540
cmpl $0x5f0f3cf5, %eax       # imm = 0x5F0F3CF5
jne 0x3b2d
movq -0x28(%rbp), %rdi
addq $0x34, %rdi
callq 0x4a70
cwtl
cmpl $0x0, %eax
je 0x3b5a
movq 0xf4ac(%rip), %rax      # 0x12fe0
movq (%rax), %rdi
leaq 0xad2e(%rip), %rsi      # 0xe86c
movb $0x0, %al
callq 0x21e0
movq -0x28(%rbp), %rdi
callq 0x21b0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3d80
movq -0x28(%rbp), %rdi
addq $0x12, %rdi
callq 0x46f0
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, 0x48(%rax)
movq -0x28(%rbp), %rdi
addq $0x32, %rdi
callq 0x4a70
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, 0x4a(%rax)
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
andl $0x40000, %eax          # imm = 0x40000
cmpl $0x0, %eax
je 0x3c83
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
andl $0x8000, %eax           # imm = 0x8000
cmpl $0x0, %eax
jne 0x3c83
movl $0x0, -0x2c(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x2050
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x2200
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x3be1
jmp 0x3c4b
leaq -0x430(%rbp), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rcx
movl $0x1, %esi
movl $0x400, %edx            # imm = 0x400
callq 0x21f0
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
andl $0x3, %eax
cmpl $0x0, %eax
je 0x3c31
leaq -0x430(%rbp), %rdi
movslq -0x1c(%rbp), %rax
addq %rax, %rdi
movl -0x1c(%rbp), %ecx
andl $0x3, %ecx
movl $0x4, %eax
subl %ecx, %eax
movslq %eax, %rdx
xorl %esi, %esi
callq 0x20e0
leaq -0x430(%rbp), %rdi
movl -0x1c(%rbp), %esi
callq 0x41a0
addl -0x2c(%rbp), %eax
movl %eax, -0x2c(%rbp)
jmp 0x3bc7
cmpl $0xb1b0afba, -0x2c(%rbp) # imm = 0xB1B0AFBA
je 0x3c81
movq 0xf385(%rip), %rax      # 0x12fe0
movq (%rax), %rdi
leaq 0xac2a(%rip), %rsi      # 0xe88f
movb $0x0, %al
callq 0x21e0
movq -0x28(%rbp), %rdi
callq 0x21b0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3d80
jmp 0x3c83
movq -0x28(%rbp), %rdi
callq 0x21b0
movq -0x10(%rbp), %rdi
movl $0x6d617870, %esi       # imm = 0x6D617870
leaq -0x1c(%rbp), %rdx
callq 0x4000
movq %rax, -0x438(%rbp)
cmpq $0x0, -0x438(%rbp)
je 0x3d7a
movq -0x438(%rbp), %rdi
callq 0x3540
movl %eax, -0x43c(%rbp)
cmpl $0x5000, -0x43c(%rbp)   # imm = 0x5000
jne 0x3d02
cmpl $0x6, -0x1c(%rbp)
jne 0x3d02
movq -0x10(%rbp), %rdi
callq 0x46c0
cmpl $0x0, %eax
je 0x3d02
movq -0x438(%rbp), %rdi
addq $0x4, %rdi
callq 0x46f0
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, 0x4c(%rax)
jmp 0x3d6e
cmpl $0x10000, -0x43c(%rbp)  # imm = 0x10000
jne 0x3d3f
cmpl $0x20, -0x1c(%rbp)
jne 0x3d3f
movq -0x10(%rbp), %rdi
callq 0x46c0
cmpl $0x0, %eax
jne 0x3d3f
movq -0x438(%rbp), %rdi
addq $0x4, %rdi
callq 0x46f0
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, 0x4c(%rax)
jmp 0x3d6c
movq 0xf29a(%rip), %rax      # 0x12fe0
movq (%rax), %rdi
leaq 0xab56(%rip), %rsi      # 0xe8a6
movb $0x0, %al
callq 0x21e0
movq -0x438(%rbp), %rdi
callq 0x21b0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3d80
jmp 0x3d6e
movq -0x438(%rbp), %rdi
callq 0x21b0
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x450, %rsp            # imm = 0x450
popq %rbp
retq
nopl (%rax)