// File: /workspace/github_c_makefile_star2_O2/richarddurbin[P]hash10x/moshmap.c
// Function: referenceFastaRead
void referenceFastaRead (Reference *ref, FILE *f, BOOL isAdd)
{
  char *seq, *seqName ;
  int len ;
  U64 totLen = 0 ;
  
  dna2indexConv['N'] = dna2indexConv['n'] = 0 ; /* to get 2-bit encoding */
  while (readSequence (f, dna2indexConv, &seq, &seqName, 0, &len))
    { int id ;
      if (!dictAdd (ref->dict, seqName, &id)) die ("duplicate ref sequence name %s", seqName) ;
      array (ref->len, id, int) = len ;
      totLen += len ;
      SeqhashRCiterator *mi = moshRCiterator (ref->ms->hasher, seq, len) ;
      U64 hash ; int pos ;
      while (moshRCnext (mi, &hash, &pos, 0))
	{ U32 index = moshsetIndexFind (ref->ms, hash, isAdd) ;
	  if (index)
	    { if (ref->max+1 >= ref->size) die ("reference size overflow") ;
	      ref->index[ref->max] = index ;
	      ++ref->depth[index] ;
	      ref->offset[ref->max] = pos ;
	      ref->id[ref->max] = id ;
	      ++ref->max ;
	    }
	}
      seqhashRCiteratorDestroy (mi) ;
      free (seq) ; free (seqName) ;
    }
  fclose (f) ;

  fprintf (outFile, "  %d hashes from %d reference sequences, total length %lld\n",
	   ref->max, dictMax(ref->dict), totLen) ;
  int i ; U32 *d = &ref->depth[1] ; U32 n1 = 0, n2 = 0, nM = 0 ;
  for (i = 1 ; i <= ref->ms->max ; ++i, ++d)
    if (*d == 1) { msSetCopy1 (ref->ms, i) ; ++n1 ; }
    else if (*d == 2) { msSetCopy2 (ref->ms, i) ; ++n2 ; }
    else { msSetCopyM (ref->ms, i) ; ++nM ; }
  fprintf (outFile, "  %d copy 1, %d copy 2, %d multiple\n", n1, n2, nM) ;

  if (isAdd) moshsetPack (ref->ms) ;
  referencePack (ref) ;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %edx, %ebp
movq %rsi, 0x20(%rsp)
movq %rdi, %rbx
leaq 0x9166(%rip), %rax      # 0xa730
andl $0x0, 0x1b8(%rax)
andl $0x0, 0x138(%rax)
leaq 0x40(%rsp), %r13
leaq 0x1c(%rsp), %r12
xorl %r15d, %r15d
movq 0x20(%rsp), %rdi
leaq 0x913f(%rip), %rsi      # 0xa730
leaq 0x28(%rsp), %rdx
leaq 0x10(%rsp), %rcx
xorl %r8d, %r8d
leaq 0xc(%rsp), %r9
callq 0x2b58
testl %eax, %eax
je 0x1719
movq %r15, 0x38(%rsp)
movq 0x40(%rbx), %rdi
movq 0x10(%rsp), %rsi
leaq 0x8(%rsp), %rdx
callq 0x5254
testl %eax, %eax
jne 0x163f
movq 0x10(%rsp), %rsi
leaq 0x4a32(%rip), %rdi      # 0x606a
xorl %eax, %eax
callq 0x5b50
movl 0xc(%rsp), %r14d
movq 0x48(%rbx), %rdi
movl 0x8(%rsp), %esi
callq 0x5674
movl %r14d, (%rax)
movl 0xc(%rsp), %eax
movslq %eax, %rdx
movq (%rbx), %rax
movq (%rax), %rdi
movq 0x28(%rsp), %rsi
movq %rdx, 0x30(%rsp)
callq 0x3efd
movq %rax, %r14
movq %r14, %rdi
movq %r13, %rsi
movq %r12, %rdx
xorl %ecx, %ecx
callq 0x4025
testb %al, %al
je 0x16ee
movq (%rbx), %rdi
movq 0x40(%rsp), %rsi
movl %ebp, %edx
callq 0x428f
testl %eax, %eax
je 0x1673
movl %eax, %r15d
movl 0xc(%rbx), %eax
leal 0x1(%rax), %ecx
cmpl 0x8(%rbx), %ecx
jb 0x16b9
leaq 0x49da(%rip), %rdi      # 0x6089
xorl %eax, %eax
callq 0x5b50
movl 0xc(%rbx), %eax
movq 0x10(%rbx), %rcx
movl %eax, %eax
movl %r15d, (%rcx,%rax,4)
movq 0x28(%rbx), %rax
movl %r15d, %ecx
incl (%rax,%rcx,4)
movl 0x1c(%rsp), %eax
movq 0x18(%rbx), %rcx
movl 0xc(%rbx), %edx
movl %eax, (%rcx,%rdx,4)
movl 0x8(%rsp), %eax
movq 0x20(%rbx), %rcx
movl 0xc(%rbx), %edx
movl %eax, (%rcx,%rdx,4)
incl 0xc(%rbx)
jmp 0x1673
movq 0x38(%rsp), %r15
addq 0x30(%rsp), %r15
movq %r14, %rdi
callq 0x17e3
movq 0x28(%rsp), %rdi
callq 0x1040
movq 0x10(%rsp), %rdi
callq 0x1040
jmp 0x15e5
movq 0x20(%rsp), %rdi
callq 0x1090
movq 0x9c1e(%rip), %rdi      # 0xb348
movl 0xc(%rbx), %edx
movq 0x40(%rbx), %rax
movl 0x10(%rax), %ecx
leaq 0x4966(%rip), %rsi      # 0x60a1
xorl %r14d, %r14d
movq %r15, %r8
xorl %eax, %eax
callq 0x1120
movq 0x28(%rbx), %rax
pushq $0x1
popq %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
movq (%rbx), %rsi
movl 0x40(%rsi), %edi
cmpq %rdi, %rdx
ja 0x17a7
movl (%rax,%rdx,4), %r9d
movq 0x38(%rsi), %rsi
movb (%rsi,%rdx), %dil
cmpl $0x2, %r9d
je 0x1787
cmpl $0x1, %r9d
jne 0x1797
andb $-0x4, %dil
incb %dil
movb %dil, (%rsi,%rdx)
incl %r14d
jmp 0x17a2
andb $-0x4, %dil
orb $0x2, %dil
movb %dil, (%rsi,%rdx)
incl %ecx
jmp 0x17a2
orb $0x3, %dil
movb %dil, (%rsi,%rdx)
incl %r8d
incq %rdx
jmp 0x1754
movq 0x9b9a(%rip), %rdi      # 0xb348
leaq 0x4928(%rip), %rsi      # 0x60dd
movl %r14d, %edx
xorl %eax, %eax
callq 0x1120
testb %bpl, %bpl
je 0x17cc
movq (%rbx), %rdi
callq 0x41c5
movq %rbx, %rdi
callq 0x1428
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq