// File: /workspace/github_c_makefile_star2_O0/felipelouza[P]egap/./merge16.h
// Function: gap16
void gap16(g_data *g, bool lastRound) {

  // check we can really use 4 bits
  assert(g->numBwt<=16);
  if(g->numBwt<=8 && g->bwtOnly && !g->algorithm) return gap8(g,lastRound);
  if(g->verbose>0) puts("BWT merging with gap16");
  assert(!g->lcpCompute);
  assert(!g->extMem);
  // init local global vars
  check_g_data(g);
  // allocate and clear bit/int array B 
  if(!g->lcpMerge) g->bitB = tba_alloc(g->mergeLen, g->mmapB);
  else alloc0_B_array(g); // alloc and clear blockBeginsAt array
    
  // allocate Z (merge) Znew 
  alloc_merge_array(g);
  // allocate other useful arrays
  g->inCnt = malloc(g->numBwt*sizeof(customInt)); 
  g->firstColumn = malloc(g->sizeOfAlpha*sizeof(customInt));
  g->F = malloc(g->sizeOfAlpha*sizeof(customInt));
  if(!g->inCnt || !g->firstColumn || !g->F) die(__func__);
    
  // init the above arrays
  if(g->smallAlpha) init_arrays16(g);
  else init_arrays16_largealpha(g);  
  customInt prefixLength = 1;
  
  // init liquid block (containing list of allocated mem)
  liquidBlock *liquid = liquid_new(g); 
  // init list (on disk) of irrelevant blocks, initially empty 
  solidBlockFile *ibList = ibHead_new(g);

  // main loop
  int round=0;
  if(g->numBwt>1) {
    bool merge_completed; 
    do {
      prefixLength+= 1;
      if(prefixLength>MAX_LCP_SIZE && !g->bwtOnly) {fprintf(stderr,"LCP too large\n");die(__func__);}
      bool mergeChanged = false; // the Z vector has changed in this iteration (used when g->bwtOnly)
      ibList->fout = gap_tmpfile(g->outPath);
      merge_completed=addCharToPrefix16(ibList,liquid,prefixLength,&mergeChanged,round,g);
      #if MALLOC_COUNT_FLAG
        if (g->verbose>1 && lastRound) {
          printf("Lcp: "CUSTOM_FORMAT". Memory: %zu peak, %zu current, %.4lf/%.4lf bytes/symbol\n", 
               prefixLength-1, malloc_count_peak(),
               malloc_count_current(), (double)malloc_count_peak()/g->mergeLen,
               (double)malloc_count_current()/g->mergeLen);
        }
      #endif
      if(g->bwtOnly && !mergeChanged) {
        if(g->verbose>1) puts("Gap bwt-only early termination");
        fclose(ibList->fout);
        break;
      }
      round  = 1 - round; // change round parity
      if(ibList->fin!=NULL) fclose(ibList->fin);
      rewind(ibList->fout);
      ibList->fin = ibList->fout;
    } while(!merge_completed);  // end main loop
    if(ibList->fin!=NULL) fclose(ibList->fin);
  }
  if (g->verbose>0) {
    #if MALLOC_COUNT_FLAG
      if(lastRound)
        printf("Merge16 completed (%d bwts). Mem: %zu peak, %zu current, %.2lf/%.2lf bytes/symbol\n", g->numBwt, malloc_count_peak(),
             malloc_count_current(), (double)malloc_count_peak()/g->mergeLen,
             (double)malloc_count_current()/g->mergeLen);
      else if(g->verbose>1)
        printf("Merge16 completed (%d bwts). Mem: %zu peak, %zu current\n", g->numBwt, malloc_count_peak(),
             malloc_count_current());
      #else
        printf("Merge16 completed (%d bwts).\n", g->numBwt);
      #endif
  }
  liquid_free(liquid);
  ibHead_free(ibList);  

  // normalize mergeColor
  if(round!=0) for(customInt i=0;i<g->mergeLen;i++) g->mergeColor[i] >>=4;
  else for(customInt i=0;i<g->mergeLen;i++) g->mergeColor[i] &= 0x0F;
  // computation complete, do the merging. The following call writes the
  // (possibly remapped) merged BWT back to g->bws[0]; and if lcpMerge==true the merged LCP to g->lcps[0]     
  mergeBWTandLCP(g,lastRound);

  // free B array 
  if(!g->lcpMerge) tba_free(g->bitB, g->mergeLen, g->mmapB);
  else free_B_array(g); 
  free(g->F); // last five arrays deallocated
  free(g->firstColumn); 
  free(g->inCnt);
  free_merge_array(g);// contains merge and newMerge
}

