// File: /workspace/github_c_makefile_star2_O1/smilingthax[P]libfontembed/main.c
// Function: example_write_fontdescr
void example_write_fontdescr(OTF_FILE *otf,const char *outfile) // {{{
{
  FONTFILE *ff=fontfile_open_sfnt(otf);
  EMB_PARAMS *emb=emb_new(ff,
                          EMB_DEST_PDF16,
//                          EMB_C_KEEP_T1
                          EMB_C_FORCE_MULTIBYTE

                          );
  EMB_PDF_FONTDESCR *fdes=emb_pdf_fontdescr(emb);
  assert(fdes);

  emb_get(emb,'a');
  emb_get(emb,0x400);

  EMB_PDF_FONTWIDTHS *fwid=emb_pdf_fontwidths(emb);
  assert(fwid);

  printf("0 0 obj\n");
  char *res=emb_pdf_simple_fontdescr(emb,fdes,1);
  assert(res);
  fputs(res,stdout);
  free(res);
  printf("endobj\n");

  printf("1 0 obj\n"
         "<<\n");
  if (emb_pdf_get_fontfile_subtype(emb)) {
    printf("  /Subtype /%s\n",
           emb_pdf_get_fontfile_subtype(emb));
  }
  if (emb->outtype==EMB_FMT_T1) {
    printf("  /Length1 ?\n"
           "  /Length2 ?\n"
           "  /Length3 ?\n");
  } else if (emb->outtype==EMB_FMT_TTF) {
    printf("  /Length1 2 0 R\n");
  }
  printf("  /Length 2 0 R\n" // maybe compress it...
         ">>\n"
         "stream\n");
  int outlen=0; // TODO
// TODO
  if (outfile) {
    FILE *f=fopen(outfile,"w");
    if (!f) {
      fprintf(stderr,"Opening \"%s\" for writing failed: %m\n",outfile);
      assert(0);
      emb_close(emb);
      return;
    }
    outlen=emb_embed(emb,example_outfn,f);
//    outlen=otf_ttc_extract(emb->font->sfnt,example_outfn,f);
    fclose(f);
  }
puts("...");
  printf("endstream\n"
         "endobj\n");
  printf("2 0 obj\n"
         "%d\n"
         "endobj\n",
         outlen
         );

  printf("3 0 obj\n");
  res=emb_pdf_simple_font(emb,fdes,fwid,0);
  assert(res);
  fputs(res,stdout);
  free(res);
  printf("endobj\n");

  if (emb->plan&EMB_A_MULTIBYTE) {
    printf("4 0 obj\n");
    res=emb_pdf_simple_cidfont(emb,fdes->fontname,3);
    assert(res);
    fputs(res,stdout);
    free(res);
    printf("endobj\n");
  }

  free(fdes);
  free(fwid);
  emb_close(emb);
#if 1
  free(ff); // TODO
#else
  ff->sfnt=NULL; // TODO
  fontfile_close(ff);
#endif
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r13
callq 0x7968
movq %rax, %r12
movq %rax, %rdi
movl $0x2, %esi
movl $0x8, %edx
callq 0x4a64
movq %rax, %r14
movq %rax, %rdi
callq 0x65be
testq %rax, %rax
je 0x3343
movq %rax, %r15
movq 0x10(%r14), %rax
movq (%rax), %rdi
movl $0x61, %esi
callq 0x48a4
movq 0x20(%r14), %rdx
testq %rdx, %rdx
je 0x310f
testb $0x1, 0xc(%r14)
je 0x310f
movzwl %ax, %esi
movl $0x1, %edi
movl %eax, %ecx
shll %cl, %edi
shrq $0x5, %rsi
orl %edi, (%rdx,%rsi,4)
movq 0x10(%r14), %rax
movq (%rax), %rdi
movl $0x400, %esi            # imm = 0x400
callq 0x48a4
movq 0x20(%r14), %rdx
testq %rdx, %rdx
je 0x3143
testb $0x1, 0xc(%r14)
je 0x3143
movzwl %ax, %esi
movl $0x1, %edi
movl %eax, %ecx
shll %cl, %edi
shrq $0x5, %rsi
orl %edi, (%rdx,%rsi,4)
movq %r14, %rdi
callq 0x6c76
movq %rax, (%rsp)
testq %rax, %rax
je 0x3362
leaq 0x6fdf(%rip), %rdi      # 0xa13e
callq 0x2210
movq %r14, %rdi
movq %r15, %rsi
movl $0x1, %edx
callq 0x6cfa
testq %rax, %rax
je 0x3381
movq %rax, %rbx
movq 0xbe39(%rip), %rax      # 0xefc0
movq (%rax), %rsi
movq %rbx, %rdi
callq 0x2190
movq %rbx, %rdi
callq 0x21b0
leaq 0x700c(%rip), %rdi      # 0xa1ad
callq 0x2210
leaq 0x6f99(%rip), %rdi      # 0xa146
callq 0x2210
movq %r14, %rdi
callq 0x657d
testq %rax, %rax
je 0x31d8
movq %r14, %rdi
callq 0x657d
leaq 0x6e82(%rip), %rdi      # 0xa050
movq %rax, %rsi
xorl %eax, %eax
callq 0x2040
movl 0x4(%r14), %eax
testl %eax, %eax
je 0x31ee
cmpl $0x1, %eax
jne 0x31fa
leaq 0x6f65(%rip), %rdi      # 0xa151
jmp 0x31f5
leaq 0x6f6d(%rip), %rdi      # 0xa162
callq 0x2210
leaq 0x6f88(%rip), %rdi      # 0xa189
callq 0x2210
testq %r13, %r13
je 0x3244
leaq 0x6e4e(%rip), %rsi      # 0xa060
movq %r13, %rdi
callq 0x21a0
testq %rax, %rax
je 0x33bf
movq %rax, %rbx
leaq 0x1b9(%rip), %rsi       # 0x33e6
movq %r14, %rdi
movq %rax, %rdx
callq 0x4c91
movl %eax, %ebp
movq %rbx, %rdi
callq 0x2140
jmp 0x3246
xorl %ebp, %ebp
leaq 0x6e3a(%rip), %rdi      # 0xa087
callq 0x2210
leaq 0x6f4a(%rip), %rdi      # 0xa1a3
callq 0x2210
leaq 0x6e26(%rip), %rdi      # 0xa08b
movl %ebp, %esi
xorl %eax, %eax
callq 0x2040
leaq 0x6f3f(%rip), %rdi      # 0xa1b4
callq 0x2210
movq %r14, %rdi
movq %r15, %rsi
movq (%rsp), %rbp
movq %rbp, %rdx
xorl %ecx, %ecx
callq 0x71a9
testq %rax, %rax
je 0x33a0
movq %rax, %rbx
movq 0xbd1f(%rip), %rax      # 0xefc0
movq (%rax), %rsi
movq %rbx, %rdi
callq 0x2190
movq %rbx, %rdi
callq 0x21b0
leaq 0x6ef2(%rip), %rdi      # 0xa1ad
callq 0x2210
testb $0x1, 0xc(%r14)
je 0x3315
leaq 0x6eee(%rip), %rdi      # 0xa1bc
callq 0x2210
movq (%r15), %rsi
movq %r14, %rdi
movl $0x3, %edx
callq 0x74b2
testq %rax, %rax
je 0x33c7
movq %rax, %rbx
movq 0xbcca(%rip), %rax      # 0xefc0
movq (%rax), %rsi
movq %rbx, %rdi
callq 0x2190
movq %rbx, %rdi
callq 0x21b0
leaq 0x6e9d(%rip), %rdi      # 0xa1ad
callq 0x2210
movq %r15, %rdi
callq 0x21b0
movq %rbp, %rdi
callq 0x21b0
movq %r14, %rdi
callq 0x4c66
movq %r12, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x21b0
leaq 0x6cba(%rip), %rdi      # 0xa004
leaq 0x6cb8(%rip), %rsi      # 0xa009
leaq 0x6cb8(%rip), %rcx      # 0xa010
movl $0x3a, %edx
callq 0x20e0
leaq 0x6cde(%rip), %rdi      # 0xa047
leaq 0x6c99(%rip), %rsi      # 0xa009
leaq 0x6c99(%rip), %rcx      # 0xa010
movl $0x40, %edx
callq 0x20e0
leaq 0x6cc4(%rip), %rdi      # 0xa04c
leaq 0x6c7a(%rip), %rsi      # 0xa009
leaq 0x6c7a(%rip), %rcx      # 0xa010
movl $0x44, %edx
callq 0x20e0
leaq 0x6ca5(%rip), %rdi      # 0xa04c
leaq 0x6c5b(%rip), %rsi      # 0xa009
leaq 0x6c5b(%rip), %rcx      # 0xa010
movl $0x72, %edx
callq 0x20e0
movq %r13, %rdi
callq 0x22b0
leaq 0x6c7e(%rip), %rdi      # 0xa04c
leaq 0x6c34(%rip), %rsi      # 0xa009
leaq 0x6c34(%rip), %rcx      # 0xa010
movl $0x7a, %edx
callq 0x20e0