// File: /workspace/github_c_makefile_star2_O2/felipelouza[P]egap/mergegap.c
// Function: init_arrays
static void init_arrays(g_data *g)
{
  customInt i=0; // position inside Z newZ and B  
  FILE *fnewmerge=NULL, *fmerge=NULL;
  if(g->extMem) {
    fnewmerge = fopen(g->newmerge_fname,"wb");
    if(!fnewmerge) die("mergegap:init_arrays:fnewmerge open");
    fmerge = fopen(g->merge_fname,"wb");
    if(!fmerge) die("mergegap:init_arrays:fmerge open");
  }
  for(int j=0;j<g->sizeOfAlpha;j++) {
    if(!g->lcpMerge) tba_or_m(g->bitB,i,1);
    else g->blockBeginsAt[i]=1;  // start of symbol j, correct lcp is 0
    g->firstColumn[j] = i;  // symbol j starts at position i
    for(int b=0;b<g->numBwt;b++) {
      for(customInt t=0;t<g->bwtOcc[b][j];t++) { 
        if(j==0) { // zero chars are all different, Z, Znew never change 
          if(!g->lcpMerge) tba_or_m(g->bitB,i,1);
          else g->blockBeginsAt[i]=1;
           //for 0-chars write b also to newmerge aka newZ 
          if(g->extMem)  fwrite_color(b,fnewmerge);
          else           g->newMergeColor[i]=b;          
        }
        // all colors are written to merge aka Z
        if(g->extMem) fwrite_color(b,fmerge);
        else g->mergeColor[i] = b;
        i++;
      } // end for t
    } // end for b 
  } // end for j
  assert(i==g->mergeLen); 
  // extra check on mergeColor, can be commented out
  if(g->extMem) {
    assert(ftell(fmerge)==g->mergeLen*sizeof(palette));
    if(fclose(fmerge)!=0) die("init_arrays:fmerge close"); 
    if(fclose(fnewmerge)!=0) die("mergegap:init_arrays:fnewmerge close"); 
  }
  else {
    #ifndef NDEBUG
    customInt cnt[MAX_NUMBER_OF_BWTS] = {0};
    for(i=0;i<g->mergeLen;i++) cnt[g->mergeColor[i]]++;
    for(int i=0; i<g->numBwt; i++)
      assert(cnt[i]==g->bwtLen[i]);
    #endif
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %r14
cmpb $0x1, 0x69(%rdi)
jne 0xa721
movq 0x50e0(%r14), %rdi
leaq 0x3253(%rip), %rsi      # 0xd92e
callq 0x21e0
movq %rax, 0x10(%rsp)
testq %rax, %rax
jne 0xa6f6
leaq 0x4a13(%rip), %rdi      # 0xf104
callq 0x35b7
movq 0x50d8(%r14), %rdi
leaq 0x322a(%rip), %rsi      # 0xd92e
callq 0x21e0
movq %rax, 0x8(%rsp)
testq %rax, %rax
jne 0xa733
leaq 0x4a0e(%rip), %rdi      # 0xf128
callq 0x35b7
jmp 0xa72a
movq $0x0, 0x10(%rsp)
movq $0x0, 0x8(%rsp)
xorl %r13d, %r13d
xorl %ebp, %ebp
movslq 0x38(%r14), %rax
cmpq %rax, %r13
jge 0xa839
movq 0x98(%r14), %rax
cmpb $0x0, 0x3d(%r14)
je 0xa759
movb $0x1, (%rax,%rbp)
jmp 0xa771
movq %rbp, %rdx
leal (,%rbp,2), %ecx
pushq $0x1
popq %rsi
shlq %cl, %rsi
shrq $0x5, %rdx
orq %rsi, (%rax,%rdx,8)
movq 0x5108(%r14), %rax
movq %rbp, (%rax,%r13,8)
xorl %r12d, %r12d
movslq 0x20(%r14), %rax
cmpq %rax, %r12
jge 0xa831
leaq (,%rbp,2), %rbx
xorl %r15d, %r15d
movq 0x18(%r14), %rax
movq (%rax,%r12,8), %rax
cmpq (%rax,%r13,8), %r15
jae 0xa829
testq %r13, %r13
jne 0xa7f9
movq 0x98(%r14), %rax
cmpb $0x0, 0x3d(%r14)
je 0xa7c2
movb $0x1, (%rax,%rbp)
jmp 0xa7d8
movq %rbp, %rdx
movl %ebx, %ecx
andb $0x3e, %cl
pushq $0x1
popq %rsi
shlq %cl, %rsi
shrq $0x5, %rdx
orq %rsi, (%rax,%rdx,8)
cmpb $0x1, 0x69(%r14)
jne 0xa7ee
movl %r12d, %edi
movq 0x10(%rsp), %rsi
callq 0xb3c2
jmp 0xa7f9
movq 0x50f0(%r14), %rax
movb %r12b, (%rax,%rbp)
cmpb $0x1, 0x69(%r14)
jne 0xa80f
movl %r12d, %edi
movq 0x8(%rsp), %rsi
callq 0xb3c2
jmp 0xa81a
movq 0x50e8(%r14), %rax
movb %r12b, (%rax,%rbp)
incq %rbp
incq %r15
addq $0x2, %rbx
jmp 0xa797
incq %r12
jmp 0xa77f
incq %r13
jmp 0xa738
cmpb $0x0, 0x69(%r14)
je 0xa882
movq 0x8(%rsp), %rdi
callq 0x20e0
testl %eax, %eax
je 0xa85a
leaq 0x48f4(%rip), %rdi      # 0xf149
callq 0x35b7
movq 0x10(%rsp), %rdi
callq 0x20e0
testl %eax, %eax
je 0xa882
leaq 0x48f3(%rip), %rdi      # 0xf162
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x35b7
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq