// File: /workspace/github_c_makefile_star2_O3/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 0xba42(%rip), %rax      # 0x10388
movq 0x8(%rax), %r12
movslq 0x14(%rax), %rax
movslq %edi, %r13
imulq %rax, %r13
cmpl $0x0, 0x8(%r12,%r13)
je 0x4aff
movl (%r12,%r13), %edi
movl $0x4, %esi
callq 0x96e8
movq %rax, %rbx
movl 0x8(%r12,%r13), %edi
incl %edi
shlq $0x2, %rdi
callq 0x96c0
movq %rax, %r14
movl 0x8(%r12,%r13), %edi
incl %edi
movl $0x4, %esi
callq 0x96e8
movq %rax, %r15
xorl %ecx, %ecx
movl %ecx, (%r14,%rcx,4)
leaq 0x1(%rcx), %rdx
movl 0x8(%r12,%r13), %eax
cmpq %rax, %rcx
movq %rdx, %rcx
jb 0x499b
cmpl $0x0, 0x4(%r12,%r13)
je 0x4a35
movq 0x10(%r12,%r13), %rax
xorl %ecx, %ecx
movzbl 0x6(%rax,%rcx,8), %edx
movl (%r14,%rdx,4), %edi
testl %edi, %edi
je 0x4a23
movzwl 0x4(%rax,%rcx,8), %esi
movslq (%rbx,%rsi,4), %rdx
movl (%r14,%rdx,4), %edx
cmpl %edx, %edi
je 0x4a23
testl %edx, %edx
je 0x4a20
cmpl %edx, %edi
movl %edx, %esi
cmovll %edi, %esi
cmovgl %edi, %edx
movl 0x8(%r12,%r13), %edi
testl %edi, %edi
je 0x4a13
xorl %r8d, %r8d
cmpl %edx, 0x4(%r14,%r8,4)
jne 0x4a08
movl %esi, 0x4(%r14,%r8,4)
movl 0x8(%r12,%r13), %edi
movl %edi, %r9d
incq %r8
cmpq %r9, %r8
jb 0x49f7
movslq %edx, %rdx
movl $0x1, (%r15,%rdx,4)
jmp 0x4a23
movl %edi, (%rbx,%rsi,4)
incq %rcx
movl 0x4(%r12,%r13), %edx
cmpq %rdx, %rcx
jb 0x49bf
movl 0x8(%r12,%r13), %eax
testl %eax, %eax
je 0x4a7a
movl (%r15), %eax
xorl %ecx, %ecx
subl 0x4(%r15,%rcx,4), %eax
incl %eax
movl %eax, 0x4(%r15,%rcx,4)
movl 0x8(%r12,%r13), %edx
incq %rcx
cmpq %rdx, %rcx
jb 0x4a3e
testl %edx, %edx
je 0x4a7a
xorl %ecx, %ecx
movslq 0x4(%r14,%rcx,4), %rax
movl (%r15,%rax,4), %eax
movl %eax, 0x4(%r14,%rcx,4)
movl 0x8(%r12,%r13), %eax
incq %rcx
cmpq %rax, %rcx
jb 0x4a5d
jmp 0x4a7c
xorl %eax, %eax
movl (%r15,%rax,4), %eax
movl %eax, 0x8(%r12,%r13)
movl 0x4(%r12,%r13), %eax
testq %rax, %rax
je 0x4aac
movq 0x10(%r12,%r13), %rcx
xorl %edx, %edx
movzbl 0x6(%rcx,%rdx,8), %esi
movb (%r14,%rsi,4), %sil
movb %sil, 0x6(%rcx,%rdx,8)
incq %rdx
cmpq %rdx, %rax
jne 0x4a96
movq %rbx, %rdi
callq 0x1040
movq %r14, %rdi
callq 0x1040
movq %r15, %rdi
callq 0x1040
cmpb $0x0, 0xb8a6(%rip)      # 0x10371
je 0x4aff
movq 0xb8bc(%rip), %rdi      # 0x10390
movl 0x8(%r12,%r13), %edx
leaq 0x5e7e(%rip), %rsi      # 0xa95e
xorl %eax, %eax
callq 0x1150
movq 0xa4da(%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