// File: /workspace/github_c_makefile_star2_O2/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 $0x1b8, %rsp            # imm = 0x1B8
andq $0x0, 0x20(%rsp)
andq $0x0, 0x18(%rsp)
andq $0x0, 0x58(%rsp)
movq %rsi, %rbx
movl %edi, %r14d
pushq $0xa
popq %rax
movq %rax, 0x8(%rsp)
movl $0x0, 0x50(%rsp)
leaq 0x5df8(%rip), %r15      # 0x835f
leaq 0x5ac2(%rip), %r13      # 0x8030
movl $0x0, 0x30(%rsp)
movl $0x0, 0x64(%rsp)
xorl %r12d, %r12d
movl $0x0, 0x38(%rsp)
movl $0x0, 0x54(%rsp)
movl $0x0, 0x40(%rsp)
movl $0x0, 0x14(%rsp)
xorl %ebp, %ebp
movl %r14d, %edi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x2210
leal -0x62(%rax), %ecx
cmpl $0x14, %ecx
ja 0x25cc
movslq (%r13,%rcx,4), %rax
addq %r13, %rax
jmpq *%rax
pushq $0x1
popq %rax
movl %eax, 0x40(%rsp)
jmp 0x25a3
cmpl $0x41, %eax
je 0x2661
cmpl $0x4c, %eax
je 0x267a
cmpl $-0x1, %eax
je 0x268a
cmpl $0x3f, %eax
jne 0x25a3
jmp 0x324d
movq 0x99e0(%rip), %rax      # 0xbfd8
movq (%rax), %rdi
callq 0x2230
movl %eax, 0x30(%rsp)
jmp 0x25a3
incl 0x64(%rsp)
jmp 0x25a3
movq 0x99c5(%rip), %rax      # 0xbfd8
movq (%rax), %rdi
callq 0x2230
cltq
movq %rax, 0x58(%rsp)
jmp 0x25a3
incl 0x14(%rsp)
jmp 0x25a3
pushq $0x1
popq %rax
movl %eax, 0x38(%rsp)
jmp 0x25a3
incl %r12d
jmp 0x25a3
incl 0x50(%rsp)
jmp 0x25a3
movl $0x0, 0x40(%rsp)
jmp 0x25a3
incl %ebp
jmp 0x25a3
movq 0x9970(%rip), %rax      # 0xbfd8
movq (%rax), %rdi
callq 0x2230
movq %rax, 0x8(%rsp)
jmp 0x25a3
pushq $0x1
popq %rax
movl %eax, 0x38(%rsp)
movl %eax, 0x54(%rsp)
jmp 0x25a3
movq 0x9947(%rip), %rax      # 0xbfd8
movq (%rax), %rdi
callq 0x77a6
movq 0x9930(%rip), %rax      # 0xbfd0
movslq (%rax), %rcx
leal 0x1(%rcx), %edx
cmpl %r14d, %edx
jne 0x3227
movl %r14d, (%rax)
movq (%rbx,%rcx,8), %rax
movq %rax, 0x68(%rsp)
testl %ebp, %ebp
movl %r12d, 0x4c(%rsp)
movl 0x30(%rsp), %r13d
jle 0x2708
leaq 0x5ca0(%rip), %rdi      # 0x8370
callq 0x2080
xorl %eax, %eax
testl %r14d, %r14d
cmovlel %eax, %r14d
leaq 0x5c99(%rip), %r15      # 0x837e
xorl %r12d, %r12d
cmpq %r12, %r14
je 0x2700
movq (%rbx,%r12,8), %rsi
movq %r15, %rdi
xorl %eax, %eax
callq 0x20f0
incq %r12
jmp 0x26e8
pushq $0xa
popq %rdi
callq 0x2040
andq $0x0, (%rsp)
cmpl $0x0, 0x40(%rsp)
movl %r13d, 0x30(%rsp)
je 0x27bf
leaq 0x5f8a(%rip), %rsi      # 0x86ae
movq 0x68(%rsp), %rbp
movq %rbp, %rdi
callq 0x21f0
testq %rax, %rax
je 0x322f
movq %rax, %rbx
pushq $0x2
popq %rdx
movq %rax, %rdi
xorl %esi, %esi
callq 0x21d0
testl %eax, %eax
jne 0x3238
movq %rbx, %rdi
callq 0x2190
movq %rax, %r15
movq %rbx, %rdi
callq 0x2110
leaq 0x1(%r15), %r14
movq %r14, %rdi
callq 0x76d0
testq %rax, %rax
je 0x3241
movq %rax, %r13
pushq $0x1
popq %rsi
movq %rax, %rdi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x2090
movq %r14, (%rsp)
movb $0x0, (%r13,%r15)
leaq 0x5c10(%rip), %rdi      # 0x83af
movq %r14, %rsi
xorl %eax, %eax
callq 0x20f0
leaq 0x5c0e(%rip), %rdi      # 0x83be
pushq $0x4
popq %rsi
xorl %eax, %eax
callq 0x20f0
jmp 0x284b
leaq 0x58(%rsp), %rsi
movq %rsp, %rdx
movq 0x68(%rsp), %rbp
movq %rbp, %rdi
callq 0x3b34
testq %rax, %rax
je 0x2ac4
movq %rax, %rbx
movq 0x58(%rsp), %rsi
movq %rsp, %r14
movq %rax, %rdi
movq %r14, %rdx
callq 0x239c
movq %rax, %r13
movq 0x58(%rsp), %rsi
leaq 0x5ba4(%rip), %rdi      # 0x83a6
xorl %r15d, %r15d
xorl %eax, %eax
callq 0x20f0
movq (%r14), %rsi
leaq 0x5b99(%rip), %rdi      # 0x83af
xorl %eax, %eax
callq 0x20f0
leaq 0x5b9a(%rip), %rdi      # 0x83be
pushq $0x4
popq %rsi
xorl %eax, %eax
callq 0x20f0
cmpq 0x58(%rsp), %r15
jae 0x2843
movq (%rbx,%r15,8), %rdi
callq 0x77a6
incq %r15
jmp 0x282e
movq %rbx, %rdi
callq 0x77a6
cmpl $0x0, 0x50(%rsp)
setne %al
movq 0x8(%rsp), %rdx
cmpl $0x5, %edx
sete %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x2883
movq (%rsp), %r12
leaq 0x1(%r12), %rdi
callq 0x76d0
movq %rax, %rbx
movq %rax, %rdi
movq %r13, %rsi
callq 0x2070
jmp 0x288e
movq (%rsp), %r12
cmpl $0xb, %edx
jge 0x2904
xorl %ebx, %ebx
leaq (,%r12,4), %r15
movq %r15, %rdi
callq 0x76d0
movq %rax, %r14
xorl %eax, %eax
movq 0x8(%rsp), %rcx
cmpq %rax, %r12
je 0x28b7
andl $0x0, (%r14,%rax,4)
incq %rax
jmp 0x28a8
cmpl $0x6, %ecx
jge 0x2911
xorl %r15d, %r15d
leal -0x1(%rcx), %eax
cmpl $0xa, %eax
movl 0x4c(%rsp), %r12d
movq %r15, 0x28(%rsp)
ja 0x2c1e
leaq 0x57a8(%rip), %rcx      # 0x8084
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x5cf4(%rip), %rdi      # 0x85e0
callq 0x2080
movl (%rsp), %edx
movq %r13, %rdi
movq %r14, %rsi
callq 0x54e7
jmp 0x2c19
leaq (,%r12,4), %r15
xorl %r14d, %r14d
xorl %ebx, %ebx
movq %r15, %rdi
callq 0x76d0
movq %rax, %r15
xorl %eax, %eax
movq 0x8(%rsp), %rcx
cmpq %rax, %r12
je 0x28bf
andl $0x0, (%r15,%rax,4)
incq %rax
jmp 0x2923
leaq 0x5c5b(%rip), %rdi      # 0x8594
callq 0x2080
movl (%rsp), %edx
movq %r13, %rdi
movq %r14, %rsi
callq 0x43e0
jmp 0x2c19
leaq 0x5baa(%rip), %rdi      # 0x8502
callq 0x2080
cmpl $0x0, 0x14(%rsp)
jne 0x2ae9
movl (%rsp), %ecx
movq %r13, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x7634
jmp 0x2c19
leaq 0x5c36(%rip), %rdi      # 0x85bb
callq 0x2080
movl (%rsp), %edx
movq %r13, %rdi
movq %r14, %rsi
callq 0x55cb
jmp 0x2c19
leaq 0x5c06(%rip), %rdi      # 0x85aa
callq 0x2080
movl (%rsp), %edx
movq %r13, %rdi
movq %r14, %rsi
callq 0x5271
jmp 0x2c19
leaq 0x5b7e(%rip), %rdi      # 0x8541
callq 0x2080
cmpl $0x0, 0x14(%rsp)
jne 0x2b0e
movl (%rsp), %ecx
movq %r13, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x75a5
jmp 0x2c19
leaq 0x5bd9(%rip), %rdi      # 0x85c9
callq 0x2080
cmpl $0x0, 0x14(%rsp)
jne 0x2b33
movl (%rsp), %edx
movq %r13, %rdi
movq %r14, %rsi
callq 0x5dcf
jmp 0x2c19
leaq 0x5b67(%rip), %rdi      # 0x8581
callq 0x2080
cmpl $0x0, 0x14(%rsp)
jne 0x2b55
movl (%rsp), %ecx
movq %r13, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x5ddb
jmp 0x2c19
leaq 0x5b1a(%rip), %rdi      # 0x8561
callq 0x2080
cmpl $0x0, 0x14(%rsp)
jne 0x2b77
movl (%rsp), %ecx
movq %r13, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x755e
jmp 0x2c19
leaq 0x5a76(%rip), %rdi      # 0x84ea
callq 0x2080
cmpl $0x0, 0x14(%rsp)
jne 0x2b99
movl (%rsp), %edx
movq %r13, %rdi
movq %r15, %rsi
callq 0x752b
jmp 0x2c19
leaq 0x5a83(%rip), %rdi      # 0x8521
callq 0x2080
cmpl $0x0, 0x14(%rsp)
jne 0x2bb8
movl (%rsp), %ecx
movq %r13, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x75ed
jmp 0x2c19
movq 0x952d(%rip), %rax      # 0xbff8
movq (%rax), %rdi
movq 0x58(%rsp), %rdx
leaq 0x58a8(%rip), %rsi      # 0x8382
movq %rbp, %rcx
xorl %eax, %eax
callq 0x2180
jmp 0x3043
leaq 0x20(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x3258
movl (%rsp), %ecx
movq %r13, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x7634
jmp 0x2bd8
leaq 0x20(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x3258
movl (%rsp), %ecx
movq %r13, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x75a5
jmp 0x2bd8
leaq 0x20(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x3258
movl (%rsp), %edx
movq %r13, %rdi
movq %r14, %rsi
callq 0x5dcf
jmp 0x2bd8
leaq 0x20(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x3258
movl (%rsp), %ecx
movq %r13, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x5ddb
jmp 0x2bd8
leaq 0x20(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x3258
movl (%rsp), %ecx
movq %r13, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x755e
jmp 0x2bd8
leaq 0x20(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x3258
movl (%rsp), %edx
movq %r13, %rdi
movq %r15, %rsi
callq 0x752b
jmp 0x2bd8
leaq 0x20(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x3258
movl (%rsp), %ecx
movq %r13, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x75ed
leaq 0x59fa(%rip), %rdi      # 0x85d9
callq 0x2080
movq 0x940d(%rip), %rax      # 0xbff8
movq (%rax), %r15
leaq 0x20(%rsp), %rax
movq (%rax), %rdi
leaq 0x18(%rsp), %rax
movq (%rax), %rsi
callq 0x327c
leaq 0x57fd(%rip), %rsi      # 0x8407
movq %r15, %rdi
movq 0x28(%rsp), %r15
movb $0x1, %al
callq 0x2180
movq 0x8(%rsp), %rcx
cmpl $0x0, 0x50(%rsp)
je 0x2c34
cmpl $0x5, %ecx
jne 0x2c3e
movq %r13, %rdi
callq 0x77a6
jmp 0x2c41
movq %r13, %rbx
movl 0x30(%rsp), %r13d
jmp 0x2cb4
movq %r13, %rbx
leaq 0x57c6(%rip), %rdi      # 0x840e
xorl %eax, %eax
callq 0x20f0
movl (%rsp), %edx
movq %rbx, %rdi
movq %r14, %rsi
xorl %ecx, %ecx
callq 0x527b
testl %eax, %eax
movl 0x30(%rsp), %r13d
je 0x31d9
leaq 0x5991(%rip), %rdi      # 0x8604
callq 0x2080
testq %r15, %r15
je 0x2cb4
leaq 0x5796(%rip), %rdi      # 0x841a
xorl %eax, %eax
callq 0x20f0
movq (%rsp), %rdx
pushq $0x1
popq %rcx
movq %rbx, %rdi
movq %r15, %rsi
xorl %r8d, %r8d
callq 0x477f
testl %eax, %eax
je 0x3206
leaq 0x5965(%rip), %rdi      # 0x8614
callq 0x2080
testl %r13d, %r13d
je 0x2db8
leaq 0x595b(%rip), %rdi      # 0x861f
callq 0x2080
leaq 0x575e(%rip), %rdi      # 0x842e
xorl %eax, %eax
callq 0x20f0
testq %r15, %r15
je 0x2cea
leaq 0x5752(%rip), %rdi      # 0x8435
xorl %eax, %eax
callq 0x20f0
leaq 0x5ab1(%rip), %rdi      # 0x87a2
callq 0x2080
movslq %r13d, %rax
movq %rax, 0x30(%rsp)
pushq $0x23
popq %rbp
pushq $0x24
popq %r12
xorl %r13d, %r13d
movq (%rsp), %rax
movq 0x30(%rsp), %rcx
cmpq %rcx, %rax
cmovaeq %rcx, %rax
cmpq %rax, %r13
jae 0x2da2
movl (%r14,%r13,4), %edx
leaq 0x570d(%rip), %rdi      # 0x8439
movq %r13, %rsi
xorl %eax, %eax
callq 0x20f0
testq %r15, %r15
je 0x2d4d
movl (%r15,%r13,4), %esi
leaq 0x59e2(%rip), %rdi      # 0x8728
xorl %eax, %eax
callq 0x20f0
movslq %r13d, %r15
movslq (%r14,%r13,4), %rax
addq %r13, %rax
movq (%rsp), %rcx
cmpq %rcx, %rax
cmovaeq %rcx, %rax
cltq
cmpq %rax, %r15
jge 0x2d8d
movzbl (%rbx,%r15), %eax
movl %ebp, %edi
testl %eax, %eax
je 0x2d83
cmpl $0x1, %eax
jne 0x2d7e
movl %r12d, %edi
jmp 0x2d83
decb %al
movsbl %al, %edi
callq 0x2040
incq %r15
jmp 0x2d50
pushq $0xa
popq %rdi
callq 0x2040
incq %r13
movq 0x28(%rsp), %r15
jmp 0x2d08
leaq 0x5876(%rip), %rdi      # 0x861f
callq 0x2080
movl 0x4c(%rsp), %r12d
movq 0x68(%rsp), %rbp
cmpl $0x0, 0x64(%rsp)
je 0x2ed4
leaq 0x585e(%rip), %rdi      # 0x8628
callq 0x2080
testq %r14, %r14
je 0x2e26
leaq 0x5667(%rip), %rsi      # 0x8442
leaq 0x70(%rsp), %r15
movq %r15, %rdi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x2260
movq %r15, %rdi
callq 0x2080
leaq 0x564c(%rip), %rsi      # 0x8448
movq %r15, %rdi
callq 0x36a4
movq %rax, %r15
movq (%rsp), %rdx
pushq $0x4
popq %rsi
movq %r14, %rdi
movq %rax, %rcx
callq 0x2280
movq %r15, %rdi
movq 0x28(%rsp), %r15
callq 0x36d1
testq %r15, %r15
je 0x2e7b
movq %r15, %r13
leaq 0x5616(%rip), %rsi      # 0x844b
leaq 0x70(%rsp), %r15
movq %r15, %rdi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x2260
movq %r15, %rdi
callq 0x2080
leaq 0x55f2(%rip), %rsi      # 0x8448
movq %r15, %rdi
callq 0x36a4
movq %rax, %r15
movq (%rsp), %rdx
pushq $0x4
popq %rsi
movq %r13, %rdi
movq %rax, %rcx
callq 0x2280
movq %r15, %rdi
callq 0x36d1
leaq 0x55cf(%rip), %rsi      # 0x8451
leaq 0x70(%rsp), %r15
movq %r15, %rdi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x2260
movq %r15, %rdi
callq 0x2080
leaq 0x55a5(%rip), %rsi      # 0x8448
movq %r15, %rdi
callq 0x36a4
movq %rax, %r15
movq (%rsp), %rdx
pushq $0x1
popq %rsi
movq %rbx, %rdi
movq %rax, %rcx
callq 0x2280
movq %r15, %rdi
callq 0x36d1
cmpl $0x0, 0x38(%rsp)
jne 0x2eeb
jmp 0x3016
cmpl $0x0, 0x38(%rsp)
je 0x3016
leaq 0x5742(%rip), %rdi      # 0x8628
callq 0x2080
leaq 0x5566(%rip), %rsi      # 0x8458
xorl %r13d, %r13d
leaq 0x70(%rsp), %r15
movq %r15, %rdi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x2260
movq %r15, %rdi
callq 0x2080
leaq 0x5532(%rip), %rsi      # 0x8448
movq %r15, %rdi
callq 0x36a4
movq %rax, 0x38(%rsp)
cmpl $0x0, 0x54(%rsp)
je 0x2f5d
leaq 0x552e(%rip), %rsi      # 0x845f
leaq 0x70(%rsp), %r15
movq %r15, %rdi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x2260
movq %r15, %rdi
callq 0x2080
leaq 0x5514(%rip), %rsi      # 0x8466
movq %r15, %rdi
callq 0x36a4
movq %rax, %r13
leaq 0x170(%rsp), %r15
xorl %ebp, %ebp
cmpq (%rsp), %rbp
jae 0x300c
movq %r15, %rdi
leaq 0x54ed(%rip), %rsi      # 0x8468
movq %rbp, %rdx
xorl %eax, %eax
callq 0x2260
movq %r15, %rdi
callq 0x20c0
movq %r15, %rdi
pushq $0x1
popq %rsi
movq %rax, %rdx
movq 0x38(%rsp), %rcx
callq 0x2280
cmpl $0x0, 0x54(%rsp)
je 0x3000
movq %rbp, %r12
movslq (%r14,%rbp,4), %rax
addq %rbp, %rax
cmpq %rax, %r12
jae 0x2fe9
movb (%rbx,%r12), %al
cmpl $0x0, 0x40(%rsp)
je 0x2fd1
movsbl %al, %edi
movq %r13, %rsi
callq 0x2160
incq %r12
jmp 0x2faa
movzbl %al, %ecx
testl %ecx, %ecx
je 0x2fe1
cmpl $0x1, %ecx
jne 0x2fe5
movb $0x24, %al
jmp 0x2fc1
movb $0x23, %al
jmp 0x2fc1
decb %al
jmp 0x2fc1
cmpl $0x0, 0x40(%rsp)
movl 0x4c(%rsp), %r12d
jne 0x3000
pushq $0xa
popq %rdi
movq %r13, %rsi
callq 0x2160
movslq (%r14,%rbp,4), %rax
addq %rax, %rbp
jmp 0x2f67
movq 0x38(%rsp), %rdi
callq 0x36d1
testq %r14, %r14
setne %al
testl %r12d, %r12d
setne %cl
andb %al, %cl
cmpb $0x1, %cl
je 0x3057
movq %rbx, %rdi
callq 0x77a6
movq %r14, %rdi
callq 0x77a6
movq 0x28(%rsp), %rdi
callq 0x77a6
xorl %eax, %eax
addq $0x1b8, %rsp            # imm = 0x1B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
movq (%rsp), %rcx
xorl %ebp, %ebp
xorl %r15d, %r15d
xorl %r13d, %r13d
cmpq %rax, %rcx
je 0x307f
movslq (%r14,%rax,4), %rdx
addq %rdx, %r13
cmpl %ebp, %edx
cmovgl %edx, %ebp
cmovgl %eax, %r15d
incq %rax
jmp 0x3065
leaq 0x54b8(%rip), %rdi      # 0x853e
callq 0x2080
leaq 0x53db(%rip), %rdi      # 0x846d
xorl %r12d, %r12d
movl %r15d, %esi
movl %ebp, %edx
xorl %eax, %eax
callq 0x20f0
movq %r13, %xmm1
movq 0x4f62(%rip), %xmm2     # 0x8010
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x4f66(%rip), %xmm3     # 0x8020
subpd %xmm3, %xmm1
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
movq (%rsp), %xmm1
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
subpd %xmm3, %xmm1
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
divsd %xmm2, %xmm0
leaq 0x5391(%rip), %rdi      # 0x847f
movb $0x1, %al
callq 0x20f0
movq (%rsp), %rax
xorl %ebp, %ebp
xorl %r15d, %r15d
cmpq %rax, %r12
jae 0x3114
incl %r15d
movslq (%r14,%r12,4), %rcx
cmpl %ebp, %ecx
cmovgl %ecx, %ebp
addq %rcx, %r12
jmp 0x30fe
leaq 0x5423(%rip), %r12      # 0x853e
movq %r12, %rdi
callq 0x2080
leaq 0x5368(%rip), %rdi      # 0x8492
movl %r15d, %esi
xorl %eax, %eax
callq 0x20f0
movsd (%rsp), %xmm1
movsd 0x4ecf(%rip), %xmm0     # 0x8010
unpcklps %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
movapd 0x4ed4(%rip), %xmm0     # 0x8020
subpd %xmm0, %xmm1
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
cvtsi2sd %r15d, %xmm1
movsd %xmm1, 0x40(%rsp)
divsd %xmm1, %xmm0
leaq 0x533f(%rip), %rdi      # 0x84b1
movb $0x1, %al
callq 0x20f0
leaq 0x5348(%rip), %rdi      # 0x84c8
movl %ebp, %esi
xorl %eax, %eax
callq 0x20f0
movq %r12, %rdi
callq 0x2080
movq 0x8e60(%rip), %rax      # 0xbff8
movq (%rax), %rdi
movsd (%rsp), %xmm1
unpcklps 0x4e69(%rip), %xmm1     # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x4e71(%rip), %xmm1     # 0x8020
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
divsd 0x40(%rsp), %xmm0
leaq 0x5315(%rip), %rsi      # 0x84dd
movl %r15d, %edx
movl %ebp, %ecx
movb $0x1, %al
callq 0x2180
jmp 0x3029
leaq 0x5411(%rip), %rdi      # 0x85f1
callq 0x2080
movq 0x8e0c(%rip), %rax      # 0xbff8
movq (%rax), %rcx
leaq 0x521d(%rip), %rdi      # 0x8413
pushq $0x6
popq %rsi
pushq $0x1
popq %rdx
callq 0x2280
jmp 0x2c78
movq 0x8deb(%rip), %rax      # 0xbff8
movq (%rax), %rcx
leaq 0x5208(%rip), %rdi      # 0x841f
pushq $0xe
popq %rsi
pushq $0x1
popq %rdx
callq 0x2280
jmp 0x2cb4
movq (%rbx), %rdi
callq 0x244d
leaq 0x51a1(%rip), %rdi      # 0x83d7
jmp 0x3248
leaq 0x51af(%rip), %rdi      # 0x83ee
jmp 0x3248
leaq 0x51b2(%rip), %rdi      # 0x83fa
callq 0x2200
pushq $0x1
popq %rdi
callq 0x2270
nopl (%rax)