// File: /workspace/github_c_makefile_star2_O0/smilingthax[P]libfontembed/embed.c
// Function: emb_new
EMB_PARAMS *emb_new(FONTFILE *font,EMB_DESTINATION dest,EMB_CONSTRAINTS mode) // {{{
{
  assert(font);

  EMB_PARAMS *ret=calloc(1,sizeof(EMB_PARAMS));
  if (!ret) {
    fprintf(stderr,"Bad alloc: %s\n", strerror(errno));
    if (mode&EMB_C_TAKE_FONTFILE) {
      fontfile_close(font);
    }
    return NULL;
  }
  ret->dest=dest;
  ret->font=font;
  if (mode&EMB_C_TAKE_FONTFILE) {
    ret->plan|=EMB_A_CLOSE_FONTFILE;
  }

  // check parameters
  if ( (mode&EMB_C_KEEP_T1)&&(mode&EMB_C_FORCE_MULTIBYTE) ) {
    fprintf(stderr,"Incompatible mode: KEEP_T1 and FORCE_MULTIBYTE\n");
    emb_close(ret);
    return NULL;
  }
  if ((mode&0x07)>5) {
    fprintf(stderr,"Bad subset specification\n");
    emb_close(ret);
    return NULL;
  }

  // determine intype
  int numGlyphs=0;
  if (font->sfnt) {
    if (font->sfnt->flags&OTF_F_FMT_CFF) {
      ret->intype=EMB_FMT_OTF;
    } else {
      ret->intype=EMB_FMT_TTF;
    }
    ret->rights=emb_otf_get_rights(ret->font->sfnt);
    numGlyphs=ret->font->sfnt->numGlyphs; // TODO
  } else if (font->stdname) {
    ret->intype=EMB_FMT_STDFONT;
    ret->rights=EMB_RIGHT_NONE;
  } else {
    assert(0);
  }
/*
  if ( (ret->intype==EMB_FMT_CFF)&&
       (ret->cffFont.is_cid()) ) {
     ?= || ( (ret->intype==EMB_FMT_OTF)&&(ret->sfnt->cffFont.is_cid()) ) // TODO?
    ret->plan|=EMB_A_MULTIBYTE;
  }
*/

  // determine outtype
  if (ret->intype==EMB_FMT_STDFONT) {
    ret->outtype=ret->intype;
    if (mode&EMB_C_FORCE_MULTIBYTE) {
      fprintf(stderr,"Multibyte stdfonts are not possible\n");
      emb_close(ret);
      return NULL;
    }
    return ret; // never subset, no multibyte
  } else if (ret->intype==EMB_FMT_T1) {
    if (mode&EMB_C_KEEP_T1) {
      ret->outtype=EMB_FMT_T1;
    } else {
      ret->plan|=EMB_A_T1_TO_CFF;
      ret->outtype=EMB_FMT_CFF;
    }
  } else {
    ret->outtype=ret->intype;
  }
  if (ret->outtype==EMB_FMT_CFF) {
    if (mode&EMB_C_PDF_OT) {
      ret->outtype=EMB_FMT_OTF;
      ret->plan|=EMB_A_CFF_TO_OTF;
    }
  } else if (ret->outtype==EMB_FMT_OTF) {
    // TODO: no support yet;  but we want to get the FontDescriptor/Name right
    mode|=EMB_C_NEVER_SUBSET;
    if (!(mode&EMB_C_PDF_OT)) { // TODO!?!
      ret->outtype=EMB_FMT_CFF;
      ret->plan|=EMB_A_OTF_TO_CFF;
    }
  }

  if (mode&EMB_C_FORCE_MULTIBYTE) {
    ret->plan|=EMB_A_MULTIBYTE;
  }

  // check rights (for subsetting)
  if (  (ret->rights&EMB_RIGHT_NONE)||
        (ret->rights&EMB_RIGHT_BITMAPONLY)||
        ( (ret->rights&EMB_RIGHT_READONLY)&&(mode&EMB_C_EDITABLE_SUBSET) )||
        ( (ret->rights&EMB_RIGHT_NO_SUBSET)&&(mode&EMB_C_MUST_SUBSET) )  ) {
    fprintf(stderr,"The font does not permit the requested embedding\n");
    emb_close(ret);
    return NULL;
  } else if ( (!(ret->rights&EMB_RIGHT_NO_SUBSET))&&
              (!(mode&EMB_C_NEVER_SUBSET)) ) {
    ret->plan|=EMB_A_SUBSET;
  }

  // alloc subset
  if (ret->plan&EMB_A_SUBSET) {
    ret->subset=bitset_new(numGlyphs);
    if (!ret->subset) {
      fprintf(stderr,"Bad alloc: %s\n", strerror(errno));
      emb_close(ret);
      return NULL;
    }
  }

  return ret;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x592b
jmp 0x594a
leaq 0x8f97(%rip), %rdi      # 0xe8c9
leaq 0x8f95(%rip), %rsi      # 0xe8ce
movl $0x48, %edx
leaq 0x8f91(%rip), %rcx      # 0xe8d6
callq 0x2100
movl $0x1, %edi
movl $0x28, %esi
callq 0x2110
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x59b6
movq 0xd675(%rip), %rax      # 0x12fe0
movq (%rax), %rax
movq %rax, -0x30(%rbp)
callq 0x2040
movl (%rax), %edi
callq 0x2070
movq -0x30(%rbp), %rdi
movq %rax, %rdx
leaq 0x89d0(%rip), %rsi      # 0xe35c
movb $0x0, %al
callq 0x21e0
movl -0x18(%rbp), %eax
andl $0x8000, %eax           # imm = 0x8000
cmpl $0x0, %eax
je 0x59a9
movq -0x10(%rbp), %rdi
callq 0xa290
movq $0x0, -0x8(%rbp)
jmp 0x5d60
movl -0x14(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x10(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
movl -0x18(%rbp), %eax
andl $0x8000, %eax           # imm = 0x8000
cmpl $0x0, %eax
je 0x59e9
movq -0x20(%rbp), %rax
movl 0xc(%rax), %ecx
orl $0x8000, %ecx           # imm = 0x8000
movl %ecx, 0xc(%rax)
movl -0x18(%rbp), %eax
andl $0x20, %eax
cmpl $0x0, %eax
je 0x5a2d
movl -0x18(%rbp), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x5a2d
movq 0xd5da(%rip), %rax      # 0x12fe0
movq (%rax), %rdi
leaq 0x8f08(%rip), %rsi      # 0xe918
movb $0x0, %al
callq 0x21e0
movq -0x20(%rbp), %rdi
callq 0x5d70
movq $0x0, -0x8(%rbp)
jmp 0x5d60
movl -0x18(%rbp), %eax
andl $0x7, %eax
cmpl $0x5, %eax
jbe 0x5a66
movq 0xd5a1(%rip), %rax      # 0x12fe0
movq (%rax), %rdi
leaq 0x8eff(%rip), %rsi      # 0xe948
movb $0x0, %al
callq 0x21e0
movq -0x20(%rbp), %rdi
callq 0x5d70
movq $0x0, -0x8(%rbp)
jmp 0x5d60
movl $0x0, -0x24(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, (%rax)
je 0x5ace
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl 0x8(%rax), %eax
andl $0x10000, %eax          # imm = 0x10000
cmpl $0x0, %eax
je 0x5a97
movq -0x20(%rbp), %rax
movl $0x2, (%rax)
jmp 0x5aa1
movq -0x20(%rbp), %rax
movl $0x1, (%rax)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq (%rax), %rdi
callq 0x6310
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x18(%rax)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq (%rax), %rax
movzwl 0x4c(%rax), %eax
movl %eax, -0x24(%rbp)
jmp 0x5b11
movq -0x10(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x5af0
movq -0x20(%rbp), %rax
movl $0x4, (%rax)
movq -0x20(%rbp), %rax
movl $0x2, 0x18(%rax)
jmp 0x5b0f
leaq 0x9209(%rip), %rdi      # 0xed00
leaq 0x8dd0(%rip), %rsi      # 0xe8ce
movl $0x72, %edx
leaq 0x8dcc(%rip), %rcx      # 0xe8d6
callq 0x2100
jmp 0x5b11
movq -0x20(%rbp), %rax
cmpl $0x4, (%rax)
jne 0x5b6d
movq -0x20(%rbp), %rax
movl (%rax), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x4(%rax)
movl -0x18(%rbp), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x5b60
movq 0xd4a7(%rip), %rax      # 0x12fe0
movq (%rax), %rdi
leaq 0x8e1f(%rip), %rsi      # 0xe962
movb $0x0, %al
callq 0x21e0
movq -0x20(%rbp), %rdi
callq 0x5d70
movq $0x0, -0x8(%rbp)
jmp 0x5d60
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x5d60
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x5ba8
movl -0x18(%rbp), %eax
andl $0x20, %eax
cmpl $0x0, %eax
je 0x5b8e
movq -0x20(%rbp), %rax
movl $0x0, 0x4(%rax)
jmp 0x5ba6
movq -0x20(%rbp), %rax
movl 0xc(%rax), %ecx
orl $0x4, %ecx
movl %ecx, 0xc(%rax)
movq -0x20(%rbp), %rax
movl $0x3, 0x4(%rax)
jmp 0x5bb5
movq -0x20(%rbp), %rax
movl (%rax), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x4(%rax)
jmp 0x5bb7
movq -0x20(%rbp), %rax
cmpl $0x3, 0x4(%rax)
jne 0x5be6
movl -0x18(%rbp), %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0x5be4
movq -0x20(%rbp), %rax
movl $0x2, 0x4(%rax)
movq -0x20(%rbp), %rax
movl 0xc(%rax), %ecx
orl $0x8, %ecx
movl %ecx, 0xc(%rax)
jmp 0x5c20
movq -0x20(%rbp), %rax
cmpl $0x2, 0x4(%rax)
jne 0x5c1e
movl -0x18(%rbp), %eax
orl $0x4, %eax
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %eax
andl $0x10, %eax
cmpl $0x0, %eax
jne 0x5c1c
movq -0x20(%rbp), %rax
movl $0x3, 0x4(%rax)
movq -0x20(%rbp), %rax
movl 0xc(%rax), %ecx
orl $0x10, %ecx
movl %ecx, 0xc(%rax)
jmp 0x5c1e
jmp 0x5c20
movl -0x18(%rbp), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x5c38
movq -0x20(%rbp), %rax
movl 0xc(%rax), %ecx
orl $0x1, %ecx
movl %ecx, 0xc(%rax)
movq -0x20(%rbp), %rax
movl 0x18(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
jne 0x5c8e
movq -0x20(%rbp), %rax
movl 0x18(%rax), %eax
andl $0x200, %eax            # imm = 0x200
cmpl $0x0, %eax
jne 0x5c8e
movq -0x20(%rbp), %rax
movl 0x18(%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x5c72
movl -0x18(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
jne 0x5c8e
movq -0x20(%rbp), %rax
movl 0x18(%rax), %eax
andl $0x100, %eax            # imm = 0x100
cmpl $0x0, %eax
je 0x5cbc
movl -0x18(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x5cbc
movq 0xd34b(%rip), %rax      # 0x12fe0
movq (%rax), %rdi
leaq 0x8ce8(%rip), %rsi      # 0xe987
movb $0x0, %al
callq 0x21e0
movq -0x20(%rbp), %rdi
callq 0x5d70
movq $0x0, -0x8(%rbp)
jmp 0x5d60
movq -0x20(%rbp), %rax
movl 0x18(%rax), %eax
andl $0x100, %eax            # imm = 0x100
cmpl $0x0, %eax
jne 0x5ce5
movl -0x18(%rbp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
jne 0x5ce5
movq -0x20(%rbp), %rax
movl 0xc(%rax), %ecx
orl $0x2, %ecx
movl %ecx, 0xc(%rax)
jmp 0x5ce7
movq -0x20(%rbp), %rax
movl 0xc(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x5d58
movl -0x24(%rbp), %edi
callq 0x5dc0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x20(%rbp), %rax
cmpq $0x0, 0x20(%rax)
jne 0x5d56
movq 0xd2c5(%rip), %rax      # 0x12fe0
movq (%rax), %rax
movq %rax, -0x38(%rbp)
callq 0x2040
movl (%rax), %edi
callq 0x2070
movq -0x38(%rbp), %rdi
movq %rax, %rdx
leaq 0x8620(%rip), %rsi      # 0xe35c
movb $0x0, %al
callq 0x21e0
movq -0x20(%rbp), %rdi
callq 0x5d70
movq $0x0, -0x8(%rbp)
jmp 0x5d60
jmp 0x5d58
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nopw (%rax,%rax)