// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x220, %rsp            # imm = 0x220
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq 0xbc64(%rip), %rax      # 0xe004
movq %rax, -0x18(%rbp)
cmpl $0x2, -0x8(%rbp)
jne 0x23b6
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
callq 0x3d90
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x23cc
jmp 0x23eb
leaq 0xbc65(%rip), %rdi      # 0xe038
leaq 0xbc62(%rip), %rsi      # 0xe03c
movl $0x52, %edx
leaq 0xbc61(%rip), %rcx      # 0xe047
callq 0x2100
movq -0x20(%rbp), %rdi
callq 0xa1c0
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
movl $0x2, %esi
movl $0x8008, %edx           # imm = 0x8008
callq 0x5910
movq %rax, -0x30(%rbp)
leaq 0xbc48(%rip), %rdi      # 0xe05e
leaq 0xbc4a(%rip), %rsi      # 0xe067
callq 0x21a0
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x242f
jmp 0x244e
leaq 0xbc2f(%rip), %rdi      # 0xe065
leaq 0xbbff(%rip), %rsi      # 0xe03c
movl $0x5a, %edx
leaq 0xbbfe(%rip), %rcx      # 0xe047
callq 0x2100
movl $0x3, -0x1d4(%rbp)
movq -0x38(%rbp), %rdi
leaq 0xbc06(%rip), %rsi      # 0xe069
movb $0x0, %al
callq 0x21e0
movq -0x38(%rbp), %rdi
callq 0x2030
movl %eax, %ecx
movl -0x1d4(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x1d4(%rbp)
cltq
movl %ecx, -0x1d0(%rbp,%rax,4)
movq -0x38(%rbp), %rdi
movl -0x1d4(%rbp), %edx
leaq 0xbbd4(%rip), %rsi      # 0xe074
movb $0x0, %al
callq 0x21e0
movq -0x38(%rbp), %rdi
movl -0x1d4(%rbp), %edx
addl $0x1, %edx
leaq 0xbbc3(%rip), %rsi      # 0xe07e
movb $0x0, %al
callq 0x21e0
movq -0x38(%rbp), %rdi
leaq 0xbbc6(%rip), %rsi      # 0xe093
movb $0x0, %al
callq 0x21e0
movq -0x38(%rbp), %rdi
callq 0x2030
movq %rax, %rcx
xorl %eax, %eax
subq %rcx, %rax
movl %eax, -0x1d8(%rbp)
movq -0x38(%rbp), %rdi
leaq 0xbba8(%rip), %rsi      # 0xe09e
movb $0x0, %al
callq 0x21e0
movq -0x38(%rbp), %rdi
movq -0x30(%rbp), %rsi
leaq 0xbbaf(%rip), %rdx      # 0xe0bb
callq 0x2c00
movq -0x38(%rbp), %rdi
leaq 0xbba5(%rip), %rsi      # 0xe0c1
movb $0x0, %al
callq 0x21e0
movq -0x38(%rbp), %rdi
callq 0x2030
movq %rax, %rcx
movslq -0x1d8(%rbp), %rax
addq %rcx, %rax
movl %eax, -0x1d8(%rbp)
movq -0x38(%rbp), %rdi
leaq 0xbb7f(%rip), %rsi      # 0xe0c9
movb $0x0, %al
callq 0x21e0
movq -0x38(%rbp), %rdi
callq 0x2030
movl %eax, %ecx
movl -0x1d4(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x1d4(%rbp)
cltq
movl %ecx, -0x1d0(%rbp,%rax,4)
movq -0x38(%rbp), %rdi
movl -0x1d4(%rbp), %edx
leaq 0xbaed(%rip), %rsi      # 0xe074
movb $0x0, %al
callq 0x21e0
movq -0x38(%rbp), %rdi
movl -0x1d8(%rbp), %edx
leaq 0xcd7e(%rip), %rsi      # 0xf31d
movb $0x0, %al
callq 0x21e0
movq -0x38(%rbp), %rdi
leaq 0xbc11(%rip), %rsi      # 0xe1c2
movb $0x0, %al
callq 0x21e0
movq -0x30(%rbp), %rdi
movl $0x61, %esi
callq 0x2d50
movq -0x30(%rbp), %rdi
callq 0x83a0
movq %rax, -0x1e0(%rbp)
cmpq $0x0, -0x1e0(%rbp)
je 0x25e2
jmp 0x2601
leaq 0xbaf2(%rip), %rdi      # 0xe0db
leaq 0xba4c(%rip), %rsi      # 0xe03c
movl $0x6d, %edx
leaq 0xba4b(%rip), %rcx      # 0xe047
callq 0x2100
movq -0x30(%rbp), %rdi
callq 0x8e30
movq %rax, -0x1e8(%rbp)
cmpq $0x0, -0x1e8(%rbp)
je 0x261d
jmp 0x263c
leaq 0xbabc(%rip), %rdi      # 0xe0e0
leaq 0xba11(%rip), %rsi      # 0xe03c
movl $0x6f, %edx
leaq 0xba10(%rip), %rcx      # 0xe047
callq 0x2100
movq -0x38(%rbp), %rdi
callq 0x2030
movl %eax, %ecx
movl -0x1d4(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x1d4(%rbp)
cltq
movl %ecx, -0x1d0(%rbp,%rax,4)
movq -0x38(%rbp), %rdi
movl -0x1d4(%rbp), %edx
leaq 0xba02(%rip), %rsi      # 0xe074
movb $0x0, %al
callq 0x21e0
movq -0x38(%rbp), %rdi
movl -0x1d4(%rbp), %edx
addl $0x1, %edx
leaq 0xb9f1(%rip), %rsi      # 0xe07e
movb $0x0, %al
callq 0x21e0
movl -0x1d4(%rbp), %eax
movl %eax, -0x1ec(%rbp)
movq -0x30(%rbp), %rdi
callq 0x8330
cmpq $0x0, %rax
je 0x26db
movq -0x38(%rbp), %rax
movq %rax, -0x218(%rbp)
movq -0x30(%rbp), %rdi
callq 0x8330
movq -0x218(%rbp), %rdi
movq %rax, %rdx
leaq 0xba11(%rip), %rsi      # 0xe0e5
movb $0x0, %al
callq 0x21e0
movq -0x30(%rbp), %rax
cmpl $0x0, 0x4(%rax)
jne 0x26f9
movq -0x38(%rbp), %rdi
leaq 0xba05(%rip), %rsi      # 0xe0f5
movb $0x0, %al
callq 0x21e0
jmp 0x2720
movq -0x30(%rbp), %rax
cmpl $0x1, 0x4(%rax)
jne 0x271e
movq -0x38(%rbp), %rdi
movl -0x1d4(%rbp), %edx
addl $0x2, %edx
leaq 0xba06(%rip), %rsi      # 0xe11d
movb $0x0, %al
callq 0x21e0
jmp 0x2720
movq -0x38(%rbp), %rdi
leaq 0xb968(%rip), %rsi      # 0xe093
movb $0x0, %al
callq 0x21e0
movq -0x38(%rbp), %rdi
callq 0x2030
movq %rax, %rcx
xorl %eax, %eax
subq %rcx, %rax
movl %eax, -0x1d8(%rbp)
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rdx
leaq 0x638(%rip), %rsi       # 0x2d90
callq 0x5df0
movl %eax, -0x1f0(%rbp)
movq -0x38(%rbp), %rdi
callq 0x2030
movq %rax, %rcx
movslq -0x1d8(%rbp), %rax
addq %rcx, %rax
movl %eax, -0x1d8(%rbp)
movq -0x38(%rbp), %rdi
leaq 0xb93f(%rip), %rsi      # 0xe0c9
movb $0x0, %al
callq 0x21e0
movq -0x38(%rbp), %rdi
callq 0x2030
movl %eax, %ecx
movl -0x1d4(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x1d4(%rbp)
cltq
movl %ecx, -0x1d0(%rbp,%rax,4)
movq -0x38(%rbp), %rdi
movl -0x1d4(%rbp), %edx
leaq 0xb8ad(%rip), %rsi      # 0xe074
movb $0x0, %al
callq 0x21e0
movq -0x38(%rbp), %rdi
movl -0x1d8(%rbp), %edx
leaq 0xcb3e(%rip), %rsi      # 0xf31d
movb $0x0, %al
callq 0x21e0
movq -0x38(%rbp), %rdi
leaq 0xb9d1(%rip), %rsi      # 0xe1c2
movb $0x0, %al
callq 0x21e0
movq -0x30(%rbp), %rax
cmpl $0x1, 0x4(%rax)
jne 0x2869
movq -0x38(%rbp), %rdi
callq 0x2030
movl %eax, %ecx
movl -0x1d4(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x1d4(%rbp)
cltq
movl %ecx, -0x1d0(%rbp,%rax,4)
movq -0x38(%rbp), %rdi
movl -0x1d4(%rbp), %edx
leaq 0xb83c(%rip), %rsi      # 0xe074
movb $0x0, %al
callq 0x21e0
movq -0x38(%rbp), %rdi
movl -0x1f0(%rbp), %edx
leaq 0xcacd(%rip), %rsi      # 0xf31d
movb $0x0, %al
callq 0x21e0
movq -0x38(%rbp), %rdi
leaq 0xb960(%rip), %rsi      # 0xe1c2
movb $0x0, %al
callq 0x21e0
movq -0x38(%rbp), %rdi
callq 0x2030
movl %eax, %ecx
movl -0x1d4(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x1d4(%rbp)
cltq
movl %ecx, -0x1d0(%rbp,%rax,4)
movq -0x38(%rbp), %rdi
movl -0x1d4(%rbp), %edx
leaq 0xb7d5(%rip), %rsi      # 0xe074
movb $0x0, %al
callq 0x21e0
movl -0x1d4(%rbp), %eax
movl %eax, -0x1f4(%rbp)
movq -0x30(%rbp), %rdi
movq -0x1e0(%rbp), %rsi
movl -0x1ec(%rbp), %edx
callq 0x8f50
movq %rax, -0x200(%rbp)
cmpq $0x0, -0x200(%rbp)
je 0x28db
jmp 0x28fa
leaq 0xb84e(%rip), %rdi      # 0xe130
leaq 0xb753(%rip), %rsi      # 0xe03c
movl $0x8a, %edx
leaq 0xb752(%rip), %rcx      # 0xe047
callq 0x2100
movq -0x200(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x2190
movq -0x200(%rbp), %rdi
callq 0x21b0
movq -0x38(%rbp), %rdi
leaq 0xb8a1(%rip), %rsi      # 0xe1c2
movb $0x0, %al
callq 0x21e0
movq -0x38(%rbp), %rdi
callq 0x2030
movl %eax, %ecx
movl -0x1d4(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x1d4(%rbp)
cltq
movl %ecx, -0x1d0(%rbp,%rax,4)
movq -0x38(%rbp), %rdi
movl -0x1d4(%rbp), %edx
leaq 0xb716(%rip), %rsi      # 0xe074
movb $0x0, %al
callq 0x21e0
movl -0x1d4(%rbp), %eax
movl %eax, -0x204(%rbp)
movq -0x30(%rbp), %rdi
movq -0x1e0(%rbp), %rsi
movq -0x1e8(%rbp), %rdx
movl -0x1f4(%rbp), %ecx
callq 0x9600
movq %rax, -0x200(%rbp)
cmpq $0x0, -0x200(%rbp)
je 0x29a1
jmp 0x29c0
leaq 0xb788(%rip), %rdi      # 0xe130
leaq 0xb68d(%rip), %rsi      # 0xe03c
movl $0x92, %edx
leaq 0xb68c(%rip), %rcx      # 0xe047
callq 0x2100
movq -0x200(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x2190
movq -0x200(%rbp), %rdi
callq 0x21b0
movq -0x38(%rbp), %rdi
leaq 0xb7db(%rip), %rsi      # 0xe1c2
movb $0x0, %al
callq 0x21e0
movq -0x30(%rbp), %rax
movl 0xc(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x2ac3
movq -0x38(%rbp), %rdi
callq 0x2030
movl %eax, %ecx
movl -0x1d4(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x1d4(%rbp)
cltq
movl %ecx, -0x1d0(%rbp,%rax,4)
movq -0x38(%rbp), %rdi
movl -0x1d4(%rbp), %edx
leaq 0xb63d(%rip), %rsi      # 0xe074
movb $0x0, %al
callq 0x21e0
movq -0x30(%rbp), %rdi
movq -0x1e0(%rbp), %rax
movq (%rax), %rsi
movl -0x204(%rbp), %edx
callq 0x99d0
movq %rax, -0x200(%rbp)
movl -0x1d4(%rbp), %eax
movl %eax, -0x204(%rbp)
cmpq $0x0, -0x200(%rbp)
je 0x2a76
jmp 0x2a95
leaq 0xb6b3(%rip), %rdi      # 0xe130
leaq 0xb5b8(%rip), %rsi      # 0xe03c
movl $0x9b, %edx
leaq 0xb5b7(%rip), %rcx      # 0xe047
callq 0x2100
movq -0x200(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x2190
movq -0x200(%rbp), %rdi
callq 0x21b0
movq -0x38(%rbp), %rdi
leaq 0xb706(%rip), %rsi      # 0xe1c2
movb $0x0, %al
callq 0x21e0
movq -0x1e0(%rbp), %rdi
callq 0x21b0
movq -0x1e8(%rbp), %rdi
callq 0x21b0
movq -0x38(%rbp), %rdi
callq 0x2030
movl %eax, -0x1c8(%rbp)
movq -0x38(%rbp), %rdi
movl -0x204(%rbp), %edx
leaq 0xb639(%rip), %rsi      # 0xe134
movb $0x0, %al
callq 0x21e0
movq -0x38(%rbp), %rdi
callq 0x2030
movl %eax, -0x1cc(%rbp)
movq -0x38(%rbp), %rdi
leaq 0xb6ae(%rip), %rsi      # 0xe1ca
movb $0x0, %al
callq 0x21e0
movq -0x38(%rbp), %rdi
callq 0x2030
movl %eax, -0x1d0(%rbp)
movq -0x38(%rbp), %rdi
leaq 0xb6c8(%rip), %rsi      # 0xe205
movb $0x0, %al
callq 0x21e0
movq -0x38(%rbp), %rdi
callq 0x2030
movl %eax, -0x20c(%rbp)
movq -0x38(%rbp), %rdi
movl -0x1d4(%rbp), %edx
addl $0x1, %edx
leaq 0xb6d0(%rip), %rsi      # 0xe237
xorl %ecx, %ecx
movb $0x0, %al
callq 0x21e0
movl $0x0, -0x208(%rbp)
movl -0x208(%rbp), %eax
cmpl -0x1d4(%rbp), %eax
jge 0x2bb9
movq -0x38(%rbp), %rdi
movslq -0x208(%rbp), %rax
movl -0x1d0(%rbp,%rax,4), %edx
leaq 0xb6b0(%rip), %rsi      # 0xe251
movb $0x0, %al
callq 0x21e0
movl -0x208(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x208(%rbp)
jmp 0x2b7a
movq -0x38(%rbp), %rdi
movl -0x1d4(%rbp), %edx
addl $0x1, %edx
movl -0x20c(%rbp), %ecx
leaq 0xb68e(%rip), %rsi      # 0xe261
movb $0x0, %al
callq 0x21e0
movq -0x38(%rbp), %rdi
callq 0x2150
movq -0x30(%rbp), %rdi
callq 0x5d70
xorl %eax, %eax
addq $0x220, %rsp            # imm = 0x220
popq %rbp
retq
nopw (%rax,%rax)