LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_c_makefile_star2_O1/smilingthax[P]libfontembed/sfnt.c
// Function: otf_close
void otf_close(OTF_FILE *otf) // {{{
{
  assert(otf);
  if (otf) {
    if (otf->flags&OTF_F_CACHE_GLYF) {
      free(otf->glyf);
    } else {
      free(otf->gly);
    }
    free(otf->cmap);
    free(otf->name);
    free(otf->hmtx);
    free(otf->glyphOffsets);
    fclose(otf->f);
    free(otf->tables);
    free(otf);
  }
}

// Assembly:
pushq %rbx
testq %rdi, %rdi
je 0x4081
movq %rdi, %rbx
movl 0x8(%rdi), %eax
andl $0x1, %eax
shll $0x4, %eax
movq 0x80(%rdi,%rax), %rdi
callq 0x21a0
movq 0x70(%rbx), %rdi
callq 0x21a0
movq 0x68(%rbx), %rdi
callq 0x21a0
movq 0x60(%rbx), %rdi
callq 0x21a0
movq 0x50(%rbx), %rdi
callq 0x21a0
movq (%rbx), %rdi
callq 0x2130
movq 0x40(%rbx), %rdi
callq 0x21a0
movq %rbx, %rdi
popq %rbx
jmp 0x21a0
leaq 0x5fb0(%rip), %rdi      # 0xa038
leaq 0x69c0(%rip), %rsi      # 0xaa4f
leaq 0x6316(%rip), %rcx      # 0xa3ac
movl $0x1d6, %edx            # imm = 0x1D6
callq 0x20e0
// File: /workspace/github_c_makefile_star2_O1/smilingthax[P]libfontembed/sfnt.c
// Function: otf_load_header
static int otf_load_header(OTF_FILE *otf,int pos) // {{{
{
  char buf[12];
  if (!otf_read(otf,buf,pos,12)) {
    fprintf(stderr,"Not a ttf font\n");
    return -1;
  }
  otf->version=get_ULONG(buf);
  otf->numTables=get_USHORT(buf+4);
  // don't need the other fields...
  pos+=12;
  return pos;
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x18, %rsp
movl %esi, %ebx
movq %rdi, %r14
movl %esi, %edx
leaq 0xc(%rsp), %rsi
movl $0xc, %ecx
callq 0x3ffd
testq %rax, %rax
je 0x40e7
movl 0xc(%rsp), %eax
bswapl %eax
movl %eax, 0x14(%r14)
movzwl 0x10(%rsp), %eax
rolw $0x8, %ax
movw %ax, 0x38(%r14)
addl $0xc, %ebx
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r14
retq
callq 0x261a
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x40dd
// File: /workspace/github_c_makefile_star2_O1/smilingthax[P]libfontembed/sfnt.c
// Function: otf_load
OTF_FILE *otf_load(const char *file) // {{{
{
  FILE *f;
  int use_ttc=-1;

  if ((f=fopen(file,"rb"))==NULL) {
    // check for TTC
    char *tmp=strrchr(file,'/'),*end;
    if (tmp) {
      use_ttc=strtoul(tmp+1,&end,10);
      if (!*end) {
        end=malloc((tmp-file+1)*sizeof(char));
        if (!end) {
          fprintf(stderr,"Bad alloc: %s\n", strerror(errno));
          return NULL;
        }
        strncpy(end,file,tmp-file);
        end[tmp-file]=0;
        f=fopen(end,"rb");
        free(end);
      }
    }
    if (!f) {
      fprintf(stderr,"Could not open \"%s\": %s\n", file, strerror(errno));
      return NULL;
    }
  }
  return otf_load2(f,use_ttc);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %r14
leaq 0x628b(%rip), %rsi      # 0xa390
callq 0x2190
testq %rax, %rax
je 0x411c
movq %rax, %r15
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x41ab
movq %r14, %rdi
movl $0x2f, %esi
callq 0x2150
testq %rax, %rax
je 0x4198
movq %rax, %r15
leaq 0x1(%rax), %rdi
movq %rsp, %r12
movq %r12, %rsi
movl $0xa, %edx
callq 0x2060
movq %rax, %rbx
movq (%r12), %rax
cmpb $0x0, (%rax)
jne 0x419d
subq %r14, %r15
leaq 0x1(%r15), %rdi
callq 0x21c0
movq %rax, (%rsp)
testq %rax, %rax
je 0x41dd
movq %rax, %r12
movq %rax, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x20a0
movb $0x0, (%r12,%r15)
leaq 0x620d(%rip), %rsi      # 0xa390
movq %r12, %rdi
callq 0x2190
movq %rax, %r15
movq %r12, %rdi
callq 0x21a0
jmp 0x41a0
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
xorl %r15d, %r15d
movb $0x1, %al
testq %r15, %r15
je 0x41ce
testb %al, %al
je 0x41c0
movq %r15, %rdi
movl %ebx, %esi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0x3a22
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movq %r14, %rdi
callq 0x2668
xorl %r15d, %r15d
xorl %eax, %eax
jmp 0x41a7
callq 0x263c
jmp 0x41d6
// File: /workspace/github_c_makefile_star2_O1/smilingthax[P]libfontembed/sfnt.c
// Function: otf_get_table
char *otf_get_table(OTF_FILE *otf,unsigned int tag,int *ret_len) // {{{
{
  assert(otf);
  assert(ret_len);

  const int idx=otf_find_table(otf,tag);
  if (idx==-1) {
    return NULL;
  }
  const OTF_DIRENT *table=otf->tables+idx;

  char *ret=otf_read_table(otf,NULL,table);
  if (!ret) {
    return NULL;
  }
  if (otf->flags&OTF_F_DO_CHECKSUM) {
    unsigned int csum=otf_checksum(ret,table->length);
    if (tag==OTF_TAG('h','e','a','d')) { // special case
      csum-=get_ULONG(ret+8);
    }
    if (csum!=table->checkSum) {
      fprintf(stderr,"Wrong checksum for %c%c%c%c\n",OTF_UNTAG(tag));
      free(ret);
      return NULL;
    }
  }
  *ret_len=table->length;
  return ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
testq %rdi, %rdi
je 0x42fb
movq %rdx, %rbx
testq %rdx, %rdx
je 0x431a
movl %esi, %ebp
movq %rdi, %r15
callq 0x41e4
cmpl $-0x1, %eax
je 0x42ec
cltq
leaq (%rax,%rax,4), %r14
shlq $0x2, %r14
addq 0x40(%r15), %r14
xorl %r12d, %r12d
movq %r15, %rdi
xorl %esi, %esi
movq %r14, %rdx
callq 0x3858
testq %rax, %rax
je 0x42ef
testb $0x4, 0xa(%r15)
je 0x42d7
movl 0xc(%r14), %edx
addl $0x3, %edx
xorl %ecx, %ecx
cmpl $0x4, %edx
jb 0x42c2
shrl $0x2, %edx
xorl %esi, %esi
xorl %ecx, %ecx
movl (%rax,%rsi,4), %edi
bswapl %edi
addl %edi, %ecx
incq %rsi
cmpl %esi, %edx
jne 0x42b4
cmpl $0x68656164, %ebp       # imm = 0x68656164
jne 0x42d1
movl 0x8(%rax), %edx
bswapl %edx
subl %edx, %ecx
cmpl 0x4(%r14), %ecx
jne 0x42e2
movl 0xc(%r14), %ecx
movl %ecx, (%rbx)
movq %rax, %r12
jmp 0x42ef
movl %ebp, %edi
movq %rax, %rsi
callq 0x26a3
xorl %r12d, %r12d
movq %r12, %rax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x5d36(%rip), %rdi      # 0xa038
leaq 0x6746(%rip), %rsi      # 0xaa4f
leaq 0x60b7(%rip), %rcx      # 0xa3c7
movl $0x226, %edx            # imm = 0x226
callq 0x20e0
leaq 0x60db(%rip), %rdi      # 0xa3fc
leaq 0x6727(%rip), %rsi      # 0xaa4f
leaq 0x6098(%rip), %rcx      # 0xa3c7
movl $0x227, %edx            # imm = 0x227
callq 0x20e0
// File: /workspace/github_c_makefile_star2_O1/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 %rbx
subq $0x10, %rsp
movq %rdi, %rbx
leaq 0xc(%rsp), %rdx
movl $0x636d6170, %esi       # imm = 0x636D6170
callq 0x4249
testq %rax, %rax
je 0x48d0
movb 0x1(%rax), %cl
orb (%rax), %cl
jne 0x48d0
movzwl 0x2(%rax), %edx
rolw $0x8, %dx
movl 0xc(%rsp), %ecx
movzwl %dx, %esi
leal 0x4(,%rsi,8), %edx
cmpl %edx, %ecx
jl 0x48d0
testl %esi, %esi
je 0x48b3
leal (,%rsi,8), %edx
movl %edx, %edx
addq %rax, %rdx
addq $0x4, %rdx
movl %esi, %esi
xorl %edi, %edi
movl 0x8(%rax,%rdi,8), %r9d
bswapl %r9d
cmpl %ecx, %r9d
jae 0x48c8
leaq (%rax,%r9), %r8
cmpq %rdx, %r8
jb 0x48c8
movzwl 0x2(%r8), %r10d
rolw $0x8, %r10w
movzwl %r10w, %r10d
addl %r9d, %r10d
cmpl %ecx, %r10d
ja 0x48c8
movzwl 0x4(%rax,%rdi,8), %r9d
rolw $0x8, %r9w
cmpw $0x3, %r9w
jne 0x48ab
movzwl 0x6(%rax,%rdi,8), %r9d
rolw $0x8, %r9w
cmpw $0x1, %r9w
ja 0x48ab
movzwl (%r8), %r9d
rolw $0x8, %r9w
cmpw $0x4, %r9w
jne 0x48ab
movb 0x5(%r8), %r9b
orb 0x4(%r8), %r9b
jne 0x48ab
movq %r8, 0x78(%rbx)
incq %rdi
cmpq %rdi, %rsi
jne 0x483d
movq 0x70(%rbx), %rdi
testq %rdi, %rdi
jne 0x48d8
movq %rax, 0x70(%rbx)
xorl %eax, %eax
addq $0x10, %rsp
popq %rbx
retq
movq %rax, %rdi
callq 0x2855
movq %rax, %rdi
callq 0x289c
callq 0x21a0
leaq 0x63dc(%rip), %rdi      # 0xacc0
leaq 0x6164(%rip), %rsi      # 0xaa4f
leaq 0x5c8b(%rip), %rcx      # 0xa57d
movl $0x30d, %edx            # imm = 0x30D
callq 0x20e0
// File: /workspace/github_c_makefile_star2_O1/smilingthax[P]libfontembed/sfnt.c
// Function: otf_get_width
int otf_get_width(OTF_FILE *otf,unsigned short gid) // {{{  -1 on error
{
  assert(otf);

  if (gid>=otf->numGlyphs) {
    return -1;
  }

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

  return get_width_fast(otf,gid);
#if 0
  if (gid>=otf->numberOfHMetrics) {
    return get_USHORT(otf->hmtx+(otf->numberOfHMetrics-1)*2);
    // TODO? lsb=get_SHORT(otf->hmtx+otf->numberOfHMetrics*2+gid*2);  // lsb: left_side_bearing (also in table)
  }
  return get_USHORT(otf->hmtx+gid*4);
  // TODO? lsb=get_SHORT(otf->hmtx+gid*4+2);
#endif
}

// Assembly:
pushq %rbp
pushq %rbx
pushq %rax
testq %rdi, %rdi
je 0x496a
movl %esi, %ebp
movq %rdi, %rbx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpw %bp, 0x4c(%rdi)
jbe 0x4963
cmpq $0x0, 0x60(%rbx)
jne 0x4927
movq %rbx, %rdi
callq 0x4605
testl %eax, %eax
jne 0x4989
movzwl 0x58(%rbx), %eax
cmpw %bp, %ax
jbe 0x4944
movzwl %bp, %eax
movq 0x60(%rbx), %rdx
leaq (%rdx,%rax,4), %rcx
leaq (%rdx,%rax,4), %rax
incq %rax
jmp 0x4958
movq 0x60(%rbx), %rdx
leaq (%rdx,%rax,4), %rcx
addq $-0x4, %rcx
leaq (%rdx,%rax,4), %rax
addq $-0x3, %rax
movzbl (%rcx), %ecx
shll $0x8, %ecx
movzbl (%rax), %eax
orl %ecx, %eax
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
leaq 0x56c7(%rip), %rdi      # 0xa038
leaq 0x60d7(%rip), %rsi      # 0xaa4f
leaq 0x5c2c(%rip), %rcx      # 0xa5ab
movl $0x317, %edx            # imm = 0x317
callq 0x20e0
leaq 0x6330(%rip), %rdi      # 0xacc0
leaq 0x60b8(%rip), %rsi      # 0xaa4f
leaq 0x5c0d(%rip), %rcx      # 0xa5ab
movl $0x320, %edx            # imm = 0x320
callq 0x20e0
// File: /workspace/github_c_makefile_star2_O1/smilingthax[P]libfontembed/sfnt.c
// Function: otf_get_name
const char *otf_get_name(OTF_FILE *otf,int platformID,int encodingID,int languageID,int nameID,int *ret_len) // {{{
{
  assert(otf);
  assert(ret_len);

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

  char key[8];
  set_USHORT(key,platformID);
  set_USHORT(key+2,encodingID);
  set_USHORT(key+4,languageID);
  set_USHORT(key+6,nameID);

  char *res=bsearch(key,otf->name+6,get_USHORT(otf->name+2),12,otf_name_compare);
  if (res) {
    *ret_len=get_USHORT(res+8);
    int npos=get_USHORT(res+10);
    const char *nstore=otf->name+get_USHORT(otf->name+4);
    return nstore+npos;
  }
  *ret_len=0;
  return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
testq %rdi, %rdi
je 0x4a86
movq %r9, %r15
testq %r9, %r9
je 0x4aa5
movl %r8d, %eax
movl %esi, %ebx
movq %rdi, %r14
cmpq $0x0, 0x68(%rdi)
jne 0x49f7
movq %r14, %rdi
movl %eax, %ebp
movl %ecx, %r12d
movl %edx, %r13d
callq 0x4605
movl %r13d, %edx
movl %r12d, %ecx
testl %eax, %eax
movl %ebp, %eax
jne 0x4ac4
movb %bh, (%rsp)
movq %rsp, %rdi
movb %bl, 0x1(%rdi)
movb %dh, 0x2(%rsp)
movb %dl, 0x3(%rdi)
movb %ch, 0x4(%rsp)
movb %cl, 0x5(%rdi)
movb %ah, 0x6(%rsp)
movb %al, 0x7(%rdi)
movq 0x68(%r14), %rsi
movzwl 0x2(%rsi), %eax
addq $0x6, %rsi
rolw $0x8, %ax
movzwl %ax, %edx
leaq 0xbb(%rip), %r8         # 0x4aea
movl $0xc, %ecx
callq 0x21b0
testq %rax, %rax
je 0x4a6e
movzwl 0x8(%rax), %ecx
rolw $0x8, %cx
movzwl %cx, %ecx
movl %ecx, (%r15)
movzwl 0xa(%rax), %eax
rolw $0x8, %ax
movq 0x68(%r14), %rcx
movzwl 0x4(%rcx), %edx
rolw $0x8, %dx
movzwl %ax, %esi
movzwl %dx, %eax
addq %rcx, %rax
addq %rsi, %rax
jmp 0x4a77
movl $0x0, (%r15)
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x55ab(%rip), %rdi      # 0xa038
leaq 0x5fbb(%rip), %rsi      # 0xaa4f
leaq 0x5b3e(%rip), %rcx      # 0xa5d9
movl $0x339, %edx            # imm = 0x339
callq 0x20e0
leaq 0x5950(%rip), %rdi      # 0xa3fc
leaq 0x5f9c(%rip), %rsi      # 0xaa4f
leaq 0x5b1f(%rip), %rcx      # 0xa5d9
movl $0x33a, %edx            # imm = 0x33A
callq 0x20e0
movl $0xffffffff, (%r15)     # imm = 0xFFFFFFFF
leaq 0x61ee(%rip), %rdi      # 0xacc0
leaq 0x5f76(%rip), %rsi      # 0xaa4f
leaq 0x5af9(%rip), %rcx      # 0xa5d9
movl $0x340, %edx            # imm = 0x340
callq 0x20e0
// File: /workspace/github_c_makefile_star2_O1/smilingthax[P]libfontembed/sfnt.c
// Function: otf_get_glyph
int otf_get_glyph(OTF_FILE *otf,unsigned short gid) // {{{ result in >otf->gly, returns length, -1 on error
{
  assert(otf);
  assert(!is_CFF(otf)); // not for CFF

  if (gid>=otf->numGlyphs) {
    return -1;
  }

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

  const int len=otf->glyphOffsets[gid+1]-otf->glyphOffsets[gid];
  if (len==0) {
    return 0;
  }

  assert(otf->glyfTable->length>=otf->glyphOffsets[gid+1]);
  if (otf->glyf) { // i.e. OTF_F_CACHE_GLYF
    otf->gly=otf->glyf+otf->glyphOffsets[gid];
  } else if (otf->gly) {
    if (otf->flags&OTF_F_WOFF) {
      fprintf(stderr,"OTF_F_CACHE_GLYF is needed to read glyphs from wOFF files\n");
      return -1;
    }
    if (!otf_read_raw(otf->f,otf->gly,
                  otf->glyfTable->offset+otf->glyphOffsets[gid],len)) {
      return -1;
    }
  } else {
    assert(0);
    return -1;
  }

  return len;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
testq %rdi, %rdi
je 0x4bbd
movq %rdi, %r14
testb $0x1, 0xa(%rdi)
jne 0x4bdc
movl %esi, %ebp
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
cmpw %bp, 0x4c(%r14)
jbe 0x4baf
cmpq $0x0, 0x50(%r14)
jne 0x4b45
movq %r14, %rdi
callq 0x4605
testl %eax, %eax
jne 0x4c1a
movzwl %bp, %eax
movq 0x50(%r14), %rcx
movl (%rcx,%rax,4), %edx
movl 0x4(%rcx,%rax,4), %ecx
movl %ecx, %ebp
subl %edx, %ebp
je 0x4b81
movq 0x88(%r14), %rax
cmpl %ecx, 0xc(%rax)
jb 0x4bfb
movq 0x90(%r14), %rcx
testq %rcx, %rcx
je 0x4b85
addq %rdx, %rcx
movq %rcx, 0x80(%r14)
jmp 0x4bad
xorl %ebx, %ebx
jmp 0x4baf
movq 0x80(%r14), %rsi
testq %rsi, %rsi
je 0x4c39
testb $-0x80, 0x9(%r14)
jne 0x4bb6
movq (%r14), %rdi
addl 0x8(%rax), %edx
movl %ebp, %ecx
callq 0x39e3
testl %eax, %eax
je 0x4baf
movl %ebp, %ebx
movl %ebx, %eax
popq %rbx
popq %r14
popq %rbp
retq
callq 0x28e3
jmp 0x4baf
leaq 0x5474(%rip), %rdi      # 0xa038
leaq 0x5e84(%rip), %rsi      # 0xaa4f
leaq 0x5a47(%rip), %rcx      # 0xa619
movl $0x359, %edx            # imm = 0x359
callq 0x20e0
leaq 0x583e(%rip), %rdi      # 0xa421
leaq 0x5e65(%rip), %rsi      # 0xaa4f
leaq 0x5a28(%rip), %rcx      # 0xa619
movl $0x35a, %edx            # imm = 0x35A
callq 0x20e0
leaq 0x5a45(%rip), %rdi      # 0xa647
leaq 0x5e46(%rip), %rsi      # 0xaa4f
leaq 0x5a09(%rip), %rcx      # 0xa619
movl $0x36d, %edx            # imm = 0x36D
callq 0x20e0
leaq 0x609f(%rip), %rdi      # 0xacc0
leaq 0x5e27(%rip), %rsi      # 0xaa4f
leaq 0x59ea(%rip), %rcx      # 0xa619
movl $0x363, %edx            # imm = 0x363
callq 0x20e0
leaq 0x6080(%rip), %rdi      # 0xacc0
leaq 0x5e08(%rip), %rsi      # 0xaa4f
leaq 0x59cb(%rip), %rcx      # 0xa619
movl $0x37a, %edx            # imm = 0x37A
callq 0x20e0
// File: /workspace/github_c_makefile_star2_O1/smilingthax[P]libfontembed/embed.c
// Function: emb_close
void emb_close(EMB_PARAMS *emb) // {{{
{
  if (emb) {
    free(emb->subset);
    if (emb->plan&EMB_A_CLOSE_FONTFILE) {
      fontfile_close(emb->font);
    }
    free(emb);
  }
}

// Assembly:
testq %rdi, %rdi
je 0x5044
pushq %rbx
movq %rdi, %rbx
movq 0x20(%rdi), %rdi
callq 0x21a0
testb $-0x80, 0xd(%rbx)
je 0x503b
movq 0x10(%rbx), %rdi
callq 0x7dac
movq %rbx, %rdi
popq %rbx
jmp 0x21a0
retq
// File: /workspace/github_c_makefile_star2_O1/smilingthax[P]libfontembed/embed_sfnt.c
// Function: emb_otf_get_rights
EMB_RIGHT_TYPE emb_otf_get_rights(OTF_FILE *otf) // {{{
{
  EMB_RIGHT_TYPE ret=EMB_RIGHT_FULL;

  int len;
  char *os2=otf_get_table(otf,OTF_TAG('O','S','/','2'),&len);
  if (os2) {
    const unsigned short os2_version=get_USHORT(os2);
    // check len
    assert( (os2_version!=0x0000)||(len==78) );
    assert( (os2_version!=0x0001)||(len==86) );
    assert( (os2_version<0x0002)||(os2_version>0x0004)||(len==96) );
    if (os2_version<=0x0004) {
      // get rights
      unsigned short fsType=get_USHORT(os2+8);
      // from Adobe's Fontpolicies_v9.pdf, pg 13:
      if (fsType==0x0002) {
        ret=EMB_RIGHT_NONE;
      } else {
        ret=fsType&0x0300; // EMB_RIGHT_BITMAPONLY, EMB_RIGHT_NO_SUBSET
        if ((fsType&0x000c)==0x0004) {
          ret|=EMB_RIGHT_READONLY;
        }
      }
    }
    free(os2);
  }
  return ret;
}

// Assembly:
pushq %rbx
subq $0x10, %rsp
leaq 0xc(%rsp), %rdx
movl $0x4f532f32, %esi       # imm = 0x4F532F32
callq 0x4249
testq %rax, %rax
je 0x5479
movzwl (%rax), %ecx
rolw $0x8, %cx
testw %cx, %cx
setne %sil
movl 0xc(%rsp), %edx
cmpl $0x4e, %edx
sete %dil
orb %sil, %dil
je 0x5483
cmpw $0x1, %cx
setne %sil
cmpl $0x56, %edx
sete %dil
orb %sil, %dil
je 0x54a2
leal -0x5(%rcx), %esi
cmpw $-0x3, %si
setb %sil
cmpl $0x60, %edx
sete %dl
orb %sil, %dl
je 0x54c1
xorl %ebx, %ebx
cmpw $0x4, %cx
ja 0x546f
movzwl 0x8(%rax), %ecx
rolw $0x8, %cx
movl $0x2, %ebx
cmpw $0x2, %cx
je 0x546f
movzwl %cx, %ecx
movl %ecx, %edx
andl $0x300, %edx            # imm = 0x300
andl $0xc, %ecx
leal 0x4(%rdx), %ebx
cmpl $0x4, %ecx
cmovnel %edx, %ebx
movq %rax, %rdi
callq 0x21a0
jmp 0x547b
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x10, %rsp
popq %rbx
retq
leaq 0x559e(%rip), %rdi      # 0xaa28
leaq 0x55b8(%rip), %rsi      # 0xaa49
leaq 0x55be(%rip), %rcx      # 0xaa56
movl $0x14, %edx
callq 0x20e0
leaq 0x55db(%rip), %rdi      # 0xaa84
leaq 0x5599(%rip), %rsi      # 0xaa49
leaq 0x559f(%rip), %rcx      # 0xaa56
movl $0x15, %edx
callq 0x20e0
leaq 0x55dd(%rip), %rdi      # 0xaaa5
leaq 0x557a(%rip), %rsi      # 0xaa49
leaq 0x5580(%rip), %rcx      # 0xaa56
movl $0x16, %edx
callq 0x20e0
// File: /workspace/github_c_makefile_star2_O1/smilingthax[P]libfontembed/embed_sfnt.c
// Function: emb_otf_get_fontname
const char *emb_otf_get_fontname(OTF_FILE *otf) // {{{
{
  static char fontname[64];

  int len;
  const char *fname=otf_get_name(otf,3,1,0x409,6,&len); // microsoft
  if (fname) {
    int iA,iB=0;
    for (iA=0;(iA<63)&&(iA*2<len);iA++) {
      if ( (fname[2*iA]==0)&&
           (fname[2*iA+1]>=33)&&(fname[2*iA+1]<=126)&&
           (!strchr("[](){}<>/%",fname[iA*2+1])) ) {
        fontname[iB++]=fname[iA*2+1];
      }
    }
    fontname[iB]=0;
  } else if ((fname=otf_get_name(otf,1,0,0,6,&len))) { // mac
    int iA,iB=0;
    for (iA=0;(iA<63)&&(iA<len);iA++) {
      if ( (fname[iA]>=33)&&(fname[iA]<=126)&&
           (!strchr("[](){}<>/%",fname[iA])) ) {
        fontname[iB++]=fname[iA];
      }
    }
    fontname[iB]=0;
  } else {
    fontname[0]=0;
  }
  if (!*fontname) {
    // TODO construct a fontname, eg from */*/*/4
    fprintf(stderr,"WARNING: no fontName\n");
  }
  return fontname;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %r14
leaq 0x4(%rsp), %r9
movl $0x3, %esi
movl $0x1, %edx
movl $0x409, %ecx            # imm = 0x409
movl $0x6, %r8d
callq 0x49a8
testq %rax, %rax
je 0x558d
movslq 0x4(%rsp), %r12
xorl %r15d, %r15d
testq %r12, %r12
jle 0x5619
movq %rax, %rbx
xorl %ebp, %ebp
xorl %r13d, %r13d
cmpb $0x0, (%rbx,%r13)
jne 0x556a
movb 0x1(%rbx,%r13), %r14b
leal -0x7f(%r14), %eax
cmpb $-0x5e, %al
jb 0x556a
movzbl %r14b, %esi
movl $0xb, %edx
leaq 0x558c(%rip), %rdi      # 0xaadb
callq 0x2170
testq %rax, %rax
jne 0x556a
movslq %r15d, %rax
incl %r15d
leaq 0x9bfa(%rip), %rcx      # 0xf160
movb %r14b, (%rax,%rcx)
cmpq $0x3d, %rbp
ja 0x5616
addq $0x2, %r13
leaq 0x2(,%rbp,2), %rax
incq %rbp
cmpq %r12, %rax
jb 0x552b
jmp 0x5616
leaq 0x4(%rsp), %r9
movq %r14, %rdi
movl $0x1, %esi
xorl %edx, %edx
xorl %ecx, %ecx
movl $0x6, %r8d
callq 0x49a8
testq %rax, %rax
je 0x5644
movq %rax, %rbx
movl 0x4(%rsp), %eax
xorl %r15d, %r15d
testl %eax, %eax
jle 0x5619
decl %eax
cmpl $0x3e, %eax
movl $0x3e, %r12d
cmovbl %eax, %r12d
incl %r12d
leaq 0x5502(%rip), %r14      # 0xaadb
xorl %ebp, %ebp
movb (%rbx,%rbp), %r13b
leal -0x7f(%r13), %eax
cmpb $-0x5e, %al
jb 0x560e
movzbl %r13b, %esi
movl $0xb, %edx
movq %r14, %rdi
callq 0x2170
testq %rax, %rax
jne 0x560e
movslq %r15d, %rax
incl %r15d
leaq 0x9b56(%rip), %rcx      # 0xf160
movb %r13b, (%rax,%rcx)
incq %rbp
cmpq %rbp, %r12
jne 0x55db
movslq %r15d, %r15
leaq 0x9b40(%rip), %rax      # 0xf160
movb $0x0, (%r15,%rax)
cmpb $0x0, 0x9b34(%rip)      # 0xf160
je 0x564d
leaq 0x9b2b(%rip), %rax      # 0xf160
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb $0x0, 0x9b15(%rip)      # 0xf160
jmp 0x5625
callq 0x2aac
jmp 0x562e
// File: /workspace/github_c_makefile_star2_O1/smilingthax[P]libfontembed/embed_sfnt.c
// Function: emb_otf_get_pdf_cidwidths
EMB_PDF_FONTWIDTHS *emb_otf_get_pdf_cidwidths(OTF_FILE *otf,const BITSET glyphs) // {{{ // glyphs==NULL -> output all
{
  assert(otf);

  // ensure hmtx is there
  if (!otf->hmtx) {
    if (otf_load_more(otf)!=0) {
      assert(0);
      return NULL;
    }
  }
//  int dw=emb_otf_pdf_glyphwidth(otf,0); // e.g.
  int dw=-1; // let them estimate

  return emb_pdf_fw_cidwidths(glyphs,otf->numGlyphs,dw,emb_otf_pdf_glyphwidth,otf);
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
testq %rdi, %rdi
je 0x5e30
movq %rsi, %r14
movq %rdi, %rbx
cmpq $0x0, 0x60(%rdi)
jne 0x5e0e
movq %rbx, %rdi
callq 0x4605
testl %eax, %eax
jne 0x5e4f
movzwl 0x4c(%rbx), %esi
leaq 0x55(%rip), %rcx        # 0x5e6e
movq %r14, %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq %rbx, %r8
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x6d10
leaq 0x4201(%rip), %rdi      # 0xa038
leaq 0x4c0b(%rip), %rsi      # 0xaa49
leaq 0x4f0c(%rip), %rcx      # 0xad51
movl $0x129, %edx            # imm = 0x129
callq 0x20e0
leaq 0x4e6a(%rip), %rdi      # 0xacc0
leaq 0x4bec(%rip), %rsi      # 0xaa49
leaq 0x4eed(%rip), %rcx      # 0xad51
movl $0x12e, %edx            # imm = 0x12E
callq 0x20e0
// File: /workspace/github_c_makefile_star2_O1/smilingthax[P]libfontembed/./sfnt_int.h
// Function: emb_otf_pdf_glyphwidth
static inline int get_width_fast(OTF_FILE *otf,int gid) // {{{
{
  if (gid>=otf->numberOfHMetrics) {
    return get_USHORT(otf->hmtx+(otf->numberOfHMetrics-1)*4);
  } else {
    return get_USHORT(otf->hmtx+gid*4);
  }
}

// Assembly:
movzwl 0x58(%rdi), %eax
movq 0x60(%rdi), %rcx
leal (,%rsi,4), %edx
movslq %edx, %rdx
leaq (%rcx,%rdx), %r8
cmpl %esi, %eax
leaq -0x4(%rcx,%rax,4), %rsi
leaq -0x3(%rcx,%rax,4), %rax
leaq 0x1(%rcx,%rdx), %rcx
cmovleq %rax, %rcx
cmovgq %r8, %rsi
movzbl (%rsi), %eax
shll $0x8, %eax
movzbl (%rcx), %ecx
orl %eax, %ecx
imull $0x3e8, %ecx, %eax      # imm = 0x3E8
movzwl 0x48(%rdi), %ecx
xorl %edx, %edx
divl %ecx
retq
// File: /workspace/github_c_makefile_star2_O1/smilingthax[P]libfontembed/embed_sfnt.c
// Function: get_glyphname
static const char *get_glyphname(const char *post,unsigned short *to_unicode,int charcode,unsigned short gid) // {{{ if charcode==0 -> force gid to be used
{
  if (gid==0) {
    return ".notdef";
  }
  const char *postName=emb_otf_get_post_name(post,gid);
  if (postName) {
    return postName;
  }
  static char ret[255];
  if (charcode) {
    if (to_unicode) { // i.e. encoding was there
      charcode=to_unicode[charcode];
      // TODO!? to_unicode should be able to represent more than one unicode character?
      // TODO for additional credit: for ligatures, etc  create /f_f /uni12341234  or the like
    }
    const char *aglname=aglfn13(charcode); // TODO? special case ZapfDingbats?
    if (aglname) {
      return aglname;
    }
    snprintf(ret,250,"uni%04X",charcode); // allows extraction
  } else {
    snprintf(ret,250,"c%d",gid);  // last resort: only by gid
  }
  return ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl %ecx, %ebp
movl %edx, %ebx
movq %rsi, %r14
testq %rdi, %rdi
je 0x673e
movl (%rdi), %eax
bswapl %eax
cmpl $0x25000, %eax          # imm = 0x25000
je 0x66d9
cmpl $0x20000, %eax          # imm = 0x20000
jne 0x673e
movzwl 0x20(%rdi), %edx
rolw $0x8, %dx
movb $0x1, %al
cmpw %bp, %dx
jbe 0x673a
movzwl %bp, %ecx
movzbl 0x22(%rdi,%rcx,2), %esi
shll $0x8, %esi
movzbl 0x23(%rdi,%rcx,2), %ecx
orl %esi, %ecx
movzwl %cx, %r8d
cmpl $0x101, %r8d            # imm = 0x101
ja 0x66f3
testw %cx, %cx
jne 0x673a
xorl %eax, %eax
xorl %r15d, %r15d
jmp 0x673a
movzwl 0x20(%rdi), %eax
rolw $0x8, %ax
cmpw %bp, %ax
jbe 0x673e
movzwl %bp, %eax
movsbl 0x22(%rdi,%rax), %eax
addw %bp, %ax
jmp 0x673e
testw %si, %si
js 0x673a
movzwl %dx, %eax
addq $0x22, %rdi
leaq (%rdi,%rax,2), %rsi
addw $0xfefe, %cx            # imm = 0xFEFE
je 0x6718
movzbl (%rsi), %eax
addq %rax, %rsi
incq %rsi
decw %cx
jne 0x670a
movzbl (%rsi), %r12d
incq %rsi
leaq 0x8b7a(%rip), %r15      # 0xf2a0
movq %r15, %rdi
movq %r12, %rdx
callq 0x2100
movb $0x0, (%r12,%r15)
xorl %eax, %eax
jmp 0x673a
testb %al, %al
je 0x6741
xorl %r15d, %r15d
testq %r15, %r15
jne 0x67a0
testl %ebx, %ebx
je 0x6781
testq %r14, %r14
je 0x6757
movslq %ebx, %rax
movzwl (%r14,%rax,2), %ebx
movzwl %bx, %edi
callq 0x7dd0
movq %rax, %r15
testq %rax, %rax
jne 0x67a0
leaq 0x8a32(%rip), %r15      # 0xf1a0
leaq 0x4874(%rip), %rdx      # 0xafe9
movl $0xfa, %esi
movq %r15, %rdi
movl %ebx, %ecx
jmp 0x6799
leaq 0x8a18(%rip), %r15      # 0xf1a0
leaq 0x4862(%rip), %rdx      # 0xaff1
movl $0xfa, %esi
movq %r15, %rdi
movl %ebp, %ecx
xorl %eax, %eax
callq 0x2210
movq %r15, %rax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/smilingthax[P]libfontembed/embed_sfnt.c
// Function: outfilter_ascii_ps
static void outfilter_ascii_ps(const char *buf,int len,void *context)  // {{{
{
  struct OUTFILTER_PS *of=context;
  OUTPUT_FN out=of->out;
  int iA;

  (*out)("<",1,of->ctx);
  of->len++;

  const char *last=buf;
  char tmp[256];
  while (len>0) {
    for (iA=0;(iA<76)&&(len>0);iA+=2,len--) {
      const unsigned char ch=buf[iA>>1];
      tmp[iA]="0123456789abcdef"[ch>>4];
      tmp[iA+1]="0123456789abcdef"[ch&0x0f];
    }
    buf+=iA>>1;
    if (buf<last+64000) {
      if (len>0) {
        tmp[iA++]='\n';
      }
      (*out)(tmp,iA,of->ctx);
    } else {
      last=buf;
      strcpy(tmp+iA,"00>\n<");
      iA+=5;
      (*out)(tmp,iA,of->ctx);
    }
    of->len+=iA;
  }

  (*out)("00>\n",4,of->ctx);
  of->len+=4;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq %rdx, %rbx
movl %esi, %r15d
movq %rdi, %r14
movq (%rdx), %rax
movq 0x8(%rdx), %rdx
leaq 0x4836(%rip), %rdi      # 0xb00a
movl $0x1, %esi
movq %rax, (%rsp)
callq *%rax
incl 0x10(%rbx)
testl %r15d, %r15d
jle 0x6893
leaq 0x4803(%rip), %r12      # 0xaff5
movq %r14, 0x8(%rsp)
xorl %r13d, %r13d
movl %r15d, %eax
movq %r13, %rcx
movzbl (%r14), %edx
movl %edx, %esi
shrl $0x4, %esi
movb (%rsi,%r12), %sil
movb %sil, 0x10(%rsp,%r13)
andl $0xf, %edx
movb (%rdx,%r12), %dl
movb %dl, 0x11(%rsp,%r13)
addq $0x2, %r13
leal -0x1(%rax), %r15d
incq %r14
cmpq $0x49, %rcx
ja 0x6834
cmpl $0x1, %eax
jg 0x67fa
movq 0x8(%rsp), %rcx
addq $0xfa00, %rcx           # imm = 0xFA00
cmpq %rcx, %r14
jae 0x6859
cmpl $0x1, %eax
jle 0x6873
movb $0xa, 0x10(%rsp,%r13)
leal 0x1(%r13), %eax
movl %eax, %r13d
jmp 0x6873
movw $0x3c, 0x14(%rsp,%r13)
movl $0xa3e3030, 0x10(%rsp,%r13) # imm = 0xA3E3030
addl $0x5, %r13d
movq %r14, 0x8(%rsp)
leal 0x1(%r15), %ebp
movq 0x8(%rbx), %rdx
leaq 0x10(%rsp), %rdi
movl %r13d, %esi
callq *(%rsp)
addl %r13d, 0x10(%rbx)
cmpl $0x1, %ebp
jg 0x67f7
movq 0x8(%rbx), %rdx
leaq 0x476e(%rip), %rdi      # 0xb00c
movl $0x4, %esi
callq *(%rsp)
addl $0x4, 0x10(%rbx)
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/smilingthax[P]libfontembed/embed_pdf.c
// Function: emb_pdf_fontdescr
EMB_PDF_FONTDESCR *emb_pdf_fontdescr(EMB_PARAMS *emb) // {{{ -  to be freed by user
{
  assert(emb);

  const char *subset_tag=NULL;
  // {{{ generate pdf subtag
  static unsigned int rands=0;
  if (!rands) {
    rands=time(NULL);
  }

  char subtag[7];
  subtag[6]=0;
  if (emb->plan&EMB_A_SUBSET) {
    int iA;
    for (iA=0;iA<6;iA++) {
      const int x=(int)(26.0*(rand_r(&rands)/(RAND_MAX+1.0)));
      subtag[iA]='A'+x;
    }
    subset_tag=subtag;
  }
  // }}}

  const char *fontname=NULL;
  if ( (emb->intype==EMB_FMT_TTF)||(emb->intype==EMB_FMT_OTF) ) { // TODO? use fontinfo from CFF when outtype==CFT, etc.?
    assert(emb->font->sfnt);
    fontname=emb_otf_get_fontname(emb->font->sfnt);
  } else if (emb->outtype==EMB_FMT_STDFONT) {
    return NULL;
  } else {
    fprintf(stderr,"NOT IMPLEMENTED\n");
    assert(0);
    return NULL;
  }

  EMB_PDF_FONTDESCR *ret;
  if (emb->plan&EMB_A_MULTIBYTE) { // multibyte
    ret=emb_pdf_fd_new(fontname,subset_tag,"Adobe","Identity",0); // TODO other /ROS ?
  } else {
    ret=emb_pdf_fd_new(fontname,subset_tag,NULL,NULL,-1);
  }
  if (!ret) {
    return NULL;
  }

  if ( (emb->intype==EMB_FMT_TTF)||(emb->intype==EMB_FMT_OTF) ) {
    emb_otf_get_pdf_fontdescr(emb->font->sfnt,ret);
  } else {
    assert(0);
  }
  return ret;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
testq %rdi, %rdi
je 0x6a79
movq %rdi, %rbx
cmpl $0x0, 0x8a13(%rip)      # 0xf3a0
jne 0x699c
xorl %edi, %edi
callq 0x2110
movl %eax, 0x8a04(%rip)      # 0xf3a0
movb $0x0, 0x7(%rsp)
testb $0x2, 0xc(%rbx)
jne 0x69ac
xorl %r14d, %r14d
jmp 0x69ee
xorl %r12d, %r12d
leaq 0x89ea(%rip), %r15      # 0xf3a0
leaq 0x1(%rsp), %r14
movq %r15, %rdi
callq 0x2140
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
mulsd 0x4646(%rip), %xmm0     # 0xb018
mulsd 0x4646(%rip), %xmm0     # 0xb020
cvttsd2si %xmm0, %eax
addb $0x41, %al
movb %al, 0x1(%rsp,%r12)
incq %r12
cmpq $0x6, %r12
jne 0x69bb
movl (%rbx), %eax
decl %eax
cmpl $0x1, %eax
ja 0x6a24
movq 0x10(%rbx), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x6a98
callq 0x54e0
testb $0x1, 0xc(%rbx)
jne 0x6a33
movq %rax, %rdi
movq %r14, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
jmp 0x6a4a
cmpl $0x4, 0x4(%rbx)
jne 0x6ab7
xorl %r14d, %r14d
jmp 0x6a6a
leaq 0x46ca(%rip), %rdx      # 0xb104
leaq 0x46c9(%rip), %rcx      # 0xb10a
movq %rax, %rdi
movq %r14, %rsi
xorl %r8d, %r8d
callq 0x6adb
movq %rax, %r14
movl (%rbx), %eax
decl %eax
cmpl $0x1, %eax
ja 0x6abc
movq 0x10(%rbx), %rax
movq (%rax), %rdi
movq %r14, %rsi
callq 0x5654
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
leaq 0x3854(%rip), %rdi      # 0xa2d4
leaq 0x45a1(%rip), %rsi      # 0xb028
leaq 0x4643(%rip), %rcx      # 0xb0d1
movl $0x99, %edx
callq 0x20e0
leaq 0x3f30(%rip), %rdi      # 0xa9cf
leaq 0x4582(%rip), %rsi      # 0xb028
leaq 0x4624(%rip), %rcx      # 0xb0d1
movl $0xb0, %edx
callq 0x20e0
callq 0x2bc5
leaq 0x41fd(%rip), %rdi      # 0xacc0
leaq 0x455e(%rip), %rsi      # 0xb028
leaq 0x4600(%rip), %rcx      # 0xb0d1
movl $0xc7, %edx
callq 0x20e0
// File: /workspace/github_c_makefile_star2_O1/smilingthax[P]libfontembed/embed_pdf.c
// Function: emb_pdf_fw_new
EMB_PDF_FONTWIDTHS *emb_pdf_fw_new(int datasize) // {{{
{
  assert(datasize>=0);
  EMB_PDF_FONTWIDTHS *ret=calloc(1,sizeof(EMB_PDF_FONTWIDTHS)+datasize*sizeof(int));
  if (!ret) {
    fprintf(stderr,"Bad alloc: %s\n", strerror(errno));
    assert(0);
    return NULL;
  }
  return ret;
}

// Assembly:
pushq %rax
testl %edi, %edi
js 0x6cec
movl %edi, %eax
leaq 0x20(,%rax,4), %rsi
movl $0x1, %edi
callq 0x20f0
testq %rax, %rax
je 0x6d0b
popq %rcx
retq
leaq 0x4420(%rip), %rdi      # 0xb113
leaq 0x432e(%rip), %rsi      # 0xb028
leaq 0x441e(%rip), %rcx      # 0xb11f
movl $0xcf, %edx
callq 0x20e0
callq 0x2c49
// File: /workspace/github_c_makefile_star2_O1/smilingthax[P]libfontembed/embed_pdf.c
// Function: emb_pdf_fontwidths
EMB_PDF_FONTWIDTHS *emb_pdf_fontwidths(EMB_PARAMS *emb) // {{{
{
  assert(emb);

  if ( (emb->intype==EMB_FMT_TTF)||(emb->intype==EMB_FMT_OTF) ) {
    assert(emb->font->sfnt);
    if (emb->plan&EMB_A_MULTIBYTE) {
      return emb_otf_get_pdf_cidwidths(emb->font->sfnt,emb->subset);
    } else {
      return emb_otf_get_pdf_widths(emb->font->sfnt,/*encoding*/NULL,emb->font->sfnt->numGlyphs,emb->subset); // TODO: encoding
    }
  } else {
    fprintf(stderr,"NOT IMPLEMENTED\n");
    assert(0);
    return NULL;
  }
}

// Assembly:
pushq %rax
testq %rdi, %rdi
je 0x706b
movl (%rdi), %eax
decl %eax
cmpl $0x1, %eax
ja 0x708a
movq 0x10(%rdi), %rax
movq (%rax), %rax
testq %rax, %rax
je 0x708f
testb $0x1, 0xc(%rdi)
jne 0x705e
movzwl 0x4c(%rax), %edx
movq 0x20(%rdi), %rcx
movq %rax, %rdi
xorl %esi, %esi
popq %rax
jmp 0x5bf4
movq 0x20(%rdi), %rsi
movq %rax, %rdi
popq %rax
jmp 0x5dec
leaq 0x3262(%rip), %rdi      # 0xa2d4
leaq 0x3faf(%rip), %rsi      # 0xb028
leaq 0x4144(%rip), %rcx      # 0xb1c4
movl $0x151, %edx            # imm = 0x151
callq 0x20e0
callq 0x2c93
leaq 0x3939(%rip), %rdi      # 0xa9cf
leaq 0x3f8b(%rip), %rsi      # 0xb028
leaq 0x4120(%rip), %rcx      # 0xb1c4
movl $0x154, %edx            # imm = 0x154
callq 0x20e0
// File: /workspace/github_c_makefile_star2_O1/smilingthax[P]libfontembed/embed_pdf.c
// Function: emb_pdf_escape_name
static const char *emb_pdf_escape_name(const char *name,int len) // {{{ // - statically allocated buffer
{
  assert(name);
  if (len==-1) {
    len=strlen(name);
  }
  assert(len<=127); // pdf implementation limit

  static char buf[128*3];
  int iA,iB;
  const char hex[]="0123456789abcdef";

  for (iA=0,iB=0;iA<len;iA++,iB++) {
    if ( ((unsigned char)name[iA]<33)||((unsigned char)name[iA]>126)||
         (strchr("#()<>[]{}/%",name[iA])) ) {
      buf[iB]='#';
      buf[++iB]=hex[(name[iA]>>4)&0x0f];
      buf[++iB]=hex[name[iA]&0xf];
    } else {
      buf[iB]=name[iA];
    }
  }
  buf[iB]=0;
  return buf;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
testq %rdi, %rdi
je 0x751f
movq %rdi, %rbx
callq 0x2090
movq %rax, %r14
cmpl $0x7f, %r14d
jg 0x753e
xorl %r12d, %r12d
testl %r14d, %r14d
jle 0x7504
andl $0x7fffffff, %r14d      # imm = 0x7FFFFFFF
leaq 0x7f18(%rip), %r13      # 0xf3b0
xorl %r15d, %r15d
movb (%rbx,%r15), %bpl
leal -0x7f(%rbp), %eax
cmpb $-0x5e, %al
jb 0x74c0
movzbl %bpl, %esi
movl $0xc, %edx
leaq 0x423e(%rip), %rdi      # 0xb6f4
callq 0x2170
testq %rax, %rax
je 0x74ef
movslq %r12d, %r12
movb $0x23, (%r12,%r13)
movzbl (%rbx,%r15), %eax
shrl $0x4, %eax
leaq 0x4229(%rip), %rcx      # 0xb700
movb (%rax,%rcx), %al
movb %al, 0x1(%r12,%r13)
movzbl (%rbx,%r15), %eax
andl $0xf, %eax
movb (%rax,%rcx), %bpl
addl $0x2, %r12d
movslq %r12d, %r12
movb %bpl, (%r12,%r13)
incq %r15
incl %r12d
cmpq %r15, %r14
jne 0x749b
movslq %r12d, %r12
leaq 0x7ea5(%rip), %rax      # 0xf3b0
movb $0x0, (%r12,%rax)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4067(%rip), %rdi      # 0xb58d
leaq 0x3afb(%rip), %rsi      # 0xb028
leaq 0x4184(%rip), %rcx      # 0xb6b8
movl $0x29, %edx
callq 0x20e0
leaq 0x41a6(%rip), %rdi      # 0xb6eb
leaq 0x3adc(%rip), %rsi      # 0xb028
leaq 0x4165(%rip), %rcx      # 0xb6b8
movl $0x2d, %edx
callq 0x20e0
// File: /workspace/github_c_makefile_star2_O1/smilingthax[P]libfontembed/embed_pdf.c
// Function: emb_pdf_simple_cidfont
char *emb_pdf_simple_cidfont(EMB_PARAMS *emb,const char *fontname,int descendant_obj_ref) // {{{ - to be freed by user
{
  assert(emb);
  assert(fontname);

  char *ret=NULL,*pos;
  int len,size;

  size=250;
  pos=ret=malloc(size);
  if (!ret) {
    fprintf(stderr,"Bad alloc: %s\n", strerror(errno));
    return NULL;
  }
     // for CFF: one of:
     // UniGB-UCS2-H, UniCNS-UCS2-H, UniJIS-UCS2-H, UniKS-UCS2-H
  const char *encoding="Identity-H",*addenc="-";
  if (emb->outtype==EMB_FMT_TTF) { // !=CidType0
    addenc="";
  }

  len=snprintf(pos,size,
               "<</Type /Font\n"
               "  /Subtype /Type0\n"
               "  /BaseFont /%s%s%s\n"
               "  /Encoding /%s\n"
               "  /DescendantFonts [%d 0 R]\n",
//               "  /ToUnicode ?\n" // TODO
               emb_pdf_escape_name(fontname,-1),
               addenc,((addenc[0])?encoding:""),
               encoding,
               descendant_obj_ref);
  NEXT;

  len=snprintf(pos,size,">>\n");
  NEXT;

  return ret;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
testq %rdi, %rdi
je 0x793f
movq %rsi, %r15
testq %rsi, %rsi
je 0x795e
movl %edx, %r14d
movq %rdi, %r12
movl $0xfa, %edi
callq 0x21c0
testq %rax, %rax
je 0x7936
movq %rax, %rbx
cmpl $0x1, 0x4(%r12)
leaq 0x2c9a(%rip), %r12      # 0xa547
leaq 0x3c3d(%rip), %r13      # 0xb4f1
cmoveq %r12, %r13
movq %r15, %rdi
callq 0x7459
cmpb $0x0, (%r13)
leaq 0x3c1a(%rip), %r10      # 0xb4e6
cmovneq %r10, %r12
leaq 0x3c1c(%rip), %rdx      # 0xb4f3
leaq 0x7ad2(%rip), %rcx      # 0xf3b0
movl $0xfa, %esi
movq %rbx, %rdi
movq %r13, %r8
movq %r12, %r9
xorl %eax, %eax
pushq %r14
pushq %r10
callq 0x2210
addq $0x10, %rsp
cmpl $0xfa, %eax
jae 0x797d
movl %eax, %ecx
movq %rbx, %rdi
addq %rcx, %rdi
movl $0xfa, %r14d
subl %eax, %r14d
leaq 0x3a0c(%rip), %rdx      # 0xb326
movq %r14, %rsi
xorl %eax, %eax
callq 0x2210
cmpl %r14d, %eax
jae 0x799c
movq %rbx, %rax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
callq 0x2cfb
xorl %ebx, %ebx
jmp 0x7929
leaq 0x298e(%rip), %rdi      # 0xa2d4
leaq 0x36db(%rip), %rsi      # 0xb028
leaq 0x3b4b(%rip), %rcx      # 0xb49f
movl $0x212, %edx            # imm = 0x212
callq 0x20e0
leaq 0x3b78(%rip), %rdi      # 0xb4dd
leaq 0x36bc(%rip), %rsi      # 0xb028
leaq 0x3b2c(%rip), %rcx      # 0xb49f
movl $0x213, %edx            # imm = 0x213
callq 0x20e0
leaq 0x333c(%rip), %rdi      # 0xacc0
leaq 0x369d(%rip), %rsi      # 0xb028
leaq 0x3b0d(%rip), %rcx      # 0xb49f
movl $0x230, %edx            # imm = 0x230
callq 0x20e0
leaq 0x331d(%rip), %rdi      # 0xacc0
leaq 0x367e(%rip), %rsi      # 0xb028
leaq 0x3aee(%rip), %rcx      # 0xb49f
movl $0x233, %edx            # imm = 0x233
callq 0x20e0
// File: /workspace/github_c_makefile_star2_O1/smilingthax[P]libfontembed/embed_pdf.c
// Function: emb_pdf_simple_stdfont
char *emb_pdf_simple_stdfont(EMB_PARAMS *emb) // {{{ - to be freed by user
{
  assert(emb);
  assert(emb->font->stdname);

  char *ret=NULL,*pos;
  int len,size;

  size=300;
  pos=ret=malloc(size);
  if (!ret) {
    fprintf(stderr,"Bad alloc: %s\n", strerror(errno));
    return NULL;
  }

  len=snprintf(pos,size,
               "<</Type/Font\n"
               "  /Subtype /Type1\n"
               "  /BaseFont /%s\n"
               ">>\n",
//               emb_pdf_get_font_subtype(emb),
               emb->font->stdname);
  NEXT;

  return ret;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
testq %rdi, %rdi
je 0x7a17
movq 0x10(%rdi), %rax
movq 0x8(%rax), %r14
testq %r14, %r14
je 0x7a36
movl $0x12c, %edi            # imm = 0x12C
callq 0x21c0
testq %rax, %rax
je 0x7a0e
movq %rax, %rbx
leaq 0x3ba8(%rip), %rdx      # 0xb592
movl $0x12c, %esi            # imm = 0x12C
movq %rax, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x2210
cmpl $0x12c, %eax            # imm = 0x12C
jae 0x7a55
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
callq 0x2d27
xorl %ebx, %ebx
jmp 0x7a03
leaq 0x28b6(%rip), %rdi      # 0xa2d4
leaq 0x3603(%rip), %rsi      # 0xb028
leaq 0x3b28(%rip), %rcx      # 0xb554
movl $0x23b, %edx            # imm = 0x23B
callq 0x20e0
leaq 0x3b42(%rip), %rdi      # 0xb57f
leaq 0x35e4(%rip), %rsi      # 0xb028
leaq 0x3b09(%rip), %rcx      # 0xb554
movl $0x23c, %edx            # imm = 0x23C
callq 0x20e0
leaq 0x3264(%rip), %rdi      # 0xacc0
leaq 0x35c5(%rip), %rsi      # 0xb028
leaq 0x3aea(%rip), %rcx      # 0xb554
movl $0x24f, %edx            # imm = 0x24F
callq 0x20e0
// File: /workspace/github_c_makefile_star2_O1/smilingthax[P]libfontembed/dynstring.c
// Function: dyn_init
int dyn_init(DYN_STRING *ds,int reserve_size) // {{{
{
  assert(ds);
  assert(reserve_size>0);

  ds->len=0;
  ds->alloc=reserve_size;
  ds->buf=malloc(ds->alloc+1);
  if (!ds->buf) {
    fprintf(stderr,"Bad alloc: %s\n", strerror(errno));
    assert(0);
    ds->len=-1;
    return -1;
  }
  return 0;
}

// Assembly:
pushq %rbx
testq %rdi, %rdi
je 0x7aa1
testl %esi, %esi
jle 0x7ac0
movq %rdi, %rbx
movl $0x0, (%rdi)
movl %esi, 0x4(%rdi)
incl %esi
movq %rsi, %rdi
callq 0x21c0
movq %rax, 0x8(%rbx)
testq %rax, %rax
je 0x7adf
xorl %eax, %eax
popq %rbx
retq
leaq 0x3c69(%rip), %rdi      # 0xb711
leaq 0x3c65(%rip), %rsi      # 0xb714
leaq 0x3c6a(%rip), %rcx      # 0xb720
movl $0xb, %edx
callq 0x20e0
leaq 0x3c79(%rip), %rdi      # 0xb740
leaq 0x3c46(%rip), %rsi      # 0xb714
leaq 0x3c4b(%rip), %rcx      # 0xb720
movl $0xc, %edx
callq 0x20e0
callq 0x2d53
// File: /workspace/github_c_makefile_star2_O1/smilingthax[P]libfontembed/dynstring.c
// Function: dyn_free
void dyn_free(DYN_STRING *ds) // {{{
{
  assert(ds);

  ds->len=-1;
  ds->alloc=0;
  free(ds->buf);
  ds->buf=NULL;
}

// Assembly:
pushq %rbx
testq %rdi, %rdi
je 0x7b08
movq %rdi, %rbx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rax, (%rdi)
movq 0x8(%rdi), %rdi
callq 0x21a0
movq $0x0, 0x8(%rbx)
popq %rbx
retq
leaq 0x3c02(%rip), %rdi      # 0xb711
leaq 0x3bfe(%rip), %rsi      # 0xb714
leaq 0x3c32(%rip), %rcx      # 0xb74f
movl $0x1d, %edx
callq 0x20e0
// File: /workspace/github_c_makefile_star2_O1/smilingthax[P]libfontembed/dynstring.c
// Function: dyn_ensure
int dyn_ensure(DYN_STRING *ds,int free_space) // {{{
{
  assert(ds);
  assert(free_space);

  if (ds->len<0) {
    return -1;
  }
  if (ds->alloc - ds->len >= free_space) {
    return 0; // done
  }
  ds->alloc+=free_space;
  char *tmp=realloc(ds->buf,ds->alloc+1);
  if (!tmp) {
    ds->len=-1;
    fprintf(stderr,"Bad alloc: %s\n", strerror(errno));
    assert(0);
    return -1;
  }
  ds->buf=tmp;
  return 0;
}

// Assembly:
pushq %rbp
pushq %rbx
pushq %rax
testq %rdi, %rdi
je 0x7b78
testl %esi, %esi
je 0x7b97
movq %rdi, %rbx
movl (%rdi), %ecx
testl %ecx, %ecx
js 0x7b6a
movl 0x4(%rbx), %eax
movl %eax, %edx
subl %ecx, %edx
xorl %ebp, %ebp
cmpl %esi, %edx
jge 0x7b6f
leal (%rax,%rsi), %ecx
movl %ecx, 0x4(%rbx)
movq 0x8(%rbx), %rdi
addl %esi, %eax
incl %eax
movslq %eax, %rsi
callq 0x2230
testq %rax, %rax
je 0x7bb6
movq %rax, 0x8(%rbx)
jmp 0x7b6f
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
leaq 0x3b92(%rip), %rdi      # 0xb711
leaq 0x3b8e(%rip), %rsi      # 0xb714
leaq 0x3bde(%rip), %rcx      # 0xb76b
movl $0x28, %edx
callq 0x20e0
leaq 0x3bef(%rip), %rdi      # 0xb78d
leaq 0x3b6f(%rip), %rsi      # 0xb714
leaq 0x3bbf(%rip), %rcx      # 0xb76b
movl $0x29, %edx
callq 0x20e0
movq %rbx, %rdi
callq 0x2d9b
// File: /workspace/github_c_makefile_star2_O1/smilingthax[P]libfontembed/dynstring.c
// Function: dyn_vprintf
int dyn_vprintf(DYN_STRING *ds,const char *fmt,va_list ap) // {{{
{
  assert(ds);

  int need,len=strlen(fmt)+100;
  va_list va;

  if (dyn_ensure(ds,len)==-1) {
    return -1;
  }

  while (1) {
    va_copy(va,ap);
    need=vsnprintf(ds->buf+ds->len,ds->alloc-ds->len+1,fmt,va);
    va_end(va);
    if (need==-1) {
      len+=100;
    } else if (need>=len) {
      len=need;
    } else {
      ds->len+=need;
      break;
    }
    if (dyn_ensure(ds,len)==-1) {
      return -1;
    }
  }
  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
testq %rdi, %rdi
je 0x7c76
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r14
movq %rsi, %rdi
callq 0x2090
movq %rax, %r13
addl $0x64, %r13d
movq %r14, %rdi
movl %r13d, %esi
callq 0x7b27
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpl $-0x1, %eax
je 0x7c65
movq %rsp, %r12
movq 0x10(%rbx), %rax
movq %rax, 0x10(%rsp)
movups (%rbx), %xmm0
movaps %xmm0, (%rsp)
movslq (%r14), %rdi
movl 0x4(%r14), %eax
subl %edi, %eax
addq 0x8(%r14), %rdi
incl %eax
movslq %eax, %rsi
movq %r15, %rdx
movq %r12, %rcx
callq 0x20d0
cmpl $-0x1, %eax
je 0x7c40
movl %eax, %ebp
cmpl %r13d, %eax
jge 0x7c47
jmp 0x7c60
addl $0x64, %r13d
movl %r13d, %ebp
movq %r14, %rdi
movl %ebp, %esi
callq 0x7b27
movl %ebp, %r13d
cmpl $-0x1, %eax
jne 0x7c05
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
jmp 0x7c65
addl %ebp, (%r14)
xorl %ecx, %ecx
movl %ecx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3a94(%rip), %rdi      # 0xb711
leaq 0x3a90(%rip), %rsi      # 0xb714
leaq 0x3b0d(%rip), %rcx      # 0xb798
movl $0x40, %edx
callq 0x20e0
// File: /workspace/github_c_makefile_star2_O1/smilingthax[P]libfontembed/fontfile.c
// Function: fontfile_open_sfnt
FONTFILE *fontfile_open_sfnt(OTF_FILE *otf) // {{{
{
  if (!otf) {
    assert(0);
    return NULL;
  }
  FONTFILE *ret=calloc(1,sizeof(FONTFILE));

  ret->sfnt=otf;

  return ret;
}

// Assembly:
pushq %rbx
testq %rdi, %rdi
je 0x7d39
movq %rdi, %rbx
movl $0x1, %edi
movl $0x18, %esi
callq 0x20f0
movq %rbx, (%rax)
popq %rbx
retq
leaq 0x2f80(%rip), %rdi      # 0xacc0
leaq 0x3a95(%rip), %rsi      # 0xb7dc
leaq 0x3a99(%rip), %rcx      # 0xb7e7
movl $0x13, %edx
callq 0x20e0
// File: /workspace/github_c_makefile_star2_O1/smilingthax[P]libfontembed/fontfile.c
// Function: fontfile_open_std
FONTFILE *fontfile_open_std(const char *name) // {{{
{
  assert(name);
  FONTFILE *ret=calloc(1,sizeof(FONTFILE));

  ret->stdname=strdup(name);

  return ret;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
testq %rdi, %rdi
je 0x7d8d
movq %rdi, %rbx
movl $0x1, %edi
movl $0x18, %esi
callq 0x20f0
movq %rax, %r14
movq %rbx, %rdi
callq 0x2240
movq %rax, 0x8(%r14)
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
leaq 0x37f9(%rip), %rdi      # 0xb58d
leaq 0x3a41(%rip), %rsi      # 0xb7dc
leaq 0x3a6e(%rip), %rcx      # 0xb810
movl $0x20, %edx
callq 0x20e0
// File: /workspace/github_c_makefile_star2_O1/smilingthax[P]libfontembed/fontfile.c
// Function: fontfile_close
void fontfile_close(FONTFILE *ff) // {{{
{
  if (ff) {
    otf_close(ff->sfnt);
    // ??? cff_close(ff->cff);
    free(ff->stdname);
    free(ff);
  }
}

// Assembly:
testq %rdi, %rdi
je 0x7dcf
pushq %rbx
movq %rdi, %rbx
movq (%rdi), %rdi
callq 0x4024
movq 0x8(%rbx), %rdi
callq 0x21a0
movq %rbx, %rdi
popq %rbx
jmp 0x21a0
retq
// File: /workspace/github_c_makefile_star2_O1/smilingthax[P]libfontembed/frequent.c
// Function: frequent_new
FREQUENT *frequent_new(int size) // {{{ - just free() it
{
  assert(size>0);
  FREQUENT *ret=malloc(sizeof(ret[0])+sizeof(ret->pair[0])*size);
  if (!ret) {
    return NULL;
  }
  ret->size=size;
  ret->czero=0;
  ret->sorted=1;
  int iA;
  for (iA=0;iA<size;iA++) {
    ret->pair[iA].key=INTPTR_MIN;
    ret->pair[iA].count=0;
    ret->pair[iA].zero=0;
  }

  return ret;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
testl %edi, %edi
jle 0x7e36
movl %edi, %ebx
movl %edi, %r14d
movq %r14, %rdi
shlq $0x4, %rdi
addq $0x10, %rdi
callq 0x21c0
testq %rax, %rax
je 0x7e2c
movl %ebx, (%rax)
movl $0x0, 0x4(%rax)
movb $0x1, 0x8(%rax)
shlq $0x4, %r14
xorl %ecx, %ecx
movabsq $-0x8000000000000000, %rdx # imm = 0x8000000000000000
movq %rdx, 0x10(%rax,%rcx)
movq $0x0, 0x18(%rax,%rcx)
addq $0x10, %rcx
cmpq %rcx, %r14
jne 0x7e13
jmp 0x7e2e
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
leaq 0x390b(%rip), %rdi      # 0xb748
leaq 0x39f6(%rip), %rsi      # 0xb83a
leaq 0x39fa(%rip), %rcx      # 0xb845
movl $0x11, %edx
callq 0x20e0