// File: /workspace/github_c_makefile_star2_O2/richarddurbin[P]hash10x/moshasm.c
// Function: readsetFileRead
void readsetFileRead (Readset *rs, char *filename)
{
  char *seq ;			/* ignore the name for now */
  int len ;
  Array hitsA = arrayCreate (1024, U32) ; /* reuse these to build the lists of hits and dx */
  Array dxA = arrayCreate (1024, U16) ;

  memset (rs->ms->depth, 0, (rs->ms->max+1)*sizeof(U16)) ; /* rebuild depth from this file */
  dna2indexConv['N'] = dna2indexConv['n'] = 0 ; /* to get 2-bit encoding */
  SeqIO *si = seqIOopen (filename, dna2indexConv, FALSE) ;
  while (seqIOread (si))
    { Read *read = arrayp(rs->reads, arrayMax(rs->reads), Read) ;
      read->len = si->seqLen ;
      SeqhashRCiterator *mi = moshRCiterator (rs->ms->hasher, sqioSeq(si), si->seqLen) ;
      hitsA = arrayReCreate (hitsA, 1024, U32) ;
      dxA = arrayReCreate (dxA, 1024, U16) ;
      U64 hash ; int lastPos = 0, pos ; BOOL isForward ;
      while (moshRCnext (mi, &hash, &pos, &isForward))
	{ U32 index = moshsetIndexFind (rs->ms, hash, FALSE) ;
	  if (index)
	    { array(hitsA,read->nHit,U32) = isForward ? (index | TOPBIT) : index ;
	      array(dxA,read->nHit,U16) = pos - lastPos ; lastPos = pos ;
	      ++read->nHit ;
	      U16 *di = &rs->ms->depth[index] ; ++*di ; if (!*di) *di = U16MAX ;
	    }
	  else ++read->nMiss ;
	}
      seqhashRCiteratorDestroy (mi) ;
      if (read->nHit)
	{ read->hit = new (read->nHit, U32) ;
	  memcpy (read->hit, arrp(hitsA,0,U32), read->nHit*sizeof(U32)) ;
	  read->dx = new(read->nHit,U16) ;
	  memcpy (read->dx, arrp(dxA,0,U16), read->nHit*sizeof(U16)) ;
	  rs->totHit += read->nHit ;
	}
    }
  seqIOclose (si) ;

  invBuild (rs) ;
  arrayDestroy (hitsA) ; arrayDestroy (dxA) ;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %r14
movq %rdi, %rbx
pushq $0x4
popq %rsi
movl $0x400, %edi            # imm = 0x400
callq 0x5d68
movq %rax, 0x18(%rsp)
pushq $0x2
popq %rsi
movl $0x400, %edi            # imm = 0x400
callq 0x5d68
movq %rax, 0x10(%rsp)
movq (%rbx), %rax
movq 0x30(%rax), %rdi
movl 0x40(%rax), %edx
incl %edx
addq %rdx, %rdx
xorl %esi, %esi
callq 0x10e0
leaq 0x9e6d(%rip), %rsi      # 0xb760
andl $0x0, 0x1b8(%rsi)
andl $0x0, 0x138(%rsi)
movq %r14, %rdi
xorl %edx, %edx
callq 0x37e0
movq %rax, %r12
leaq 0xf(%rsp), %r14
movq %rax, 0x28(%rsp)
movq %r12, %rdi
callq 0x3998
testb %al, %al
je 0x1ac6
movq 0x8(%rbx), %rdi
movl 0x18(%rdi), %esi
callq 0x6000
movq %rax, %r15
movl 0x18(%r12), %edx
movl %edx, (%rax)
cmpl $0x2, (%r12)
jne 0x194c
movq 0x70(%r12), %rsi
jmp 0x1956
movslq 0x24(%r12), %rsi
addq 0x50(%r12), %rsi
movq (%rbx), %rax
movq (%rax), %rdi
callq 0x4889
movq %rax, %r13
movq 0x18(%rsp), %rdi
movl $0x400, %esi            # imm = 0x400
pushq $0x4
popq %rdx
callq 0x5de3
movq %rax, 0x18(%rsp)
movq 0x10(%rsp), %rdi
movl $0x400, %esi            # imm = 0x400
pushq $0x2
popq %rdx
callq 0x5de3
movq %rax, 0x10(%rsp)
movl $0x0, 0x20(%rsp)
movq %r13, %rdi
leaq 0x30(%rsp), %rsi
leaq 0x24(%rsp), %rdx
movq %r14, %rcx
callq 0x49b1
testb %al, %al
je 0x1a44
movq (%rbx), %rdi
movq 0x30(%rsp), %rsi
xorl %edx, %edx
callq 0x4c1b
testl %eax, %eax
jne 0x19d0
incl 0x1c(%r15)
jmp 0x199a
movl %eax, %ebp
movl %eax, %r12d
orl $0x80000000, %r12d      # imm = 0x80000000
cmpb $0x0, 0xf(%rsp)
cmovel %eax, %r12d
movl 0x4(%r15), %esi
movq 0x18(%rsp), %rdi
callq 0x6000
movl %r12d, (%rax)
movl 0x24(%rsp), %r12d
subl 0x20(%rsp), %r12d
movl 0x4(%r15), %esi
movq 0x10(%rsp), %rdi
callq 0x6000
movw %r12w, (%rax)
movq 0x28(%rsp), %r12
movl 0x24(%rsp), %eax
movl %eax, 0x20(%rsp)
incl 0x4(%r15)
movq (%rbx), %rax
movq 0x30(%rax), %rax
movl %ebp, %ecx
movzwl (%rax,%rcx,2), %edx
incw %dx
movl $0xffff, %esi           # imm = 0xFFFF
cmovel %esi, %edx
movw %dx, (%rax,%rcx,2)
jmp 0x199a
movq 0x28(%r13), %rdi
callq 0x1040
movq 0x30(%r13), %rdi
callq 0x1040
movq %r13, %rdi
callq 0x1040
movslq 0x4(%r15), %rdi
testq %rdi, %rdi
je 0x1918
shlq $0x2, %rdi
callq 0x659c
movq %rax, 0x8(%r15)
movq 0x18(%rsp), %rcx
movq 0x8(%rcx), %rsi
movslq 0x4(%r15), %rdx
shlq $0x2, %rdx
movq %rax, %rdi
callq 0x1150
movslq 0x4(%r15), %rdi
addq %rdi, %rdi
callq 0x659c
movq %rax, 0x10(%r15)
movq 0x10(%rsp), %rcx
movq 0x8(%rcx), %rsi
movslq 0x4(%r15), %rdx
addq %rdx, %rdx
movq %rax, %rdi
callq 0x1150
movslq 0x4(%r15), %rax
addq %rax, 0x10(%rbx)
jmp 0x1918
movq %r12, %rdi
callq 0x3967
movq %rbx, %rdi
callq 0x1753
movq 0x18(%rsp), %rdi
callq 0x5ea8
movq 0x10(%rsp), %rdi
callq 0x5ea8
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq