// File: /workspace/github_c_makefile_star2_O0/smilingthax[P]libfontembed/sfnt.c
// Function: otf_load_cmap
int otf_load_cmap(OTF_FILE *otf) // {{{  - 0 on success
{
  int iA;
  int len;

  char *cmap=otf_get_table(otf,OTF_TAG('c','m','a','p'),&len);
  if ( (!cmap)||
       (get_USHORT(cmap)!=0x0000)|| // version
       (len<get_USHORT(cmap+2)*8+4) ) {
    fprintf(stderr,"Unsupported OTF font / cmap table \n");
    free(cmap);
    assert(0);
    return -1;
  }
  // check bounds, find (3,0) or (3,1) [TODO?]
  const int numTables=get_USHORT(cmap+2);
  for (iA=0;iA<numTables;iA++) {
    const char *nrec=cmap+4+8*iA;
    const unsigned int offset=get_ULONG(nrec+4);
    const char *ndata=cmap+offset;
    if ( (ndata<cmap+4+8*numTables)||
         (offset>=len)||
         (offset+get_USHORT(ndata+2)>len) ) {
      fprintf(stderr,"Bad cmap table\n");
      free(cmap);
      assert(0);
      return -1;
    }
    if ( (get_USHORT(nrec)==3)&&
         (get_USHORT(nrec+2)<=1)&&
         (get_USHORT(ndata)==4)&&
         (get_USHORT(ndata+4)==0) ) {
      otf->unimap=ndata;
    }
  }
  if (otf->cmap) {
    free(otf->cmap);
    assert(0);
  }
  otf->cmap=cmap;

  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
movl $0x636d6170, %esi       # imm = 0x636D6170
leaq -0x10(%rbp), %rdx
callq 0x4000
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x4af0
movq -0x18(%rbp), %rdi
callq 0x46f0
movzwl %ax, %eax
cmpl $0x0, %eax
jne 0x4af0
movl -0x10(%rbp), %eax
movl %eax, -0x3c(%rbp)
movq -0x18(%rbp), %rdi
addq $0x2, %rdi
callq 0x46f0
movw %ax, %cx
movl -0x3c(%rbp), %eax
movzwl %cx, %ecx
shll $0x3, %ecx
addl $0x4, %ecx
cmpl %ecx, %eax
jge 0x4b30
movq 0xe4e9(%rip), %rax      # 0x12fe0
movq (%rax), %rdi
leaq 0x9a5b(%rip), %rsi      # 0xe55c
movb $0x0, %al
callq 0x21e0
movq -0x18(%rbp), %rdi
callq 0x21b0
leaq 0xa1e8(%rip), %rdi      # 0xed00
leaq 0x9f70(%rip), %rsi      # 0xea8f
movl $0x2f3, %edx            # imm = 0x2F3
leaq 0x9a55(%rip), %rcx      # 0xe580
callq 0x2100
movq -0x18(%rbp), %rdi
addq $0x2, %rdi
callq 0x46f0
movzwl %ax, %eax
movl %eax, -0x1c(%rbp)
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x4c7c
movq -0x18(%rbp), %rax
addq $0x4, %rax
movl -0xc(%rbp), %ecx
shll $0x3, %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
addq $0x4, %rdi
callq 0x3540
movl %eax, -0x2c(%rbp)
movq -0x18(%rbp), %rax
movl -0x2c(%rbp), %ecx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x18(%rbp), %rcx
addq $0x4, %rcx
movl -0x1c(%rbp), %edx
shll $0x3, %edx
movslq %edx, %rdx
addq %rdx, %rcx
cmpq %rcx, %rax
jb 0x4bd4
movl -0x2c(%rbp), %eax
cmpl -0x10(%rbp), %eax
jae 0x4bd4
movl -0x2c(%rbp), %eax
movl %eax, -0x40(%rbp)
movq -0x38(%rbp), %rdi
addq $0x2, %rdi
callq 0x46f0
movw %ax, %cx
movl -0x40(%rbp), %eax
movzwl %cx, %ecx
addl %ecx, %eax
cmpl -0x10(%rbp), %eax
jbe 0x4c14
movq 0xe405(%rip), %rax      # 0x12fe0
movq (%rax), %rdi
leaq 0x99b9(%rip), %rsi      # 0xe59e
movb $0x0, %al
callq 0x21e0
movq -0x18(%rbp), %rdi
callq 0x21b0
leaq 0xa104(%rip), %rdi      # 0xed00
leaq 0x9e8c(%rip), %rsi      # 0xea8f
movl $0x301, %edx            # imm = 0x301
leaq 0x9971(%rip), %rcx      # 0xe580
callq 0x2100
movq -0x28(%rbp), %rdi
callq 0x46f0
movzwl %ax, %eax
cmpl $0x3, %eax
jne 0x4c6c
movq -0x28(%rbp), %rdi
addq $0x2, %rdi
callq 0x46f0
movzwl %ax, %eax
cmpl $0x1, %eax
jg 0x4c6c
movq -0x38(%rbp), %rdi
callq 0x46f0
movzwl %ax, %eax
cmpl $0x4, %eax
jne 0x4c6c
movq -0x38(%rbp), %rdi
addq $0x4, %rdi
callq 0x46f0
movzwl %ax, %eax
cmpl $0x0, %eax
jne 0x4c6c
movq -0x38(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x78(%rax)
jmp 0x4c6e
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x4b4a
movq -0x8(%rbp), %rax
cmpq $0x0, 0x70(%rax)
je 0x4cb3
movq -0x8(%rbp), %rax
movq 0x70(%rax), %rdi
callq 0x21b0
leaq 0xa065(%rip), %rdi      # 0xed00
leaq 0x9ded(%rip), %rsi      # 0xea8f
movl $0x30d, %edx            # imm = 0x30D
leaq 0x98d2(%rip), %rcx      # 0xe580
callq 0x2100
movq -0x18(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x70(%rax)
xorl %eax, %eax
addq $0x40, %rsp
popq %rbp
retq
nopw (%rax,%rax)