// Assembly:
subq $0xd8, %rsp
movb %sil, %al
movq %rdi, 0xd0(%rsp)
andb $0x1, %al
movb %al, 0xcf(%rsp)
movq 0xd0(%rsp), %rax
cmpl $0x8, 0x20(%rax)
jg 0xa563
movq 0xd0(%rsp), %rax
testb $0x1, 0x3c(%rax)
je 0xa563
movq 0xd0(%rsp), %rax
cmpl $0x0, 0x6c(%rax)
jne 0xa563
movq 0xd0(%rsp), %rdi
movb 0xcf(%rsp), %al
andb $0x1, %al
movzbl %al, %esi
callq 0x9150
jmp 0xacc1
movq 0xd0(%rsp), %rax
cmpl $0x0, 0x94(%rax)
jle 0xa580
leaq 0xb5e0(%rip), %rdi      # 0x15b5b
callq 0x2080
movq 0xd0(%rsp), %rdi
callq 0x3dd0
movq 0xd0(%rsp), %rax
testb $0x1, 0x3d(%rax)
jne 0xa5d0
movq 0xd0(%rsp), %rax
movq 0x28(%rax), %rdi
movq 0xd0(%rsp), %rax
movb 0x71(%rax), %al
andb $0x1, %al
movzbl %al, %esi
callq 0x8fe0
movq %rax, %rcx
movq 0xd0(%rsp), %rax
movq %rcx, 0x98(%rax)
jmp 0xa5dd
movq 0xd0(%rsp), %rdi
callq 0x69b0
movq 0xd0(%rsp), %rdi
callq 0x6830
movq 0xd0(%rsp), %rax
movslq 0x20(%rax), %rdi
shlq $0x3, %rdi
callq 0x127b0
movq %rax, %rcx
movq 0xd0(%rsp), %rax
movq %rcx, 0x5118(%rax)
movq 0xd0(%rsp), %rax
movslq 0x38(%rax), %rdi
shlq $0x3, %rdi
callq 0x127b0
movq %rax, %rcx
movq 0xd0(%rsp), %rax
movq %rcx, 0x5108(%rax)
movq 0xd0(%rsp), %rax
movslq 0x38(%rax), %rdi
shlq $0x3, %rdi
callq 0x127b0
movq %rax, %rcx
movq 0xd0(%rsp), %rax
movq %rcx, 0x5110(%rax)
movq 0xd0(%rsp), %rax
cmpq $0x0, 0x5118(%rax)
je 0xa695
movq 0xd0(%rsp), %rax
cmpq $0x0, 0x5108(%rax)
je 0xa695
movq 0xd0(%rsp), %rax
cmpq $0x0, 0x5110(%rax)
jne 0xa6a1
leaq 0xb4d0(%rip), %rdi      # 0x15b6c
callq 0x3ce0
movq 0xd0(%rsp), %rax
testb $0x1, 0x68(%rax)
je 0xa6be
movq 0xd0(%rsp), %rdi
callq 0xacd0
jmp 0xa6cb
movq 0xd0(%rsp), %rdi
callq 0xae50
movq $0x1, 0xc0(%rsp)
movq 0xd0(%rsp), %rdi
callq 0x84d0
movq %rax, 0xb8(%rsp)
movq 0xd0(%rsp), %rdi
callq 0x8640
movq %rax, 0xb0(%rsp)
movl $0x0, 0xac(%rsp)
movq 0xd0(%rsp), %rax
cmpl $0x1, 0x20(%rax)
jle 0xa9d6
jmp 0xa720
movq 0xc0(%rsp), %rax
addq $0x1, %rax
movq %rax, 0xc0(%rsp)
cmpq $0xff, 0xc0(%rsp)
jbe 0xa774
movq 0xd0(%rsp), %rax
testb $0x1, 0x3c(%rax)
jne 0xa774
movq 0xe8a1(%rip), %rax      # 0x18ff8
movq (%rax), %rdi
leaq 0xb411(%rip), %rsi      # 0x15b72
movb $0x0, %al
callq 0x21b0
leaq 0xb3fd(%rip), %rdi      # 0x15b6c
callq 0x3ce0
movb $0x0, 0xaa(%rsp)
movq 0xd0(%rsp), %rax
movq 0x80(%rax), %rdi
callq 0x7750
movq %rax, %rcx
movq 0xb0(%rsp), %rax
movq %rcx, 0x8(%rax)
movq 0xb0(%rsp), %rdi
movq 0xb8(%rsp), %rsi
movq 0xc0(%rsp), %rdx
movl 0xac(%rsp), %r8d
movq 0xd0(%rsp), %r9
leaq 0xaa(%rsp), %rcx
callq 0xafa0
andb $0x1, %al
movb %al, 0xab(%rsp)
movq 0xd0(%rsp), %rax
cmpl $0x1, 0x94(%rax)
jle 0xa904
testb $0x1, 0xcf(%rsp)
je 0xa904
movq 0xc0(%rsp), %rax
decq %rax
movq %rax, 0x78(%rsp)
callq 0x12730
movq %rax, 0x80(%rsp)
callq 0x12720
movq %rax, 0x88(%rsp)
callq 0x12730
movq %rax, %xmm0
movaps 0x97d5(%rip), %xmm3     # 0x14010
movaps %xmm3, 0x50(%rsp)
punpckldq %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
movapd 0x97d4(%rip), %xmm2     # 0x14020
movaps %xmm2, 0x60(%rsp)
subpd %xmm2, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movq 0xd0(%rsp), %rax
movq 0x28(%rax), %xmm1
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x90(%rsp)
callq 0x12720
movaps 0x50(%rsp), %xmm4
movaps 0x60(%rsp), %xmm3
movq 0x78(%rsp), %rsi
movq 0x80(%rsp), %rdx
movq 0x88(%rsp), %rcx
movsd 0x90(%rsp), %xmm0
movq %rax, %xmm1
punpckldq %xmm4, %xmm1    # xmm1 = xmm1[0],xmm4[0],xmm1[1],xmm4[1]
subpd %xmm3, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
movq 0xd0(%rsp), %rax
movq 0x28(%rax), %xmm2
punpckldq %xmm4, %xmm2    # xmm2 = xmm2[0],xmm4[0],xmm2[1],xmm4[1]
subpd %xmm3, %xmm2
movaps %xmm2, %xmm3
unpckhpd %xmm2, %xmm2            # xmm2 = xmm2[1,1]
addsd %xmm3, %xmm2
divsd %xmm2, %xmm1
leaq 0xb284(%rip), %rdi      # 0x15b81
movb $0x2, %al
callq 0x20f0
movq 0xd0(%rsp), %rax
testb $0x1, 0x3c(%rax)
je 0xa94c
testb $0x1, 0xaa(%rsp)
jne 0xa94c
movq 0xd0(%rsp), %rax
cmpl $0x1, 0x94(%rax)
jle 0xa939
leaq 0xb148(%rip), %rdi      # 0x15a7c
callq 0x2080
movq 0xb0(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x20d0
jmp 0xa9b6
movl $0x1, %eax
subl 0xac(%rsp), %eax
movl %eax, 0xac(%rsp)
movq 0xb0(%rsp), %rax
cmpq $0x0, (%rax)
je 0xa97d
movq 0xb0(%rsp), %rax
movq (%rax), %rdi
callq 0x20d0
movq 0xb0(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x2110
movq 0xb0(%rsp), %rax
movq 0x8(%rax), %rcx
movq 0xb0(%rsp), %rax
movq %rcx, (%rax)
movb 0xab(%rsp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0xa720
movq 0xb0(%rsp), %rax
cmpq $0x0, (%rax)
je 0xa9d4
movq 0xb0(%rsp), %rax
movq (%rax), %rdi
callq 0x20d0
jmp 0xa9d6
movq 0xd0(%rsp), %rax
cmpl $0x0, 0x94(%rax)
jle 0xab38
testb $0x1, 0xcf(%rsp)
je 0xaaeb
movq 0xd0(%rsp), %rax
movl 0x20(%rax), %eax
movl %eax, 0x34(%rsp)
callq 0x12730
movq %rax, 0x38(%rsp)
callq 0x12720
movq %rax, 0x40(%rsp)
callq 0x12730
movq %rax, %xmm0
movaps 0x95e3(%rip), %xmm3     # 0x14010
movaps %xmm3, 0x10(%rsp)
punpckldq %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
movapd 0x95e2(%rip), %xmm2     # 0x14020
movaps %xmm2, 0x20(%rsp)
subpd %xmm2, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movq 0xd0(%rsp), %rax
movq 0x28(%rax), %xmm1
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x48(%rsp)
callq 0x12720
movaps 0x10(%rsp), %xmm4
movaps 0x20(%rsp), %xmm3
movl 0x34(%rsp), %esi
movq 0x38(%rsp), %rdx
movq 0x40(%rsp), %rcx
movsd 0x48(%rsp), %xmm0
movq %rax, %xmm1
punpckldq %xmm4, %xmm1    # xmm1 = xmm1[0],xmm4[0],xmm1[1],xmm4[1]
subpd %xmm3, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
movq 0xd0(%rsp), %rax
movq 0x28(%rax), %xmm2
punpckldq %xmm4, %xmm2    # xmm2 = xmm2[0],xmm4[0],xmm2[1],xmm4[1]
subpd %xmm3, %xmm2
movaps %xmm2, %xmm3
unpckhpd %xmm2, %xmm2            # xmm2 = xmm2[1,1]
addsd %xmm3, %xmm2
divsd %xmm2, %xmm1
leaq 0xb0e2(%rip), %rdi      # 0x15bc4
movb $0x2, %al
callq 0x20f0
jmp 0xab36
movq 0xd0(%rsp), %rax
cmpl $0x1, 0x94(%rax)
jle 0xab34
movq 0xd0(%rsp), %rax
movl 0x20(%rax), %eax
movl %eax, 0x4(%rsp)
callq 0x12730
movq %rax, 0x8(%rsp)
callq 0x12720
movl 0x4(%rsp), %esi
movq 0x8(%rsp), %rdx
movq %rax, %rcx
leaq 0xb0ea(%rip), %rdi      # 0x15c17
movb $0x0, %al
callq 0x20f0
jmp 0xab36
jmp 0xab38
movq 0xb8(%rsp), %rdi
callq 0x8620
movq 0xb0(%rsp), %rdi
callq 0x86d0
cmpl $0x0, 0xac(%rsp)
je 0xabb7
movq $0x0, 0xa0(%rsp)
movq 0xa0(%rsp), %rax
movq 0xd0(%rsp), %rcx
cmpq 0x28(%rcx), %rax
jae 0xabb5
movq 0xd0(%rsp), %rax
movq 0x50e8(%rax), %rax
movq 0xa0(%rsp), %rcx
movzbl (%rax,%rcx), %edx
sarl $0x4, %edx
movb %dl, (%rax,%rcx)
movq 0xa0(%rsp), %rax
addq $0x1, %rax
movq %rax, 0xa0(%rsp)
jmp 0xab68
jmp 0xac12
movq $0x0, 0x98(%rsp)
movq 0x98(%rsp), %rax
movq 0xd0(%rsp), %rcx
cmpq 0x28(%rcx), %rax
jae 0xac10
movq 0xd0(%rsp), %rax
movq 0x50e8(%rax), %rax
movq 0x98(%rsp), %rcx
movzbl (%rax,%rcx), %edx
andl $0xf, %edx
movb %dl, (%rax,%rcx)
movq 0x98(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x98(%rsp)
jmp 0xabc3
jmp 0xac12
movq 0xd0(%rsp), %rdi
movb 0xcf(%rsp), %al
andb $0x1, %al
movzbl %al, %esi
callq 0x4390
movq 0xd0(%rsp), %rax
testb $0x1, 0x3d(%rax)
jne 0xac6b
movq 0xd0(%rsp), %rax
movq 0x98(%rax), %rdi
movq 0xd0(%rsp), %rax
movq 0x28(%rax), %rsi
movq 0xd0(%rsp), %rax
movb 0x71(%rax), %al
andb $0x1, %al
movzbl %al, %edx
callq 0x9090
jmp 0xac78
movq 0xd0(%rsp), %rdi
callq 0x6a60
movq 0xd0(%rsp), %rax
movq 0x5110(%rax), %rdi
callq 0x12940
movq 0xd0(%rsp), %rax
movq 0x5108(%rax), %rdi
callq 0x12940
movq 0xd0(%rsp), %rax
movq 0x5118(%rax), %rdi
callq 0x12940
movq 0xd0(%rsp), %rdi
callq 0x6930
addq $0xd8, %rsp
retq
nopl (%rax)