// File: /workspace/github_c_makefile_star2_O3/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 $0x48, %rsp
movq %rsi, %r15
movl %edi, %ebp
xorl %ebx, %ebx
leaq 0x433c(%rip), %r12      # 0x6004
movq $0x0, (%rsp)
xorl %r14d, %r14d
xorl %r13d, %r13d
movl %r13d, %ecx
movl %ecx, %r13d
movl %ebp, %edi
movq %r15, %rsi
movq %r12, %rdx
callq 0x1050
movl $0x1, %ecx
cmpl $0x73, %eax
jg 0x1cff
cmpl $-0x1, %eax
je 0x1d31
cmpl $0x73, %eax
jne 0x1cd9
jmp 0x1d25
cmpl $0x74, %eax
je 0x1d15
cmpl $0x77, %eax
jne 0x1cd9
movq 0x82b8(%rip), %rax      # 0x9fc8
movq (%rax), %rbx
jmp 0x1cd6
movq 0x82ac(%rip), %rax      # 0x9fc8
movq (%rax), %rax
movq %rax, (%rsp)
jmp 0x1cd6
movq 0x829c(%rip), %rax      # 0x9fc8
movq (%rax), %r14
jmp 0x1cd6
movq 0x82a8(%rip), %rax      # 0x9fe0
movslq (%rax), %rax
leal 0x1(%rax), %ecx
cmpl %ebp, %ecx
jne 0x1f96
testq %rbx, %rbx
setne %cl
cmpq $0x0, (%rsp)
setne %dl
testb %dl, %cl
jne 0x1fa6
testl %r13d, %r13d
jne 0x1fab
movq (%r15,%rax,8), %rdi
callq 0x2a5e
testq %rax, %rax
je 0x1fba
movq %rax, %r12
testq %r14, %r14
je 0x1ece
movzwl 0x4c(%r12), %esi
addl $0x1f, %esi
shrl $0x3, %esi
andl $-0x4, %esi
movl $0x1, %edi
callq 0x10d0
testq %rax, %rax
je 0x1ebf
movq %rax, %r15
decq %r14
movb 0x1(%r14), %al
incq %r14
cmpb $0x20, %al
je 0x1dab
movq %r14, 0x10(%rsp)
movl %eax, %ecx
andb $-0x21, %cl
cmpb $0x55, %cl
jne 0x1eb3
leaq 0x10(%rsp), %r13
cmpb $0x2b, 0x1(%r14)
jne 0x1eb7
addq $0x2, %r14
movq %r14, 0x10(%rsp)
movq %r13, %rdi
leaq 0xc(%rsp), %rsi
callq 0x206a
testl %eax, %eax
js 0x1eb7
movl %eax, %ebp
movq 0x10(%rsp), %r14
cmpb $0x2d, (%r14)
movl 0xc(%rsp), %ecx
jne 0x1e48
testl %ecx, %ecx
jg 0x1eb7
incq %r14
movq %r14, 0x10(%rsp)
movq %r13, %rdi
xorl %esi, %esi
callq 0x206a
testl %eax, %eax
js 0x1eb7
cmpl %ebp, %eax
jb 0x2040
movq %r12, %rdi
movq %r15, %rsi
movl %ebp, %edx
movl %eax, %ecx
callq 0x216a
movq 0x10(%rsp), %r14
jmp 0x1e7e
testl %ecx, %ecx
je 0x1e5d
addl %ebp, %ecx
movq %r12, %rdi
movq %r15, %rsi
movl %ebp, %edx
callq 0x216a
jmp 0x1e7e
movq %r12, %rdi
movl %ebp, %esi
callq 0x3580
movzwl %ax, %ecx
movl $0x1, %eax
shll %cl, %eax
shrq $0x5, %rcx
orl %eax, (%r15,%rcx,4)
jmp 0x1e7e
incq %r14
movzbl (%r14), %eax
cmpl $0x20, %eax
je 0x1e7b
cmpl $0x2c, %eax
jne 0x1e9d
movzbl 0x1(%r14), %eax
incq %r14
cmpl $0x20, %eax
je 0x1e8c
testl %eax, %eax
je 0x1eb7
movq %r14, 0x10(%rsp)
movb (%r14), %al
movl %eax, %ecx
andb $-0x21, %cl
cmpb $0x55, %cl
je 0x1dce
testb %al, %al
je 0x1ed1
movq %r15, %rdi
callq 0x1130
leaq 0x10(%rsp), %rdi
callq 0x1259
jmp 0x1fe8
xorl %r15d, %r15d
movq %r12, %rdi
callq 0x51bc
testq %rax, %rax
je 0x1fc1
movq %rax, %r13
testq %rbx, %rbx
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %rbp
movaps %xmm0, 0x20(%rbp)
movaps %xmm0, 0x10(%rbp)
movaps %xmm0, (%rbp)
cmoveq %rbx, %rbp
movq %rbx, %rax
movq (%rsp), %rdi
orq %rdi, %rax
je 0x1fcb
testq %rbx, %rbx
cmovneq %rbx, %rdi
leaq 0x4241(%rip), %rsi      # 0x615f
callq 0x1120
testq %rax, %rax
je 0x1fdd
movq %rax, %rbx
testq %r15, %r15
je 0x1f5f
testb $0x1, 0xa(%r12)
jne 0x1ffe
leaq 0x103(%rip), %r8        # 0x204a
movq %r12, %rdi
movq %r15, %rsi
movl $0x1, %edx
movq %rbp, %rcx
movq %rbx, %r9
callq 0x3987
jmp 0x1f74
leaq 0xe4(%rip), %rdx        # 0x204a
movq %r12, %rdi
movq %rbp, %rsi
movq %rbx, %rcx
callq 0x3740
movl %eax, %ebp
movq %rbx, %rdi
callq 0x10f0
movq %r13, %rdi
callq 0x524c
movq %r15, %rdi
callq 0x1130
shrl $0x1d, %ebp
andl $-0x4, %ebp
jmp 0x1fed
movq %rbx, %rdi
movq (%rsp), %rsi
callq 0x11f0
testb $0x1, %al
je 0x1fab
callq 0x1354
movq %r15, %rdi
callq 0x1370
movl $0x1, %ebp
jmp 0x1fed
callq 0x1338
jmp 0x1fe8
movq %r15, %rdi
callq 0x12f7
jmp 0x1fe8
movq %r13, %rdi
movq %r15, %rsi
callq 0x127b
movl $0x3, %ebp
jmp 0x1fed
movq %r13, %rdi
movq %r15, %rsi
callq 0x12b9
movl $0x2, %ebp
movl %ebp, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x7fd3(%rip), %rax      # 0x9fd8
movq (%rax), %rcx
leaq 0x4189(%rip), %rdi      # 0x6198
movl $0x3e, %esi
movl $0x1, %edx
callq 0x11d0
leaq 0x25(%rip), %r8         # 0x204a
movq %r12, %rdi
movq %r15, %rsi
movl $0x1, %edx
movq %rbp, %rcx
movq %rbx, %r9
callq 0x4221
jmp 0x1f74
callq 0x1237
jmp 0x1eb7