// File: /workspace/github_c_makefile_star2_O1/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, %r14
movl %edi, %ebp
movq $0x0, 0x10(%rsp)
leaq 0x4365(%rip), %r15      # 0x6004
movq 0x8322(%rip), %rbx      # 0x9fc8
movq $0x0, 0x8(%rsp)
xorl %r13d, %r13d
xorl %r12d, %r12d
movl %r12d, %ecx
movl %ecx, %r12d
movl %ebp, %edi
movq %r14, %rsi
movq %r15, %rdx
callq 0x1050
movl $0x1, %ecx
cmpl $0x73, %eax
jg 0x1cde
cmpl $-0x1, %eax
je 0x1d01
cmpl $0x73, %eax
jne 0x1cb8
jmp 0x1cfc
cmpl $0x74, %eax
je 0x1cf2
cmpl $0x77, %eax
jne 0x1cb8
movq (%rbx), %rax
movq %rax, 0x10(%rsp)
jmp 0x1cb5
movq (%rbx), %rax
movq %rax, 0x8(%rsp)
jmp 0x1cb5
movq (%rbx), %r13
jmp 0x1cb5
movq 0x82d8(%rip), %rax      # 0x9fe0
movslq (%rax), %rax
leal 0x1(%rax), %ecx
cmpl %ebp, %ecx
jne 0x1fc2
movq (%r14,%rax,8), %r15
movq 0x10(%rsp), %rbx
movq 0x8(%rsp), %rbp
testq %rbx, %rbx
setne %al
testq %rbp, %rbp
setne %cl
andb %al, %cl
cmpb $0x1, %cl
je 0x1fd5
testl %r12d, %r12d
jne 0x1fe5
movq %r15, %rdi
callq 0x2ab7
testq %rax, %rax
je 0x1ff4
movq %rax, %r15
testq %r13, %r13
je 0x1ed8
movq %r13, 0x20(%rsp)
movzwl 0x4c(%r15), %esi
addl $0x1f, %esi
shrl $0x3, %esi
andl $-0x4, %esi
movl $0x1, %edi
callq 0x10d0
testq %rax, %rax
je 0x1ef0
movq %rax, %r14
decq %r13
cmpb $0x20, 0x1(%r13)
leaq 0x1(%r13), %r13
je 0x1d8d
movq %r13, 0x20(%rsp)
movb (%r13), %al
movl %eax, %ecx
andb $-0x21, %cl
cmpb $0x55, %cl
jne 0x1edd
cmpb $0x2b, 0x1(%r13)
jne 0x1edd
leaq 0x20(%rsp), %r12
addq $0x2, %r13
movq %r13, 0x20(%rsp)
movq %r12, %rdi
leaq 0x1c(%rsp), %rsi
callq 0x20b9
movl $0x6, %ebx
testl %eax, %eax
js 0x1e6a
movl %eax, %ebp
movq 0x20(%rsp), %rax
cmpb $0x2d, (%rax)
movl 0x1c(%rsp), %ecx
jne 0x1e37
testl %ecx, %ecx
jg 0x1e6a
incq %rax
movq %rax, 0x20(%rsp)
xorl %r13d, %r13d
movq %r12, %rdi
xorl %esi, %esi
callq 0x20b9
movl $0x6, %ebx
testl %eax, %eax
js 0x1e30
cmpl %ebp, %eax
jl 0x1ecb
movq %r15, %rdi
movq %r14, %rsi
movl %ebp, %edx
movl %eax, %ecx
callq 0x21d8
xorl %ebx, %ebx
movb $0x1, %r13b
testb %r13b, %r13b
jne 0x1e68
jmp 0x1e6a
testl %ecx, %ecx
je 0x1e4c
addl %ebp, %ecx
movq %r15, %rdi
movq %r14, %rsi
movl %ebp, %edx
callq 0x21d8
jmp 0x1e68
movq %r15, %rdi
movl %ebp, %esi
callq 0x361c
movzwl %ax, %ecx
movl $0x1, %eax
shll %cl, %eax
shrq $0x5, %rcx
orl %eax, (%r14,%rcx,4)
xorl %ebx, %ebx
testl %ebx, %ebx
jne 0x2081
movq 0x20(%rsp), %r13
movq 0x10(%rsp), %rbx
movq 0x8(%rsp), %rbp
movzbl (%r13), %eax
cmpl $0x20, %eax
jne 0x1e90
incq %r13
jmp 0x1e81
cmpl $0x2c, %eax
jne 0x1eab
movq %r13, 0x20(%rsp)
movzbl 0x1(%r13), %eax
incq %r13
cmpl $0x20, %eax
je 0x1e9a
testl %eax, %eax
je 0x1ee3
movq %r13, 0x20(%rsp)
movb (%r13), %al
movl %eax, %ecx
andb $-0x21, %cl
cmpb $0x55, %cl
jne 0x1edd
cmpb $0x2b, 0x1(%r13)
je 0x1dbf
jmp 0x1edd
callq 0x1246
xorl %r13d, %r13d
jmp 0x1e30
xorl %r14d, %r14d
jmp 0x1efc
testb %al, %al
jne 0x1ee8
jmp 0x1ef3
movq %r13, 0x20(%rsp)
movq %r14, %rdi
callq 0x1130
xorl %r14d, %r14d
testq %r14, %r14
je 0x2024
movq %r15, %rdi
callq 0x52ec
testq %rax, %rax
je 0x1ffb
movq %rax, %r12
testq %rbx, %rbx
xorps %xmm0, %xmm0
leaq 0x20(%rsp), %r13
movaps %xmm0, 0x20(%r13)
movaps %xmm0, 0x10(%r13)
movaps %xmm0, (%r13)
cmoveq %rbx, %r13
movq %rbx, %rax
orq %rbp, %rax
je 0x2005
testq %rbx, %rbx
cmovneq %rbx, %rbp
leaq 0x4217(%rip), %rsi      # 0x615f
movq %rbp, %rdi
callq 0x1120
testq %rax, %rax
je 0x2017
movq %rax, %rbx
testq %r14, %r14
je 0x1f8b
testb $0x1, 0xa(%r15)
jne 0x203f
leaq 0x126(%rip), %r8        # 0x2099
movq %r15, %rdi
movq %r14, %rsi
movl $0x1, %edx
movq %r13, %rcx
movq %rbx, %r9
callq 0x3a31
jmp 0x1fa0
leaq 0x107(%rip), %rdx       # 0x2099
movq %r15, %rdi
movq %r13, %rsi
movq %rbx, %rcx
callq 0x37dc
movl %eax, %ebp
movq %rbx, %rdi
callq 0x10f0
movq %r12, %rdi
callq 0x537c
movq %r14, %rdi
callq 0x1130
shrl $0x1d, %ebp
andl $-0x4, %ebp
jmp 0x202e
callq 0x11f0
movl $0x1, %r12d
xorl %r15d, %r15d
jmp 0x1d1a
callq 0x120c
movl $0x1, %r12d
jmp 0x1d3b
movq %r14, %rdi
callq 0x1228
movl $0x1, %ebp
jmp 0x202e
callq 0x1347
jmp 0x2029
movq %r14, %rdi
callq 0x1306
jmp 0x2029
movq %r12, %rdi
movq %r14, %rsi
callq 0x128a
movl $0x3, %ebp
jmp 0x202e
movq %r12, %rdi
movq %r14, %rsi
callq 0x12c8
jmp 0x2029
callq 0x1268
movl $0x2, %ebp
movl %ebp, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x7f92(%rip), %rax      # 0x9fd8
movq (%rax), %rcx
leaq 0x4148(%rip), %rdi      # 0x6198
movl $0x3e, %esi
movl $0x1, %edx
callq 0x11d0
leaq 0x33(%rip), %r8         # 0x2099
movq %r15, %rdi
movq %r14, %rsi
movl $0x1, %edx
movq %r13, %rcx
movq %rbx, %r9
callq 0x42c3
jmp 0x1fa0
cmpl $0x6, %ebx
movq 0x10(%rsp), %rbx
movq 0x8(%rsp), %rbp
je 0x1ee8
jmp 0x1ef3