// File: /workspace/github_c_makefile_star2_O2/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 %r12
pushq %rbx
testq %rdi, %rdi
je 0x4959
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
movl 0x8(%rdi), %eax
cmpl $0x1, %eax
je 0x47d3
testl %eax, %eax
je 0x491e
cmpl $0x2, %eax
ja 0x491e
movl 0x4(%r15), %eax
cmpl $0x3, %eax
je 0x489d
cmpl $0x2, %eax
je 0x486a
cmpl $0x1, %eax
jne 0x491e
movq 0x10(%r15), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x4978
testb $0x2, 0xc(%r15)
jne 0x48cc
cmpl $0x0, 0xc(%rdi)
je 0x488a
movq %r14, %rsi
movq %rbx, %rdx
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x782f
movq 0x10(%r15), %rax
movq (%rax), %rdi
callq 0x4b9a
movq %rax, %r12
leaq 0x61c5(%rip), %rdi      # 0xa9ae
pushq $0xd
popq %rsi
movq %rbx, %rdx
callq *%r14
movq %r12, %rdi
callq 0x2090
movq %r12, %rdi
movl %eax, %esi
movq %rbx, %rdx
callq *%r14
leaq 0x5d3a(%rip), %rdi      # 0xa546
pushq $0x1
popq %rsi
movq %rbx, %rdx
callq *%r14
cmpl $0x1, 0x4(%r15)
jne 0x491e
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 0x5584
cmpl $-0x1, %eax
je 0x48fa
movl %eax, %ebp
cmpl $-0x2, %eax
je 0x491e
leaq 0x6166(%rip), %rdi      # 0xa9bc
pushq $0xa
popq %rsi
movq %rbx, %rdx
callq *%r14
movl %ebp, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movl 0xc(%r15), %eax
testb $0x8, %al
jne 0x491e
movq 0x10(%r15), %rcx
movq (%rcx), %rdi
testq %rdi, %rdi
je 0x4997
testb $0x2, %al
jne 0x48e3
movq %r14, %rsi
movq %rbx, %rdx
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x49d5
movl 0xc(%r15), %eax
testb $0x10, %al
je 0x491e
movq 0x10(%r15), %rcx
movq (%rcx), %rdi
testq %rdi, %rdi
je 0x49b6
testb $0x2, %al
jne 0x491e
movq %r14, %rsi
movq %rbx, %rdx
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x8420
movq 0x20(%r15), %rsi
movq %r14, %rdx
movq %rbx, %rcx
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x820a
movq 0x20(%r15), %rsi
movq %r14, %rdx
movq %rbx, %rcx
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x8411
movq 0xa6df(%rip), %rax      # 0xefe0
movq (%rax), %rcx
leaq 0x60bc(%rip), %rdi      # 0xa9c7
pushq $0x7
popq %rsi
pushq $0x1
popq %rdx
callq 0x2280
pushq $-0x1
popq %rbp
jmp 0x485f
movq 0xa6bb(%rip), %rax      # 0xefe0
movq (%rax), %rcx
leaq 0x60b0(%rip), %rdi      # 0xa9df
pushq $0x10
popq %rsi
pushq $0x1
popq %rdx
callq 0x2280
leaq 0x637f(%rip), %rdi      # 0xacc0
leaq 0x5f4c(%rip), %rsi      # 0xa894
leaq 0x6030(%rip), %rcx      # 0xa97f
movl $0xff, %edx
callq 0x20f0
leaq 0x5974(%rip), %rdi      # 0xa2d4
leaq 0x5f2d(%rip), %rsi      # 0xa894
leaq 0x6011(%rip), %rcx      # 0xa97f
movl $0xbe, %edx
callq 0x20f0
leaq 0x6050(%rip), %rdi      # 0xa9cf
leaq 0x5f0e(%rip), %rsi      # 0xa894
leaq 0x5ff2(%rip), %rcx      # 0xa97f
movl $0xd8, %edx
callq 0x20f0
leaq 0x6031(%rip), %rdi      # 0xa9cf
leaq 0x5eef(%rip), %rsi      # 0xa894
leaq 0x5fd3(%rip), %rcx      # 0xa97f
movl $0xe9, %edx
callq 0x20f0
leaq 0x6012(%rip), %rdi      # 0xa9cf
leaq 0x5ed0(%rip), %rsi      # 0xa894
leaq 0x5fb4(%rip), %rcx      # 0xa97f
movl $0xf2, %edx
callq 0x20f0