// File: /workspace/github_c_makefile_star2_O3/smilingthax[P]libfontembed/embed_sfnt.c
// Function: emb_otf_get_pdf_widths
EMB_PDF_FONTWIDTHS *emb_otf_get_pdf_widths(OTF_FILE *otf,const unsigned short *encoding,int len,const BITSET glyphs) // {{{ glyphs==NULL -> all from 0 to len
{
  assert(otf);

  int first=len,last=0;
  int iA;

  if (glyphs) {
    for (iA=0;iA<len;iA++) { // iA is a "gid" when in multi_byte mode...
      const int gid=(encoding)?encoding[iA]:otf_from_unicode(otf,iA); // TODO
      if (bit_check(glyphs,gid)) {
        if (first>iA) { // first is a character index
          first=iA;
        }
        if (last<iA) {
          last=iA;
        }
      }
    }
  } else {
    first=0;
    last=len;
  }
  if (last<first) {
    // empty
    fprintf(stderr,"WARNING: empty embedding range\n");
    return NULL;
  }

  // ensure hmtx is there
  if (!otf->hmtx) {
    if (otf_load_more(otf)!=0) {
      assert(0);
      return NULL;
    }
  }

  // now create the array
  EMB_PDF_FONTWIDTHS *ret=emb_pdf_fw_new(last-first+1);
  if (!ret) {
    return NULL;
  }
  ret->first=first;
  ret->last=last;
  ret->widths=ret->data;
  for (iA=0;first<=last;iA++,first++) {
    const int gid=(encoding)?encoding[first]:otf_from_unicode(otf,first); // TODO
    if (gid>=otf->numGlyphs) {
      fprintf(stderr,"Bad glyphid\n");
      assert(0);
      free(ret);
      return NULL;
    }
    if ( (!glyphs)||(bit_check(glyphs,gid)) ) {
      ret->widths[iA]=get_width_fast(otf,gid)*1000/otf->unitsPerEm;
    } // else 0 from calloc
  }

  return ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
testq %rdi, %rdi
je 0x5d63
movq %rcx, %rbx
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %r15
testq %rcx, %rcx
je 0x5c3d
testl %ebp, %ebp
jle 0x5c44
movl %ebp, %edi
xorl %r12d, %r12d
xorl %r13d, %r13d
movq %rbx, (%rsp)
testq %r14, %r14
je 0x5bef
movzwl (%r14,%r12,2), %eax
jmp 0x5c0a
movq %r14, %rbx
movq %rdi, %r14
movq %r15, %rdi
movl %r12d, %esi
callq 0x4c28
movq %r14, %rdi
movq %rbx, %r14
movq (%rsp), %rbx
movzwl %ax, %ecx
shrq $0x5, %rcx
movl (%rbx,%rcx,4), %edx
movl %ebp, %ecx
cmpl %r12d, %ebp
jl 0x5c1e
movl %r12d, %ecx
movl %r13d, %esi
cmpl %r12d, %r13d
jg 0x5c29
movl %r12d, %esi
btl %eax, %edx
cmovbl %esi, %r13d
cmovbl %ecx, %ebp
incq %r12
cmpq %r12, %rdi
jne 0x5be3
jmp 0x5c47
movl %ebp, %r13d
xorl %ebp, %ebp
jmp 0x5c47
xorl %r13d, %r13d
movl %r13d, %r12d
subl %ebp, %r12d
jl 0x5d44
cmpq $0x0, 0x60(%r15)
jne 0x5c6a
movq %r15, %rdi
callq 0x45d8
testl %eax, %eax
jne 0x5d82
incl %r12d
movl %r12d, %edi
callq 0x6c5c
testq %rax, %rax
je 0x5d49
movl %r12d, %ecx
movq %rax, %r12
movl %ebp, (%rax)
movl %r13d, 0x4(%rax)
addq $0x20, %rax
movq %rax, 0x8(%r12)
movslq %ebp, %rax
movl %ecx, %r13d
movl %ebp, %ecx
movq %rcx, 0x8(%rsp)
leaq (%r14,%rax,2), %rax
movq %rax, 0x10(%rsp)
xorl %ebp, %ebp
testq %r14, %r14
je 0x5cbb
movq 0x10(%rsp), %rax
movzwl (%rax,%rbp,2), %eax
jmp 0x5ccb
movq 0x8(%rsp), %rax
leal (%rax,%rbp), %esi
movq %r15, %rdi
callq 0x4c28
cmpw 0x4c(%r15), %ax
jae 0x5d5e
movzwl %ax, %ecx
testq %rbx, %rbx
je 0x5ceb
movl %ecx, %edx
shrl $0x5, %edx
movl (%rbx,%rdx,4), %edx
btl %ecx, %edx
jae 0x5d36
movzwl 0x58(%r15), %edx
cmpw %ax, %dx
movq 0x60(%r15), %rax
movl %ecx, %ecx
leaq (%rax,%rcx,4), %rsi
leaq 0x1(%rax,%rcx,4), %rcx
leaq -0x3(%rax,%rdx,4), %rdi
cmovaq %rcx, %rdi
leaq -0x4(%rax,%rdx,4), %rax
cmovaq %rsi, %rax
movzbl (%rax), %eax
movzbl (%rdi), %ecx
shll $0x8, %eax
orl %ecx, %eax
imull $0x3e8, %eax, %eax      # imm = 0x3E8
movzwl 0x48(%r15), %ecx
xorl %edx, %edx
divl %ecx
movq 0x8(%r12), %rcx
movl %eax, (%rcx,%rbp,4)
incq %rbp
cmpq %rbp, %r13
jne 0x5cab
jmp 0x5d4c
callq 0x2b95
xorl %r12d, %r12d
movq %r12, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x2b59
leaq 0x42ce(%rip), %rdi      # 0xa038
leaq 0x4cd8(%rip), %rsi      # 0xaa49
leaq 0x4f4a(%rip), %rcx      # 0xacc2
movl $0xe3, %edx
callq 0x20e0
leaq 0x4f37(%rip), %rdi      # 0xacc0
leaq 0x4cb9(%rip), %rsi      # 0xaa49
leaq 0x4f2b(%rip), %rcx      # 0xacc2
movl $0x101, %edx            # imm = 0x101
callq 0x20e0