// File: /workspace/github_c_makefile_star2_O2/smilingthax[P]libfontembed/embed_pdf.c
// Function: emb_pdf_simple_font
char *emb_pdf_simple_font(EMB_PARAMS *emb,EMB_PDF_FONTDESCR *fdes,EMB_PDF_FONTWIDTHS *fwid,int fontdescr_obj_ref) // {{{ - to be freed by user
{
  assert(emb);
  assert(fdes);
  assert(fwid);

  int iA,iB;
  DYN_STRING ret;

  if (dyn_init(&ret,500)==-1) {
    return NULL;
  }

  dyn_printf(&ret,"<</Type /Font\n"
                  "  /Subtype /%s\n"
                  "  /BaseFont /%s\n"
                  "  /FontDescriptor %d 0 R\n",
                  emb_pdf_get_font_subtype(emb),
                  emb_pdf_escape_name(fdes->fontname,-1),
                  fontdescr_obj_ref);

  if (emb->plan&EMB_A_MULTIBYTE) { // multibyte
    assert(fwid->warray);
    dyn_printf(&ret,"  /CIDSystemInfo <<\n"
                    "    /Registry (%s)\n"
                    "    /Ordering (%s)\n"
                    "    /Supplement %d\n"
                    "  >>\n"
                    "  /DW %d\n",
//                    "  /CIDToGIDMap /Id...\n" // TrueType only, default /Identity  [optional?  which PDF version says what?]
                    fdes->registry,
                    fdes->ordering,
                    fdes->supplement,
                    fwid->default_width);

    if (fwid->warray[0]) {
      dyn_printf(&ret,"  /W [");
      for (iA=0;fwid->warray[iA];) {
        if (fwid->warray[iA]<0) { // c1 (c1-len) w
          dyn_printf(&ret," %d %d %d",
                          fwid->warray[iA+1],
                          fwid->warray[iA+1]-fwid->warray[iA],
                          fwid->warray[iA+2]);
          iA+=3;
        } else { // c [w ... w]
          iB=fwid->warray[iA++]; // len
          dyn_printf(&ret," %d [",fwid->warray[iA++]); // c
          for (;iB>0;iB--) {
            dyn_printf(&ret," %d",fwid->warray[iA++]);
          }
          dyn_printf(&ret,"]");
        }
      }
      dyn_printf(&ret,"]\n");
    }
  } else { // "not std14"
    assert(fwid->widths);
    dyn_printf(&ret,
                    "  /Encoding /MacRomanEncoding\n"  // optional; TODO!!!!!
//                    "  /ToUnicode ?\n"  // optional
                    "  /FirstChar %d\n"
                    "  /LastChar %d\n"
                    "  /Widths [",
                    fwid->first,
                    fwid->last);
    for (iA=0,iB=fwid->first;iB<=fwid->last;iA++,iB++) {
      dyn_printf(&ret," %d",fwid->widths[iA]);
    }
    dyn_printf(&ret,"]\n");
  }
  dyn_printf(&ret,">>\n");
  if (ret.len==-1) {
    dyn_free(&ret);
    assert(0);
    return NULL;
  }

  return ret.buf;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
testq %rdi, %rdi
je 0x6ebb
movq %rsi, %r14
testq %rsi, %rsi
je 0x6eda
movq %rdx, %rbx
testq %rdx, %rdx
je 0x6ef9
movl %ecx, %ebp
movq %rdi, %r15
leaq 0x8(%rsp), %rdi
movl $0x1f4, %esi            # imm = 0x1F4
callq 0x71e0
cmpl $-0x1, %eax
je 0x6d8a
movl 0x4(%r15), %eax
movl 0xc(%r15), %ecx
andl $0x1, %ecx
shlq $0x4, %rax
leaq 0x7fe6(%rip), %rdx      # 0xece0
addq %rax, %rdx
movq (%rdx,%rcx,8), %r12
movq (%r14), %rdi
callq 0x6b9b
leaq 0x4672(%rip), %rsi      # 0xb382
leaq 0x86a9(%rip), %rcx      # 0xf3c0
leaq 0x8(%rsp), %rdi
movq %r12, %rdx
movl %ebp, %r8d
xorl %eax, %eax
callq 0x745d
testb $0x1, 0xc(%r15)
jne 0x6d91
cmpq $0x0, 0x8(%rbx)
je 0x6f41
movl (%rbx), %edx
movl 0x4(%rbx), %ecx
leaq 0x470f(%rip), %rsi      # 0xb456
leaq 0x8(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x745d
movl (%rbx), %r12d
leaq 0x46df(%rip), %r15      # 0xb43f
xorl %r13d, %r13d
leal (%r12,%r13), %eax
cmpl 0x4(%rbx), %eax
jg 0x6e79
movq 0x8(%rbx), %rax
movl (%rax,%r13,4), %edx
movq %r14, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x745d
incq %r13
jmp 0x6d63
xorl %eax, %eax
jmp 0x6eac
cmpq $0x0, 0x18(%rbx)
je 0x6f60
movq 0x40(%r14), %rdx
movq 0x48(%r14), %rcx
movl 0x50(%r14), %r8d
movl 0x10(%rbx), %r9d
leaq 0x4623(%rip), %rsi      # 0xb3d6
leaq 0x8(%rsp), %rdi
xorl %eax, %eax
callq 0x745d
movq 0x18(%rbx), %rax
cmpl $0x0, (%rax)
je 0x6e8c
leaq 0x465f(%rip), %rsi      # 0xb432
leaq 0x8(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x745d
leaq 0x4656(%rip), %r13      # 0xb43f
xorl %r15d, %r15d
movq 0x18(%rbx), %rax
movslq %r15d, %r15
movl (%rax,%r15,4), %r12d
testl %r12d, %r12d
je 0x6e79
js 0x6e50
leal 0x2(%r15), %ebp
movl 0x4(%rax,%r15,4), %edx
movq %r14, %rdi
leaq 0x4632(%rip), %rsi      # 0xb443
xorl %eax, %eax
callq 0x745d
movslq %ebp, %r15
testl %r12d, %r12d
jle 0x6e3d
movq 0x18(%rbx), %rax
movl (%rax,%r15,4), %edx
incq %r15
movq %r14, %rdi
movq %r13, %rsi
xorl %eax, %eax
callq 0x745d
decl %r12d
jmp 0x6e1b
movq %r14, %rdi
leaq 0x382f(%rip), %rsi      # 0xa676
xorl %eax, %eax
callq 0x745d
jmp 0x6dec
movl 0x4(%rax,%r15,4), %edx
movl 0x8(%rax,%r15,4), %r8d
movl %edx, %ecx
subl %r12d, %ecx
movq %r14, %rdi
leaq 0x45d0(%rip), %rsi      # 0xb439
xorl %eax, %eax
callq 0x745d
addl $0x3, %r15d
jmp 0x6dec
leaq 0x46d1(%rip), %rsi      # 0xb551
leaq 0x8(%rsp), %rdi
xorl %eax, %eax
callq 0x745d
leaq 0x4493(%rip), %rsi      # 0xb326
leaq 0x8(%rsp), %rbx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x745d
cmpl $-0x1, (%rbx)
je 0x6f18
movq 0x10(%rsp), %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3412(%rip), %rdi      # 0xa2d4
leaq 0x415f(%rip), %rsi      # 0xb028
leaq 0x445a(%rip), %rcx      # 0xb32a
movl $0x1bd, %edx            # imm = 0x1BD
callq 0x20f0
leaq 0x31fa(%rip), %rdi      # 0xa0db
leaq 0x4140(%rip), %rsi      # 0xb028
leaq 0x443b(%rip), %rcx      # 0xb32a
movl $0x1be, %edx            # imm = 0x1BE
callq 0x20f0
leaq 0x31e0(%rip), %rdi      # 0xa0e0
leaq 0x4121(%rip), %rsi      # 0xb028
leaq 0x441c(%rip), %rcx      # 0xb32a
movl $0x1bf, %edx            # imm = 0x1BF
callq 0x20f0
leaq 0x8(%rsp), %rdi
callq 0x7283
leaq 0x3d97(%rip), %rdi      # 0xacc0
leaq 0x40f8(%rip), %rsi      # 0xb028
leaq 0x43f3(%rip), %rcx      # 0xb32a
movl $0x204, %edx            # imm = 0x204
callq 0x20f0
leaq 0x4501(%rip), %rdi      # 0xb449
leaq 0x40d9(%rip), %rsi      # 0xb028
leaq 0x43d4(%rip), %rcx      # 0xb32a
movl $0x1f3, %edx            # imm = 0x1F3
callq 0x20f0
leaq 0x4462(%rip), %rdi      # 0xb3c9
leaq 0x40ba(%rip), %rsi      # 0xb028
leaq 0x43b5(%rip), %rcx      # 0xb32a
movl $0x1d1, %edx            # imm = 0x1D1
callq 0x20f0