// File: /workspace/github_c_makefile_star2_O1/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 0x77a2
movq %rsi, %r14
testq %rsi, %rsi
je 0x77c1
movq %rdx, %rbx
testq %rdx, %rdx
je 0x77e0
movl %ecx, %ebp
movq %rdi, %r15
leaq 0x8(%rsp), %rdi
movl $0x1f4, %esi            # imm = 0x1F4
callq 0x7a74
cmpl $-0x1, %eax
je 0x765d
movl 0x4(%r15), %eax
movl 0xc(%r15), %ecx
andl $0x1, %ecx
shlq $0x4, %rax
leaq 0x7721(%rip), %rdx      # 0xece0
addq %rax, %rdx
movq (%rdx,%rcx,8), %r12
movq (%r14), %rdi
callq 0x7459
leaq 0x3dad(%rip), %rsi      # 0xb382
leaq 0x7dd4(%rip), %rcx      # 0xf3b0
leaq 0x8(%rsp), %rdi
movq %r12, %rdx
movl %ebp, %r8d
xorl %eax, %eax
callq 0x7c95
testb $0x1, 0xc(%r15)
jne 0x7664
cmpq $0x0, 0x8(%rbx)
je 0x7828
movl (%rbx), %edx
movl 0x4(%rbx), %ecx
leaq 0x3e4a(%rip), %rsi      # 0xb456
leaq 0x8(%rsp), %rdi
xorl %eax, %eax
callq 0x7c95
movl (%rbx), %r12d
cmpl 0x4(%rbx), %r12d
jg 0x7760
decl %r12d
leaq 0x3e10(%rip), %r14      # 0xb43f
leaq 0x8(%rsp), %r15
xorl %r13d, %r13d
movq 0x8(%rbx), %rax
movl (%rax,%r13,4), %edx
movq %r15, %rdi
movq %r14, %rsi
xorl %eax, %eax
callq 0x7c95
incq %r13
leal (%r12,%r13), %eax
cmpl 0x4(%rbx), %eax
jl 0x7637
jmp 0x7760
xorl %eax, %eax
jmp 0x7793
cmpq $0x0, 0x18(%rbx)
je 0x7847
movq 0x40(%r14), %rdx
movq 0x48(%r14), %rcx
movl 0x50(%r14), %r8d
movl 0x10(%rbx), %r9d
leaq 0x3d50(%rip), %rsi      # 0xb3d6
leaq 0x8(%rsp), %rdi
xorl %eax, %eax
callq 0x7c95
movq 0x18(%rbx), %rax
cmpl $0x0, (%rax)
je 0x7773
leaq 0x3d8c(%rip), %rsi      # 0xb432
leaq 0x8(%rsp), %rdi
xorl %eax, %eax
callq 0x7c95
movq 0x18(%rbx), %rax
movl (%rax), %r12d
testl %r12d, %r12d
je 0x7760
leaq 0x8(%rsp), %r15
leaq 0x3d71(%rip), %r13      # 0xb43f
leaq 0x2fa1(%rip), %rbp      # 0xa676
xorl %r14d, %r14d
movl 0x4(%rax), %edx
testl %r12d, %r12d
js 0x772b
movq %r15, %rdi
leaq 0x3d59(%rip), %rsi      # 0xb443
xorl %eax, %eax
callq 0x7c95
addl $0x2, %r14d
movslq %r14d, %r14
incl %r12d
movq 0x18(%rbx), %rax
movl (%rax,%r14,4), %edx
incq %r14
movq %r15, %rdi
movq %r13, %rsi
xorl %eax, %eax
callq 0x7c95
decl %r12d
cmpl $0x1, %r12d
jg 0x76fb
movq %r15, %rdi
movq %rbp, %rsi
xorl %eax, %eax
callq 0x7c95
jmp 0x7749
movl %edx, %ecx
subl %r12d, %ecx
movl 0x8(%rax), %r8d
movq %r15, %rdi
leaq 0x3cfb(%rip), %rsi      # 0xb439
xorl %eax, %eax
callq 0x7c95
addl $0x3, %r14d
movq 0x18(%rbx), %rax
movslq %r14d, %rcx
leaq (%rax,%rcx,4), %rax
movl (%rax), %r12d
testl %r12d, %r12d
jne 0x76d8
leaq 0x3dea(%rip), %rsi      # 0xb551
leaq 0x8(%rsp), %rdi
xorl %eax, %eax
callq 0x7c95
leaq 0x3bac(%rip), %rsi      # 0xb326
leaq 0x8(%rsp), %rbx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x7c95
cmpl $-0x1, (%rbx)
je 0x77ff
movq 0x10(%rsp), %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2b2b(%rip), %rdi      # 0xa2d4
leaq 0x3878(%rip), %rsi      # 0xb028
leaq 0x3b73(%rip), %rcx      # 0xb32a
movl $0x1bd, %edx            # imm = 0x1BD
callq 0x20e0
leaq 0x2913(%rip), %rdi      # 0xa0db
leaq 0x3859(%rip), %rsi      # 0xb028
leaq 0x3b54(%rip), %rcx      # 0xb32a
movl $0x1be, %edx            # imm = 0x1BE
callq 0x20e0
leaq 0x28f9(%rip), %rdi      # 0xa0e0
leaq 0x383a(%rip), %rsi      # 0xb028
leaq 0x3b35(%rip), %rcx      # 0xb32a
movl $0x1bf, %edx            # imm = 0x1BF
callq 0x20e0
leaq 0x8(%rsp), %rdi
callq 0x7ae4
leaq 0x34b0(%rip), %rdi      # 0xacc0
leaq 0x3811(%rip), %rsi      # 0xb028
leaq 0x3b0c(%rip), %rcx      # 0xb32a
movl $0x204, %edx            # imm = 0x204
callq 0x20e0
leaq 0x3c1a(%rip), %rdi      # 0xb449
leaq 0x37f2(%rip), %rsi      # 0xb028
leaq 0x3aed(%rip), %rcx      # 0xb32a
movl $0x1f3, %edx            # imm = 0x1F3
callq 0x20e0
leaq 0x3b7b(%rip), %rdi      # 0xb3c9
leaq 0x37d3(%rip), %rsi      # 0xb028
leaq 0x3ace(%rip), %rcx      # 0xb32a
movl $0x1d1, %edx            # imm = 0x1D1
callq 0x20e0