// File: /workspace/github_c_makefile_star2_O0/felipelouza[P]egap/tools/mergelcp.c
// Function: main
int main(int argc, char **argv) {                   
  
  extern char *optarg;
  extern int optind, opterr, optopt;
  
  int c=0, time=0, verbose=0;
  char *c_file=NULL;
  int heap_size=HEAP_SIZE;
  int pos_size=4, lcp_size=4;
  size_t RAM=0;
  int k=0, e;
  
  while ((c=getopt(argc, argv, "s:vthk:m:")) != -1) {
    switch (c)
    {
      case 's':
        heap_size=atoi(optarg); break;  // compute LCP and output in Gap format 
      case 'v':
        verbose++; break;
      case 't':
        time++; break;
      case 'h':
        usage(argv[0]); break;       // show usage and stop
      case 'k':
        k=atoi(optarg); break;       // k-truncated LCP merging
      case 'm':
        RAM=(size_t)atoi(optarg)*MB; break;
      case '?':
        exit(EXIT_FAILURE);
    }
  }
  
  if(verbose>0) {
    puts("Command line:");
    int i;
    for(i=0;i<argc;i++)
      printf(" %s",argv[i]);
    puts("");
  }

  if(optind+3==argc) {
    c_file=argv[optind++];
    pos_size=atoi(argv[optind++]);
    lcp_size=atoi(argv[optind++]);
    
    if(pos_size+lcp_size>16) {
      fprintf(stderr,"POS_SIZE+LCP_SIZE can be at most 16\n");
      exit(EXIT_FAILURE);
    } 
    if(pos_size<=0 || lcp_size<=0) {
      fprintf(stderr,"Both POS_SIZE LCP_SIZE must be at least 1\n");
      exit(EXIT_FAILURE);
    } 
  }
  else{
    usage(argv[0]);
  }
  
  if(heap_size<2){
    puts("ERROR: s must be larger than 1");
    exit(EXIT_FAILURE);
  }

  
  //config
  char c_lcp[PATH_MAX], c_size[PATH_MAX];
  char c_lcp_multi[PATH_MAX], c_size_multi[PATH_MAX]; //multilevel
  
  sprintf(c_lcp, "%s.pair.lcp",  c_file);
  sprintf(c_size, "%s.size.lcp", c_file);
  
  printf("INPUT:\t%s, %s\n", c_lcp, c_size);
  
  if(verbose){
    printf("sizeof(pos) = %d bytes\n", pos_size);
    printf("sizeof(lcp) = %d bytes\n", lcp_size);
  }

  printf("##\n");
  if(RAM){
    if(RAM<pow(2,20)) printf("RAM = %.2lf KB\n", RAM/pow(2,10));
    else if (RAM>=pow(2,20) && RAM<pow(2,30)) printf("RAM = %.2lf MB\n", RAM/pow(2,20));
    else printf("RAM = %.2lf GB\n", (double)RAM/pow(2,30));
    //fprintf(stderr,"RAM = %.2lf GB\n", (double)RAM/pow(2,30));
  }
  else printf("RAM = unlimited\n");

  // inits 
  time_t t_start=0, t_total=0;
  clock_t c_start=0, c_total=0;
   
  time_start(&t_start, &c_start);
  time_start(&t_total, &c_total);
  
  //alloc heap
  int level=0, onelevel=0;
  size_t i, blocks;
  FILE *f_size, *f_lcp;
  heap *h;
  size_t size, seek=0;
  size_t sum;

  f_size = fopen(c_size, "rb");//header file
  size_t n;
  e = fread(&n, sizeof(size_t), 1, f_size);
  if(e!=1) {perror (__func__); exit(EXIT_FAILURE);}
  printf("Number of LCP entries in output file: = %zu\n", n);
  
  //LEVEL 1 
  do{ // multilevel merging
  
    //printf("INPUT: %s\t%s\n", c_lcp, c_size);
    seek=0;
    
    blocks=1; i=0; sum=0;
    level++;
    h = heap_alloc(heap_size, c_lcp, level, pos_size, lcp_size, RAM);
    
    
    //output
    sprintf(c_lcp_multi, "%s.pair.%d.lcp", c_file, level);  
    f_lcp = file_open(c_lcp_multi, "wb");//lists file
    
    sprintf(c_size_multi, "%s.size.%d.lcp", c_file, level);
    FILE* f_size_multi = file_open(c_size_multi, "wb");
    
    /**/
    while(fread(&size, sizeof(size_t), 1, f_size)){
      //init heap
      #if DEBUG
        printf("%zu (%zu): ", size, seek);
      #endif
      heap_insert(h, seek); //size == seek
      seek+=size;
      
      if(++i == heap_size){
            
        heap_sort_level(h, f_lcp, &sum, c_file, level, k);     
        fwrite(&sum, sizeof(size_t), 1, f_size_multi);
      
        //new heap
        heap_free(h, f_lcp, level);
        h = heap_alloc(heap_size, c_lcp, level, pos_size, lcp_size, RAM);
        
        blocks++;
        i=0;
        sum=0;
      }
    }
    
    if(i){//last block
      
      if(blocks==1 && level==1){
        onelevel=1;
        fclose(f_lcp); fclose(f_size); fclose(f_size_multi);
        //empty files
        remove(c_size_multi);
        remove(c_lcp_multi);
        break;
      }
      
      heap_sort_level(h, f_lcp, &sum, c_file, level, k);
      fwrite(&sum, sizeof(size_t), 1, f_size_multi);    
    }
        
    heap_free(h, f_lcp, level);
    fclose(f_lcp); fclose(f_size); fclose(f_size_multi);
    
    if(verbose)
      printf("%zux%d+%zu\t\n", blocks-1, heap_size, i);
    
    if(level>1){//do not remove the original inputs
      remove(c_lcp);
      remove(c_size);
    }
    
    //input for the next level
    sprintf(c_lcp, "%s.pair.%d.lcp", c_file, level);
    sprintf(c_size, "%s.size.%d.lcp", c_file, level);

    f_size = fopen(c_size, "rb");//header file
  }
  while(blocks>heap_size);
  
  if(onelevel){
    if(verbose)
      printf("%zux%d+%zu\t\n", blocks-1, heap_size, i);
  }
  else{
    /**/
    if(time){
      printf("## LEVEL 1 ##\n");
      //fprintf(stderr,"%.6lf\n", time_stop(t_start, c_start));
      time_stop(t_start, c_start);
      time_start(&t_start, &c_start);
    }
    /**/
    
    //LEVEL 2
    
    //printf("INPUT: %s\t%s\n", c_lcp_multi, c_size_multi);
    if(verbose)
      printf("%dx%zu\t\n", 1, blocks);
    
    f_size = file_open(c_size_multi, "rb");//header file

    h = heap_alloc(blocks, c_lcp_multi, 0, pos_size, lcp_size, RAM);
    seek=0;
    
    while(fread(&size, sizeof(size_t), 1, f_size)){
      #if DEBUG
        printf("%zu (%zu): ", size, seek);
      #endif
      heap_insert(h, seek); //size == seek
      seek+=size;
    }
    
    fclose(f_size);
  }
  
  sprintf(c_lcp, "%s.%d.lcp", c_file, lcp_size);//linal
  f_lcp = file_open(c_lcp, "wb");
    
  size_t total=0;
  
  #if CHECK == 1
    if(heap_sort_level(h, f_lcp, &total, c_file, 0, k)) printf("isSorted!!\n");
    else printf("isNotSorted!!\n");
  #else
    heap_sort_level(h, f_lcp, &total, c_file, 0, k);
  #endif
  
  printf("N = %zu (%zu)\n", total, n);

  if(k){
    //complete LCP empty entries
    /**/
    int64_t curr=total;
    int64_t pos=n;

    pair aux=lcp(k); //k-truncated LCP-values
    for(;curr<pos;curr++){
      #if CHECK == 1
        fprintf(stderr,"** %lu, %lu (lcp = %lu)\n", pos, curr, lcp(aux));
      #endif
      heap_write(h, f_lcp, aux, level);
    }
    /**/
  }
  
  heap_free(h, f_lcp, 0);
  fclose(f_lcp);
  
  /**/
  if(time){
    printf("## LEVEL 2 ##\n");
    time_stop(t_start, c_start);
  }
  /**/
  
  if(time){
    printf("## TOTAL ##\n");
    fprintf(stderr,"%.6lf\n", time_stop(t_total, c_total));
  }
  
  printf("OUTPUT:\t%s\n", c_lcp);
  
  remove(c_lcp_multi);
  remove(c_size_multi);
  
  //checking
  #if CHECK == 2
    printf("CHECK:\t");
    char c_pos[500];
    sprintf(c_pos, "%s.pos.lcp", c_file);
    FILE* f_pos = file_open(c_pos, "rb");
    f_lcp = file_open(c_lcp, "rb");
    uint64_t pos=0,lcp=0;
    int true=1; 
    size_t previous=0;
    sum=0;
    while(fread(&pos, pos_size, 1, f_pos)){
      fread(&lcp, lcp_size, 1, f_lcp);
      #if DEBUG
        printf("<%lu, %lu> ", pos, lcp);
      #endif
      if(previous>pos){
        true=0; break;
      }
      previous=pos;
      sum++;
    }
    printf("\n");
    if(true) printf("isSorted!! (%zu)\n", sum);
    else printf("isNotSorted!!\n");

    fclose(f_pos);
    fclose(f_lcp);
  #endif

  /**/
  sprintf(c_lcp, "%s.pair.lcp",  c_file);
  sprintf(c_size, "%s.size.lcp", c_file);

  remove(c_lcp);
  remove(c_size);
  /**/


return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x4140, %rsp           # imm = 0x4140
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movq $0x0, -0x28(%rbp)
movl $0x100, -0x2c(%rbp)     # imm = 0x100
movl $0x4, -0x30(%rbp)
movl $0x4, -0x34(%rbp)
movq $0x0, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0x3b86(%rip), %rdx      # 0x534e
callq 0x1180
movl %eax, -0x14(%rbp)
cmpl $-0x1, %eax
je 0x187e
movl -0x14(%rbp), %eax
addl $-0x3f, %eax
movl %eax, %ecx
movq %rcx, -0x4108(%rbp)
subl $0x37, %eax
ja 0x1879
movq -0x4108(%rbp), %rax
leaq 0x3851(%rip), %rcx      # 0x5050
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x67c9(%rip), %rax      # 0x7fd8
movq (%rax), %rdi
callq 0x11b0
movl %eax, -0x2c(%rbp)
jmp 0x1879
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x1879
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x1879
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x16c0
jmp 0x1879
movq 0x6791(%rip), %rax      # 0x7fd8
movq (%rax), %rdi
callq 0x11b0
movl %eax, -0x44(%rbp)
jmp 0x1879
movq 0x677d(%rip), %rax      # 0x7fd8
movq (%rax), %rdi
callq 0x11b0
cltq
shlq $0x14, %rax
movq %rax, -0x40(%rbp)
jmp 0x1879
movl $0x1, %edi
callq 0x11d0
jmp 0x17ba
cmpl $0x0, -0x1c(%rbp)
jle 0x18d0
leaq 0x3acd(%rip), %rdi      # 0x5358
callq 0x1070
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x18c4
movq -0x10(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
leaq 0x3ab4(%rip), %rdi      # 0x5366
movb $0x0, %al
callq 0x10d0
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x1897
leaq 0x3c14(%rip), %rdi      # 0x54df
callq 0x1070
movq 0x66f9(%rip), %rax      # 0x7fd0
movl (%rax), %eax
addl $0x3, %eax
cmpl -0x8(%rbp), %eax
jne 0x19bc
movq -0x10(%rbp), %rax
movq 0x66e0(%rip), %rcx      # 0x7fd0
movl (%rcx), %ecx
movl %ecx, %esi
addl $0x1, %esi
movq 0x66d2(%rip), %rdx      # 0x7fd0
movl %esi, (%rdx)
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq 0x66ba(%rip), %rcx      # 0x7fd0
movl (%rcx), %ecx
movl %ecx, %esi
addl $0x1, %esi
movq 0x66ac(%rip), %rdx      # 0x7fd0
movl %esi, (%rdx)
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
callq 0x11b0
movl %eax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x6690(%rip), %rcx      # 0x7fd0
movl (%rcx), %ecx
movl %ecx, %esi
addl $0x1, %esi
movq 0x6682(%rip), %rdx      # 0x7fd0
movl %esi, (%rdx)
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
callq 0x11b0
movl %eax, -0x34(%rbp)
movl -0x30(%rbp), %eax
addl -0x34(%rbp), %eax
cmpl $0x10, %eax
jle 0x198c
movq 0x6687(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
leaq 0x39ef(%rip), %rsi      # 0x536a
movb $0x0, %al
callq 0x1100
movl $0x1, %edi
callq 0x11d0
cmpl $0x0, -0x30(%rbp)
jle 0x1998
cmpl $0x0, -0x34(%rbp)
jg 0x19ba
movq 0x6659(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
leaq 0x39e6(%rip), %rsi      # 0x538f
movb $0x0, %al
callq 0x1100
movl $0x1, %edi
callq 0x11d0
jmp 0x19c8
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x16c0
cmpl $0x2, -0x2c(%rbp)
jge 0x19e4
leaq 0x39e5(%rip), %rdi      # 0x53ba
callq 0x1070
movl $0x1, %edi
callq 0x11d0
leaq -0x1050(%rbp), %rdi
movq -0x28(%rbp), %rdx
leaq 0x39e3(%rip), %rsi      # 0x53d9
movb $0x0, %al
callq 0x11c0
leaq -0x2050(%rbp), %rdi
movq -0x28(%rbp), %rdx
leaq 0x39d6(%rip), %rsi      # 0x53e5
movb $0x0, %al
callq 0x11c0
leaq -0x1050(%rbp), %rsi
leaq -0x2050(%rbp), %rdx
leaq 0x39c6(%rip), %rdi      # 0x53f1
movb $0x0, %al
callq 0x10d0
cmpl $0x0, -0x1c(%rbp)
je 0x1a5a
movl -0x30(%rbp), %esi
leaq 0x39be(%rip), %rdi      # 0x5400
movb $0x0, %al
callq 0x10d0
movl -0x34(%rbp), %esi
leaq 0x39c5(%rip), %rdi      # 0x5418
movb $0x0, %al
callq 0x10d0
leaq 0x3a8a(%rip), %rdi      # 0x54eb
movb $0x0, %al
callq 0x10d0
cmpq $0x0, -0x40(%rbp)
je 0x1c9e
movaps 0x35b6(%rip), %xmm1     # 0x5030
movq -0x40(%rbp), %xmm0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x35b5(%rip), %xmm1     # 0x5040
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd %xmm0, -0x4110(%rbp)
movsd 0x355e(%rip), %xmm0     # 0x5008
movsd 0x355e(%rip), %xmm1     # 0x5010
callq 0x1090
movsd -0x4110(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x1b2b
movaps 0x3564(%rip), %xmm1     # 0x5030
movq -0x40(%rbp), %xmm0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x3563(%rip), %xmm1     # 0x5040
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd %xmm0, -0x4118(%rbp)
movsd 0x350c(%rip), %xmm0     # 0x5008
movsd 0x351c(%rip), %xmm1     # 0x5020
callq 0x1090
movaps %xmm0, %xmm1
movsd -0x4118(%rbp), %xmm0
divsd %xmm1, %xmm0
leaq 0x3911(%rip), %rdi      # 0x5430
movb $0x1, %al
callq 0x10d0
jmp 0x1c9c
movaps 0x34fe(%rip), %xmm1     # 0x5030
movq -0x40(%rbp), %xmm0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x34fd(%rip), %xmm1     # 0x5040
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd %xmm0, -0x4120(%rbp)
movsd 0x34a6(%rip), %xmm0     # 0x5008
movsd 0x34a6(%rip), %xmm1     # 0x5010
callq 0x1090
movaps %xmm0, %xmm1
movsd -0x4120(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jb 0x1c39
movaps 0x34a5(%rip), %xmm1     # 0x5030
movq -0x40(%rbp), %xmm0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x34a4(%rip), %xmm1     # 0x5040
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd %xmm0, -0x4128(%rbp)
movsd 0x344d(%rip), %xmm0     # 0x5008
movsd 0x3455(%rip), %xmm1     # 0x5018
callq 0x1090
movsd -0x4128(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x1c39
movaps 0x3453(%rip), %xmm1     # 0x5030
movq -0x40(%rbp), %xmm0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x3452(%rip), %xmm1     # 0x5040
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd %xmm0, -0x4130(%rbp)
movsd 0x33fb(%rip), %xmm0     # 0x5008
movsd 0x33fb(%rip), %xmm1     # 0x5010
callq 0x1090
movaps %xmm0, %xmm1
movsd -0x4130(%rbp), %xmm0
divsd %xmm1, %xmm0
leaq 0x3810(%rip), %rdi      # 0x5440
movb $0x1, %al
callq 0x10d0
jmp 0x1c9a
movaps 0x33f0(%rip), %xmm1     # 0x5030
movq -0x40(%rbp), %xmm0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x33ef(%rip), %xmm1     # 0x5040
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd %xmm0, -0x4138(%rbp)
movsd 0x3398(%rip), %xmm0     # 0x5008
movsd 0x33a0(%rip), %xmm1     # 0x5018
callq 0x1090
movaps %xmm0, %xmm1
movsd -0x4138(%rbp), %xmm0
divsd %xmm1, %xmm0
leaq 0x37bd(%rip), %rdi      # 0x5450
movb $0x1, %al
callq 0x10d0
jmp 0x1c9c
jmp 0x1cac
leaq 0x37bb(%rip), %rdi      # 0x5460
movb $0x0, %al
callq 0x10d0
movq $0x0, -0x4058(%rbp)
movq $0x0, -0x4060(%rbp)
movq $0x0, -0x4068(%rbp)
movq $0x0, -0x4070(%rbp)
leaq -0x4058(%rbp), %rdi
leaq -0x4068(%rbp), %rsi
callq 0x2500
leaq -0x4060(%rbp), %rdi
leaq -0x4070(%rbp), %rsi
callq 0x2500
movl $0x0, -0x4074(%rbp)
movl $0x0, -0x4078(%rbp)
movq $0x0, -0x40b0(%rbp)
leaq -0x2050(%rbp), %rdi
leaq 0x3746(%rip), %rsi      # 0x5471
callq 0x1160
movq %rax, -0x4090(%rbp)
movq -0x4090(%rbp), %rcx
leaq -0x40c0(%rbp), %rdi
movl $0x8, %esi
movl $0x1, %edx
callq 0x1080
movl %eax, -0x48(%rbp)
cmpl $0x1, -0x48(%rbp)
je 0x1d73
leaq 0x3710(%rip), %rdi      # 0x5474
callq 0x1170
movl $0x1, %edi
callq 0x11d0
movq -0x40c0(%rbp), %rsi
leaq 0x36f8(%rip), %rdi      # 0x5479
movb $0x0, %al
callq 0x10d0
movq $0x0, -0x40b0(%rbp)
movq $0x1, -0x4088(%rbp)
movq $0x0, -0x4080(%rbp)
movq $0x0, -0x40b8(%rbp)
movl -0x4074(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4074(%rbp)
movl -0x2c(%rbp), %edi
leaq -0x1050(%rbp), %rsi
movl -0x4074(%rbp), %edx
movl -0x30(%rbp), %ecx
movl -0x34(%rbp), %r8d
movq -0x40(%rbp), %r9
callq 0x3080
movq %rax, -0x40a0(%rbp)
leaq -0x3050(%rbp), %rdi
movq -0x28(%rbp), %rdx
movl -0x4074(%rbp), %ecx
leaq 0x36a4(%rip), %rsi      # 0x54a6
movb $0x0, %al
callq 0x11c0
leaq -0x3050(%rbp), %rdi
leaq 0x369e(%rip), %rsi      # 0x54b5
callq 0x1300
movq %rax, -0x4098(%rbp)
leaq -0x4050(%rbp), %rdi
movq -0x28(%rbp), %rdx
movl -0x4074(%rbp), %ecx
leaq 0x367d(%rip), %rsi      # 0x54b8
movb $0x0, %al
callq 0x11c0
leaq -0x4050(%rbp), %rdi
leaq 0x3665(%rip), %rsi      # 0x54b5
callq 0x1300
movq %rax, -0x40c8(%rbp)
movq -0x4090(%rbp), %rcx
leaq -0x40a8(%rbp), %rdi
movl $0x8, %esi
movl $0x1, %edx
callq 0x1080
cmpq $0x0, %rax
je 0x1f99
movq -0x40a8(%rbp), %rsi
movq -0x40b0(%rbp), %rdx
leaq 0x362f(%rip), %rdi      # 0x54c7
movb $0x0, %al
callq 0x10d0
movq -0x40a0(%rbp), %rdi
movq -0x40b0(%rbp), %rsi
callq 0x3940
movq -0x40a8(%rbp), %rax
addq -0x40b0(%rbp), %rax
movq %rax, -0x40b0(%rbp)
movq -0x4080(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x4080(%rbp)
movslq -0x2c(%rbp), %rcx
cmpq %rcx, %rax
jne 0x1f94
movq -0x40a0(%rbp), %rdi
movq -0x4098(%rbp), %rsi
movq -0x28(%rbp), %rcx
movl -0x4074(%rbp), %r8d
movl -0x44(%rbp), %r9d
leaq -0x40b8(%rbp), %rdx
callq 0x1360
movq -0x40c8(%rbp), %rcx
leaq -0x40b8(%rbp), %rdi
movl $0x8, %esi
movl $0x1, %edx
callq 0x11e0
movq -0x40a0(%rbp), %rdi
movq -0x4098(%rbp), %rsi
movl -0x4074(%rbp), %edx
callq 0x3420
movl -0x2c(%rbp), %edi
leaq -0x1050(%rbp), %rsi
movl -0x4074(%rbp), %edx
movl -0x30(%rbp), %ecx
movl -0x34(%rbp), %r8d
movq -0x40(%rbp), %r9
callq 0x3080
movq %rax, -0x40a0(%rbp)
movq -0x4088(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x4088(%rbp)
movq $0x0, -0x4080(%rbp)
movq $0x0, -0x40b8(%rbp)
jmp 0x1e5c
cmpq $0x0, -0x4080(%rbp)
je 0x204b
cmpq $0x1, -0x4088(%rbp)
jne 0x2005
cmpl $0x1, -0x4074(%rbp)
jne 0x2005
movl $0x1, -0x4078(%rbp)
movq -0x4098(%rbp), %rdi
callq 0x10b0
movq -0x4090(%rbp), %rdi
callq 0x10b0
movq -0x40c8(%rbp), %rdi
callq 0x10b0
leaq -0x4050(%rbp), %rdi
callq 0x1050
leaq -0x3050(%rbp), %rdi
callq 0x1050
jmp 0x213e
movq -0x40a0(%rbp), %rdi
movq -0x4098(%rbp), %rsi
movq -0x28(%rbp), %rcx
movl -0x4074(%rbp), %r8d
movl -0x44(%rbp), %r9d
leaq -0x40b8(%rbp), %rdx
callq 0x1360
movq -0x40c8(%rbp), %rcx
leaq -0x40b8(%rbp), %rdi
movl $0x8, %esi
movl $0x1, %edx
callq 0x11e0
movq -0x40a0(%rbp), %rdi
movq -0x4098(%rbp), %rsi
movl -0x4074(%rbp), %edx
callq 0x3420
movq -0x4098(%rbp), %rdi
callq 0x10b0
movq -0x4090(%rbp), %rdi
callq 0x10b0
movq -0x40c8(%rbp), %rdi
callq 0x10b0
cmpl $0x0, -0x1c(%rbp)
je 0x20b1
movq -0x4088(%rbp), %rsi
subq $0x1, %rsi
movl -0x2c(%rbp), %edx
movq -0x4080(%rbp), %rcx
leaq 0x3429(%rip), %rdi      # 0x54d3
movb $0x0, %al
callq 0x10d0
cmpl $0x1, -0x4074(%rbp)
jle 0x20d2
leaq -0x1050(%rbp), %rdi
callq 0x1050
leaq -0x2050(%rbp), %rdi
callq 0x1050
leaq -0x1050(%rbp), %rdi
movq -0x28(%rbp), %rdx
movl -0x4074(%rbp), %ecx
leaq 0x33bc(%rip), %rsi      # 0x54a6
movb $0x0, %al
callq 0x11c0
leaq -0x2050(%rbp), %rdi
movq -0x28(%rbp), %rdx
movl -0x4074(%rbp), %ecx
leaq 0x33af(%rip), %rsi      # 0x54b8
movb $0x0, %al
callq 0x11c0
leaq -0x2050(%rbp), %rdi
leaq 0x3353(%rip), %rsi      # 0x5471
callq 0x1160
movq %rax, -0x4090(%rbp)
movq -0x4088(%rbp), %rax
movslq -0x2c(%rbp), %rcx
cmpq %rcx, %rax
ja 0x1d88
cmpl $0x0, -0x4078(%rbp)
je 0x2175
cmpl $0x0, -0x1c(%rbp)
je 0x2170
movq -0x4088(%rbp), %rsi
subq $0x1, %rsi
movl -0x2c(%rbp), %edx
movq -0x4080(%rbp), %rcx
leaq 0x336a(%rip), %rdi      # 0x54d3
movb $0x0, %al
callq 0x10d0
jmp 0x2292
cmpl $0x0, -0x18(%rbp)
je 0x21af
leaq 0x335e(%rip), %rdi      # 0x54e0
movb $0x0, %al
callq 0x10d0
movq -0x4058(%rbp), %rdi
movq -0x4068(%rbp), %rsi
callq 0x2540
leaq -0x4058(%rbp), %rdi
leaq -0x4068(%rbp), %rsi
callq 0x2500
cmpl $0x0, -0x1c(%rbp)
je 0x21cf
movq -0x4088(%rbp), %rdx
leaq 0x332c(%rip), %rdi      # 0x54ef
movl $0x1, %esi
movb $0x0, %al
callq 0x10d0
leaq -0x4050(%rbp), %rdi
leaq 0x3294(%rip), %rsi      # 0x5471
callq 0x1300
movq %rax, -0x4090(%rbp)
movq -0x4088(%rbp), %rax
movl %eax, %edi
leaq -0x3050(%rbp), %rsi
movl -0x30(%rbp), %ecx
movl -0x34(%rbp), %r8d
movq -0x40(%rbp), %r9
xorl %edx, %edx
callq 0x3080
movq %rax, -0x40a0(%rbp)
movq $0x0, -0x40b0(%rbp)
movq -0x4090(%rbp), %rcx
leaq -0x40a8(%rbp), %rdi
movl $0x8, %esi
movl $0x1, %edx
callq 0x1080
cmpq $0x0, %rax
je 0x2286
movq -0x40a8(%rbp), %rsi
movq -0x40b0(%rbp), %rdx
leaq 0x3272(%rip), %rdi      # 0x54c7
movb $0x0, %al
callq 0x10d0
movq -0x40a0(%rbp), %rdi
movq -0x40b0(%rbp), %rsi
callq 0x3940
movq -0x40a8(%rbp), %rax
addq -0x40b0(%rbp), %rax
movq %rax, -0x40b0(%rbp)
jmp 0x221d
movq -0x4090(%rbp), %rdi
callq 0x10b0
leaq -0x1050(%rbp), %rdi
movq -0x28(%rbp), %rdx
movl -0x34(%rbp), %ecx
leaq 0x3251(%rip), %rsi      # 0x54f8
movb $0x0, %al
callq 0x11c0
leaq -0x1050(%rbp), %rdi
leaq 0x31f9(%rip), %rsi      # 0x54b5
callq 0x1300
movq %rax, -0x4098(%rbp)
movq $0x0, -0x40d0(%rbp)
movq -0x40a0(%rbp), %rdi
movq -0x4098(%rbp), %rsi
movq -0x28(%rbp), %rcx
movl -0x44(%rbp), %r9d
leaq -0x40d0(%rbp), %rdx
xorl %r8d, %r8d
callq 0x1360
movq -0x40d0(%rbp), %rsi
movq -0x40c0(%rbp), %rdx
leaq 0x31f5(%rip), %rdi      # 0x5502
movb $0x0, %al
callq 0x10d0
cmpl $0x0, -0x44(%rbp)
je 0x23da
movq -0x40d0(%rbp), %rax
movq %rax, -0x40d8(%rbp)
movq -0x40c0(%rbp), %rax
movq %rax, -0x40e0(%rbp)
movslq -0x44(%rbp), %rax
movq -0x40a0(%rbp), %rcx
movslq 0x218(%rcx), %rcx
shlq $0x4, %rcx
leaq 0x2dd9(%rip), %rdx      # 0x5130
movq (%rcx,%rdx), %rcx
andq %rcx, %rax
movq %rax, -0x40f0(%rbp)
movq $0x0, -0x40e8(%rbp)
movq -0x40d8(%rbp), %rax
cmpq -0x40e0(%rbp), %rax
jge 0x23d8
movq -0x40a0(%rbp), %rdi
movq -0x4098(%rbp), %rsi
movq -0x40f0(%rbp), %rax
movq -0x40e8(%rbp), %rcx
movl -0x4074(%rbp), %r8d
movq %rcx, -0x40f8(%rbp)
movq %rax, -0x4100(%rbp)
movq -0x4100(%rbp), %rdx
movq -0x40f8(%rbp), %rcx
callq 0x3bc0
movq -0x40d8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40d8(%rbp)
jmp 0x2370
jmp 0x23da
movq -0x40a0(%rbp), %rdi
movq -0x4098(%rbp), %rsi
xorl %edx, %edx
callq 0x3420
movq -0x4098(%rbp), %rdi
callq 0x10b0
cmpl $0x0, -0x18(%rbp)
je 0x2422
leaq 0x3109(%rip), %rdi      # 0x5511
movb $0x0, %al
callq 0x10d0
movq -0x4058(%rbp), %rdi
movq -0x4068(%rbp), %rsi
callq 0x2540
cmpl $0x0, -0x18(%rbp)
je 0x246f
leaq 0x30f1(%rip), %rdi      # 0x5520
movb $0x0, %al
callq 0x10d0
movq 0x5bbb(%rip), %rax      # 0x7ff8
movq (%rax), %rax
movq %rax, -0x4140(%rbp)
movq -0x4060(%rbp), %rdi
movq -0x4070(%rbp), %rsi
callq 0x2540
movq -0x4140(%rbp), %rdi
leaq 0x30c5(%rip), %rsi      # 0x552d
movb $0x1, %al
callq 0x1100
leaq -0x1050(%rbp), %rsi
leaq 0x30b7(%rip), %rdi      # 0x5534
movb $0x0, %al
callq 0x10d0
leaq -0x3050(%rbp), %rdi
callq 0x1050
leaq -0x4050(%rbp), %rdi
callq 0x1050
leaq -0x1050(%rbp), %rdi
movq -0x28(%rbp), %rdx
leaq 0x2f2b(%rip), %rsi      # 0x53d9
movb $0x0, %al
callq 0x11c0
leaq -0x2050(%rbp), %rdi
movq -0x28(%rbp), %rdx
leaq 0x2f1e(%rip), %rsi      # 0x53e5
movb $0x0, %al
callq 0x11c0
leaq -0x1050(%rbp), %rdi
callq 0x1050
leaq -0x2050(%rbp), %rdi
callq 0x1050
xorl %eax, %eax
addq $0x4140, %rsp           # imm = 0x4140
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)