// File: /workspace/github_c_makefile_star2_O2/richarddurbin[P]hash10x/hash10x.c
// Function: codeClusterReadMerge
void codeClusterReadMerge (int code)
{
  ClusterBlock *b = arrp(clusterBlocks, code, ClusterBlock) ;
  if (!b->nSubCluster) return ;	/* nothing to do */
  int i, j ;
  int *readMap = new0 (b->nRead, int), *trueCluster = new (b->nSubCluster+1, int) ;
  int *deadCluster = new0 (b->nSubCluster+1, int) ;
  for (i = 0 ; i <= b->nSubCluster ; ++i) trueCluster[i] = i ; /* initialisation */
  for (i = 0 ; i < b->nHash ; ++i)
    { int hashCluster = trueCluster[b->clusHash[i].subCluster] ; if (!hashCluster) continue ;
      int readCluster = trueCluster[readMap[b->clusHash[i].read]] ;
      if (hashCluster == readCluster) continue ;
      else if (!readCluster)
	readMap[b->clusHash[i].read] = hashCluster ;
      else			/* merge clusters hashCluster and readCluster */
	{ if (hashCluster > readCluster)
	    { int t = hashCluster ; hashCluster = readCluster ; readCluster = t ; }
	  for (j = 1 ; j <= b->nSubCluster ; ++j)
	    if (trueCluster[j] == readCluster) trueCluster[j] = hashCluster ;
	  deadCluster[readCluster] = 1 ;
	}
    }

  /* now compactify trueCluster, reusing deadCluster[] for the map removing dead indices */
  for (j = 1 ; j <= b->nSubCluster ; ++j) deadCluster[j] = deadCluster[j-1] + 1 - deadCluster[j] ;
  for (j = 1 ; j <= b->nSubCluster ; ++j) trueCluster[j] = deadCluster[trueCluster[j]] ;
  b->nSubCluster = deadCluster[b->nSubCluster] ;
  for (i = 0 ; i < b->nHash ; ++i) b->clusHash[i].subCluster = trueCluster[b->clusHash[i].subCluster] ;

  free (readMap) ; free(trueCluster) ; free(deadCluster) ;
  if (isVerbose) { fprintf (outFile, " then %d merged clusters\n", b->nSubCluster) ; fflush (stdout) ; }
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq 0xc60c(%rip), %rax      # 0x10398
movq 0x8(%rax), %r12
movslq 0x14(%rax), %rax
movslq %edi, %r13
imulq %rax, %r13
cmpl $0x0, 0x8(%r12,%r13)
je 0x3f26
movl (%r12,%r13), %edi
pushq $0x4
popq %r15
movq %r15, %rsi
callq 0x8b24
movq %rax, %rbx
movl 0x8(%r12,%r13), %edi
incl %edi
shlq $0x2, %rdi
callq 0x8afc
movq %rax, %r14
movl 0x8(%r12,%r13), %edi
incl %edi
movq %r15, %rsi
callq 0x8b24
movq %rax, %r15
xorl %eax, %eax
movl 0x8(%r12,%r13), %ecx
cmpq %rcx, %rax
ja 0x3df4
movl %eax, (%r14,%rax,4)
incq %rax
jmp 0x3de1
xorl %eax, %eax
pushq $0x1
popq %rcx
movl 0x4(%r12,%r13), %edx
cmpq %rdx, %rax
jae 0x3e65
movq 0x10(%r12,%r13), %rdx
movzbl 0x6(%rdx,%rax,8), %esi
movl (%r14,%rsi,4), %edi
testl %edi, %edi
je 0x3e60
movzwl 0x4(%rdx,%rax,8), %esi
movslq (%rbx,%rsi,4), %rdx
movl (%r14,%rdx,4), %edx
cmpl %edx, %edi
je 0x3e60
testl %edx, %edx
je 0x3e5d
cmpl %edx, %edi
movl %edx, %esi
cmovll %edi, %esi
cmovgl %edi, %edx
movq %rcx, %rdi
movl 0x8(%r12,%r13), %r8d
cmpq %r8, %rdi
ja 0x3e50
cmpl %edx, (%r14,%rdi,4)
jne 0x3e4b
movl %esi, (%r14,%rdi,4)
incq %rdi
jmp 0x3e37
movslq %edx, %rdx
movl $0x1, (%r15,%rdx,4)
jmp 0x3e60
movl %edi, (%rbx,%rsi,4)
incq %rax
jmp 0x3df9
pushq $0x1
popq %rax
movl 0x8(%r12,%r13), %ecx
cmpq %rcx, %rax
ja 0x3e86
movl -0x4(%r15,%rax,4), %ecx
subl (%r15,%rax,4), %ecx
incl %ecx
movl %ecx, (%r15,%rax,4)
incq %rax
jmp 0x3e68
pushq $0x1
popq %rax
movl %ecx, %ecx
cmpq %rcx, %rax
ja 0x3ea6
movslq (%r14,%rax,4), %rcx
movl (%r15,%rcx,4), %ecx
movl %ecx, (%r14,%rax,4)
incq %rax
movl 0x8(%r12,%r13), %ecx
jmp 0x3e89
movl (%r15,%rcx,4), %eax
movl %eax, 0x8(%r12,%r13)
movl 0x4(%r12,%r13), %eax
xorl %ecx, %ecx
cmpq %rcx, %rax
je 0x3ed3
movq 0x10(%r12,%r13), %rdx
movzbl 0x6(%rdx,%rcx,8), %esi
movb (%r14,%rsi,4), %sil
movb %sil, 0x6(%rdx,%rcx,8)
incq %rcx
jmp 0x3eb6
movq %rbx, %rdi
callq 0x1040
movq %r14, %rdi
callq 0x1040
movq %r15, %rdi
callq 0x1040
cmpb $0x0, 0xc48f(%rip)      # 0x10381
je 0x3f26
movq 0xc4a5(%rip), %rdi      # 0x103a0
movl 0x8(%r12,%r13), %edx
leaq 0x5a17(%rip), %rsi      # 0x991e
xorl %eax, %eax
callq 0x1150
movq 0xb0b3(%rip), %rax      # 0xefc8
movq (%rax), %rdi
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x11a0
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq