// File: /workspace/github_c_makefile_star2_O1/felipelouza[P]lyndon-array/main.c
// Function: main
int main(int argc, char** argv){

  time_t t_start=0;
  clock_t c_start=0;

  extern char *optarg;
  extern int optind, opterr, optopt;

  int c=0, verbose=0, time=0, check=0, print=0, output=0, stats=0, factors=0, subs=0;
  //input options
  int bin=0;// bin or formatted (default) input (txt, fasta and fastq)
  char *c_file=NULL;

  size_t  d=0; //number of documents
  int ALG=10;//Algorithm

  while ((c=getopt(argc, argv, "vthp:d:A:cosbflL")) != -1) {
    switch (c)
    {
      case 'v':
        verbose++; break;
      case 't':
        time++; break;
      case 'p':
        print=(size_t)atoi(optarg); break;
      case 'h':
        usage(argv[0]); break;       // show usage and stop
      case 'd':
        d=(size_t)atoi(optarg); break;
      case 'A':
        ALG=(size_t)atoi(optarg); break;
      case 'c':
        check++; break;
      case 'o':
        output++; break;
      case 's':
        stats++; break;
      case 'b':
        bin=1; break;
      case 'f':
        bin=0; break;
      case 'l':
        factors=1; break;
      case 'L':
        factors =1; subs=1; break;
      case '?':
        exit(EXIT_FAILURE);
    }
  }
  free(optarg);
  
  if(optind+1==argc) {
    c_file=argv[optind++];
  }
  else  usage(argv[0]);

  if(verbose>0) {
    puts("Command line:");
    int i;
    for(i=0;i<argc;i++)
      printf(" %s",argv[i]);
    puts("");
  }

  /********/
  unsigned char *str = NULL;
  size_t i, n=0;

  if(bin==0){
    // reading the input as a collection of documents
    unsigned char **R;

    //disk access
    R = (unsigned char**) file_load_multiple(c_file, &d, &n);
    if(!R){
      fprintf(stderr, "Error: less than %zu strings in %s\n", d, c_file);
      return 0;
    }

    //concatenate strings
    str = cat_char(R, d, &n);

    printf("d = %zu\n", d);
    printf("N = %zu bytes\n", n);
    printf("sizeof(int) = %zu bytes\n", sizeof(int_t));

    #if DEBUG
      printf("R:\n");
      for(i=0; i<d; i++)
        printf("%zu) %s (%zu)\n", i, R[i], strlen((char*)R[i]));
    #endif

    //free memory
    for(i=0; i<d; i++)
      free(R[i]);
    free(R);
  }
  else{ //bin
    // reading the input file as a single document
    FILE *f = fopen(c_file,"r");
    if(f==NULL) {perror("Cannot open input file"); exit(1);}
    int e = fseek(f,0,SEEK_END);
    if(e)  {perror("Cannot seek"); exit(1);}
    n = ftell(f);
    rewind(f);

    str = malloc((n+1)*sizeof(char));
    if(str==NULL) {perror("Cannot alloc"); exit(1);}

    e = fread(str,1,n,f);
    if(e!=n) if(f==NULL) {perror("Cannot read from input file"); exit(1);}
    str[n++] = 0; // terminator 

    (void) d;
    printf("N = %zu bytes\n", n);
    printf("sizeof(int) = %zu bytes\n", sizeof(int_t));  
  }

  /********/

  char* copy = NULL;
  if(check && ALG==5){
      copy = (char*) malloc((n+1)*sizeof(char));
      strcpy(copy, (char*)str);
  }

  //lyndon array
  int_t *LA = NULL;
  if(ALG<=10){
    LA = (int_t*) malloc(n*sizeof(int_t));
    for(i=0; i<n; i++) LA[i]=0;
  }

  int_t *SA = NULL;
  if(ALG>=6){ //also computes SA[1,n]
    SA = (int_t*) malloc(n*sizeof(int_t));
    for(i=0; i<n; i++) SA[i]=0;
  }


  switch(ALG){

    /****/
    case 1:  printf("## LYNDON_NSV ##\n"); 
      compute_lyndon_nsv(str, (int_t*)LA, n);
      break;

    case 2:  printf("## GSACA_LYN ##\n"); 
      if(time)
        time_start(&t_start, &c_start);
      gsaca_cl(str, (uint_t*)LA, n);
      if(time){
        printf("TOTAL:\n");
        fprintf(stderr,"%.6lf\n", time_stop(t_start, c_start));
      }
      break;

    case 3:  printf("## MAX_LYN ##\n"); 
      compute_lyndon_max_lyn(str, (int_t*)LA, n);
      break;

    case 4: printf("## LYNDON_BWT ##\n"); 
      compute_lyndon_bwt(str, (int_t*)LA, n);
      break;

    case 5:  printf("## BWT_INPLACE_LYN ##\n"); 
      bwt_lyndon_inplace((char*)str, (int_t*)LA, n);
      break;

    /****/
    case 6:  printf("## GSACA_LYN_SA ##\n"); 
      if(time)
        time_start(&t_start, &c_start);
      gsaca_cl_la(str, (uint_t*)SA, (uint_t*)LA, n);
      if(time){
        printf("TOTAL:\n");
        fprintf(stderr,"%.6lf\n", time_stop(t_start, c_start));
      }
      break;
    
    case 7:  printf("## SACAK_LYNDON (non-linear) ##\n"); 
      if(time)
        time_start(&t_start, &c_start);
      sacak_lyndon_9n_non_linear(str, (int_t*)SA, (int_t*)LA, n);
      if(time){
        printf("TOTAL:\n");
        fprintf(stderr,"%.6lf\n", time_stop(t_start, c_start));
      }
      break;

    case 8:  printf("## SACAK_LYNDON 17n (linear) ##\n"); 
      if(time)
        time_start(&t_start, &c_start);
      sacak_lyndon_17n_linear(str, (int_t*)SA, (int_t*)LA, n);
      if(time){
        printf("TOTAL:\n");
        fprintf(stderr,"%.6lf\n", time_stop(t_start, c_start));
      }
      break;
    
    case 9:  printf("## SACAK_LYNDON 13n (linear) ##\n"); 
      if(time)
        time_start(&t_start, &c_start);
      sacak_lyndon_13n_linear(str, (int_t*)SA, (int_t*)LA, n);
      if(time){
        printf("TOTAL:\n");
        fprintf(stderr,"%.6lf\n", time_stop(t_start, c_start));
      }
      break;
    
    case 10:  printf("## SACAK_LYNDON 9n (linear) ##\n"); 
      if(time)
        time_start(&t_start, &c_start);
      sacak_lyndon_9n_linear(str, (int_t*)SA, (int_t*)LA, n);
      if(time){
        printf("TOTAL:\n");
        fprintf(stderr,"%.6lf\n", time_stop(t_start, c_start));
      }
      break;

    case 11:  printf("## SACAK 5n (linear) ##\n"); 
      if(time)
        time_start(&t_start, &c_start);
      sacak(str, (int_t*)SA, n);
      if(time){
        printf("TOTAL:\n");
        fprintf(stderr,"%.6lf\n", time_stop(t_start, c_start));
      }
      break;
    
    /****/

    default: break;
  }

  // validate  
  if(check){
    if(ALG==5){
      free(str);
      str = (unsigned char*) copy;
    }

    printf("LA: ");
    if(!lyndon_check(str, LA, n, 0)){
      printf("isNOTLyndonArray!!\n");
      fprintf(stderr, "ERROR\n");
    }
    else {
      printf("isLyndonArray!!\n");
    }
    if(SA){
      printf("SA: ");
      if(!suffix_array_check((unsigned char*)str, (int_t*)SA, n, sizeof(char), 0)) fprintf(stderr,"isNotSorted!!\n");//compares upt to symbol '0'
      else printf("isSorted!!\n");
    }
  }

  if(print){ 
    printf("########\n");
    printf("i) LA\t");
    if(SA) printf("SA\t");
    printf("suffixes\n");
    for(i=0; i<min(n,print); i++){
      printf("%zu) %" PRIdN "\t", i, LA[i]);
      if(SA) printf("%" PRIdN "\t", SA[i]);
      int_t j=i;
      for(j=i; j<(int_t) min(i+LA[i],n); j++){
        char c = (str[j]==0)?'#':(str[j]>1?str[j]-1:'$');
        printf("%c", c);
      }
      printf("\n");
    }
    printf("########\n");
  }

  if(output){
    char c_out[255];
    FILE *f_out = NULL;
    printf("OUTPUT:\n");
    if(LA){
      sprintf(c_out, "%s.la", c_file);
      printf("%s\n", c_out);
      f_out = file_open(c_out, "wb");
      fwrite(LA, sizeof(int_t), n, f_out);
      file_close(f_out);
    }
    if(SA){
      sprintf(c_out, "%s.sa", c_file);
      printf("%s\n", c_out);
      f_out = file_open(c_out, "wb");
      fwrite(SA, sizeof(int_t), n, f_out);
      file_close(f_out);
    }
    {
      sprintf(c_out, "%s.bin", c_file);
      printf("%s\n", c_out);
      f_out = file_open(c_out, "wb");
      fwrite(str, sizeof(unsigned char), n, f_out);
      file_close(f_out);
    }
  }
  if(factors){

    if(!output) printf("OUTPUT:\n");
    char c_out[255];
    FILE *f_out = NULL, *F_out = NULL;
    sprintf(c_out, "%s.pos", c_file);
    printf("%s\n", c_out);
    f_out = file_open(c_out, "wb");

    if(subs==1){
      sprintf(c_out, "%s.lyn", c_file);
      printf("%s\n", c_out);
      F_out = file_open(c_out, "w");
    }

    size_t curr;
    i=0;
    char tmp[64], l='\n';
    while(i<n){
      curr=i;
      sprintf(tmp, "%lu\n", i);
      fwrite(tmp, sizeof(char), strlen(tmp), f_out);
      if(subs==1){
        size_t j;
        for(j=curr; j<curr+LA[i]; j++){
          char c;
          if(bin) c = str[j];
          else  c = (str[j]==0)?'#':(str[j]>1?str[j]-1:'$');
          fwrite(&c, sizeof(unsigned char),1, F_out);
          //printf("%c", c);
        }
        if(!bin)  fwrite(&l, sizeof(unsigned char),1, F_out);
      }
      i+=LA[i];
    }

    file_close(f_out);
    if(subs==2)
      file_close(F_out);
  }

  if(LA && stats){
    int_t max=0, j=0;
    size_t sum=0;
    
    for(i=0;i<n;i++){
      sum+=LA[i];
      if(LA[i]>max){max=LA[i];j=i;}
    }

    printf("##\n");
    printf("Max(LA[%d]): % "PRIdN"\n", j, max);
    printf("Avg(LA[i]): %.2lf\n", (double)sum/(double)n);

    i=0;
    int_t count=0;
    max=0;
    while(i<n){
      #if DEBUG
      printf("%zu\t%d\n", i, LA[i]);
      #endif
      count++;
      if(LA[i]>max) max=LA[i];
      i+=LA[i];
    }

    printf("##\n");
    printf("Number of Lyndon factors: % "PRIdN"\n", count);
    printf("Average length: %.2lf\n", (double)n/(double)count);
    printf("Maximum length: % "PRIdN"\n", max);
    printf("##\n");

    fprintf(stderr, "%"PRIdN"\t%.2lf\t%"PRIdN"\n", count, (double)n/(double)count, max);
  }

  free(str);
  if(LA) free(LA);
  if(SA) free(SA);

return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1a8, %rsp            # imm = 0x1A8
movq %rsi, %rbx
movl %edi, %r14d
xorl %eax, %eax
movq %rax, 0x20(%rsp)
movq %rax, 0x18(%rsp)
movq $0x0, 0x30(%rsp)
movq %rax, 0x38(%rsp)
movl $0xa, %eax
movq %rax, 0x8(%rsp)
leaq 0x60c0(%rip), %r15      # 0x935f
movq 0x9d32(%rip), %rbp      # 0xcfd8
leaq 0x5d57(%rip), %r12      # 0x9004
movl $0x0, 0x44(%rsp)
movl $0x0, 0x48(%rsp)
movl $0x0, 0x54(%rsp)
movl $0x0, 0x50(%rsp)
movl $0x0, 0x4c(%rsp)
movl $0x0, 0x2c(%rsp)
movl $0x0, 0x14(%rsp)
xorl %r13d, %r13d
movl %r14d, %edi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x2210
cmpl $0x4b, %eax
jle 0x3316
leal -0x62(%rax), %ecx
cmpl $0x14, %ecx
ja 0x332f
movslq (%r12,%rcx,4), %rax
addq %r12, %rax
jmpq *%rax
movl $0x1, 0x2c(%rsp)
jmp 0x32e8
cmpl $0x41, %eax
jne 0x33b5
movq (%rbp), %rdi
callq 0x2230
movq %rax, 0x8(%rsp)
jmp 0x32e8
cmpl $0x4c, %eax
jne 0x32e8
movl $0x1, 0x50(%rsp)
movl $0x1, 0x4c(%rsp)
jmp 0x32e8
movq (%rbp), %rdi
callq 0x2230
movl %eax, 0x44(%rsp)
jmp 0x32e8
incl 0x48(%rsp)
jmp 0x32e8
movq (%rbp), %rdi
callq 0x2230
cltq
movq %rax, 0x38(%rsp)
jmp 0x32e8
incl 0x14(%rsp)
jmp 0x32e8
movl $0x1, 0x50(%rsp)
jmp 0x32e8
incl 0x54(%rsp)
jmp 0x32e8
movq 0x30(%rsp), %rax
incl %eax
movq %rax, 0x30(%rsp)
jmp 0x32e8
movl $0x0, 0x2c(%rsp)
jmp 0x32e8
incl %r13d
jmp 0x32e8
cmpl $-0x1, %eax
je 0x33cd
cmpl $0x3f, %eax
jne 0x32e8
movl $0x1, %edi
callq 0x2270
movq (%rbp), %rdi
callq 0x7fc5
movq 0x9bf3(%rip), %rax      # 0xcfd0
movslq (%rax), %rcx
leal 0x1(%rcx), %edx
cmpl %r14d, %edx
jne 0x3e08
movl %edx, (%rax)
movq (%rbx,%rcx,8), %rbp
testl %r13d, %r13d
movq 0x8(%rsp), %r13
jle 0x343a
leaq 0x5f6d(%rip), %rdi      # 0x9370
callq 0x2080
testl %r14d, %r14d
jle 0x3430
movl %r14d, %r15d
leaq 0x5f67(%rip), %r14      # 0x937e
xorl %r12d, %r12d
movq (%rbx,%r12,8), %rsi
movq %r14, %rdi
xorl %eax, %eax
callq 0x20f0
incq %r12
cmpq %r12, %r15
jne 0x341a
movl $0xa, %edi
callq 0x2040
movq $0x0, (%rsp)
cmpl $0x0, 0x2c(%rsp)
je 0x34f5
leaq 0x625a(%rip), %rsi      # 0x96ae
movq %rbp, %rdi
callq 0x21f0
testq %rax, %rax
je 0x3e10
movq %rax, %r14
movq %rax, %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0x21d0
testl %eax, %eax
jne 0x3e15
movq %r14, %rdi
callq 0x2190
movq %rax, (%rsp)
movq %r14, %rdi
callq 0x2110
movq (%rsp), %r15
leaq 0x1(%r15), %rdi
callq 0x7f0e
testq %rax, %rax
je 0x3e1a
movq %rax, %rbx
movl $0x1, %esi
movq %rax, %rdi
movq %r15, %rdx
movq %r14, %rcx
callq 0x2090
movq (%rsp), %rax
leaq 0x1(%rax), %rsi
movq %rsi, (%rsp)
movb $0x0, (%rbx,%rax)
leaq 0x5ed9(%rip), %rdi      # 0x93af
xorl %eax, %eax
callq 0x20f0
leaq 0x5eda(%rip), %rdi      # 0x93be
movl $0x4, %esi
xorl %eax, %eax
callq 0x20f0
jmp 0x358f
leaq 0x38(%rsp), %rsi
movq %rsp, %rdx
movq %rbp, %rdi
callq 0x47d5
movq %rax, %r14
testq %rax, %rax
je 0x382d
movq 0x38(%rsp), %rsi
movq %rsp, %r15
movq %r14, %rdi
movq %r15, %rdx
callq 0x30cc
movq %rax, %r12
movq 0x38(%rsp), %rsi
leaq 0x5e73(%rip), %rdi      # 0x93a6
xorl %eax, %eax
callq 0x20f0
movq (%r15), %rsi
leaq 0x5e6b(%rip), %rdi      # 0x93af
xorl %eax, %eax
callq 0x20f0
leaq 0x5e6c(%rip), %rdi      # 0x93be
movl $0x4, %esi
xorl %eax, %eax
callq 0x20f0
cmpq $0x0, 0x38(%rsp)
je 0x357b
xorl %ebx, %ebx
movq (%r14,%rbx,8), %rdi
callq 0x7fc5
incq %rbx
cmpq 0x38(%rsp), %rbx
jb 0x3568
movq %r14, %rdi
callq 0x7fc5
movq %r12, %rbx
testq %r14, %r14
je 0x3dd3
cmpl $0x0, 0x30(%rsp)
setne %al
cmpl $0x5, %r13d
sete %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x35c1
movq (%rsp), %rdi
incq %rdi
callq 0x7f0e
movq %rax, %r14
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2070
jmp 0x35c4
xorl %r14d, %r14d
cmpl $0xa, %r13d
jg 0x360b
movq %r13, 0x8(%rsp)
movq %rbp, %r13
movq %rbx, %rbp
movq (%rsp), %r12
leaq (,%r12,4), %rbx
movq %rbx, %rdi
callq 0x7f0e
movq %rax, %r15
testq %r12, %r12
je 0x35fe
movq %r15, %rdi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x2130
movq %rbp, %rbx
movq %r13, %rbp
movq 0x8(%rsp), %r13
jmp 0x360e
xorl %r15d, %r15d
cmpl $0x6, %r13d
movq %rbp, 0x58(%rsp)
jl 0x3657
movq %rbx, %rbp
movq (%rsp), %r12
leaq (,%r12,4), %rbx
movq %rbx, %rdi
callq 0x7f0e
movq %rax, %r13
testq %r12, %r12
je 0x3645
movq %r13, %rdi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x2130
movq %r13, %r12
movq 0x8(%rsp), %r13
movq %rbp, %rbx
movq 0x58(%rsp), %rbp
jmp 0x365a
xorl %r12d, %r12d
leal -0x1(%r13), %eax
cmpl $0xa, %eax
movq %r12, 0x8(%rsp)
ja 0x3984
leaq 0x59e5(%rip), %rcx      # 0x9058
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x5f5d(%rip), %rdi      # 0x95e0
callq 0x2080
movl (%rsp), %edx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2cf7
jmp 0x3984
leaq 0x5ef2(%rip), %rdi      # 0x9594
callq 0x2080
movl (%rsp), %edx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x512e
jmp 0x3984
leaq 0x5e41(%rip), %rdi      # 0x9502
callq 0x2080
cmpl $0x0, 0x14(%rsp)
jne 0x3854
movl (%rsp), %ecx
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x7e95
jmp 0x3984
leaq 0x5ecd(%rip), %rdi      # 0x95bb
callq 0x2080
movl (%rsp), %edx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2dd1
jmp 0x3984
leaq 0x5e9d(%rip), %rdi      # 0x95aa
callq 0x2080
movl (%rsp), %edx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2ced
jmp 0x3984
leaq 0x5e15(%rip), %rdi      # 0x9541
callq 0x2080
cmpl $0x0, 0x14(%rsp)
jne 0x3879
movl (%rsp), %ecx
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x7e00
jmp 0x3984
leaq 0x5e70(%rip), %rdi      # 0x95c9
callq 0x2080
cmpl $0x0, 0x14(%rsp)
jne 0x389e
movl (%rsp), %edx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x6351
jmp 0x3984
leaq 0x5dfe(%rip), %rdi      # 0x9581
callq 0x2080
cmpl $0x0, 0x14(%rsp)
jne 0x38c0
movl (%rsp), %ecx
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x635f
jmp 0x3984
leaq 0x5db1(%rip), %rdi      # 0x9561
callq 0x2080
cmpl $0x0, 0x14(%rsp)
jne 0x38e2
movl (%rsp), %ecx
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x7db7
jmp 0x3984
leaq 0x5d0d(%rip), %rdi      # 0x94ea
callq 0x2080
cmpl $0x0, 0x14(%rsp)
jne 0x3904
movl (%rsp), %edx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x7d7d
jmp 0x3984
leaq 0x5d1a(%rip), %rdi      # 0x9521
callq 0x2080
cmpl $0x0, 0x14(%rsp)
jne 0x3923
movl (%rsp), %ecx
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x7e4c
jmp 0x3984
movq 0x97c4(%rip), %rax      # 0xcff8
movq (%rax), %rdi
movq 0x38(%rsp), %rdx
leaq 0x5b3f(%rip), %rsi      # 0x9382
xorl %ebx, %ebx
movq %rbp, %rcx
xorl %eax, %eax
callq 0x2180
jmp 0x3586
leaq 0x20(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x3e20
movl (%rsp), %ecx
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x7e95
jmp 0x3943
leaq 0x20(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x3e20
movl (%rsp), %ecx
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x7e00
jmp 0x3943
leaq 0x20(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x3e20
movl (%rsp), %edx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x6351
jmp 0x3943
leaq 0x20(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x3e20
movl (%rsp), %ecx
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x635f
jmp 0x3943
leaq 0x20(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x3e20
movl (%rsp), %ecx
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x7db7
jmp 0x3943
leaq 0x20(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x3e20
movl (%rsp), %edx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x7d7d
jmp 0x3943
leaq 0x20(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x3e20
movl (%rsp), %ecx
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x7e4c
leaq 0x5c8f(%rip), %rdi      # 0x95d9
callq 0x2080
movq 0x96a2(%rip), %rax      # 0xcff8
movq (%rax), %r12
leaq 0x20(%rsp), %rax
movq (%rax), %rdi
leaq 0x18(%rsp), %rax
movq (%rax), %rsi
callq 0x3e44
leaq 0x5a92(%rip), %rsi      # 0x9407
movq %r12, %rdi
movq 0x8(%rsp), %r12
movb $0x1, %al
callq 0x2180
cmpl $0x0, 0x30(%rsp)
je 0x399b
cmpl $0x5, %r13d
jne 0x39a4
movq %rbx, %rdi
callq 0x7fc5
jmp 0x39a7
movq %rbx, %r14
movl 0x44(%rsp), %ebx
jmp 0x3a1b
movq %rbx, %r14
leaq 0x5a60(%rip), %rdi      # 0x940e
xorl %eax, %eax
callq 0x20f0
movl (%rsp), %edx
movq %r14, %rdi
movq %r15, %rsi
xorl %ecx, %ecx
callq 0x5956
testl %eax, %eax
movl 0x44(%rsp), %ebx
je 0x3df4
leaq 0x5c2c(%rip), %rdi      # 0x9604
callq 0x2080
testq %r12, %r12
je 0x3a1b
leaq 0x5a31(%rip), %rdi      # 0x941a
xorl %eax, %eax
callq 0x20f0
movq (%rsp), %rdx
movq %r14, %rdi
movq %r12, %rsi
movl $0x1, %ecx
xorl %r8d, %r8d
callq 0x5547
testl %eax, %eax
je 0x3dfe
leaq 0x5bfe(%rip), %rdi      # 0x9614
callq 0x2080
testl %ebx, %ebx
je 0x3b2f
leaq 0x5bf5(%rip), %rdi      # 0x961f
callq 0x2080
leaq 0x59f8(%rip), %rdi      # 0x942e
xorl %eax, %eax
callq 0x20f0
testq %r12, %r12
je 0x3a50
leaq 0x59ec(%rip), %rdi      # 0x9435
xorl %eax, %eax
callq 0x20f0
leaq 0x5d4b(%rip), %rdi      # 0x97a2
callq 0x2080
cmpq $0x0, (%rsp)
je 0x3b1e
movslq %ebx, %rbp
leaq 0x59c8(%rip), %rbx      # 0x9439
xorl %r13d, %r13d
movl (%r15,%r13,4), %edx
movq %rbx, %rdi
movq %r13, %rsi
xorl %eax, %eax
callq 0x20f0
testq %r12, %r12
je 0x3a9c
movl (%r12,%r13,4), %esi
leaq 0x5c93(%rip), %rdi      # 0x9728
xorl %eax, %eax
callq 0x20f0
movslq (%r15,%r13,4), %rax
addq %r13, %rax
movq (%rsp), %rcx
cmpq %rcx, %rax
cmovaeq %rcx, %rax
cmpl %eax, %r13d
jge 0x3af8
movslq %r13d, %r12
movzbl (%r14,%r12), %eax
testl %eax, %eax
je 0x3acb
cmpl $0x1, %eax
jne 0x3ad2
movl $0x24, %edi
jmp 0x3ad7
movl $0x23, %edi
jmp 0x3ad7
decb %al
movsbl %al, %edi
callq 0x2040
incq %r12
movslq (%r15,%r13,4), %rax
addq %r13, %rax
movq (%rsp), %rcx
cmpq %rcx, %rax
cmovaeq %rcx, %rax
cltq
cmpq %rax, %r12
jl 0x3ab6
movl $0xa, %edi
callq 0x2040
incq %r13
movq (%rsp), %rax
cmpq %rbp, %rax
cmovaeq %rbp, %rax
cmpq %rax, %r13
movq 0x8(%rsp), %r12
jb 0x3a74
leaq 0x5afa(%rip), %rdi      # 0x961f
callq 0x2080
movq 0x58(%rsp), %rbp
cmpl $0x0, 0x48(%rsp)
je 0x3c3d
leaq 0x5ae7(%rip), %rdi      # 0x9628
callq 0x2080
testq %r15, %r15
je 0x3b9a
leaq 0x58f0(%rip), %rsi      # 0x9442
leaq 0x60(%rsp), %rbx
movq %rbx, %rdi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x2260
movq %rbx, %rdi
callq 0x2080
leaq 0x58d5(%rip), %rsi      # 0x9448
movq %rbx, %rdi
callq 0x42ac
movq %rax, %rbx
movq (%rsp), %rdx
movl $0x4, %esi
movq %r15, %rdi
movq %rax, %rcx
callq 0x2280
movq %rbx, %rdi
callq 0x42d9
testq %r12, %r12
je 0x3bee
leaq 0x58a5(%rip), %rsi      # 0x944b
leaq 0x60(%rsp), %rbx
movq %rbx, %rdi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x2260
movq %rbx, %rdi
callq 0x2080
leaq 0x5881(%rip), %rsi      # 0x9448
movq %rbx, %rdi
callq 0x42ac
movq %rax, %rbx
movq (%rsp), %rdx
movl $0x4, %esi
movq %r12, %rdi
movq %rax, %rcx
callq 0x2280
movq %rbx, %rdi
callq 0x42d9
leaq 0x585c(%rip), %rsi      # 0x9451
leaq 0x60(%rsp), %rbx
movq %rbx, %rdi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x2260
movq %rbx, %rdi
callq 0x2080
leaq 0x5832(%rip), %rsi      # 0x9448
movq %rbx, %rdi
callq 0x42ac
movq %rax, %rbx
movq (%rsp), %rdx
movl $0x1, %esi
movq %r14, %rdi
movq %rax, %rcx
callq 0x2280
movq %rbx, %rdi
callq 0x42d9
cmpl $0x0, 0x50(%rsp)
je 0x3d9c
cmpl $0x0, 0x48(%rsp)
jne 0x3c5b
leaq 0x59d2(%rip), %rdi      # 0x9628
callq 0x2080
leaq 0x57f6(%rip), %rsi      # 0x9458
xorl %r13d, %r13d
leaq 0x60(%rsp), %rbx
movq %rbx, %rdi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x2260
movq %rbx, %rdi
callq 0x2080
leaq 0x57c2(%rip), %rsi      # 0x9448
movq %rbx, %rdi
callq 0x42ac
movq %rax, 0x30(%rsp)
cmpl $0x0, 0x4c(%rsp)
je 0x3ccd
leaq 0x57be(%rip), %rsi      # 0x945f
leaq 0x60(%rsp), %r12
movq %r12, %rdi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x2260
movq %r12, %rdi
callq 0x2080
leaq 0x57a4(%rip), %rsi      # 0x9466
movq %r12, %rdi
callq 0x42ac
movq %rax, %r13
cmpq $0x0, (%rsp)
je 0x3d8d
leaq 0x160(%rsp), %r12
xorl %ebx, %ebx
movq %r12, %rdi
leaq 0x577c(%rip), %rsi      # 0x9468
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2260
movq %r12, %rdi
callq 0x20c0
movl $0x1, %esi
movq %r12, %rdi
movq %rax, %rdx
movq 0x30(%rsp), %rcx
callq 0x2280
cmpl $0x0, 0x4c(%rsp)
je 0x3d7c
movslq (%r15,%rbx,4), %rax
addq %rbx, %rax
cmpq %rax, %rbx
jae 0x3d68
movq %rbx, %rbp
movb (%r14,%rbp), %al
cmpl $0x0, 0x2c(%rsp)
je 0x3d50
movsbl %al, %edi
movq %r13, %rsi
callq 0x2160
incq %rbp
movslq (%r15,%rbx,4), %rax
addq %rbx, %rax
cmpq %rax, %rbp
jb 0x3d29
jmp 0x3d68
movzbl %al, %ecx
testl %ecx, %ecx
je 0x3d60
cmpl $0x1, %ecx
jne 0x3d64
movb $0x24, %al
jmp 0x3d34
movb $0x23, %al
jmp 0x3d34
decb %al
jmp 0x3d34
cmpl $0x0, 0x2c(%rsp)
jne 0x3d7c
movl $0xa, %edi
movq %r13, %rsi
callq 0x2160
movslq (%r15,%rbx,4), %rax
addq %rax, %rbx
cmpq (%rsp), %rbx
jb 0x3ce2
movq 0x30(%rsp), %rdi
callq 0x42d9
movq 0x8(%rsp), %r12
testq %r15, %r15
setne %al
cmpl $0x0, 0x54(%rsp)
setne %cl
andb %al, %cl
cmpb $0x1, %cl
je 0x3de7
movq %r14, %rdi
callq 0x7fc5
testq %r15, %r15
je 0x3dc6
movq %r15, %rdi
callq 0x7fc5
testq %r12, %r12
je 0x3dd3
movq %r12, %rdi
callq 0x7fc5
xorl %eax, %eax
addq $0x1a8, %rsp            # imm = 0x1A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rsp, %rdi
movq %r15, %rsi
callq 0x233f
jmp 0x3db1
callq 0x22ef
jmp 0x39dd
callq 0x231d
jmp 0x3a1b
movq (%rbx), %rdi
callq 0x3181
callq 0x22da
callq 0x22b0
callq 0x22c5
nop