// File: /workspace/github_c_makefile_star2_O3/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, 0x38(%rsp)
movq %rax, 0x40(%rsp)
movl $0xa, %eax
movq %rax, 0x10(%rsp)
leaq 0x6050(%rip), %r15      # 0x935f
movq 0x9cc2(%rip), %rbp      # 0xcfd8
leaq 0x5ce7(%rip), %r13      # 0x9004
movl $0x0, 0x30(%rsp)
movl $0x0, 0x58(%rsp)
movl $0x0, 0x5c(%rsp)
movl $0x0, 0x34(%rsp)
movl $0x0, 0x4c(%rsp)
movl $0x0, 0x2c(%rsp)
movl $0x0, 0xc(%rsp)
xorl %r12d, %r12d
movl %r14d, %edi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x2210
cmpl $0x4b, %eax
jle 0x3387
leal -0x62(%rax), %ecx
cmpl $0x14, %ecx
ja 0x33a0
movslq (%r13,%rcx,4), %rax
addq %r13, %rax
jmpq *%rax
movl $0x1, 0x2c(%rsp)
jmp 0x3358
cmpl $0x41, %eax
jne 0x3426
movq (%rbp), %rdi
callq 0x2230
movq %rax, 0x10(%rsp)
jmp 0x3358
cmpl $0x4c, %eax
jne 0x3358
movl $0x1, 0x34(%rsp)
movl $0x1, 0x4c(%rsp)
jmp 0x3358
movq (%rbp), %rdi
callq 0x2230
movl %eax, 0x30(%rsp)
jmp 0x3358
incl 0x58(%rsp)
jmp 0x3358
movq (%rbp), %rdi
callq 0x2230
cltq
movq %rax, 0x40(%rsp)
jmp 0x3358
incl 0xc(%rsp)
jmp 0x3358
movl $0x1, 0x34(%rsp)
jmp 0x3358
incl 0x5c(%rsp)
jmp 0x3358
movq 0x38(%rsp), %rax
incl %eax
movq %rax, 0x38(%rsp)
jmp 0x3358
movl $0x0, 0x2c(%rsp)
jmp 0x3358
incl %r12d
jmp 0x3358
cmpl $-0x1, %eax
je 0x343e
cmpl $0x3f, %eax
jne 0x3358
movl $0x1, %edi
callq 0x2270
movq (%rbp), %rdi
callq 0x8611
movq 0x9b82(%rip), %rax      # 0xcfd0
movslq (%rax), %rcx
leal 0x1(%rcx), %edx
cmpl %r14d, %edx
jne 0x3e5b
movl %r14d, (%rax)
movq (%rbx,%rcx,8), %rax
movq %rax, 0x50(%rsp)
testl %r12d, %r12d
movq 0x10(%rsp), %rbp
jle 0x34b1
leaq 0x5ef6(%rip), %rdi      # 0x9370
callq 0x2080
testl %r14d, %r14d
jle 0x34a7
movl %r14d, %r15d
leaq 0x5ef0(%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 0x3491
movl $0xa, %edi
callq 0x2040
movq $0x0, (%rsp)
cmpl $0x0, 0x2c(%rsp)
je 0x3569
leaq 0x61e3(%rip), %rsi      # 0x96ae
movq 0x50(%rsp), %rdi
callq 0x21f0
testq %rax, %rax
je 0x3e63
movq %rax, %r14
movq %rax, %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0x21d0
testl %eax, %eax
jne 0x3e68
movq %r14, %rdi
callq 0x2190
movq %rax, %r12
movq %r14, %rdi
callq 0x2110
leaq 0x1(%r12), %r15
movq %r15, %rdi
callq 0x855a
testq %rax, %rax
je 0x3e6d
movq %rax, %rbx
movl $0x1, %esi
movq %rax, %rdi
movq %r12, %rdx
movq %r14, %rcx
callq 0x2090
movq %r15, (%rsp)
movb $0x0, (%rbx,%r12)
leaq 0x5e68(%rip), %rdi      # 0x93af
movq %r15, %rsi
xorl %eax, %eax
callq 0x20f0
leaq 0x5e66(%rip), %rdi      # 0x93be
movl $0x4, %esi
xorl %eax, %eax
callq 0x20f0
jmp 0x35fa
leaq 0x40(%rsp), %rsi
movq %rsp, %rdx
movq 0x50(%rsp), %rdi
callq 0x47e5
testq %rax, %rax
je 0x3876
movq %rax, %r14
movq 0x40(%rsp), %rsi
movq %rsp, %r15
movq %rax, %rdi
movq %r15, %rdx
callq 0x313c
movq %rax, %rbx
movq 0x40(%rsp), %rsi
leaq 0x5dfd(%rip), %rdi      # 0x93a6
xorl %eax, %eax
callq 0x20f0
movq (%r15), %rsi
leaq 0x5df5(%rip), %rdi      # 0x93af
xorl %eax, %eax
callq 0x20f0
leaq 0x5df6(%rip), %rdi      # 0x93be
movl $0x4, %esi
xorl %eax, %eax
callq 0x20f0
cmpq $0x0, 0x40(%rsp)
je 0x35f2
xorl %r15d, %r15d
movq (%r14,%r15,8), %rdi
callq 0x8611
incq %r15
cmpq 0x40(%rsp), %r15
jb 0x35df
movq %r14, %rdi
callq 0x8611
cmpl $0x0, 0x38(%rsp)
setne %al
cmpl $0x5, %ebp
sete %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x362c
movq (%rsp), %r13
leaq 0x1(%r13), %rdi
callq 0x855a
movq %rax, %r14
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2070
jmp 0x3638
movq (%rsp), %r13
cmpl $0xb, %ebp
jge 0x366c
xorl %r14d, %r14d
leaq (,%r13,4), %r12
movq %r12, %rdi
callq 0x855a
movq %rax, %r15
testq %r13, %r13
je 0x365d
movq %r15, %rdi
xorl %esi, %esi
movq %r12, %rdx
callq 0x2130
cmpl $0x6, %ebp
jge 0x367a
xorl %r12d, %r12d
movl 0x30(%rsp), %r13d
jmp 0x36a4
leaq (,%r13,4), %r12
xorl %r15d, %r15d
xorl %r14d, %r14d
movq %r12, %rdi
callq 0x855a
movq %rax, %rbp
testq %r13, %r13
je 0x3697
movq %rbp, %rdi
xorl %esi, %esi
movq %r12, %rdx
callq 0x2130
movl 0x30(%rsp), %r13d
movq %rbp, %r12
movq 0x10(%rsp), %rbp
leal -0x1(%rbp), %eax
cmpl $0xa, %eax
movq %r12, 0x10(%rsp)
ja 0x39cd
leaq 0x599c(%rip), %rcx      # 0x9058
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x5f14(%rip), %rdi      # 0x95e0
callq 0x2080
movl (%rsp), %edx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2d5e
jmp 0x39cd
leaq 0x5ea9(%rip), %rdi      # 0x9594
callq 0x2080
movl (%rsp), %edx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x5169
jmp 0x39cd
leaq 0x5df8(%rip), %rdi      # 0x9502
callq 0x2080
cmpl $0x0, 0xc(%rsp)
jne 0x389d
movl (%rsp), %ecx
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x84e1
jmp 0x39cd
leaq 0x5e84(%rip), %rdi      # 0x95bb
callq 0x2080
movl (%rsp), %edx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2e4d
jmp 0x39cd
leaq 0x5e54(%rip), %rdi      # 0x95aa
callq 0x2080
movl (%rsp), %edx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2d54
jmp 0x39cd
leaq 0x5dcc(%rip), %rdi      # 0x9541
callq 0x2080
cmpl $0x0, 0xc(%rsp)
jne 0x38c2
movl (%rsp), %ecx
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x844c
jmp 0x39cd
leaq 0x5e27(%rip), %rdi      # 0x95c9
callq 0x2080
cmpl $0x0, 0xc(%rsp)
jne 0x38e7
movl (%rsp), %edx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x6542
jmp 0x39cd
leaq 0x5db5(%rip), %rdi      # 0x9581
callq 0x2080
cmpl $0x0, 0xc(%rsp)
jne 0x3909
movl (%rsp), %ecx
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x6550
jmp 0x39cd
leaq 0x5d68(%rip), %rdi      # 0x9561
callq 0x2080
cmpl $0x0, 0xc(%rsp)
jne 0x392b
movl (%rsp), %ecx
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x8403
jmp 0x39cd
leaq 0x5cc4(%rip), %rdi      # 0x94ea
callq 0x2080
cmpl $0x0, 0xc(%rsp)
jne 0x394d
movl (%rsp), %edx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x83c9
jmp 0x39cd
leaq 0x5cd1(%rip), %rdi      # 0x9521
callq 0x2080
cmpl $0x0, 0xc(%rsp)
jne 0x396c
movl (%rsp), %ecx
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x8498
jmp 0x39cd
movq 0x977b(%rip), %rax      # 0xcff8
movq (%rax), %rdi
movq 0x40(%rsp), %rdx
leaq 0x5af6(%rip), %rsi      # 0x9382
movq 0x50(%rsp), %rcx
xorl %eax, %eax
callq 0x2180
jmp 0x3e23
leaq 0x20(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x3e74
movl (%rsp), %ecx
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x84e1
jmp 0x398c
leaq 0x20(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x3e74
movl (%rsp), %ecx
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x844c
jmp 0x398c
leaq 0x20(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x3e74
movl (%rsp), %edx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x6542
jmp 0x398c
leaq 0x20(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x3e74
movl (%rsp), %ecx
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x6550
jmp 0x398c
leaq 0x20(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x3e74
movl (%rsp), %ecx
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x8403
jmp 0x398c
leaq 0x20(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x3e74
movl (%rsp), %edx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x83c9
jmp 0x398c
leaq 0x20(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x3e74
movl (%rsp), %ecx
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x8498
leaq 0x5c46(%rip), %rdi      # 0x95d9
callq 0x2080
movq 0x9659(%rip), %rax      # 0xcff8
movq (%rax), %r12
leaq 0x20(%rsp), %rax
movq (%rax), %rdi
leaq 0x18(%rsp), %rax
movq (%rax), %rsi
callq 0x3e98
leaq 0x5a49(%rip), %rsi      # 0x9407
movq %r12, %rdi
movq 0x10(%rsp), %r12
movb $0x1, %al
callq 0x2180
cmpl $0x0, 0x38(%rsp)
je 0x39e3
cmpl $0x5, %ebp
jne 0x39ed
movq %rbx, %rdi
callq 0x8611
jmp 0x39f0
movq %rbx, %r14
movq 0x50(%rsp), %rbp
jmp 0x3a65
movq %rbx, %r14
leaq 0x5a17(%rip), %rdi      # 0x940e
xorl %eax, %eax
callq 0x20f0
movl (%rsp), %edx
movq %r14, %rdi
movq %r15, %rsi
xorl %ecx, %ecx
callq 0x5949
testl %eax, %eax
movq 0x50(%rsp), %rbp
je 0x3e47
leaq 0x5be2(%rip), %rdi      # 0x9604
callq 0x2080
testq %r12, %r12
je 0x3a65
leaq 0x59e7(%rip), %rdi      # 0x941a
xorl %eax, %eax
callq 0x20f0
movq (%rsp), %rdx
movq %r14, %rdi
movq %r12, %rsi
movl $0x1, %ecx
xorl %r8d, %r8d
callq 0x5538
testl %eax, %eax
je 0x3e51
leaq 0x5bb4(%rip), %rdi      # 0x9614
callq 0x2080
testl %r13d, %r13d
je 0x3b7a
leaq 0x5baa(%rip), %rdi      # 0x961f
callq 0x2080
leaq 0x59ad(%rip), %rdi      # 0x942e
xorl %eax, %eax
callq 0x20f0
testq %r12, %r12
je 0x3a9b
leaq 0x59a1(%rip), %rdi      # 0x9435
xorl %eax, %eax
callq 0x20f0
leaq 0x5d00(%rip), %rdi      # 0x97a2
callq 0x2080
cmpq $0x0, (%rsp)
je 0x3b69
movslq %r13d, %rbp
leaq 0x597d(%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 0x3ae7
movl (%r12,%r13,4), %esi
leaq 0x5c48(%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 0x3b43
movslq %r13d, %r12
movzbl (%r14,%r12), %eax
testl %eax, %eax
je 0x3b16
cmpl $0x1, %eax
jne 0x3b1d
movl $0x24, %edi
jmp 0x3b22
movl $0x23, %edi
jmp 0x3b22
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 0x3b01
movl $0xa, %edi
callq 0x2040
incq %r13
movq (%rsp), %rax
cmpq %rbp, %rax
cmovaeq %rbp, %rax
cmpq %rax, %r13
movq 0x10(%rsp), %r12
jb 0x3abf
leaq 0x5aaf(%rip), %rdi      # 0x961f
callq 0x2080
movq 0x50(%rsp), %rbp
cmpl $0x0, 0x58(%rsp)
je 0x3c94
leaq 0x5a9c(%rip), %rdi      # 0x9628
callq 0x2080
testq %r15, %r15
je 0x3be5
leaq 0x58a5(%rip), %rsi      # 0x9442
leaq 0x60(%rsp), %rbx
movq %rbx, %rdi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x2260
movq %rbx, %rdi
callq 0x2080
leaq 0x588a(%rip), %rsi      # 0x9448
movq %rbx, %rdi
callq 0x42fc
movq %rax, %rbx
movq (%rsp), %rdx
movl $0x4, %esi
movq %r15, %rdi
movq %rax, %rcx
callq 0x2280
movq %rbx, %rdi
callq 0x4329
testq %r12, %r12
je 0x3c39
leaq 0x585a(%rip), %rsi      # 0x944b
leaq 0x60(%rsp), %rbx
movq %rbx, %rdi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x2260
movq %rbx, %rdi
callq 0x2080
leaq 0x5836(%rip), %rsi      # 0x9448
movq %rbx, %rdi
callq 0x42fc
movq %rax, %rbx
movq (%rsp), %rdx
movl $0x4, %esi
movq %r12, %rdi
movq %rax, %rcx
callq 0x2280
movq %rbx, %rdi
callq 0x4329
leaq 0x5811(%rip), %rsi      # 0x9451
leaq 0x60(%rsp), %rbx
movq %rbx, %rdi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x2260
movq %rbx, %rdi
callq 0x2080
leaq 0x57e7(%rip), %rsi      # 0x9448
movq %rbx, %rdi
callq 0x42fc
movq %rax, %rbx
movq (%rsp), %rdx
movl $0x1, %esi
movq %r14, %rdi
movq %rax, %rcx
callq 0x2280
movq %rbx, %rdi
callq 0x4329
cmpl $0x0, 0x34(%rsp)
jne 0x3cab
jmp 0x3dec
cmpl $0x0, 0x34(%rsp)
je 0x3dec
leaq 0x5982(%rip), %rdi      # 0x9628
callq 0x2080
leaq 0x57a6(%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 0x5772(%rip), %rsi      # 0x9448
movq %rbx, %rdi
callq 0x42fc
movq %rax, 0x38(%rsp)
cmpl $0x0, 0x4c(%rsp)
je 0x3d1d
leaq 0x576e(%rip), %rsi      # 0x945f
leaq 0x60(%rsp), %r12
movq %r12, %rdi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x2260
movq %r12, %rdi
callq 0x2080
leaq 0x5754(%rip), %rsi      # 0x9466
movq %r12, %rdi
callq 0x42fc
movq %rax, %r13
cmpq $0x0, (%rsp)
je 0x3ddd
leaq 0x160(%rsp), %r12
xorl %ebx, %ebx
movq %r12, %rdi
leaq 0x572c(%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 0x38(%rsp), %rcx
callq 0x2280
cmpl $0x0, 0x4c(%rsp)
je 0x3dcc
movslq (%r15,%rbx,4), %rax
addq %rbx, %rax
cmpq %rax, %rbx
jae 0x3db8
movq %rbx, %rbp
movb (%r14,%rbp), %al
cmpl $0x0, 0x2c(%rsp)
je 0x3da0
movsbl %al, %edi
movq %r13, %rsi
callq 0x2160
incq %rbp
movslq (%r15,%rbx,4), %rax
addq %rbx, %rax
cmpq %rax, %rbp
jb 0x3d79
jmp 0x3db8
movzbl %al, %ecx
testl %ecx, %ecx
je 0x3db0
cmpl $0x1, %ecx
jne 0x3db4
movb $0x24, %al
jmp 0x3d84
movb $0x23, %al
jmp 0x3d84
decb %al
jmp 0x3d84
cmpl $0x0, 0x2c(%rsp)
jne 0x3dcc
movl $0xa, %edi
movq %r13, %rsi
callq 0x2160
movslq (%r15,%rbx,4), %rax
addq %rax, %rbx
cmpq (%rsp), %rbx
jb 0x3d32
movq 0x38(%rsp), %rdi
callq 0x4329
movq 0x10(%rsp), %r12
testq %r15, %r15
setne %al
cmpl $0x0, 0x5c(%rsp)
setne %cl
andb %al, %cl
cmpb $0x1, %cl
je 0x3e37
movq %r14, %rdi
callq 0x8611
testq %r15, %r15
je 0x3e16
movq %r15, %rdi
callq 0x8611
testq %r12, %r12
je 0x3e23
movq %r12, %rdi
callq 0x8611
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
movq %r14, %rdx
callq 0x233f
jmp 0x3e0e
callq 0x22ef
jmp 0x3a27
callq 0x231d
jmp 0x3a65
movq (%rbx), %rdi
callq 0x31f1
callq 0x22da
callq 0x22b0
callq 0x22c5
nop