// File: /workspace/github_c_makefile_star2_O2/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 0x7170
movq %rax, %r12
pushq $0x2
popq %rsi
pushq $0x8
popq %rdx
movq %rax, %rdi
callq 0x411c
movq %rax, %r14
movq %rax, %rdi
callq 0x5c7c
testq %rax, %rax
je 0x25f4
movq %rax, %r15
pushq $0x61
popq %rsi
movq %r14, %rdi
callq 0x26ac
movq %r14, %rdi
movl $0x400, %esi            # imm = 0x400
callq 0x26ac
movq %r14, %rdi
callq 0x639a
movq %rax, (%rsp)
testq %rax, %rax
je 0x2610
leaq 0x6d23(%rip), %rdi      # 0x913e
callq 0x2220
pushq $0x1
popq %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0x6458
testq %rax, %rax
je 0x2629
movq %rax, %rbx
movq 0xbb7f(%rip), %rax      # 0xdfc0
movq (%rax), %rsi
movq %rbx, %rdi
callq 0x21a0
movq %rbx, %rdi
callq 0x21c0
leaq 0x6d52(%rip), %rdi      # 0x91ad
callq 0x2220
leaq 0x6cdf(%rip), %rdi      # 0x9146
callq 0x2220
movq %r14, %rdi
callq 0x5c3d
testq %rax, %rax
je 0x2492
movq %r14, %rdi
callq 0x5c3d
leaq 0x6bc8(%rip), %rdi      # 0x9050
movq %rax, %rsi
xorl %eax, %eax
callq 0x2040
movl 0x4(%r14), %eax
testl %eax, %eax
je 0x24a8
cmpl $0x1, %eax
jne 0x24b4
leaq 0x6cab(%rip), %rdi      # 0x9151
jmp 0x24af
leaq 0x6cb3(%rip), %rdi      # 0x9162
callq 0x2220
leaq 0x6cce(%rip), %rdi      # 0x9189
callq 0x2220
testq %r13, %r13
je 0x24fe
leaq 0x6b94(%rip), %rsi      # 0x9060
movq %r13, %rdi
callq 0x21b0
testq %rax, %rax
je 0x265b
movq %rax, %rbx
leaq 0x1f7(%rip), %rsi       # 0x26de
movq %r14, %rdi
movq %rax, %rdx
callq 0x43d5
movl %eax, %ebp
movq %rbx, %rdi
callq 0x2150
jmp 0x2500
xorl %ebp, %ebp
leaq 0x6b80(%rip), %rdi      # 0x9087
callq 0x2220
leaq 0x6c90(%rip), %rdi      # 0x91a3
callq 0x2220
leaq 0x6b6c(%rip), %rdi      # 0x908b
movl %ebp, %esi
xorl %eax, %eax
callq 0x2040
leaq 0x6c85(%rip), %rdi      # 0x91b4
callq 0x2220
movq %r14, %rdi
movq %r15, %rsi
movq (%rsp), %rdx
xorl %ecx, %ecx
callq 0x6924
testq %rax, %rax
je 0x2642
movq %rax, %rbx
movq 0xba68(%rip), %rbp      # 0xdfc0
movq (%rbp), %rsi
movq %rax, %rdi
callq 0x21a0
movq %rbx, %rdi
callq 0x21c0
leaq 0x6c3a(%rip), %rdi      # 0x91ad
callq 0x2220
testb $0x1, 0xc(%r14)
je 0x25c5
leaq 0x6c36(%rip), %rdi      # 0x91bc
callq 0x2220
movq (%r15), %rsi
pushq $0x3
popq %rdx
movq %r14, %rdi
callq 0x6c0b
testq %rax, %rax
je 0x268f
movq %rax, %rbx
movq (%rbp), %rsi
movq %rax, %rdi
callq 0x21a0
movq %rbx, %rdi
callq 0x21c0
leaq 0x6bed(%rip), %rdi      # 0x91ad
callq 0x2220
movq %r15, %rdi
callq 0x21c0
movq (%rsp), %rdi
callq 0x21c0
movq %r14, %rdi
callq 0x43aa
movq %r12, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x21c0
leaq 0x6a09(%rip), %rdi      # 0x9004
leaq 0x6a07(%rip), %rsi      # 0x9009
leaq 0x6a07(%rip), %rcx      # 0x9010
pushq $0x3a
jmp 0x26a6
leaq 0x6a30(%rip), %rdi      # 0x9047
leaq 0x69eb(%rip), %rsi      # 0x9009
leaq 0x69eb(%rip), %rcx      # 0x9010
pushq $0x40
jmp 0x26a6
leaq 0x6a1c(%rip), %rdi      # 0x904c
leaq 0x69d2(%rip), %rsi      # 0x9009
leaq 0x69d2(%rip), %rcx      # 0x9010
pushq $0x44
jmp 0x26a6
leaq 0x6a03(%rip), %rdi      # 0x904c
leaq 0x69b9(%rip), %rsi      # 0x9009
leaq 0x69b9(%rip), %rcx      # 0x9010
pushq $0x72
jmp 0x26a6
movq 0xb976(%rip), %rax      # 0xdfd8
movq (%rax), %rdi
leaq 0x69f6(%rip), %rsi      # 0x9062
movq %r13, %rdx
xorl %eax, %eax
callq 0x2200
leaq 0x74f3(%rip), %rdi      # 0x9b70
leaq 0x6985(%rip), %rsi      # 0x9009
leaq 0x6985(%rip), %rcx      # 0x9010
pushq $0x5f
jmp 0x26a6
leaq 0x69b6(%rip), %rdi      # 0x904c
leaq 0x696c(%rip), %rsi      # 0x9009
leaq 0x696c(%rip), %rcx      # 0x9010
pushq $0x7a
popq %rdx
callq 0x20f0