// File: /workspace/github_c_makefile_star2_O1/smilingthax[P]libfontembed/embed.c
// Function: emb_embed
int emb_embed(EMB_PARAMS *emb,OUTPUT_FN output,void *context) // {{{
{
  assert(emb);

  if (emb->dest==EMB_DEST_NATIVE) {
  } else if (emb->dest<=EMB_DEST_PS) {
    int ret=-2;
    const char *fontname=emb_otf_get_fontname(emb->font->sfnt); // TODO!!
    (*output)("%%BeginFont: ",13,context);
    (*output)(fontname,strlen(fontname),context);
    (*output)("\n",1,context);
    if (emb->outtype==EMB_FMT_T1) {
    } else if (emb->outtype==EMB_FMT_TTF) { // emb->outtype==EMB_OUTPUT_OTF  is stupid (?)
      // do Type42
      ret=emb_otf_ps(emb->font->sfnt,NULL,256,NULL,output,context); // TODO?
    } else if (emb->outtype==EMB_FMT_CFF) {
    } else if (emb->outtype==EMB_FMT_STDFONT) {
    }
    if (ret!=-2) {
      if (ret!=-1) {
        (*output)("%%EndFont\n",10,context);
      } else {
        fprintf(stderr,"Failed\n");
      }
      return ret;
    }
  } else if (emb->dest<=EMB_DEST_PDF16) {
    if (emb->outtype==EMB_FMT_TTF) {
      assert(emb->font->sfnt);
      if (emb->plan&EMB_A_SUBSET) {
        return otf_subset(emb->font->sfnt,emb->subset,output,context);
      } else if (emb->font->sfnt->numTTC) { // simply copy the currently loaded numTTC
        return otf_ttc_extract(emb->font->sfnt,output,context);
      } else { // copy verbatim
        return copy_otf(emb->font->sfnt,output,context);
      }
    } else if (emb->outtype==EMB_FMT_OTF) {
      if (emb->plan&EMB_A_CFF_TO_OTF) {
        if (emb->plan&EMB_A_T1_TO_CFF) {
          // TODO
        } else {
          // assert(emb->font->cff);
          // TODO
        }
      } else {
        assert(emb->font->sfnt);
        if (emb->plan&EMB_A_SUBSET) {
          return otf_subset_cff(emb->font->sfnt,emb->subset,output,context);
        } else {
          return copy_otf(emb->font->sfnt,output,context);
        }
      }
    } else if (emb->outtype==EMB_FMT_CFF) {
      if (emb->plan&EMB_A_OTF_TO_CFF) {
        assert(emb->font->sfnt);
        if (emb->plan&EMB_A_SUBSET) {
          // TODO
        } else {
          return otf_cff_extract(emb->font->sfnt,output,context);
        }
      } else {
        // TODO
      }
    }
  }

  fprintf(stderr,"NOT IMPLEMENTED\n");
  assert(0);
  return -1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1008, %rsp           # imm = 0x1008
testq %rdi, %rdi
je 0x5318
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
movl 0x8(%rdi), %eax
cmpl $0x1, %eax
je 0x50e1
testl %eax, %eax
je 0x5313
cmpl $0x2, %eax
ja 0x5313
movl 0x4(%r15), %eax
cmpl $0x3, %eax
je 0x5212
cmpl $0x2, %eax
je 0x5191
cmpl $0x1, %eax
jne 0x5313
movq 0x10(%r15), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x5337
testb $0x2, 0xc(%r15)
jne 0x5252
cmpl $0x0, 0xc(%rdi)
je 0x5292
movq %r14, %rsi
movq %rbx, %rdx
addq $0x1008, %rsp           # imm = 0x1008
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x80af
movq 0x10(%r15), %rax
movq (%rax), %rdi
callq 0x54e0
movq %rax, %r12
leaq 0x58b7(%rip), %rdi      # 0xa9ae
movl $0xd, %esi
movq %rbx, %rdx
callq *%r14
movq %r12, %rdi
callq 0x2090
movq %r12, %rdi
movl %eax, %esi
movq %rbx, %rdx
callq *%r14
leaq 0x542a(%rip), %rdi      # 0xa546
movl $0x1, %esi
movq %rbx, %rdx
callq *%r14
movl $0xfffffffe, %ebp       # imm = 0xFFFFFFFE
cmpl $0x1, 0x4(%r15)
jne 0x5150
movq 0x10(%r15), %rax
movq (%rax), %rdi
xorl %esi, %esi
movl $0x100, %edx            # imm = 0x100
xorl %ecx, %ecx
movq %r14, %r8
movq %rbx, %r9
callq 0x5eb7
movl %eax, %ebp
cmpl $-0x2, %ebp
je 0x5313
cmpl $-0x1, %ebp
je 0x5309
leaq 0x5853(%rip), %rdi      # 0xa9bc
movl $0xa, %esi
movq %rbx, %rdx
callq *%r14
cmpl $-0x2, %ebp
je 0x5313
movl %ebp, %eax
addq $0x1008, %rsp           # imm = 0x1008
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0xc(%r15), %eax
testb $0x8, %al
jne 0x5313
movq 0x10(%r15), %rcx
movq (%rcx), %rdi
testq %rdi, %rdi
je 0x5356
testb $0x2, %al
jne 0x5272
testb $-0x80, 0x9(%rdi)
jne 0x52eb
movq (%rdi), %r15
testq %r15, %r15
je 0x5394
testq %r14, %r14
je 0x53b3
movq %r15, %rdi
callq 0x2050
xorl %ebp, %ebp
movq %rsp, %r12
movl $0x1, %esi
movl $0x1000, %edx           # imm = 0x1000
movq %r12, %rdi
movq %r15, %rcx
callq 0x21e0
movq %rax, %r13
movq %r12, %rdi
movl %r13d, %esi
movq %rbx, %rdx
callq *%r14
addl %r13d, %ebp
testl %r13d, %r13d
jg 0x51e1
jmp 0x517d
movl 0xc(%r15), %eax
testb $0x10, %al
je 0x5313
movq 0x10(%r15), %rcx
movq (%rcx), %rdi
testq %rdi, %rdi
je 0x5375
testb $0x2, %al
jne 0x5313
movq %r14, %rsi
movq %rbx, %rdx
addq $0x1008, %rsp           # imm = 0x1008
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8c5a
movq 0x20(%r15), %rsi
movq %r14, %rdx
movq %rbx, %rcx
addq $0x1008, %rsp           # imm = 0x1008
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8a4c
movq 0x20(%r15), %rsi
movq %r14, %rdx
movq %rbx, %rcx
addq $0x1008, %rsp           # imm = 0x1008
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8c4b
testb $-0x80, 0x9(%rdi)
jne 0x52eb
movq (%rdi), %r15
testq %r15, %r15
je 0x5394
testq %r14, %r14
je 0x53b3
movq %r15, %rdi
callq 0x2050
xorl %ebp, %ebp
movq %rsp, %r12
movl $0x1, %esi
movl $0x1000, %edx           # imm = 0x1000
movq %r12, %rdi
movq %r15, %rcx
callq 0x21e0
movq %rax, %r13
movq %r12, %rdi
movl %r13d, %esi
movq %rbx, %rdx
callq *%r14
addl %r13d, %ebp
testl %r13d, %r13d
jg 0x52ba
jmp 0x517d
xorl %esi, %esi
movq %r14, %rdx
movq %rbx, %rcx
addq $0x1008, %rsp           # imm = 0x1008
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x7f74
callq 0x2a54
jmp 0x5174
callq 0x2a70
leaq 0x4fb5(%rip), %rdi      # 0xa2d4
leaq 0x556e(%rip), %rsi      # 0xa894
leaq 0x5652(%rip), %rcx      # 0xa97f
movl $0xbe, %edx
callq 0x20e0
leaq 0x5691(%rip), %rdi      # 0xa9cf
leaq 0x554f(%rip), %rsi      # 0xa894
leaq 0x5633(%rip), %rcx      # 0xa97f
movl $0xd8, %edx
callq 0x20e0
leaq 0x5672(%rip), %rdi      # 0xa9cf
leaq 0x5530(%rip), %rsi      # 0xa894
leaq 0x5614(%rip), %rcx      # 0xa97f
movl $0xe9, %edx
callq 0x20e0
leaq 0x5653(%rip), %rdi      # 0xa9cf
leaq 0x5511(%rip), %rsi      # 0xa894
leaq 0x55f5(%rip), %rcx      # 0xa97f
movl $0xf2, %edx
callq 0x20e0
leaq 0x4cca(%rip), %rdi      # 0xa065
leaq 0x54f2(%rip), %rsi      # 0xa894
leaq 0x5647(%rip), %rcx      # 0xa9f0
movl $0xc, %edx
callq 0x20e0
leaq 0x565f(%rip), %rdi      # 0xaa19
leaq 0x54d3(%rip), %rsi      # 0xa894
leaq 0x5628(%rip), %rcx      # 0xa9f0
movl $0xd, %edx
callq 0x20e0
nop