// File: /workspace/github_c_makefile_star2_O3/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 0x78e4
movq %rax, %r12
movq %rax, %rdi
movl $0x2, %esi
movl $0x8, %edx
callq 0x4a44
movq %rax, %r14
movq %rax, %rdi
callq 0x655e
testq %rax, %rax
je 0x3353
movq %rax, %r15
movq 0x10(%r14), %rax
movq (%rax), %rdi
movl $0x61, %esi
callq 0x4884
movq 0x20(%r14), %rdx
testq %rdx, %rdx
je 0x311f
testb $0x1, 0xc(%r14)
je 0x311f
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 0x4884
movq 0x20(%r14), %rdx
testq %rdx, %rdx
je 0x3153
testb $0x1, 0xc(%r14)
je 0x3153
movzwl %ax, %esi
movl $0x1, %edi
movl %eax, %ecx
shll %cl, %edi
shrq $0x5, %rsi
orl %edi, (%rdx,%rsi,4)
movq %r14, %rdi
callq 0x6bf6
movq %rax, (%rsp)
testq %rax, %rax
je 0x3372
leaq 0x6fcf(%rip), %rdi      # 0xa13e
callq 0x2210
movq %r14, %rdi
movq %r15, %rsi
movl $0x1, %edx
callq 0x6c7a
testq %rax, %rax
je 0x3391
movq %rax, %rbx
movq 0xbe29(%rip), %rax      # 0xefc0
movq (%rax), %rsi
movq %rbx, %rdi
callq 0x2190
movq %rbx, %rdi
callq 0x21b0
leaq 0x6ffc(%rip), %rdi      # 0xa1ad
callq 0x2210
leaq 0x6f89(%rip), %rdi      # 0xa146
callq 0x2210
movq %r14, %rdi
callq 0x651d
testq %rax, %rax
je 0x31e8
movq %r14, %rdi
callq 0x651d
leaq 0x6e72(%rip), %rdi      # 0xa050
movq %rax, %rsi
xorl %eax, %eax
callq 0x2040
movl 0x4(%r14), %eax
testl %eax, %eax
je 0x31fe
cmpl $0x1, %eax
jne 0x320a
leaq 0x6f55(%rip), %rdi      # 0xa151
jmp 0x3205
leaq 0x6f5d(%rip), %rdi      # 0xa162
callq 0x2210
leaq 0x6f78(%rip), %rdi      # 0xa189
callq 0x2210
testq %r13, %r13
je 0x3254
leaq 0x6e3e(%rip), %rsi      # 0xa060
movq %r13, %rdi
callq 0x21a0
testq %rax, %rax
je 0x33cf
movq %rax, %rbx
leaq 0x1b9(%rip), %rsi       # 0x33f6
movq %r14, %rdi
movq %rax, %rdx
callq 0x4c7f
movl %eax, %ebp
movq %rbx, %rdi
callq 0x2140
jmp 0x3256
xorl %ebp, %ebp
leaq 0x6e2a(%rip), %rdi      # 0xa087
callq 0x2210
leaq 0x6f3a(%rip), %rdi      # 0xa1a3
callq 0x2210
leaq 0x6e16(%rip), %rdi      # 0xa08b
movl %ebp, %esi
xorl %eax, %eax
callq 0x2040
leaq 0x6f2f(%rip), %rdi      # 0xa1b4
callq 0x2210
movq %r14, %rdi
movq %r15, %rsi
movq (%rsp), %rbp
movq %rbp, %rdx
xorl %ecx, %ecx
callq 0x7126
testq %rax, %rax
je 0x33b0
movq %rax, %rbx
movq 0xbd0f(%rip), %rax      # 0xefc0
movq (%rax), %rsi
movq %rbx, %rdi
callq 0x2190
movq %rbx, %rdi
callq 0x21b0
leaq 0x6ee2(%rip), %rdi      # 0xa1ad
callq 0x2210
testb $0x1, 0xc(%r14)
je 0x3325
leaq 0x6ede(%rip), %rdi      # 0xa1bc
callq 0x2210
movq (%r15), %rsi
movq %r14, %rdi
movl $0x3, %edx
callq 0x742f
testq %rax, %rax
je 0x33d7
movq %rax, %rbx
movq 0xbcba(%rip), %rax      # 0xefc0
movq (%rax), %rsi
movq %rbx, %rdi
callq 0x2190
movq %rbx, %rdi
callq 0x21b0
leaq 0x6e8d(%rip), %rdi      # 0xa1ad
callq 0x2210
movq %r15, %rdi
callq 0x21b0
movq %rbp, %rdi
callq 0x21b0
movq %r14, %rdi
callq 0x4c54
movq %r12, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x21b0
leaq 0x6caa(%rip), %rdi      # 0xa004
leaq 0x6ca8(%rip), %rsi      # 0xa009
leaq 0x6ca8(%rip), %rcx      # 0xa010
movl $0x3a, %edx
callq 0x20e0
leaq 0x6cce(%rip), %rdi      # 0xa047
leaq 0x6c89(%rip), %rsi      # 0xa009
leaq 0x6c89(%rip), %rcx      # 0xa010
movl $0x40, %edx
callq 0x20e0
leaq 0x6cb4(%rip), %rdi      # 0xa04c
leaq 0x6c6a(%rip), %rsi      # 0xa009
leaq 0x6c6a(%rip), %rcx      # 0xa010
movl $0x44, %edx
callq 0x20e0
leaq 0x6c95(%rip), %rdi      # 0xa04c
leaq 0x6c4b(%rip), %rsi      # 0xa009
leaq 0x6c4b(%rip), %rcx      # 0xa010
movl $0x72, %edx
callq 0x20e0
movq %r13, %rdi
callq 0x22b0
leaq 0x6c6e(%rip), %rdi      # 0xa04c
leaq 0x6c24(%rip), %rsi      # 0xa009
leaq 0x6c24(%rip), %rcx      # 0xa010
movl $0x7a, %edx
callq 0x20e0