// File: /workspace/github_c_makefile_star2_O1/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 0x5dae
movl %edx, %r13d
movq %rsi, %r14
movq %rdi, %r15
testq %rcx, %rcx
movq %rcx, 0x8(%rsp)
je 0x5c7a
testl %r13d, %r13d
jle 0x5c82
movl %r13d, %ebx
xorl %r12d, %r12d
xorl %ebp, %ebp
testq %r14, %r14
je 0x5c37
movzwl (%r14,%r12,2), %eax
jmp 0x5c47
movq %r15, %rdi
movl %r12d, %esi
callq 0x4c58
movq 0x8(%rsp), %rcx
movzwl %ax, %edx
shrq $0x5, %rdx
movl (%rcx,%rdx,4), %edi
movl %r13d, %edx
cmpl %r12d, %r13d
jl 0x5c5c
movl %r12d, %edx
movl %ebp, %esi
cmpl %r12d, %ebp
jg 0x5c66
movl %r12d, %esi
btl %eax, %edi
cmovbl %esi, %ebp
cmovbl %edx, %r13d
incq %r12
cmpq %r12, %rbx
jne 0x5c2b
jmp 0x5c84
movl %r13d, %ebp
xorl %r13d, %r13d
jmp 0x5c84
xorl %ebp, %ebp
movl %ebp, %r12d
subl %r13d, %r12d
jl 0x5d90
cmpq $0x0, 0x60(%r15)
jne 0x5ca7
movq %r15, %rdi
callq 0x4605
testl %eax, %eax
jne 0x5dcd
incl %r12d
movl %r12d, %edi
callq 0x6ccc
testq %rax, %rax
je 0x5d95
movq %rax, %rbx
movl %r13d, (%rax)
movl %ebp, 0x4(%rax)
addq $0x20, %rax
movq %rax, 0x8(%rbx)
cmpl %ebp, %r13d
jg 0x5d97
movslq %r13d, %rax
movl %r13d, %ecx
movq %rcx, 0x10(%rsp)
leaq (%r14,%rax,2), %rbp
xorl %r13d, %r13d
movq 0x8(%rsp), %rsi
testq %r14, %r14
je 0x5cf9
movzwl (%rbp,%r13,2), %eax
jmp 0x5d0f
movq 0x10(%rsp), %rax
leal (%rax,%r13), %esi
movq %r15, %rdi
callq 0x4c58
movq 0x8(%rsp), %rsi
cmpw 0x4c(%r15), %ax
jae 0x5da9
movzwl %ax, %ecx
testq %rsi, %rsi
je 0x5d2f
movl %ecx, %edx
shrl $0x5, %edx
movl (%rsi,%rdx,4), %edx
btl %ecx, %edx
jae 0x5d82
movzwl 0x58(%r15), %edx
cmpw %ax, %dx
jbe 0x5d4c
movq 0x60(%r15), %rax
movl %ecx, %edx
leaq (%rax,%rdx,4), %rcx
leaq (%rax,%rdx,4), %rax
incq %rax
jmp 0x5d60
movq 0x60(%r15), %rax
leaq (%rax,%rdx,4), %rcx
addq $-0x4, %rcx
leaq (%rax,%rdx,4), %rax
addq $-0x3, %rax
movzbl (%rcx), %ecx
shll $0x8, %ecx
movzbl (%rax), %eax
orl %ecx, %eax
imull $0x3e8, %eax, %eax      # imm = 0x3E8
movzwl 0x48(%r15), %ecx
xorl %edx, %edx
divl %ecx
movq 0x8(%rbx), %rcx
movl %eax, (%rcx,%r13,4)
incq %r13
cmpq %r13, %r12
jne 0x5cec
jmp 0x5d97
callq 0x2b8d
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x2b51
leaq 0x4283(%rip), %rdi      # 0xa038
leaq 0x4c8d(%rip), %rsi      # 0xaa49
leaq 0x4eff(%rip), %rcx      # 0xacc2
movl $0xe3, %edx
callq 0x20e0
leaq 0x4eec(%rip), %rdi      # 0xacc0
leaq 0x4c6e(%rip), %rsi      # 0xaa49
leaq 0x4ee0(%rip), %rcx      # 0xacc2
movl $0x101, %edx            # imm = 0x101
callq 0x20e0