// File: /workspace/github_c_makefile_star2_O1/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 $0x1a8, %rsp            # imm = 0x1A8
cmpl $0x2, %edi
jne 0x3078
movq 0x8(%rsi), %rdi
jmp 0x307f
leaq 0x6f85(%rip), %rdi      # 0xa004
callq 0x40f3
testq %rax, %rax
je 0x3740
movq %rax, %rdi
callq 0x7d1c
movq %rax, %rdi
movl $0x2, %esi
movl $0x8008, %edx           # imm = 0x8008
callq 0x4e18
movq %rax, %rbx
leaq 0x6fad(%rip), %rdi      # 0xa05e
leaq 0x6faf(%rip), %rsi      # 0xa067
callq 0x2190
testq %rax, %rax
je 0x375f
movq %rax, %r14
leaq 0x6f99(%rip), %rsi      # 0xa069
movq %rax, %rdi
xorl %eax, %eax
callq 0x21d0
movq %r14, %rdi
callq 0x2030
movl %eax, 0x1c(%rsp)
leaq 0x6f87(%rip), %rsi      # 0xa074
movq %r14, %rdi
movl $0x4, %edx
xorl %eax, %eax
callq 0x21d0
leaq 0x6f7b(%rip), %rsi      # 0xa07e
movq %r14, %rdi
movl $0x5, %edx
xorl %eax, %eax
callq 0x21d0
leaq 0x6f7a(%rip), %rdi      # 0xa093
movl $0xa, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x2270
movq %r14, %rdi
callq 0x2030
movq %rax, %r15
leaq 0x6f61(%rip), %rdi      # 0xa09e
movl $0x1c, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x2270
testq %rbx, %rbx
je 0x377e
testb $0x1, 0xc(%rbx)
jne 0x31ce
movl $0x28, %edi
movq %r14, %rsi
callq 0x2260
movb $0x48, %al
movl $0x1, %r12d
leaq 0x6f41(%rip), %r13      # 0xa0bb
movzbl %al, %esi
movq 0x10(%rbx), %rax
movq (%rax), %rdi
callq 0x4c58
movq 0x20(%rbx), %rdx
testq %rdx, %rdx
je 0x31ab
testb $0x1, 0xc(%rbx)
je 0x31ab
movzwl %ax, %esi
movl $0x1, %edi
movl %eax, %ecx
shll %cl, %edi
shrq $0x5, %rsi
orl %edi, (%rdx,%rsi,4)
movb (%r12,%r13), %al
incq %r12
cmpq $0x6, %r12
jne 0x317a
leaq 0x6efc(%rip), %rdi      # 0xa0bb
movq %r14, %rsi
callq 0x2180
movl $0x29, %edi
jmp 0x3245
movl $0x3c, %edi
movq %r14, %rsi
callq 0x2260
movb $0x48, %al
movl $0x1, %r13d
leaq 0x70ee(%rip), %r12      # 0xa2d8
leaq 0x6eca(%rip), %rbp      # 0xa0bb
movzbl %al, %esi
movq 0x10(%rbx), %rax
movq (%rax), %rdi
callq 0x4c58
movq 0x20(%rbx), %rsi
movzwl %ax, %edx
testq %rsi, %rsi
je 0x3225
testb $0x1, 0xc(%rbx)
je 0x3225
movl $0x1, %eax
movl %edx, %ecx
shll %cl, %eax
movq %rdx, %rcx
shrq $0x5, %rcx
orl %eax, (%rsi,%rcx,4)
movq %r14, %rdi
movq %r12, %rsi
xorl %eax, %eax
callq 0x21d0
movb (%r13,%rbp), %al
incq %r13
cmpq $0x6, %r13
jne 0x31f1
movl $0x3e, %edi
movq %r14, %rsi
callq 0x2260
leaq 0x6e6d(%rip), %rdi      # 0xa0c1
movl $0x7, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x2270
movq %r14, %rdi
callq 0x2030
movq %rax, %r12
subl %r15d, %r12d
leaq 0x6e4e(%rip), %rdi      # 0xa0c9
movl $0x11, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x2270
movq %r14, %rdi
callq 0x2030
movl %eax, 0x20(%rsp)
leaq 0x6dd4(%rip), %rsi      # 0xa074
movq %r14, %rdi
movl $0x5, %edx
xorl %eax, %eax
callq 0x21d0
leaq 0x801f(%rip), %rsi      # 0xb2d5
movq %r14, %rdi
movl %r12d, %edx
xorl %eax, %eax
callq 0x21d0
leaq 0x6ef8(%rip), %rdi      # 0xa1c2
movl $0x7, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x2270
movq 0x10(%rbx), %rax
movq (%rax), %rdi
movl $0x61, %esi
callq 0x4c58
movq 0x20(%rbx), %rdx
testq %rdx, %rdx
je 0x330f
testb $0x1, 0xc(%rbx)
je 0x330f
movzwl %ax, %esi
movl $0x1, %edi
movl %eax, %ecx
shll %cl, %edi
shrq $0x5, %rsi
orl %edi, (%rdx,%rsi,4)
movq %rbx, %rdi
callq 0x6972
testq %rax, %rax
je 0x379d
movq %rax, %r15
movq %rbx, %rdi
callq 0x702a
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x37bc
movq %r14, %rdi
callq 0x2030
movl %eax, 0x24(%rsp)
leaq 0x6d28(%rip), %rsi      # 0xa074
movq %r14, %rdi
movl $0x6, %edx
xorl %eax, %eax
callq 0x21d0
leaq 0x6d1c(%rip), %rsi      # 0xa07e
movq %r14, %rdi
movl $0x7, %edx
xorl %eax, %eax
callq 0x21d0
movq %rbx, %rdi
callq 0x6931
testq %rax, %rax
je 0x339a
movq %rbx, %rdi
callq 0x6931
leaq 0x6d58(%rip), %rsi      # 0xa0e5
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x21d0
movl 0x4(%rbx), %eax
cmpl $0x1, %eax
je 0x33c1
testl %eax, %eax
jne 0x33d7
leaq 0x6d48(%rip), %rdi      # 0xa0f5
movl $0x27, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x2270
jmp 0x33d7
leaq 0x6d55(%rip), %rsi      # 0xa11d
movq %r14, %rdi
movl $0x8, %edx
xorl %eax, %eax
callq 0x21d0
leaq 0x6cb5(%rip), %rdi      # 0xa093
movl $0xa, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x2270
movq %r14, %rdi
callq 0x2030
movq %rax, %r13
leaq 0x436(%rip), %rsi       # 0x3838
movq %rbx, %rdi
movq %r14, %rdx
callq 0x5045
movl %eax, %ebp
movq %r14, %rdi
callq 0x2030
movq %rax, %r12
subl %r13d, %r12d
leaq 0x6ca5(%rip), %rdi      # 0xa0c9
movl $0x11, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x2270
movq %r14, %rdi
callq 0x2030
movl %eax, 0x28(%rsp)
leaq 0x6c2b(%rip), %rsi      # 0xa074
movl $0x7, %r13d
movq %r14, %rdi
movl $0x7, %edx
xorl %eax, %eax
callq 0x21d0
leaq 0x7e70(%rip), %rsi      # 0xb2d5
movq %r14, %rdi
movl %r12d, %edx
xorl %eax, %eax
callq 0x21d0
leaq 0x6d49(%rip), %rdi      # 0xa1c2
movl $0x7, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x2270
cmpl $0x1, 0x4(%rbx)
jne 0x34e5
movq %r14, %rdi
callq 0x2030
movl %eax, 0x2c(%rsp)
leaq 0x6bd0(%rip), %rsi      # 0xa074
movl $0x8, %r13d
movq %r14, %rdi
movl $0x8, %edx
xorl %eax, %eax
callq 0x21d0
leaq 0x7e15(%rip), %rsi      # 0xb2d5
movq %r14, %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0x21d0
leaq 0x6cef(%rip), %rdi      # 0xa1c2
movl $0x7, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x2270
movq %r14, %rdi
callq 0x2030
leal 0x1(%r13), %r12d
movl %r13d, %ecx
movl %eax, 0x10(%rsp,%rcx,4)
leaq 0x6b75(%rip), %rsi      # 0xa074
movq %r14, %rdi
movl %r12d, %edx
xorl %eax, %eax
callq 0x21d0
movq %rbx, %rdi
movq %r15, %rsi
movl $0x6, %edx
callq 0x70ae
testq %rax, %rax
je 0x37db
movq %rax, %rbp
movq %rax, %rdi
movq %r14, %rsi
callq 0x2180
movq %rbp, %rdi
callq 0x21a0
leaq 0x6c80(%rip), %rdi      # 0xa1c2
movl $0x7, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x2270
movq %r14, %rdi
callq 0x2030
leal 0x2(%r13), %ebp
movl %r12d, %ecx
movl %eax, 0x10(%rsp,%rcx,4)
leaq 0x6b06(%rip), %rsi      # 0xa074
movq %r14, %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0x21d0
movq %rbx, %rdi
movq %r15, %rsi
movq 0x8(%rsp), %rdx
movl %r12d, %ecx
callq 0x755d
testq %rax, %rax
je 0x37fa
movq %rax, %r12
movq %rax, %rdi
movq %r14, %rsi
callq 0x2180
movq %r12, %rdi
callq 0x21a0
leaq 0x6c0f(%rip), %rdi      # 0xa1c2
movl $0x7, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x2270
testb $0x1, 0xc(%rbx)
jne 0x35d0
movl %ebp, %r13d
jmp 0x363b
movq %r14, %rdi
callq 0x2030
addl $0x3, %r13d
movl %ebp, %ecx
movl %eax, 0x10(%rsp,%rcx,4)
leaq 0x6a8b(%rip), %rsi      # 0xa074
movq %r14, %rdi
movl %r13d, %edx
xorl %eax, %eax
callq 0x21d0
movq (%r15), %rsi
movq %rbx, %rdi
movl %ebp, %edx
callq 0x7866
testq %rax, %rax
je 0x3819
movq %rax, %r12
movq %rax, %rdi
movq %r14, %rsi
callq 0x2180
movq %r12, %rdi
callq 0x21a0
leaq 0x6b99(%rip), %rdi      # 0xa1c2
movl $0x7, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x2270
movq %r15, %rdi
callq 0x21a0
movq 0x8(%rsp), %rdi
callq 0x21a0
movq %r14, %rdi
callq 0x2030
movl %eax, 0x18(%rsp)
leaq 0x6ad4(%rip), %rsi      # 0xa134
movq %r14, %rdi
movl %r13d, %edx
xorl %eax, %eax
callq 0x21d0
movq %r14, %rdi
callq 0x2030
movl %eax, 0x14(%rsp)
leaq 0x6b4a(%rip), %rdi      # 0xa1ca
movl $0x3a, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x2270
movq %r14, %rdi
callq 0x2030
movl %eax, 0x10(%rsp)
leaq 0x6b60(%rip), %rdi      # 0xa205
movl $0x31, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x2270
movq %r14, %rdi
callq 0x2030
movq %rax, 0x8(%rsp)
leal 0x1(%r13), %ebp
leaq 0x6b68(%rip), %rsi      # 0xa237
movq %r14, %rdi
movl %ebp, %edx
xorl %ecx, %ecx
xorl %eax, %eax
callq 0x21d0
movl %r13d, %r13d
leaq 0x6b6a(%rip), %r12      # 0xa251
xorl %r15d, %r15d
movl 0x10(%rsp,%r15,4), %edx
movq %r14, %rdi
movq %r12, %rsi
xorl %eax, %eax
callq 0x21d0
incq %r15
cmpq %r15, %r13
jne 0x36ea
leaq 0x6b56(%rip), %rsi      # 0xa261
movq %r14, %rdi
movl %ebp, %edx
movq 0x8(%rsp), %rcx
xorl %eax, %eax
callq 0x21d0
movq %r14, %rdi
callq 0x2130
movq %rbx, %rdi
callq 0x501a
xorl %eax, %eax
addq $0x1a8, %rsp            # imm = 0x1A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x68f1(%rip), %rdi      # 0xa038
leaq 0x68ee(%rip), %rsi      # 0xa03c
leaq 0x68f2(%rip), %rcx      # 0xa047
movl $0x52, %edx
callq 0x20e0
leaq 0x68ff(%rip), %rdi      # 0xa065
leaq 0x68cf(%rip), %rsi      # 0xa03c
leaq 0x68d3(%rip), %rcx      # 0xa047
movl $0x5a, %edx
callq 0x20e0
leaq 0x6b4f(%rip), %rdi      # 0xa2d4
leaq 0x68b0(%rip), %rsi      # 0xa03c
leaq 0x6b0b(%rip), %rcx      # 0xa29e
movl $0x36, %edx
callq 0x20e0
leaq 0x6937(%rip), %rdi      # 0xa0db
leaq 0x6891(%rip), %rsi      # 0xa03c
leaq 0x6895(%rip), %rcx      # 0xa047
movl $0x6d, %edx
callq 0x20e0
leaq 0x691d(%rip), %rdi      # 0xa0e0
leaq 0x6872(%rip), %rsi      # 0xa03c
leaq 0x6876(%rip), %rcx      # 0xa047
movl $0x6f, %edx
callq 0x20e0
leaq 0x694e(%rip), %rdi      # 0xa130
leaq 0x6853(%rip), %rsi      # 0xa03c
leaq 0x6857(%rip), %rcx      # 0xa047
movl $0x8a, %edx
callq 0x20e0
leaq 0x692f(%rip), %rdi      # 0xa130
leaq 0x6834(%rip), %rsi      # 0xa03c
leaq 0x6838(%rip), %rcx      # 0xa047
movl $0x92, %edx
callq 0x20e0
leaq 0x6910(%rip), %rdi      # 0xa130
leaq 0x6815(%rip), %rsi      # 0xa03c
leaq 0x6819(%rip), %rcx      # 0xa047
movl $0x9b, %edx
callq 0x20e0