// File: /workspace/github_c_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x40a8, %rsp           # imm = 0x40A8
movq %rsi, %rbx
movl %edi, %ebp
movl $0x100, 0x8(%rsp)       # imm = 0x100
movq $0x0, 0x38(%rsp)
leaq 0x2a60(%rip), %r14      # 0x4299
leaq 0x2800(%rip), %r15      # 0x4040
movq 0x5791(%rip), %r12      # 0x6fd8
movl $0x0, 0x14(%rsp)
movl $0x0, 0xc(%rsp)
xorl %r13d, %r13d
movl %ebp, %edi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x1180
leal -0x68(%rax), %ecx
cmpl $0xe, %ecx
ja 0x1887
movslq (%r15,%rcx,4), %rax
addq %r15, %rax
jmpq *%rax
movq (%r12), %rdi
callq 0x11a0
movl %eax, 0x14(%rsp)
jmp 0x185a
cmpl $-0x1, %eax
je 0x18c6
cmpl $0x3f, %eax
jne 0x185a
jmp 0x2126
incl %r13d
jmp 0x185a
incl 0xc(%rsp)
jmp 0x185a
movq (%r12), %rdi
callq 0x11a0
movl %eax, 0x8(%rsp)
jmp 0x185a
movq (%r12), %rdi
callq 0x11a0
cltq
shlq $0x14, %rax
movq %rax, 0x38(%rsp)
jmp 0x185a
cmpl $0x0, 0xc(%rsp)
jle 0x190a
leaq 0x29cf(%rip), %rdi      # 0x42a3
callq 0x1080
testl %ebp, %ebp
jle 0x1900
movl %ebp, %r15d
leaq 0x29ca(%rip), %r14      # 0x42b1
xorl %r12d, %r12d
movq (%rbx,%r12,8), %rsi
movq %r14, %rdi
xorl %eax, %eax
callq 0x10d0
incq %r12
cmpq %r12, %r15
jne 0x18ea
movl $0xa, %edi
callq 0x1040
movq 0x56bf(%rip), %r14      # 0x6fd0
movslq (%r14), %r15
leal 0x3(%r15), %r12d
cmpl %ebp, %r12d
jne 0x2108
leaq 0x1(%r15), %rax
movl %eax, (%r14)
movq (%rbx,%r15,8), %rax
movq %rax, 0x30(%rsp)
leal 0x2(%r15), %eax
movl %eax, (%r14)
movq 0x8(%rbx,%r15,8), %rdi
callq 0x11a0
movl %r12d, (%r14)
movq %rax, %r12
movq 0x10(%rbx,%r15,8), %rdi
callq 0x11a0
movq %rax, 0x18(%rsp)
addl %r12d, %eax
cmpl $0x11, %eax
movq 0x38(%rsp), %rbp
jge 0x2110
testl %r12d, %r12d
jle 0x2115
cmpl $0x0, 0x18(%rsp)
jle 0x2115
cmpl $0x1, 0x8(%rsp)
jle 0x211a
leaq 0x2996(%rip), %rsi      # 0x4324
leaq 0xa0(%rsp), %rbx
movq %rbx, %rdi
movq 0x30(%rsp), %r15
movq %r15, %rdx
xorl %eax, %eax
callq 0x11b0
leaq 0x2981(%rip), %rsi      # 0x4330
leaq 0x30a0(%rsp), %r14
movq %r14, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x11b0
leaq 0x2971(%rip), %rdi      # 0x433c
movq %rbx, %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0x10d0
cmpl $0x0, 0xc(%rsp)
je 0x1a03
leaq 0x2965(%rip), %rdi      # 0x434b
movl %r12d, %esi
xorl %eax, %eax
callq 0x10d0
leaq 0x296c(%rip), %rdi      # 0x4363
movq 0x18(%rsp), %rsi
xorl %eax, %eax
callq 0x10d0
leaq 0x2a54(%rip), %rdi      # 0x445e
callq 0x1080
testq %rbp, %rbp
movl %r13d, 0x40(%rsp)
movq %r12, 0x50(%rsp)
je 0x1a59
movq %rbp, %xmm1
punpckldq 0x25e5(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x25ed(%rip), %xmm1     # 0x4020
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
cmpq $0x3fffffff, %rbp       # imm = 0x3FFFFFFF
ja 0x1a67
mulsd 0x25e8(%rip), %xmm0     # 0x4038
leaq 0x2924(%rip), %rdi      # 0x437b
jmp 0x1a76
leaq 0x29e3(%rip), %rdi      # 0x4443
callq 0x1080
jmp 0x1a7d
mulsd 0x25c1(%rip), %xmm0     # 0x4030
leaq 0x2915(%rip), %rdi      # 0x438b
movb $0x1, %al
callq 0x10d0
xorl %eax, %eax
leaq 0x80(%rsp), %rdi
movq %rax, (%rdi)
leaq 0x90(%rsp), %rbx
movq %rax, (%rbx)
leaq 0x78(%rsp), %rsi
movq %rax, (%rsi)
leaq 0x88(%rsp), %r14
movq %rax, (%r14)
callq 0x2138
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2138
leaq 0x28dc(%rip), %rsi      # 0x439b
leaq 0x30a0(%rsp), %rdi
callq 0x1160
movq %rax, %r13
leaq 0x70(%rsp), %rdi
movl $0x8, %esi
movl $0x1, %edx
movq %rax, %rcx
callq 0x1090
cmpl $0x1, %eax
jne 0x2130
movq 0x70(%rsp), %rsi
leaq 0x28a8(%rip), %rdi      # 0x43a3
xorl %eax, %eax
callq 0x10d0
movl 0x8(%rsp), %eax
movq %rax, 0x68(%rsp)
leaq 0xa0(%rsp), %r15
xorl %eax, %eax
movl $0x0, 0x44(%rsp)
movq $0x0, 0x58(%rsp)
movq %rax, 0x60(%rsp)
leal 0x1(%rax), %r14d
movl 0x8(%rsp), %edi
movq %r15, %rsi
movl %r14d, %edx
movq 0x50(%rsp), %rcx
movq 0x18(%rsp), %r8
movq %rbp, %r9
callq 0x2830
movq %rax, %rbx
leaq 0x20a0(%rsp), %r12
movq %r12, %rdi
leaq 0x2870(%rip), %rsi      # 0x43d0
movq 0x30(%rsp), %r15
movq %r15, %rdx
movl %r14d, %ecx
xorl %eax, %eax
callq 0x11b0
movq %r12, %rdi
leaq 0x2863(%rip), %rsi      # 0x43df
callq 0x14cc
movq %rax, %rbp
leaq 0x10a0(%rsp), %r12
movq %r12, %rdi
leaq 0x284c(%rip), %rsi      # 0x43e2
movq %r15, %rdx
movl %r14d, 0x10(%rsp)
movl %r14d, %ecx
xorl %eax, %eax
callq 0x11b0
movq %r12, %rdi
leaq 0x282d(%rip), %rsi      # 0x43df
callq 0x14cc
movq %rax, 0x48(%rsp)
movl $0x8, %esi
movl $0x1, %edx
leaq 0x28(%rsp), %rdi
movq %r13, %rcx
callq 0x1090
testq %rax, %rax
je 0x1cc4
movl $0x1, %eax
movq %rax, 0x20(%rsp)
xorl %r15d, %r15d
xorl %r12d, %r12d
movq 0x28(%rsp), %rsi
leaq 0x27f9(%rip), %rdi      # 0x43f1
movq %r15, %rdx
xorl %eax, %eax
callq 0x10d0
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2dd3
addq 0x28(%rsp), %r15
incq %r12
cmpq 0x68(%rsp), %r12
jne 0x1ca2
movq %rbx, %rdi
movq %rbp, %rsi
leaq 0x58(%rsp), %r12
movq %r12, %rdx
movq %r13, %r14
movl 0x10(%rsp), %r13d
movl %r13d, %r8d
movl 0x14(%rsp), %r9d
callq 0x14f0
movl $0x8, %esi
movl $0x1, %edx
movq %r12, %rdi
movq 0x48(%rsp), %rcx
callq 0x11d0
movq %rbx, %rdi
movq %rbp, %rsi
movl %r13d, %edx
callq 0x2acc
movl 0x8(%rsp), %edi
leaq 0xa0(%rsp), %rsi
movl %r13d, %edx
movq %r14, %r13
movq 0x50(%rsp), %rcx
movq 0x18(%rsp), %r8
movq 0x38(%rsp), %r9
callq 0x2830
movq %rax, %rbx
incq 0x20(%rsp)
movq $0x0, 0x58(%rsp)
xorl %r12d, %r12d
movl $0x8, %esi
movl $0x1, %edx
leaq 0x28(%rsp), %rdi
movq %r13, %rcx
callq 0x1090
testq %rax, %rax
jne 0x1bec
jmp 0x1cd1
xorl %r12d, %r12d
movl $0x1, %eax
movq %rax, 0x20(%rsp)
testq %r12, %r12
leaq 0xa0(%rsp), %r15
je 0x1d6e
cmpq $0x1, 0x20(%rsp)
setne %al
cmpl $0x0, 0x60(%rsp)
setne %cl
orb %al, %cl
jne 0x1d3a
movq %rbp, %rdi
callq 0x10b0
movq %r13, %rdi
callq 0x10b0
movq 0x48(%rsp), %rdi
callq 0x10b0
leaq 0x10a0(%rsp), %rdi
callq 0x1060
leaq 0x20a0(%rsp), %rdi
callq 0x1060
movl $0x1, 0x44(%rsp)
xorl %eax, %eax
jmp 0x1e2c
movq %rbx, %rdi
movq %rbp, %rsi
leaq 0x58(%rsp), %r14
movq %r14, %rdx
movl 0x10(%rsp), %r8d
movl 0x14(%rsp), %r9d
callq 0x14f0
movl $0x8, %esi
movl $0x1, %edx
movq %r14, %rdi
movq 0x48(%rsp), %rcx
callq 0x11d0
movq %rbx, %rdi
movq %rbp, %rsi
movl 0x10(%rsp), %edx
callq 0x2acc
movq %rbp, %rdi
callq 0x10b0
movq %r13, %rdi
callq 0x10b0
movq 0x48(%rsp), %rdi
callq 0x10b0
cmpl $0x0, 0xc(%rsp)
je 0x1dbc
movq 0x20(%rsp), %rax
leaq -0x1(%rax), %rsi
leaq 0x264f(%rip), %rdi      # 0x43fd
movl 0x8(%rsp), %edx
movq %r12, %rcx
xorl %eax, %eax
callq 0x10d0
cmpl $0x0, 0x60(%rsp)
leaq 0x30a0(%rsp), %r13
je 0x1ddb
movq %r15, %rdi
callq 0x1060
movq %r13, %rdi
callq 0x1060
movq %r15, %rdi
leaq 0x25eb(%rip), %rsi      # 0x43d0
movq 0x30(%rsp), %r15
movq %r15, %rdx
movl 0x10(%rsp), %ebp
movl %ebp, %ecx
xorl %eax, %eax
callq 0x11b0
movq %r13, %rdi
leaq 0x25de(%rip), %rsi      # 0x43e2
movq %r15, %rdx
leaq 0xa0(%rsp), %r15
movl %ebp, %ecx
xorl %eax, %eax
callq 0x11b0
movq %r13, %rdi
leaq 0x2579(%rip), %rsi      # 0x439b
callq 0x1160
movq %rax, %r13
movb $0x1, %al
movq 0x38(%rsp), %rbp
testb %al, %al
movq 0x20(%rsp), %rsi
movl 0x10(%rsp), %eax
je 0x1e49
cmpq 0x68(%rsp), %rsi
ja 0x1b1d
cmpl $0x0, 0x44(%rsp)
je 0x1e78
cmpl $0x0, 0xc(%rsp)
je 0x1f7b
decq %rsi
leaq 0x2598(%rip), %rdi      # 0x43fd
movl 0x8(%rsp), %edx
movq %r12, %rcx
xorl %eax, %eax
callq 0x10d0
jmp 0x1f7b
movl 0x40(%rsp), %eax
testl %eax, %eax
je 0x1eaf
leaq 0x25cc(%rip), %rdi      # 0x4453
callq 0x1080
leaq 0x80(%rsp), %rbx
movq (%rbx), %rdi
leaq 0x78(%rsp), %r15
movq (%r15), %rsi
callq 0x215c
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2138
cmpl $0x0, 0xc(%rsp)
movq 0x50(%rsp), %rbx
movq 0x20(%rsp), %r12
je 0x1ed6
leaq 0x2543(%rip), %rdi      # 0x440a
movl $0x1, %esi
movq %r12, %rdx
xorl %eax, %eax
callq 0x10d0
leaq 0x24be(%rip), %rsi      # 0x439b
leaq 0x10a0(%rsp), %rdi
callq 0x14cc
movq %rax, %r15
leaq 0x20a0(%rsp), %rsi
movl %r12d, %edi
xorl %edx, %edx
movl %ebx, %ecx
movq 0x18(%rsp), %r8
movq %rbp, %r9
callq 0x2830
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
movl $0x8, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x1090
testq %rax, %rax
je 0x1f73
leaq 0x24c2(%rip), %r14      # 0x43f1
leaq 0x28(%rsp), %r13
xorl %ebp, %ebp
movq 0x28(%rsp), %r12
movq %r14, %rdi
movq %r12, %rsi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x10d0
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x2dd3
addq %r12, %rbp
movl $0x8, %esi
movl $0x1, %edx
movq %r13, %rdi
movq %r15, %rcx
callq 0x1090
testq %rax, %rax
jne 0x1f36
movq %r15, %rdi
callq 0x10b0
leaq 0x2491(%rip), %rsi      # 0x4413
leaq 0xa0(%rsp), %r15
movq %r15, %rdi
movq 0x30(%rsp), %rdx
movq 0x18(%rsp), %rcx
xorl %eax, %eax
callq 0x11b0
leaq 0x243a(%rip), %rsi      # 0x43df
movq %r15, %rdi
callq 0x14cc
movq %rax, %r15
leaq 0x98(%rsp), %r12
movq $0x0, (%r12)
movq %rbx, %rdi
movq %rax, %rsi
movq %r12, %rdx
xorl %r8d, %r8d
movl 0x14(%rsp), %ebp
movl %ebp, %r9d
callq 0x14f0
movq (%r12), %r13
movq 0x70(%rsp), %r12
leaq 0x2435(%rip), %rdi      # 0x441d
movq %r13, %rsi
movq %r12, %rdx
xorl %eax, %eax
callq 0x10d0
testl %ebp, %ebp
movl 0x10(%rsp), %ebp
je 0x2035
subq %r13, %r12
jle 0x2035
movslq 0x14(%rsp), %r13
movslq 0x218(%rbx), %rax
shlq $0x4, %rax
leaq 0x2067(%rip), %rcx      # 0x4080
andq (%rax,%rcx), %r13
movq %rbx, %rdi
movq %r15, %rsi
movq %r13, %rdx
xorl %ecx, %ecx
movl %ebp, %r8d
callq 0x2f4f
decq %r12
jne 0x201d
movq %rbx, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x2acc
movq %r15, %rdi
callq 0x10b0
cmpl $0x0, 0x40(%rsp)
jne 0x20e1
leaq 0x23d7(%rip), %rdi      # 0x4433
leaq 0xa0(%rsp), %rbx
movq %rbx, %rsi
xorl %eax, %eax
callq 0x10d0
leaq 0x20a0(%rsp), %rdi
callq 0x1060
leaq 0x10a0(%rsp), %rdi
callq 0x1060
leaq 0x2295(%rip), %rsi      # 0x4324
movq %rbx, %rdi
movq 0x30(%rsp), %r15
movq %r15, %rdx
xorl %eax, %eax
callq 0x11b0
leaq 0x2288(%rip), %rsi      # 0x4330
leaq 0x30a0(%rsp), %r14
movq %r14, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x11b0
movq %rbx, %rdi
callq 0x1060
movq %r14, %rdi
callq 0x1060
xorl %eax, %eax
addq $0x40a8, %rsp           # imm = 0x40A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x80(%rsp), %rdi
leaq 0x78(%rsp), %rsi
leaq 0x90(%rsp), %rdx
leaq 0x88(%rsp), %rcx
callq 0x122a
jmp 0x2055
movq (%rbx), %rdi
callq 0x1777
callq 0x12b9
callq 0x1294
leaq 0x21e4(%rip), %rdi      # 0x4305
callq 0x1080
movl $0x1, %edi
callq 0x11c0
callq 0x1215
nopl (%rax)