// File: /workspace/github_c_makefile_star2_O2/smilingthax[P]libfontembed/test_pdf.c
// Function: main
int main(int argc,char **argv)
{
  const char *fn=TESTFONT;
  if (argc==2) {
    fn=argv[1];
  }
  OTF_FILE *otf=otf_load(fn);
  assert(otf);
  FONTFILE *ff=fontfile_open_sfnt(otf);
  EMB_PARAMS *emb=emb_new(ff,
                          EMB_DEST_PDF16,
                          EMB_C_FORCE_MULTIBYTE|
                          EMB_C_TAKE_FONTFILE);

  FILE *f=fopen("test.pdf","w");
  assert(f);
  int xref[100],xrefpos=3;
  int stream_len;

  fprintf(f,"%%PDF-1.3\n");
  // content
  STREAM;
  fprintf(f,"BT\n" // content
            "  100 100 Td\n"
            "  /F1 10 Tf\n");
  write_string(f,emb,"Hallo");
  fprintf(f," Tj\n"
            "ET\n");
  ENDSTREAM;

  emb_get(emb,'a');

  // {{{ do font
  EMB_PDF_FONTDESCR *fdes=emb_pdf_fontdescr(emb);
  assert(fdes);
  EMB_PDF_FONTWIDTHS *fwid=emb_pdf_fontwidths(emb);
  assert(fwid);

  STREAMDICT;
  int ff_ref=xrefpos;
  if (emb_pdf_get_fontfile_subtype(emb)) {
    fprintf(f,"  /Subtype /%s\n",
              emb_pdf_get_fontfile_subtype(emb));
  }
  if (emb->outtype==EMB_FMT_T1) {
    fprintf(f,"  /Length1 ?\n"
              "  /Length2 ?\n"
              "  /Length3 ?\n");
  } else if (emb->outtype==EMB_FMT_TTF) {
    fprintf(f,"  /Length1 %d 0 R\n",xrefpos+2);
  }
  STREAMDATA;
  const int outlen=emb_embed(emb,example_outfn,f);
  ENDSTREAM;
  if (emb->outtype==EMB_FMT_TTF) {
    OBJ;
    fprintf(f,"%d\n",outlen);
    ENDOBJ;
  }

  OBJ;
  const int fd_ref=xrefpos;
  char *res=emb_pdf_simple_fontdescr(emb,fdes,ff_ref);
  assert(res);
  fputs(res,f);
  free(res);
  ENDOBJ;

  OBJ;
  int f_ref=xrefpos;
  res=emb_pdf_simple_font(emb,fdes,fwid,fd_ref);
  assert(res);
  fputs(res,f);
  free(res);
  ENDOBJ;

  if (emb->plan&EMB_A_MULTIBYTE) {
    OBJ;
    res=emb_pdf_simple_cidfont(emb,fdes->fontname,f_ref);
    f_ref=xrefpos;
    assert(res);
    fputs(res,f);
    free(res);
    ENDOBJ;
  }

  free(fdes);
  free(fwid);
  // }}}

  int iA;

  xref[2]=ftell(f);
  fprintf(f,"3 0 obj\n"
            "<</Type/Page\n"
            "  /Parent 2 0 R\n"
            "  /MediaBox [0 0 595 842]\n"
            "  /Contents 4 0 R\n"
            "  /Resources <<\n"
            "    /Font <<\n"
            "      /F1 %d 0 R\n"
            "    >>\n"
            "  >>\n"
            ">>\n"
            "endobj\n",
            f_ref);
  xref[1]=ftell(f);
  fprintf(f,"2 0 obj\n"
            "<</Type/Pages\n"
            "  /Count 1\n"
            "  /Kids [3 0 R]"
            ">>\n"
            "endobj\n");
  xref[0]=ftell(f);
  fprintf(f,"1 0 obj\n"
            "<</Type/Catalog\n"
            "  /Pages 2 0 R\n"
            ">>\n"
            "endobj\n");
  // {{{ pdf trailer
  int xref_start=ftell(f);
  fprintf(f,"xref\n"
            "0 %d\n"
            "%010d 65535 f \n",
            xrefpos+1,0);
  for (iA=0;iA<xrefpos;iA++) {
    fprintf(f,"%010d 00000 n \n",xref[iA]);
  }
  fprintf(f,"trailer\n"
          "<<\n"
          "  /Size %d\n"
          "  /Root 1 0 R\n"
          ">>\n"
          "startxref\n"
          "%d\n"
          "%%%%EOF\n",
          xrefpos+1,xref_start);
  // }}}
  fclose(f);

  emb_close(emb);

  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1b8, %rsp            # imm = 0x1B8
cmpl $0x2, %edi
jne 0x23a8
movq 0x8(%rsi), %rdi
jmp 0x23af
leaq 0x7c55(%rip), %rdi      # 0xa004
callq 0x35a5
testq %rax, %rax
je 0x29cf
movq %rax, %rdi
callq 0x74e4
pushq $0x2
popq %rsi
movq %rax, %rdi
movl $0x8008, %edx           # imm = 0x8008
callq 0x4490
movq %rax, %rbx
leaq 0x7c7f(%rip), %rdi      # 0xa05e
leaq 0x7c81(%rip), %rsi      # 0xa067
callq 0x21a0
testq %rax, %rax
je 0x29e8
movq %rax, %r14
leaq 0x7c6b(%rip), %rsi      # 0xa069
movq %rax, %rdi
xorl %eax, %eax
callq 0x21e0
movq %r14, %rdi
callq 0x2030
movl %eax, 0x2c(%rsp)
leaq 0x7c59(%rip), %rsi      # 0xa074
pushq $0x4
popq %rdx
movq %r14, %rdi
xorl %eax, %eax
callq 0x21e0
leaq 0x7c4f(%rip), %rsi      # 0xa07e
pushq $0x5
popq %rdx
movq %r14, %rdi
xorl %eax, %eax
callq 0x21e0
leaq 0x7c50(%rip), %rdi      # 0xa093
pushq $0xa
popq %rsi
pushq $0x1
popq %r12
movq %r12, %rdx
movq %r14, %rcx
callq 0x2280
movq %r14, %rdi
callq 0x2030
movq %rax, %r15
leaq 0x7c37(%rip), %rdi      # 0xa09e
pushq $0x1c
popq %rsi
movq %r12, %rdx
movq %r14, %rcx
callq 0x2280
testq %rbx, %rbx
je 0x2a01
movq %r15, 0x8(%rsp)
testb $0x1, 0xc(%rbx)
jne 0x24b6
pushq $0x28
popq %rdi
movq %r14, %rsi
callq 0x2270
xorl %r15d, %r15d
leaq 0x7c1d(%rip), %r12      # 0xa0bb
cmpq $0x5, %r15
je 0x24fd
movzbl (%r15,%r12), %esi
movq %rbx, %rdi
callq 0x2aad
incq %r15
jmp 0x249e
pushq $0x3c
popq %rdi
movq %r14, %rsi
callq 0x2270
pushq $0x3e
popq %rbp
leaq 0x7bf0(%rip), %r13      # 0xa0bb
leaq 0x7e06(%rip), %r12      # 0xa2d8
xorl %r15d, %r15d
cmpq $0x5, %r15
je 0x250f
movzbl (%r15,%r13), %esi
movq %rbx, %rdi
callq 0x2aad
movzwl %ax, %edx
movq %r14, %rdi
movq %r12, %rsi
xorl %eax, %eax
callq 0x21e0
incq %r15
jmp 0x24d5
leaq 0x7bb7(%rip), %rdi      # 0xa0bb
movq %r14, %rsi
callq 0x2190
pushq $0x29
popq %rbp
movl %ebp, %edi
movq %r14, %rsi
callq 0x2270
leaq 0x7ba1(%rip), %rdi      # 0xa0c1
pushq $0x7
popq %r12
pushq $0x1
popq %r13
movq %r12, %rsi
movq %r13, %rdx
movq %r14, %rcx
callq 0x2280
movq %r14, %rdi
callq 0x2030
movq %rax, %rbp
subl 0x8(%rsp), %ebp
leaq 0x7b7d(%rip), %rdi      # 0xa0c9
pushq $0x11
popq %rsi
movq %r13, %rdx
movq %r14, %rcx
callq 0x2280
movq %r14, %rdi
callq 0x2030
movl %eax, 0x30(%rsp)
leaq 0x7b07(%rip), %rsi      # 0xa074
pushq $0x5
popq %rdx
movq %r14, %rdi
xorl %eax, %eax
callq 0x21e0
leaq 0x8d54(%rip), %rsi      # 0xb2d5
movq %r14, %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0x21e0
leaq 0x7c2e(%rip), %rdi      # 0xa1c2
movq %r12, %rsi
movq %r13, %rdx
movq %r14, %rcx
callq 0x2280
pushq $0x61
popq %rsi
movq %rbx, %rdi
callq 0x2aad
movq %rbx, %rdi
callq 0x5ff0
testq %rax, %rax
je 0x2a1a
movq %rax, %r12
movq %rbx, %rdi
callq 0x670e
movq %rax, 0x18(%rsp)
testq %rax, %rax
je 0x2a33
movq %r14, %rdi
callq 0x2030
movl %eax, 0x34(%rsp)
leaq 0x7a8a(%rip), %rsi      # 0xa074
pushq $0x6
popq %rdx
movq %r14, %rdi
xorl %eax, %eax
callq 0x21e0
leaq 0x7a80(%rip), %rsi      # 0xa07e
pushq $0x7
popq %r15
movq %r14, %rdi
movl %r15d, %edx
xorl %eax, %eax
callq 0x21e0
movq %rbx, %rdi
callq 0x5fb1
testq %rax, %rax
je 0x2638
movq %rbx, %rdi
callq 0x5fb1
leaq 0x7aba(%rip), %rsi      # 0xa0e5
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x21e0
movl 0x4(%rbx), %eax
cmpl $0x1, %eax
movq %r12, 0x8(%rsp)
je 0x2660
testl %eax, %eax
jne 0x2674
leaq 0x7aa5(%rip), %rdi      # 0xa0f5
pushq $0x27
popq %rsi
pushq $0x1
popq %rdx
movq %r14, %rcx
callq 0x2280
jmp 0x2674
leaq 0x7ab6(%rip), %rsi      # 0xa11d
pushq $0x8
popq %rdx
movq %r14, %rdi
xorl %eax, %eax
callq 0x21e0
leaq 0x7a18(%rip), %rdi      # 0xa093
pushq $0xa
popq %rsi
pushq $0x1
popq %r13
movq %r13, %rdx
movq %r14, %rcx
callq 0x2280
movq %r14, %rdi
callq 0x2030
movq %rax, %rbp
leaq 0x440(%rip), %rsi       # 0x2adf
movq %rbx, %rdi
movq %r14, %rdx
callq 0x4749
movl %eax, 0x10(%rsp)
movq %r14, %rdi
callq 0x2030
movq %rax, %r12
subl %ebp, %r12d
leaq 0x7a06(%rip), %rdi      # 0xa0c9
pushq $0x11
popq %rsi
movq %r13, %rdx
movq %r14, %rcx
callq 0x2280
movq %r14, %rdi
callq 0x2030
movl %eax, 0x38(%rsp)
leaq 0x7990(%rip), %rsi      # 0xa074
movq %r14, %rdi
movq %r15, %rbp
movl %ebp, %edx
xorl %eax, %eax
callq 0x21e0
leaq 0x8bdb(%rip), %rsi      # 0xb2d5
movq %r14, %rdi
movl %r12d, %edx
xorl %eax, %eax
callq 0x21e0
leaq 0x7ab4(%rip), %rdi      # 0xa1c2
pushq $0x7
popq %rsi
movq %r13, %rdx
movq %r14, %rcx
callq 0x2280
cmpl $0x1, 0x4(%rbx)
jne 0x276e
movq %r14, %rdi
callq 0x2030
movl %eax, 0x3c(%rsp)
leaq 0x793f(%rip), %rsi      # 0xa074
pushq $0x8
popq %rbp
movq %r14, %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0x21e0
leaq 0x8b8a(%rip), %rsi      # 0xb2d5
movq %r14, %rdi
movl 0x10(%rsp), %edx
xorl %eax, %eax
callq 0x21e0
leaq 0x7a62(%rip), %rdi      # 0xa1c2
pushq $0x7
popq %rsi
pushq $0x1
popq %rdx
movq %r14, %rcx
callq 0x2280
movq %r14, %rdi
callq 0x2030
leal 0x1(%rbp), %r13d
movl %ebp, %ecx
movl %eax, 0x20(%rsp,%rcx,4)
leaq 0x78ed(%rip), %rsi      # 0xa074
movq %r14, %rdi
movl %r13d, %edx
xorl %eax, %eax
callq 0x21e0
pushq $0x6
popq %rdx
movq %rbx, %rdi
movq 0x8(%rsp), %r15
movq %r15, %rsi
callq 0x67cc
testq %rax, %rax
je 0x2a50
movq %rax, %r12
movq %rax, %rdi
movq %r14, %rsi
callq 0x2190
movq %r12, %rdi
callq 0x21b0
leaq 0x79f5(%rip), %rdi      # 0xa1c2
pushq $0x7
popq %rsi
pushq $0x1
popq %rdx
movq %r14, %rcx
callq 0x2280
movq %r14, %rdi
callq 0x2030
movq %rbp, 0x10(%rsp)
addl $0x2, %ebp
movl %r13d, %ecx
movl %eax, 0x20(%rsp,%rcx,4)
leaq 0x787b(%rip), %rsi      # 0xa074
movq %r14, %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0x21e0
movq %rbx, %rdi
movq %r15, %rsi
movq 0x18(%rsp), %rdx
movl %r13d, %ecx
callq 0x6c98
testq %rax, %rax
je 0x2a6f
movq %rax, %r12
movq %rax, %rdi
movq %r14, %rsi
callq 0x2190
movq %r12, %rdi
callq 0x21b0
leaq 0x7984(%rip), %rdi      # 0xa1c2
pushq $0x7
popq %rsi
pushq $0x1
popq %rdx
movq %r14, %rcx
callq 0x2280
testb $0x1, 0xc(%rbx)
jne 0x285c
movl %ebp, %r13d
movq 0x8(%rsp), %r15
jmp 0x28cc
movq %r14, %rdi
callq 0x2030
movq 0x10(%rsp), %rdx
addl $0x3, %edx
movl %ebp, %ecx
movl %eax, 0x20(%rsp,%rcx,4)
leaq 0x77fb(%rip), %rsi      # 0xa074
movq %r14, %rdi
movq %rdx, %r13
xorl %eax, %eax
callq 0x21e0
movq 0x8(%rsp), %r15
movq (%r15), %rsi
movq %rbx, %rdi
movl %ebp, %edx
callq 0x6f7f
testq %rax, %rax
je 0x2a8e
movq %rax, %r12
movq %rax, %rdi
movq %r14, %rsi
callq 0x2190
movq %r12, %rdi
callq 0x21b0
leaq 0x7904(%rip), %rdi      # 0xa1c2
pushq $0x7
popq %rsi
pushq $0x1
popq %rdx
movq %r14, %rcx
callq 0x2280
movq %r15, %rdi
callq 0x21b0
movq 0x18(%rsp), %rdi
callq 0x21b0
movq %r14, %rdi
callq 0x2030
movl %eax, 0x28(%rsp)
leaq 0x7843(%rip), %rsi      # 0xa134
movq %r14, %rdi
movl %r13d, %edx
xorl %eax, %eax
callq 0x21e0
movq %r14, %rdi
callq 0x2030
movl %eax, 0x24(%rsp)
leaq 0x78b9(%rip), %rdi      # 0xa1ca
pushq $0x3a
popq %rsi
pushq $0x1
popq %r12
movq %r12, %rdx
movq %r14, %rcx
callq 0x2280
movq %r14, %rdi
callq 0x2030
movl %eax, 0x20(%rsp)
leaq 0x78cf(%rip), %rdi      # 0xa205
pushq $0x31
popq %rsi
movq %r12, %rdx
movq %r14, %rcx
callq 0x2280
movq %r14, %rdi
callq 0x2030
movq %rax, 0x8(%rsp)
leal 0x1(%r13), %ebp
leaq 0x78db(%rip), %rsi      # 0xa237
movq %r14, %rdi
movl %ebp, %edx
xorl %ecx, %ecx
xorl %eax, %eax
callq 0x21e0
movl %r13d, %r13d
leaq 0x78dd(%rip), %r15      # 0xa251
xorl %r12d, %r12d
cmpq %r12, %r13
je 0x2993
movl 0x20(%rsp,%r12,4), %edx
movq %r14, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x21e0
incq %r12
jmp 0x2977
leaq 0x78c7(%rip), %rsi      # 0xa261
movq %r14, %rdi
movl %ebp, %edx
movq 0x8(%rsp), %rcx
xorl %eax, %eax
callq 0x21e0
movq %r14, %rdi
callq 0x2140
movq %rbx, %rdi
callq 0x471e
xorl %eax, %eax
addq $0x1b8, %rsp            # imm = 0x1B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x7662(%rip), %rdi      # 0xa038
leaq 0x765f(%rip), %rsi      # 0xa03c
leaq 0x7663(%rip), %rcx      # 0xa047
pushq $0x52
jmp 0x2a4a
leaq 0x7676(%rip), %rdi      # 0xa065
leaq 0x7646(%rip), %rsi      # 0xa03c
leaq 0x764a(%rip), %rcx      # 0xa047
pushq $0x5a
jmp 0x2a4a
leaq 0x78cc(%rip), %rdi      # 0xa2d4
leaq 0x762d(%rip), %rsi      # 0xa03c
leaq 0x7888(%rip), %rcx      # 0xa29e
pushq $0x36
jmp 0x2a4a
leaq 0x76ba(%rip), %rdi      # 0xa0db
leaq 0x7614(%rip), %rsi      # 0xa03c
leaq 0x7618(%rip), %rcx      # 0xa047
pushq $0x6d
jmp 0x2a4a
leaq 0x76a6(%rip), %rdi      # 0xa0e0
leaq 0x75fb(%rip), %rsi      # 0xa03c
leaq 0x75ff(%rip), %rcx      # 0xa047
pushq $0x6f
popq %rdx
callq 0x20f0
leaq 0x76d9(%rip), %rdi      # 0xa130
leaq 0x75de(%rip), %rsi      # 0xa03c
leaq 0x75e2(%rip), %rcx      # 0xa047
movl $0x8a, %edx
callq 0x20f0
leaq 0x76ba(%rip), %rdi      # 0xa130
leaq 0x75bf(%rip), %rsi      # 0xa03c
leaq 0x75c3(%rip), %rcx      # 0xa047
movl $0x92, %edx
callq 0x20f0
leaq 0x769b(%rip), %rdi      # 0xa130
leaq 0x75a0(%rip), %rsi      # 0xa03c
leaq 0x75a4(%rip), %rcx      # 0xa047
movl $0x9b, %edx
callq 0x20f0