// File: /workspace/github_c_makefile_star2_O2/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 0x5472
movq %rcx, %rbx
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %r15
testq %rcx, %rcx
je 0x5328
movq %rbx, (%rsp)
xorl %r12d, %r12d
testl %ebp, %ebp
movl %ebp, %r13d
movl $0x0, %ebp
cmovgl %r13d, %ebp
xorl %ebx, %ebx
cmpq %r12, %rbp
je 0x5320
testq %r14, %r14
je 0x52e3
movzwl (%r14,%r12,2), %eax
jmp 0x52ee
movq %r15, %rdi
movl %r12d, %esi
callq 0x42a4
movzwl %ax, %ecx
shrq $0x5, %rcx
movq (%rsp), %rdx
movl (%rdx,%rcx,4), %edx
movl %r13d, %ecx
cmpl %r12d, %r13d
jl 0x5307
movl %r12d, %ecx
movl %ebx, %esi
cmpl %r12d, %ebx
jg 0x5311
movl %r12d, %esi
btl %eax, %edx
cmovbl %esi, %ebx
cmovbl %ecx, %r13d
incq %r12
jmp 0x52d2
movl %ebx, %ebp
movq (%rsp), %rbx
jmp 0x532b
xorl %r13d, %r13d
movl %ebp, %r12d
subl %r13d, %r12d
jl 0x540a
cmpq $0x0, 0x60(%r15)
jne 0x534e
movq %r15, %rdi
callq 0x3b7f
testl %eax, %eax
jne 0x5491
incl %r12d
movl %r12d, %edi
callq 0x63a5
testq %rax, %rax
je 0x5426
movl %r13d, (%rax)
movl %ebp, 0x4(%rax)
movq %rax, %rcx
addq $0x20, %rcx
movq %rax, (%rsp)
movq %rcx, 0x8(%rax)
movl %ebp, %eax
movslq %r13d, %rbp
movslq %eax, %r12
leaq (%r14,%rbp,2), %rax
movq %rax, 0x10(%rsp)
movl %r13d, %eax
movq %rax, 0x8(%rsp)
xorl %r13d, %r13d
movq %rbp, %rax
addq %r13, %rax
cmpq %r12, %rax
jg 0x5404
testq %r14, %r14
je 0x53af
movq 0x10(%rsp), %rax
movzwl (%rax,%r13,2), %eax
jmp 0x53c0
movq 0x8(%rsp), %rax
leal (%rax,%r13), %esi
movq %r15, %rdi
callq 0x42a4
cmpw 0x4c(%r15), %ax
jae 0x5437
movzwl %ax, %esi
testq %rbx, %rbx
je 0x53dc
movl %esi, %eax
shrl $0x5, %eax
movl (%rbx,%rax,4), %eax
btl %esi, %eax
jae 0x53ff
movq %r15, %rdi
callq 0x54b0
imull $0x3e8, %eax, %eax      # imm = 0x3E8
movzwl 0x48(%r15), %ecx
xorl %edx, %edx
divl %ecx
movq (%rsp), %rcx
movq 0x8(%rcx), %rcx
movl %eax, (%rcx,%r13,4)
incq %r13
jmp 0x5393
movq (%rsp), %rax
jmp 0x5428
movq 0x9bcf(%rip), %rax      # 0xefe0
movq (%rax), %rcx
leaq 0x5909(%rip), %rdi      # 0xad24
pushq $0x1f
popq %rsi
pushq $0x1
popq %rdx
callq 0x2280
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x9ba2(%rip), %rax      # 0xefe0
movq (%rax), %rcx
leaq 0x58fc(%rip), %rdi      # 0xad44
pushq $0xc
popq %rsi
pushq $0x1
popq %rdx
callq 0x2280
leaq 0x5866(%rip), %rdi      # 0xacc0
leaq 0x55e8(%rip), %rsi      # 0xaa49
leaq 0x585a(%rip), %rcx      # 0xacc2
movl $0x112, %edx            # imm = 0x112
callq 0x20f0
leaq 0x4bbf(%rip), %rdi      # 0xa038
leaq 0x55c9(%rip), %rsi      # 0xaa49
leaq 0x583b(%rip), %rcx      # 0xacc2
movl $0xe3, %edx
callq 0x20f0
leaq 0x5828(%rip), %rdi      # 0xacc0
leaq 0x55aa(%rip), %rsi      # 0xaa49
leaq 0x581c(%rip), %rcx      # 0xacc2
movl $0x101, %edx            # imm = 0x101
callq 0x20f0