// File: /workspace/github_c_makefile_star2_O3/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 0xb038
movq 0x50e0(%r14), %rdi
leaq 0x393c(%rip), %rsi      # 0xe92e
callq 0x21e0
movq %rax, 0x10(%rsp)
testq %rax, %rax
jne 0xb00d
leaq 0x5144(%rip), %rdi      # 0x1014c
callq 0x39fc
movq 0x50d8(%r14), %rdi
leaq 0x3913(%rip), %rsi      # 0xe92e
callq 0x21e0
movq %rax, 0x8(%rsp)
testq %rax, %rax
jne 0xb04a
leaq 0x513f(%rip), %rdi      # 0x10170
callq 0x39fc
jmp 0xb041
movq $0x0, 0x10(%rsp)
movq $0x0, 0x8(%rsp)
cmpl $0x0, 0x38(%r14)
jle 0xb17c
xorl %r13d, %r13d
xorl %ebp, %ebp
movq 0x98(%r14), %rax
cmpb $0x0, 0x3d(%r14)
je 0xb06e
movb $0x1, (%rax,%rbp)
jmp 0xb088
movq %rbp, %rdx
leal (,%rbp,2), %ecx
movl $0x1, %esi
shlq %cl, %rsi
shrq $0x5, %rdx
orq %rsi, (%rax,%rdx,8)
movq 0x5108(%r14), %rax
movq %rbp, (%rax,%r13,8)
movl 0x20(%r14), %ecx
testl %ecx, %ecx
jle 0xb16c
movq 0x18(%r14), %rax
xorl %r12d, %r12d
movq (%rax,%r12,8), %rdx
cmpq $0x0, (%rdx,%r13,8)
je 0xb15d
leaq (,%rbp,2), %r15
xorl %ebx, %ebx
testq %r13, %r13
jne 0xb119
movq 0x98(%r14), %rax
cmpb $0x0, 0x3d(%r14)
je 0xb0db
addq %rbp, %rax
movb $0x1, (%rbx,%rax)
jmp 0xb0f5
leaq (%rbx,%rbp), %rdx
movl %r15d, %ecx
andb $0x3e, %cl
movl $0x1, %esi
shlq %cl, %rsi
shrq $0x5, %rdx
orq %rsi, (%rax,%rdx,8)
cmpb $0x1, 0x69(%r14)
jne 0xb10b
movl %r12d, %edi
movq 0x10(%rsp), %rsi
callq 0xbd5a
jmp 0xb119
movq 0x50f0(%r14), %rax
addq %rbp, %rax
movb %r12b, (%rbx,%rax)
cmpb $0x1, 0x69(%r14)
jne 0xb12f
movl %r12d, %edi
movq 0x8(%rsp), %rsi
callq 0xbd5a
jmp 0xb13d
movq 0x50e8(%r14), %rax
addq %rbp, %rax
movb %r12b, (%rbx,%rax)
incq %rbx
movq 0x18(%r14), %rax
movq (%rax,%r12,8), %rcx
addq $0x2, %r15
cmpq (%rcx,%r13,8), %rbx
jb 0xb0bf
movl 0x20(%r14), %ecx
addq %rbx, %rbp
incq %r12
movslq %ecx, %rdx
cmpq %rdx, %r12
jl 0xb0a6
incq %r13
movslq 0x38(%r14), %rax
cmpq %rax, %r13
jl 0xb05a
cmpb $0x0, 0x69(%r14)
je 0xb1c5
movq 0x8(%rsp), %rdi
callq 0x20e0
testl %eax, %eax
je 0xb19d
leaq 0x4ff9(%rip), %rdi      # 0x10191
callq 0x39fc
movq 0x10(%rsp), %rdi
callq 0x20e0
testl %eax, %eax
je 0xb1c5
leaq 0x4ff8(%rip), %rdi      # 0x101aa
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x39fc
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq