// File: /workspace/github_c_makefile_star2_O3/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, 0x8(%rsp)
movq %rsi, %r8
movq %rdi, %rbx
leaq 0x967a(%rip), %rsi      # 0xb730
xorl %eax, %eax
movl %eax, 0x1b8(%rsi)
movl %eax, 0x138(%rsi)
leaq 0x18(%rsp), %rdx
leaq 0x10(%rsp), %rcx
leaq 0x4(%rsp), %r9
movq %r8, 0x28(%rsp)
movq %r8, %rdi
xorl %r8d, %r8d
callq 0x3020
movl $0x0, %r12d
testl %eax, %eax
je 0x2235
movsbl 0x8(%rsp), %r13d
leaq 0x40(%rsp), %rbp
leaq 0x24(%rsp), %r14
xorl %r12d, %r12d
movq %r12, 0x38(%rsp)
movq 0x40(%rbx), %rdi
movq 0x10(%rsp), %rsi
leaq 0xc(%rsp), %rdx
callq 0x5ae4
testl %eax, %eax
jne 0x2133
movq 0x10(%rsp), %rsi
leaq 0x4f3e(%rip), %rdi      # 0x706a
xorl %eax, %eax
callq 0x63e4
movl 0x4(%rsp), %r15d
movq 0x48(%rbx), %rdi
movl 0xc(%rsp), %esi
callq 0x5f1d
movl %r15d, (%rax)
movslq 0x4(%rsp), %rdx
movq (%rbx), %rax
movq (%rax), %rdi
movq 0x18(%rsp), %rsi
movq %rdx, 0x30(%rsp)
callq 0x4624
movq %rax, %r15
movq %rax, %rdi
movq %rbp, %rsi
movq %r14, %rdx
xorl %ecx, %ecx
callq 0x47cf
testb %al, %al
je 0x21e4
movq (%rbx), %rdi
movq 0x40(%rsp), %rsi
movl %r13d, %edx
callq 0x4ac3
testl %eax, %eax
je 0x21df
movl %eax, %r12d
movl 0xc(%rbx), %eax
leal 0x1(%rax), %ecx
cmpl 0x8(%rbx), %ecx
jb 0x21ac
leaq 0x4ee7(%rip), %rdi      # 0x7089
xorl %eax, %eax
callq 0x63e4
movl 0xc(%rbx), %eax
movq 0x10(%rbx), %rcx
movl %eax, %eax
movl %r12d, (%rcx,%rax,4)
movq 0x28(%rbx), %rax
movl %r12d, %ecx
incl (%rax,%rcx,4)
movl 0x24(%rsp), %eax
movq 0x18(%rbx), %rcx
movl 0xc(%rbx), %edx
movl %eax, (%rcx,%rdx,4)
movl 0xc(%rsp), %eax
movq 0x20(%rbx), %rcx
movl 0xc(%rbx), %edx
movl %eax, (%rcx,%rdx,4)
incl 0xc(%rbx)
movq %r15, %rdi
jmp 0x2168
movq 0x38(%rsp), %r12
addq 0x30(%rsp), %r12
movq %r15, %rdi
callq 0x2318
movq 0x18(%rsp), %rdi
callq 0x1040
movq 0x10(%rsp), %rdi
callq 0x1040
movq 0x28(%rsp), %rdi
leaq 0x951a(%rip), %rsi      # 0xb730
leaq 0x18(%rsp), %rdx
leaq 0x10(%rsp), %rcx
xorl %r8d, %r8d
leaq 0x4(%rsp), %r9
callq 0x3020
testl %eax, %eax
jne 0x2104
movq 0x28(%rsp), %rdi
callq 0x1090
movq 0xa102(%rip), %rdi      # 0xc348
movl 0xc(%rbx), %edx
movq 0x40(%rbx), %rax
movl 0x10(%rax), %ecx
leaq 0x4e4a(%rip), %rsi      # 0x70a1
movq %r12, %r8
xorl %eax, %eax
callq 0x1120
movq (%rbx), %rsi
cmpl $0x0, 0x40(%rsi)
movl $0x0, %ecx
movl $0x0, %r8d
movl $0x0, %edx
je 0x22dd
movq 0x28(%rbx), %rax
xorl %r10d, %r10d
xorl %r8d, %r8d
xorl %ecx, %ecx
xorl %edx, %edx
movl 0x4(%rax,%r10,4), %r9d
movq 0x38(%rsi), %rsi
movb 0x1(%rsi,%r10), %dil
cmpl $0x2, %r9d
je 0x22b2
cmpl $0x1, %r9d
jne 0x22c3
andb $-0x4, %dil
incb %dil
movb %dil, 0x1(%rsi,%r10)
incl %edx
jmp 0x22cf
andb $-0x4, %dil
orb $0x2, %dil
movb %dil, 0x1(%rsi,%r10)
incl %ecx
jmp 0x22cf
orb $0x3, %dil
movb %dil, 0x1(%rsi,%r10)
incl %r8d
movq (%rbx), %rsi
movl 0x40(%rsi), %edi
incq %r10
cmpq %rdi, %r10
jb 0x2288
movq 0xa064(%rip), %rdi      # 0xc348
leaq 0x4df2(%rip), %rsi      # 0x70dd
xorl %eax, %eax
callq 0x1120
cmpb $0x0, 0x8(%rsp)
je 0x2301
movq (%rbx), %rdi
callq 0x49f9
movq %rbx, %rdi
callq 0x1f0a
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq