// File: /workspace/github_c_makefile_star2_O0/richarddurbin[P]hash10x/moshasm.c
// Function: assembleFromRead
void assembleFromRead (Readset *rs, U32 ix)
{
  Read *x = arrp(rs->reads,ix,Read) ;
  Read *z = new0 (1,Read) ;	/* build the assembly here */
  int io, iy, ih ;

  /* first collect all the hits in all the overlapping reads */
  Array aHits = arrayCreate (1024, AssemblyHit) ;
  AssemblyHit *ah ;
  HASH  hitHash = hashCreate (1024) ;
  Array overlaps = findOverlaps (rs, x, 1) ;
  for (io = 0 ; io < arrayMax (overlaps) ; ++io)
    { Overlap *o = arrp(overlaps,io,Overlap) ;
      Read *y = arrp(rs->reads,o->iy,Read) ;
      int yPos = 0 ;
      Array lastDown = 0 ;
      for (iy = 0 ; iy < y->nHit ; ++iy)
	{ U32 hit = y->hit[iy] & TOPMASK ; yPos += y->dx[iy] ;
	  ih = hashAdd (hitHash, HASH_INT(hit)) ;
	  ah = arrayp(aHits,ih,AssemblyHit) ;
	  if (!ah->count)
	    { ah->hit = hit ;
	      ah->downHits = arrayCreate (8, int) ;
	    }
	  ++ah->count ;
	  if (iy) ++ah->upCount ;
	  if (lastDown) array(lastDown, arrayMax(lastDown), int) = ih ;
	  lastDown = ah->downHits ;
	  if (o->isPlus) ah->pos += o->offset + yPos ;
	  else ah->pos += o->offset - yPos ;
	}
    }

  /* now want to select the longest clearly supported chain */
  /* need a full chain because we want to rely on the order for future matches */

  

  /* reporting */
  
  double totCount = 0. ;
  int i, j, countA[20][20], countB[20][20] ;
  for (i = 20 ; i-- ;) for (j = 20 ; j-- ;) { countA[i][j] = 0 ; countB[i][j] = 0 ; }
  for (ih = 1 ; ih < hashCount(hitHash) ; ++ih)
    { ah = arrp(aHits,ih,AssemblyHit) ;
      ah->pos /= ah->count ;	/* just an estimate for now */
      totCount += ah->count ;
      if (!msIsCopy1 (rs->ms, ah->hit)) continue ;
      i = ah->count ; if (i > 19) i = 19 ;
      j = rs->ms->depth[ah->hit] ; if (j > 19) j = 19 ; ++countA[i][j] ;
      j = (10*ah->count - 1) / rs->ms->depth[ah->hit] ; ++countB[i][j] ;
    }
  totCount /= hashCount(hitHash) ;
  printf ("AR  %d total hits - mean count %.1f\n", hashCount(hitHash), totCount) ;
  for (i = 0 ; i < 20 ; ++i)
    { printf ("AH  %2d\t", i) ;
      for (j = 0 ; j < 20 ; ++j) if (j < i) printf ("    ") ; else printf ("%4d", countA[i][j]) ;
      printf ("    ") ;
      for (j = 0 ; j < 10 ; ++j) printf ("%4d", countB[i][j]) ;
      printf ("\n") ;
    }

  hashDestroy (hitHash) ;
  arrayDestroy (aHits) ;
  arrayDestroy (overlaps) ;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd20, %rsp            # imm = 0xD20
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rax
movl -0xc(%rbp), %ecx
movq -0x8(%rbp), %rdx
movq 0x8(%rdx), %rdx
imull 0x14(%rdx), %ecx
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, -0x18(%rbp)
movl $0x1, %edi
movl $0x48, %esi
callq 0xa230
movq %rax, -0x20(%rbp)
movl $0x400, %edi            # imm = 0x400
movl $0x18, %esi
callq 0x9220
movq %rax, -0x38(%rbp)
movl $0x400, %edi            # imm = 0x400
callq 0x7d40
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl $0x1, %edx
callq 0x2740
movq %rax, -0x50(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
movq -0x50(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jge 0x3b3f
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x24(%rbp), %ecx
movq -0x50(%rbp), %rdx
imull 0x14(%rdx), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rax
movq -0x58(%rbp), %rcx
movl (%rcx), %ecx
movq -0x8(%rbp), %rdx
movq 0x8(%rdx), %rdx
imull 0x14(%rdx), %ecx
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movl $0x0, -0x64(%rbp)
movq $0x0, -0x70(%rbp)
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
movq -0x60(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jge 0x3b2f
movq -0x60(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x28(%rbp), %rcx
movl (%rax,%rcx,4), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, -0x74(%rbp)
movq -0x60(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x28(%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
addl -0x64(%rbp), %eax
movl %eax, -0x64(%rbp)
movq -0x48(%rbp), %rdi
movl -0x74(%rbp), %eax
xorl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movq %rax, 0xc92d(%rip)      # 0x10370
movq 0xc926(%rip), %rax      # 0x10370
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rsi
callq 0x80d0
movl %eax, -0x2c(%rbp)
movq -0x38(%rbp), %rdi
movl -0x2c(%rbp), %esi
callq 0x9680
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpl $0x0, 0x4(%rax)
jne 0x3a97
movl -0x74(%rbp), %ecx
movq -0x40(%rbp), %rax
movl %ecx, (%rax)
movl $0x8, %edi
movl $0x4, %esi
callq 0x9220
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x40(%rbp), %rax
movl 0x4(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x4(%rax)
cmpl $0x0, -0x28(%rbp)
je 0x3ab7
movq -0x40(%rbp), %rax
movl 0xc(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0xc(%rax)
cmpq $0x0, -0x70(%rbp)
je 0x3adf
movl -0x2c(%rbp), %eax
movl %eax, -0xd14(%rbp)
movq -0x70(%rbp), %rdi
movq -0x70(%rbp), %rax
movl 0x18(%rax), %esi
callq 0x9680
movl -0xd14(%rbp), %ecx
movl %ecx, (%rax)
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x70(%rbp)
movq -0x58(%rbp), %rax
cmpb $0x0, 0xc(%rax)
je 0x3b0b
movq -0x58(%rbp), %rax
movl 0x8(%rax), %ecx
addl -0x64(%rbp), %ecx
movq -0x40(%rbp), %rax
addl 0x8(%rax), %ecx
movl %ecx, 0x8(%rax)
jmp 0x3b1f
movq -0x58(%rbp), %rax
movl 0x8(%rax), %ecx
subl -0x64(%rbp), %ecx
movq -0x40(%rbp), %rax
addl 0x8(%rax), %ecx
movl %ecx, 0x8(%rax)
jmp 0x3b21
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x39f1
jmp 0x3b31
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x3987
xorps %xmm0, %xmm0
movsd %xmm0, -0x88(%rbp)
movl $0x14, -0x8c(%rbp)
movl -0x8c(%rbp), %eax
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, -0x8c(%rbp)
cmpl $0x0, %eax
je 0x3bd4
movl $0x14, -0x90(%rbp)
movl -0x90(%rbp), %eax
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, -0x90(%rbp)
cmpl $0x0, %eax
je 0x3bd2
movslq -0x8c(%rbp), %rcx
leaq -0x6d0(%rbp), %rax
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movslq -0x90(%rbp), %rcx
movl $0x0, (%rax,%rcx,4)
movslq -0x8c(%rbp), %rcx
leaq -0xd10(%rbp), %rax
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movslq -0x90(%rbp), %rcx
movl $0x0, (%rax,%rcx,4)
jmp 0x3b74
jmp 0x3b54
movl $0x1, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, -0xd18(%rbp)
movq -0x48(%rbp), %rdi
callq 0x8860
movl %eax, %ecx
movl -0xd18(%rbp), %eax
cmpl %ecx, %eax
jge 0x3d40
movq -0x38(%rbp), %rdx
movq 0x8(%rdx), %rax
movl -0x2c(%rbp), %ecx
movl 0x14(%rdx), %edx
imull %edx, %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0xd20(%rbp)
movl 0x4(%rax), %ecx
movl 0x8(%rax), %eax
xorl %edx, %edx
divl %ecx
movl %eax, %ecx
movq -0xd20(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x40(%rbp), %rax
movl 0x4(%rax), %eax
cvtsi2sd %rax, %xmm0
addsd -0x88(%rbp), %xmm0
movsd %xmm0, -0x88(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rdi
movq -0x40(%rbp), %rax
movl (%rax), %esi
callq 0x30b0
cmpb $0x0, %al
jne 0x3c70
jmp 0x3d32
movq -0x40(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x8c(%rbp)
cmpl $0x13, -0x8c(%rbp)
jle 0x3c90
movl $0x13, -0x8c(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq 0x30(%rax), %rax
movq -0x40(%rbp), %rcx
movl (%rcx), %ecx
movzwl (%rax,%rcx,2), %eax
movl %eax, -0x90(%rbp)
cmpl $0x13, -0x90(%rbp)
jle 0x3cbe
movl $0x13, -0x90(%rbp)
movslq -0x8c(%rbp), %rcx
leaq -0x6d0(%rbp), %rax
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movslq -0x90(%rbp), %rcx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
movq -0x40(%rbp), %rax
imull $0xa, 0x4(%rax), %eax
subl $0x1, %eax
movq -0x8(%rbp), %rcx
movq (%rcx), %rcx
movq 0x30(%rcx), %rcx
movq -0x40(%rbp), %rdx
movl (%rdx), %edx
movzwl (%rcx,%rdx,2), %ecx
xorl %edx, %edx
divl %ecx
movl %eax, -0x90(%rbp)
movslq -0x8c(%rbp), %rcx
leaq -0xd10(%rbp), %rax
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movslq -0x90(%rbp), %rcx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x3bdb
movq -0x48(%rbp), %rdi
callq 0x8860
cvtsi2sd %eax, %xmm1
movsd -0x88(%rbp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, -0x88(%rbp)
movq -0x48(%rbp), %rdi
callq 0x8860
movl %eax, %esi
movsd -0x88(%rbp), %xmm0
leaq 0x776f(%rip), %rdi      # 0xb4ea
movb $0x1, %al
callq 0x10b0
movl $0x0, -0x8c(%rbp)
cmpl $0x14, -0x8c(%rbp)
jge 0x3e9f
movl -0x8c(%rbp), %esi
leaq 0x7769(%rip), %rdi      # 0xb50f
movb $0x0, %al
callq 0x10b0
movl $0x0, -0x90(%rbp)
cmpl $0x14, -0x90(%rbp)
jge 0x3e1e
movl -0x90(%rbp), %eax
cmpl -0x8c(%rbp), %eax
jge 0x3dde
leaq 0x7743(%rip), %rdi      # 0xb518
movb $0x0, %al
callq 0x10b0
jmp 0x3e0b
movslq -0x8c(%rbp), %rcx
leaq -0x6d0(%rbp), %rax
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movslq -0x90(%rbp), %rcx
movl (%rax,%rcx,4), %esi
leaq 0x7719(%rip), %rdi      # 0xb51d
movb $0x0, %al
callq 0x10b0
jmp 0x3e0d
movl -0x90(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x90(%rbp)
jmp 0x3db7
leaq 0x76f3(%rip), %rdi      # 0xb518
movb $0x0, %al
callq 0x10b0
movl $0x0, -0x90(%rbp)
cmpl $0xa, -0x90(%rbp)
jge 0x3e7d
movslq -0x8c(%rbp), %rcx
leaq -0xd10(%rbp), %rax
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movslq -0x90(%rbp), %rcx
movl (%rax,%rcx,4), %esi
leaq 0x76b8(%rip), %rdi      # 0xb51d
movb $0x0, %al
callq 0x10b0
movl -0x90(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x90(%rbp)
jmp 0x3e36
leaq 0x76fa(%rip), %rdi      # 0xb57e
movb $0x0, %al
callq 0x10b0
movl -0x8c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8c(%rbp)
jmp 0x3d8c
movq -0x48(%rbp), %rdi
callq 0x7e80
movq -0x38(%rbp), %rdi
callq 0x9420
movq -0x50(%rbp), %rdi
callq 0x9420
addq $0xd20, %rsp            # imm = 0xD20
popq %rbp
retq
nopw %cs:(%rax,%rax)