// File: /workspace/github_c_makefile_star2_O2/smilingthax[P]libfontembed/woffer.c
// Function: main
int main(int argc,char **argv)
{
  int opt;
  int usage=0;
  const char *fontfile=NULL;
  const char *woffout=NULL,*sfntout=NULL;

  BITSET subset=NULL;
  const char *subsetstr=NULL;

  while ((opt=getopt(argc, argv, "hw:t:s:"))!=-1) {
    switch (opt) {
    case 'w':
      woffout=optarg;
      break;
    case 't':
      sfntout=optarg;
      break;
    case 's':
      subsetstr=optarg;
      break;
    case 'h':
    default:
      usage=1;
      break;
    }
  }
  if (optind+1==argc) {
    fontfile=argv[optind];
  } else {
    fprintf(stderr,"Error: Expected fontfile\n");
    usage=1;
  }
  if ( (woffout)&&(sfntout) ) {
    fprintf(stderr,"Error: Only one of -w and -t may be given\n");
    usage=1;
  }

  if (usage) {
    fprintf(stderr,"\nUsage: %s infile [-w|-t] outfile\n"
                   "  -h: Help\n"
                   "  -w wofffile: Output as WOFF (compressed) to file\n"
                   "  -t sfntfile: Output as SFNT (uncompressed) to file\n"
                   "  -s [subset-ranges]: e.g. U+0-0d,U+5fa4,U+23??\n",  // TODO? ,'asdf'
                   argv[0]);
    return 1;
  }

  OTF_FILE *otf=otf_load(fontfile);
  if (!otf) {
    fprintf(stderr,"Error: Could not load fontfile\n");
    return 2;
  }

  if (subsetstr) {
    subset=parse_ranges(otf,subsetstr);
    if (!subset) {
      fprintf(stderr,"Error: Bad subset range\n");
      return 2;
    }
  }

  FONTFILE *ff=fontfile_open_sfnt(otf);
  if (!ff) {
    fprintf(stderr,"Bad alloc: %s\n", strerror(errno));
    free(subset);
    return 2;
  }

  FILE *f=NULL;
  struct _OTF_WRITE_WOFF woff={0,0},*woffptr=NULL; // version; no metaData, no privData
  if (woffout) {
    f=fopen(woffout,"wb");
    woffptr=&woff;
  } else if (sfntout) {
    f=fopen(sfntout,"wb");
  } else {
    // NO-OP: no output file given
    fprintf(stderr,"Nothing to do\n");
    fontfile_close(ff);
    free(subset);
    return 3;
  }
  if (!f) {
    fprintf(stderr,"Error: Could not open output fontfile\n");
    fontfile_close(ff);
    free(subset);
    return 2;
  }

  int res;
  if (subset) {
    if (is_CFF(otf)) {
      fprintf(stderr,"Note: Glyph subsetting not implemented yet for CFF-type files\n");
      res=otf_subset_cff2(otf,subset,SUBSET_DST_BROWSER,woffptr,file_outfn,f);
    } else {
      res=otf_subset2(otf,subset,SUBSET_DST_BROWSER,woffptr,file_outfn,f);
    }
  } else {
    res=otf_copy_sfnt(otf,woffptr,file_outfn,f);
  }

  fclose(f);
  fontfile_close(ff);
  free(subset);

  if (res<0) {
    return 4;
  }
  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rsi, %rbx
movl %edi, %ebp
movq $0x0, 0x8(%rsp)
leaq 0x3cf5(%rip), %r15      # 0x5004
pushq $0x1
popq %r13
movq $0x0, 0x10(%rsp)
xorl %r14d, %r14d
xorl %r12d, %r12d
movl %r12d, %ecx
movl %ecx, %r12d
movl %ebp, %edi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x1050
cmpl $-0x1, %eax
je 0x137a
cmpl $0x73, %eax
je 0x135d
cmpl $0x74, %eax
je 0x1369
movl %r13d, %ecx
cmpl $0x77, %eax
jne 0x1325
movq 0x6c75(%rip), %rax      # 0x7fc8
movq (%rax), %rax
movq %rax, 0x8(%rsp)
jmp 0x1322
movq 0x6c64(%rip), %rax      # 0x7fc8
movq (%rax), %r14
jmp 0x1322
movq 0x6c58(%rip), %rax      # 0x7fc8
movq (%rax), %rax
movq %rax, 0x10(%rsp)
jmp 0x1322
movq 0x6c5f(%rip), %rax      # 0x7fe0
movslq (%rax), %rax
leal 0x1(%rax), %ecx
cmpl %ebp, %ecx
jne 0x15f1
cmpq $0x0, 0x8(%rsp)
setne %cl
cmpq $0x0, 0x10(%rsp)
setne %dl
testb %dl, %cl
jne 0x1626
testl %r12d, %r12d
jne 0x1642
movq (%rbx,%rax,8), %rdi
callq 0x2379
testq %rax, %rax
je 0x1671
movq %rax, %r15
testq %r14, %r14
je 0x151e
movzwl 0x4c(%r15), %esi
addl $0x1f, %esi
shrl $0x3, %esi
andl $-0x4, %esi
pushq $0x1
popq %rdi
callq 0x10e0
testq %rax, %rax
je 0x14fb
movq %rax, %rbx
decq %r14
cmpb $0x20, 0x1(%r14)
leaq 0x1(%r14), %r14
je 0x13f5
leaq 0x20(%rsp), %r12
leaq 0x1c(%rsp), %r13
movq %r14, 0x20(%rsp)
movb (%r14), %al
movl %eax, %ecx
andb $-0x21, %cl
cmpb $0x55, %cl
jne 0x1522
cmpb $0x2b, 0x1(%r14)
jne 0x14f3
addq $0x2, %r14
movq %r14, 0x20(%rsp)
movq %r12, %rdi
movq %r13, %rsi
callq 0x17c4
testl %eax, %eax
js 0x14f3
movl %eax, %ebp
movq 0x20(%rsp), %r14
cmpb $0x2d, (%r14)
movl 0x1c(%rsp), %ecx
jne 0x1494
testl %ecx, %ecx
jg 0x14f3
incq %r14
movq %r14, 0x20(%rsp)
movq %r12, %rdi
xorl %esi, %esi
callq 0x17c4
testl %eax, %eax
js 0x14f3
cmpl %ebp, %eax
jb 0x1755
movq %r15, %rdi
movq %rbx, %rsi
movl %ebp, %edx
movl %eax, %ecx
callq 0x18c2
movq 0x20(%rsp), %r14
jmp 0x14c7
testl %ecx, %ecx
je 0x14a9
addl %ebp, %ecx
movq %r15, %rdi
movq %rbx, %rsi
movl %ebp, %edx
callq 0x18c2
jmp 0x14c7
movq %r15, %rdi
movl %ebp, %esi
callq 0x3078
movzwl %ax, %ecx
pushq $0x1
popq %rax
shll %cl, %eax
shrq $0x5, %rcx
orl %eax, (%rbx,%rcx,4)
jmp 0x14c7
incq %r14
movzbl (%r14), %eax
cmpl $0x20, %eax
je 0x14c4
cmpl $0x2c, %eax
jne 0x140a
movq %r14, 0x20(%rsp)
movzbl 0x1(%r14), %eax
incq %r14
cmpl $0x20, %eax
je 0x14de
testl %eax, %eax
jne 0x140a
movq %rbx, %rdi
callq 0x1140
movq 0x6ad6(%rip), %rax      # 0x7fd8
movq (%rax), %rcx
leaq 0x3c2b(%rip), %rdi      # 0x5137
pushq $0x18
popq %rsi
pushq $0x1
popq %rdx
callq 0x11e0
pushq $0x2
jmp 0x165f
xorl %ebx, %ebx
jmp 0x1526
testb %al, %al
jne 0x14f3
movq %r15, %rdi
callq 0x4d04
testq %rax, %rax
movq 0x10(%rsp), %rdi
je 0x1689
movq %rax, %r12
movq 0x8(%rsp), %rcx
testq %rcx, %rcx
xorps %xmm0, %xmm0
leaq 0x20(%rsp), %r13
movaps %xmm0, 0x20(%r13)
movaps %xmm0, 0x10(%r13)
movaps %xmm0, (%r13)
cmoveq %rcx, %r13
movq %rcx, %rax
orq %rdi, %rax
je 0x16b5
testq %rcx, %rcx
cmovneq %rcx, %rdi
leaq 0x3be3(%rip), %rsi      # 0x515f
callq 0x1130
testq %rax, %rax
je 0x16e8
movq %rax, %r14
testq %rbx, %rbx
je 0x15ba
testb $0x1, 0xa(%r15)
jne 0x1719
leaq 0x1d2(%rip), %r8        # 0x1776
pushq $0x1
popq %rdx
movq %r15, %rdi
movq %rbx, %rsi
movq %r13, %rcx
movq %r14, %r9
callq 0x34dd
jmp 0x15cf
leaq 0x1b5(%rip), %rdx       # 0x1776
movq %r15, %rdi
movq %r13, %rsi
movq %r14, %rcx
callq 0x3264
movl %eax, %ebp
movq %r14, %rdi
callq 0x1100
movq %r12, %rdi
callq 0x4d88
movq %rbx, %rdi
callq 0x1140
shrl $0x1d, %ebp
andl $-0x4, %ebp
jmp 0x1660
movq 0x69e0(%rip), %rax      # 0x7fd8
movq (%rax), %rcx
leaq 0x3a0a(%rip), %rdi      # 0x500c
pushq $0x19
popq %rsi
pushq $0x1
popq %rdx
callq 0x11e0
cmpq $0x0, 0x8(%rsp)
setne %al
cmpq $0x0, 0x10(%rsp)
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x1642
movq 0x69ab(%rip), %rax      # 0x7fd8
movq (%rax), %rcx
leaq 0x39ef(%rip), %rdi      # 0x5026
pushq $0x2a
popq %rsi
pushq $0x1
popq %rdx
callq 0x11e0
movq 0x698f(%rip), %rax      # 0x7fd8
movq (%rax), %rdi
movq (%rbx), %rdx
leaq 0x39fb(%rip), %rsi      # 0x5051
xorl %eax, %eax
callq 0x1170
pushq $0x1
popq %rbp
movl %ebp, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x6960(%rip), %rax      # 0x7fd8
movq (%rax), %rcx
leaq 0x3a95(%rip), %rdi      # 0x5117
pushq $0x1f
jmp 0x150e
movq 0x6948(%rip), %rax      # 0x7fd8
movq (%rax), %r14
callq 0x1030
movl (%rax), %edi
callq 0x1070
leaq 0x3aaa(%rip), %rsi      # 0x5150
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x1170
jmp 0x170c
movq 0x691c(%rip), %rax      # 0x7fd8
movq (%rax), %rcx
leaq 0x3a9c(%rip), %rdi      # 0x5162
pushq $0xe
popq %rsi
pushq $0x1
popq %rdx
callq 0x11e0
movq %r12, %rdi
callq 0x4d88
movq %rbx, %rdi
callq 0x1140
pushq $0x3
jmp 0x165f
movq 0x68e9(%rip), %rax      # 0x7fd8
movq (%rax), %rcx
leaq 0x3a78(%rip), %rdi      # 0x5171
pushq $0x26
popq %rsi
pushq $0x1
popq %rdx
callq 0x11e0
movq %r12, %rdi
callq 0x4d88
movq %rbx, %rdi
callq 0x1140
jmp 0x1517
movq 0x68b8(%rip), %rax      # 0x7fd8
movq (%rax), %rcx
leaq 0x3a6e(%rip), %rdi      # 0x5198
pushq $0x3e
popq %rsi
pushq $0x1
popq %rdx
callq 0x11e0
leaq 0x3a(%rip), %r8         # 0x1776
pushq $0x1
popq %rdx
movq %r15, %rdi
movq %rbx, %rsi
movq %r13, %rcx
movq %r14, %r9
callq 0x3d85
jmp 0x15cf
movq 0x687c(%rip), %rax      # 0x7fd8
movq (%rax), %rcx
leaq 0x3a71(%rip), %rdi      # 0x51d7
pushq $0x1d
popq %rsi
pushq $0x1
popq %rdx
callq 0x11e0
jmp 0x14f3