// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x38, %rsp
movq %rdi, 0x30(%rsp)
movq $0x0, 0x28(%rsp)
movq $0x0, 0x20(%rsp)
movq $0x0, 0x18(%rsp)
movq 0x30(%rsp), %rax
testb $0x1, 0x69(%rax)
je 0xf8f3
movq 0x30(%rsp), %rax
movq 0x50e0(%rax), %rdi
leaq 0x524d(%rip), %rsi      # 0x14aef
callq 0x21d0
movq %rax, 0x20(%rsp)
cmpq $0x0, 0x20(%rsp)
jne 0xf8c0
leaq 0x68dd(%rip), %rdi      # 0x16198
callq 0x3ce0
movq 0x30(%rsp), %rax
movq 0x50d8(%rax), %rdi
leaq 0x521c(%rip), %rsi      # 0x14aef
callq 0x21d0
movq %rax, 0x18(%rsp)
cmpq $0x0, 0x18(%rsp)
jne 0xf8f1
leaq 0x68d0(%rip), %rdi      # 0x161bc
callq 0x3ce0
jmp 0xf8f3
movl $0x0, 0x14(%rsp)
movl 0x14(%rsp), %eax
movq 0x30(%rsp), %rcx
cmpl 0x38(%rcx), %eax
jge 0xfaa2
movq 0x30(%rsp), %rax
testb $0x1, 0x3d(%rax)
jne 0xf935
movq 0x30(%rsp), %rax
movq 0x98(%rax), %rdi
movq 0x28(%rsp), %rsi
movl $0x1, %edx
callq 0x11120
jmp 0xf94a
movq 0x30(%rsp), %rax
movq 0x98(%rax), %rax
movq 0x28(%rsp), %rcx
movb $0x1, (%rax,%rcx)
movq 0x28(%rsp), %rdx
movq 0x30(%rsp), %rax
movq 0x5108(%rax), %rax
movslq 0x14(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
movl $0x0, 0x10(%rsp)
movl 0x10(%rsp), %eax
movq 0x30(%rsp), %rcx
cmpl 0x20(%rcx), %eax
jge 0xfa90
movq $0x0, 0x8(%rsp)
movq 0x8(%rsp), %rax
movq 0x30(%rsp), %rcx
movq 0x18(%rcx), %rcx
movslq 0x10(%rsp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq 0x14(%rsp), %rdx
cmpq (%rcx,%rdx,8), %rax
jae 0xfa7e
cmpl $0x0, 0x14(%rsp)
jne 0xfa28
movq 0x30(%rsp), %rax
testb $0x1, 0x3d(%rax)
jne 0xf9dc
movq 0x30(%rsp), %rax
movq 0x98(%rax), %rdi
movq 0x28(%rsp), %rsi
movl $0x1, %edx
callq 0x11120
jmp 0xf9f1
movq 0x30(%rsp), %rax
movq 0x98(%rax), %rax
movq 0x28(%rsp), %rcx
movb $0x1, (%rax,%rcx)
movq 0x30(%rsp), %rax
testb $0x1, 0x69(%rax)
je 0xfa0c
movl 0x10(%rsp), %edi
movq 0x20(%rsp), %rsi
callq 0x11410
jmp 0xfa26
movl 0x10(%rsp), %eax
movb %al, %dl
movq 0x30(%rsp), %rax
movq 0x50f0(%rax), %rax
movq 0x28(%rsp), %rcx
movb %dl, (%rax,%rcx)
jmp 0xfa28
movq 0x30(%rsp), %rax
testb $0x1, 0x69(%rax)
je 0xfa43
movl 0x10(%rsp), %edi
movq 0x18(%rsp), %rsi
callq 0x11410
jmp 0xfa5d
movl 0x10(%rsp), %eax
movb %al, %dl
movq 0x30(%rsp), %rax
movq 0x50e8(%rax), %rax
movq 0x28(%rsp), %rcx
movb %dl, (%rax,%rcx)
movq 0x28(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x28(%rsp)
movq 0x8(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x8(%rsp)
jmp 0xf987
jmp 0xfa80
movl 0x10(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x10(%rsp)
jmp 0xf96c
jmp 0xfa92
movl 0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x14(%rsp)
jmp 0xf8fb
movq 0x30(%rsp), %rax
testb $0x1, 0x69(%rax)
je 0xfae5
movq 0x18(%rsp), %rdi
callq 0x20d0
cmpl $0x0, %eax
je 0xfac8
leaq 0x671a(%rip), %rdi      # 0x161dd
callq 0x3ce0
movq 0x20(%rsp), %rdi
callq 0x20d0
cmpl $0x0, %eax
je 0xfae3
leaq 0x6718(%rip), %rdi      # 0x161f6
callq 0x3ce0
jmp 0xfae7
jmp 0xfae7
addq $0x38, %rsp
retq
nopl (%rax)