// File: /workspace/github_c_makefile_star2_O3/richarddurbin[P]hash10x/moshasm.c
// Function: invBuild
static void invBuild (Readset *rs) /* run this after ms->depth built from reads->hit[] */
{
  Moshset *ms = rs->ms ;
  U32 i, j ;
  U64 offset = 0 ;
  rs->inv = new0 (ms->max+1, U32*) ;
  rs->invSpace = new (rs->totHit, U32) ;
  for (i = 1 ; i <= ms->max ; ++i)
    if (ms->depth[i] && ms->depth[i] < U16MAX)
      { rs->inv[i] = rs->invSpace + offset ;
	offset += ms->depth[i] ;
      }
  Read *read = arrp(rs->reads,1,Read) ;
  for (i = 1 ; i < arrayMax(rs->reads) ; ++i, ++read)
    { for (j = 0 ; j < 4 ; ++j) read->nCopy[j] = 0 ; /* build nCopy here in case msCopy changed */
      U32 *x = read->hit ;
      for (j = 0 ; j < read->nHit ; ++j, ++x)
	{ U32 y = *x & TOPMASK ;
	  ++read->nCopy[msCopy(rs->ms,y)] ;
	  if (ms->depth[y] < U16MAX) *rs->inv[y]++ = i ; /* this is the inverse map */
	}
    }
  offset = 0 ; /* now recreate rs->inv because we moved the pointers */
  for (i = 1 ; i <= ms->max ; ++i)
    if (ms->depth[i] && ms->depth[i] < U16MAX)
      { rs->inv[i] = rs->invSpace + offset ;
	offset += ms->depth[i] ;
      }
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq %rdi, %rbx
movq (%rdi), %r14
movl 0x40(%r14), %edi
incl %edi
movl $0x8, %esi
callq 0x6f74
movq %rax, 0x18(%rbx)
movq 0x10(%rbx), %rdi
shlq $0x2, %rdi
callq 0x6f4c
movq %rax, 0x20(%rbx)
movl 0x40(%r14), %eax
testl %eax, %eax
je 0x23c3
leal 0x1(%rax), %edx
cmpl $0x3, %edx
movl $0x2, %ecx
cmovael %edx, %ecx
movq 0x30(%r14), %rdi
movl $0x1, %edx
xorl %esi, %esi
movzwl (%rdi,%rdx,2), %r8d
testl %r8d, %r8d
je 0x23bb
cmpl $0xffff, %r8d           # imm = 0xFFFF
je 0x23bb
leaq (,%rsi,4), %rdi
addq 0x20(%rbx), %rdi
movq 0x18(%rbx), %r8
movq %rdi, (%r8,%rdx,8)
movq 0x30(%r14), %rdi
movzwl (%rdi,%rdx,2), %r8d
addq %r8, %rsi
incq %rdx
cmpq %rdx, %rcx
jne 0x2388
movq 0x8(%rbx), %rdi
cmpl $0x2, 0x18(%rdi)
jb 0x246e
movq 0x8(%rdi), %rcx
movslq 0x14(%rdi), %rdx
leaq (%rcx,%rdx), %rax
addq %rdx, %rcx
addq $0x24, %rcx
movl $0x1, %edx
xorl %esi, %esi
xorps %xmm0, %xmm0
leaq (%rsi,%rsi,8), %r8
movups %xmm0, (%rcx,%r8,8)
movl 0x4(%rax), %r8d
testl %r8d, %r8d
je 0x245c
movq 0x8(%rax), %rdi
xorl %r9d, %r9d
movl (%rdi,%r9,4), %r11d
movl %r11d, %r10d
andl $0x7fffffff, %r10d      # imm = 0x7FFFFFFF
movq (%rbx), %r15
movq 0x38(%r15), %r15
movzbl (%r15,%r10), %r15d
andl $0x3, %r15d
incl 0x24(%rax,%r15,4)
movq 0x30(%r14), %r15
addl %r11d, %r11d
cmpw $-0x1, (%r15,%r11)
je 0x2450
movq 0x18(%rbx), %r8
movq (%r8,%r10,8), %r11
leaq 0x4(%r11), %r15
movq %r15, (%r8,%r10,8)
movl %edx, (%r11)
movl 0x4(%rax), %r8d
incq %r9
cmpl %r8d, %r9d
jb 0x2407
movq 0x8(%rbx), %rdi
incl %edx
addq $0x48, %rax
incq %rsi
cmpl 0x18(%rdi), %edx
jb 0x23ee
movl 0x40(%r14), %eax
testl %eax, %eax
je 0x24c1
incl %eax
cmpl $0x3, %eax
movl $0x2, %ecx
cmovael %eax, %ecx
movq 0x30(%r14), %rsi
movl $0x1, %eax
xorl %edx, %edx
movzwl (%rsi,%rax,2), %edi
testl %edi, %edi
je 0x24b9
cmpl $0xffff, %edi           # imm = 0xFFFF
je 0x24b9
leaq (,%rdx,4), %rsi
addq 0x20(%rbx), %rsi
movq 0x18(%rbx), %rdi
movq %rsi, (%rdi,%rax,8)
movq 0x30(%r14), %rsi
movzwl (%rsi,%rax,2), %edi
addq %rdi, %rdx
incq %rax
cmpq %rax, %rcx
jne 0x248a
popq %rbx
popq %r14
popq %r15
retq