// File: /workspace/github_c_makefile_star2_O3/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 0x52f1
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
movl 0x8(%rdi), %eax
cmpl $0x1, %eax
je 0x50bf
testl %eax, %eax
je 0x52ec
cmpl $0x2, %eax
ja 0x52ec
movl 0x4(%r15), %eax
cmpl $0x3, %eax
je 0x51e6
cmpl $0x2, %eax
je 0x5165
cmpl $0x1, %eax
jne 0x52ec
movq 0x10(%r15), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x5310
testb $0x2, 0xc(%r15)
jne 0x5226
cmpl $0x0, 0xc(%rdi)
je 0x5266
movq %r14, %rsi
movq %rbx, %rdx
addq $0x1008, %rsp           # imm = 0x1008
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x7ff9
movq 0x10(%r15), %rax
movq (%rax), %rdi
callq 0x54b8
movq %rax, %r12
leaq 0x58d9(%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 0x544c(%rip), %rdi      # 0xa546
movl $0x1, %esi
movq %rbx, %rdx
callq *%r14
cmpl $0x1, 0x4(%r15)
jne 0x52ec
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 0x5e6c
cmpl $-0x1, %eax
je 0x52dd
movl %eax, %ebp
cmpl $-0x2, %eax
je 0x52ec
leaq 0x5876(%rip), %rdi      # 0xa9bc
movl $0xa, %esi
movq %rbx, %rdx
callq *%r14
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 0x52ec
movq 0x10(%r15), %rcx
movq (%rcx), %rdi
testq %rdi, %rdi
je 0x532f
testb $0x2, %al
jne 0x5246
testb $-0x80, 0x9(%rdi)
jne 0x52bf
movq (%rdi), %r15
testq %r15, %r15
je 0x536d
testq %r14, %r14
je 0x538c
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 0x51b5
jmp 0x5151
movl 0xc(%r15), %eax
testb $0x10, %al
je 0x52ec
movq 0x10(%r15), %rcx
movq (%rcx), %rdi
testq %rdi, %rdi
je 0x534e
testb $0x2, %al
jne 0x52ec
movq %r14, %rsi
movq %rbx, %rdx
addq $0x1008, %rsp           # imm = 0x1008
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8bb1
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 0x899e
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 0x8ba2
testb $-0x80, 0x9(%rdi)
jne 0x52bf
movq (%rdi), %r15
testq %r15, %r15
je 0x536d
testq %r14, %r14
je 0x538c
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 0x528e
jmp 0x5151
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 0x7ecc
callq 0x2a5c
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x5151
callq 0x2a78
leaq 0x4fdc(%rip), %rdi      # 0xa2d4
leaq 0x5595(%rip), %rsi      # 0xa894
leaq 0x5679(%rip), %rcx      # 0xa97f
movl $0xbe, %edx
callq 0x20e0
leaq 0x56b8(%rip), %rdi      # 0xa9cf
leaq 0x5576(%rip), %rsi      # 0xa894
leaq 0x565a(%rip), %rcx      # 0xa97f
movl $0xd8, %edx
callq 0x20e0
leaq 0x5699(%rip), %rdi      # 0xa9cf
leaq 0x5557(%rip), %rsi      # 0xa894
leaq 0x563b(%rip), %rcx      # 0xa97f
movl $0xe9, %edx
callq 0x20e0
leaq 0x567a(%rip), %rdi      # 0xa9cf
leaq 0x5538(%rip), %rsi      # 0xa894
leaq 0x561c(%rip), %rcx      # 0xa97f
movl $0xf2, %edx
callq 0x20e0
leaq 0x4cf1(%rip), %rdi      # 0xa065
leaq 0x5519(%rip), %rsi      # 0xa894
leaq 0x566e(%rip), %rcx      # 0xa9f0
movl $0xc, %edx
callq 0x20e0
leaq 0x5686(%rip), %rdi      # 0xaa19
leaq 0x54fa(%rip), %rsi      # 0xa894
leaq 0x564f(%rip), %rcx      # 0xa9f0
movl $0xd, %edx
callq 0x20e0
nop