// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/rcut.cpp
// Function: gen_ref_bub(mc_clus_t*, kv_u_trans_t*)
asg64_v* gen_ref_bub(mc_clus_t *bc, kv_u_trans_t *ref)
{
	if(!ref) return NULL;
	asg64_v *aux; CALLOC(aux, 1); aux->n = aux->m = bc->n; double w, mmw;
	MALLOC(aux->a, bc->n); memset(aux->a, -1, sizeof((*(aux->a)))*bc->n);
	uint32_t k, l, i, *ba, bn, m, on, bid; ma_utg_t *u = NULL; uint64_t p, mm, st, j;
	u_trans_t *o = NULL; asg64_v buf; kv_init(buf); 

	for (i = bid = 0; i < bc->bub->b_ug->u.n; i++) {///set nodes within bubbles
        u = &(bc->bub->b_ug->u.a[i]);
        for (k = 0; k < u->n; k++, bid++) {
            get_bubbles(bc->bub, u->a[k]>>33, NULL, NULL, &ba, &bn, NULL);
            for (m = 0; m < bn; m++) aux->a[ba[m]>>1] = bid;
        }
    }
	// bin = bid;

	for (i = 0; i < bc->bub->ug->g->n_seq; i++) {
		if(aux->a[i] != ((uint64_t)-1)) continue;
		o = u_trans_a(*ref, i); on = u_trans_n(*ref, i);
		if(!on) continue;
		buf.n = 0; kv_resize(uint64_t, buf, on);
		for (k = 0; k < on; k++) {
			p = aux->a[o[k].tn]; p<<= 32; p += k;
			kv_push(uint64_t, buf, p);
		}

		radix_sort_mc64(buf.a, buf.a + buf.n); 
		mm = (uint32_t)-1; mmw = -1;
		for (l = 0, k = 1; k <= buf.n; k++) {
			if((k == buf.n) || ((buf.a[l]>>32) == ((uint32_t)-1)) || ((buf.a[l]>>32) != (buf.a[k]>>32))) {
				for (m = l, w = 0; m < k; m++) w += fabs(o[((uint32_t)buf.a[m])].nw);
				if(mmw < w) {
					mmw = w; mm = buf.a[l]>>32;
				}
				l = k;
			}
		}
		if(mm != ((uint32_t)-1)) aux->a[i] = mm;
	}


	///final cluster
	for (i = 0; i < bc->bub->ug->g->n_seq; i++) {
		if(aux->a[i] != ((uint64_t)-1)) continue;
		buf.n = 0; kv_push(uint64_t, buf, i);
        while (buf.n > 0) {
            k = buf.a[--buf.n];
			if(aux->a[k] != ((uint64_t)-1)) continue;
            aux->a[k] = bid;///group id
            o = u_trans_a(*ref, k); on = u_trans_n(*ref, k);
            for (st = 0, j = 1; j <= on; ++j) {
                if(j == on || o[j].tn != o[st].tn) {
					if(aux->a[o[st].tn] == ((uint64_t)-1)) {
						kv_push(uint64_t, buf, o[st].tn);
					}
                    st = j;
                }
            }
        }
		bid++;
	}

	assert(aux->n == bc->bub->ug->g->n_seq);

	for (i = 0; i < bc->bub->b_ug->u.n; i++) {///no need nodes in bubbles
        u = &(bc->bub->b_ug->u.a[i]);
        for (k = 0; k < u->n; k++) {
            get_bubbles(bc->bub, u->a[k]>>33, NULL, NULL, &ba, &bn, NULL);
            for (m = 0; m < bn; m++) aux->a[ba[m]>>1] = (uint64_t)-1;
        }
    }
	for (i = aux->n = 0; i < bc->bub->ug->g->n_seq; i++) {
		if(aux->a[i] == ((uint64_t)-1)) continue;
		aux->a[i] <<= 32; aux->a[i] |= i;//bub_id|node_id
		aux->a[aux->n++] = aux->a[i];
	}
	radix_sort_mc64(aux->a, aux->a + aux->n);
	kv_destroy(buf);
	return aux;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
xorl %r15d, %r15d
testq %rsi, %rsi
je 0x168692
movq %rdi, %rax
movq %rsi, 0x30(%rsp)
movl $0x1, %edi
movq %rax, 0x20(%rsp)
movl $0x18, %esi
callq 0x2120
movq %rax, %rbx
movq 0x20(%rsp), %rax
movl 0x54(%rax), %r13d
movq %r13, 0x8(%rbx)
movq %r13, (%rbx)
shlq $0x3, %r13
movq %r13, %rdi
callq 0x2280
movq %rax, %r12
movq %rbx, 0x18(%rsp)
movq %rax, 0x10(%rbx)
movq %rax, %rdi
movl $0xff, %esi
movq %r13, %rdx
callq 0x20e0
movq 0x20(%rsp), %rsi
movq 0x30(%rsi), %rax
movq 0xc0(%rax), %rax
cmpq $0x0, (%rax)
je 0x168487
xorl %ecx, %ecx
leaq 0x38(%rsp), %r13
leaq 0x2c(%rsp), %rbp
xorl %r15d, %r15d
movq 0x10(%rax), %rax
movq %rcx, 0x10(%rsp)
leaq (%rcx,%rcx,4), %rcx
cmpl $0x0, 0x10(%rax,%rcx,8)
je 0x16846c
leaq (%rax,%rcx,8), %r14
xorl %ebx, %ebx
movq 0x30(%rsi), %rdi
movq 0x18(%r14), %rax
movq (%rax,%rbx,8), %rsi
shrq $0x21, %rsi
movq $0x0, (%rsp)
xorl %edx, %edx
xorl %ecx, %ecx
movq %r13, %r8
movq %rbp, %r9
callq 0x13812e
movl 0x2c(%rsp), %eax
testq %rax, %rax
je 0x168458
movl %r15d, %ecx
movq 0x38(%rsp), %rdx
xorl %esi, %esi
movl (%rdx,%rsi,4), %edi
shrl %edi
movq %rcx, (%r12,%rdi,8)
incq %rsi
cmpq %rsi, %rax
jne 0x168447
incq %rbx
incl %r15d
movl 0x10(%r14), %eax
cmpq %rax, %rbx
movq 0x20(%rsp), %rsi
jb 0x16840d
movq 0x10(%rsp), %rcx
incl %ecx
movq 0x30(%rsi), %rax
movq 0xc0(%rax), %rax
cmpq %rcx, (%rax)
ja 0x1683f3
movq 0x30(%rsi), %rax
movq 0x10(%rax), %rax
movq 0x18(%rax), %rax
testl $0x7fffffff, 0x14(%rax) # imm = 0x7FFFFFFF
je 0x168699
xorl %ecx, %ecx
xorl %edi, %edi
xorl %r12d, %r12d
movq 0x18(%rsp), %r13
movq 0x30(%rsp), %r8
movq 0x10(%r13), %rax
cmpq $-0x1, (%rax,%rcx,8)
je 0x1684dd
incq %rcx
movq 0x30(%rsi), %rax
movq 0x10(%rax), %rax
movq 0x18(%rax), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpq %rax, %rcx
jb 0x1684b1
jmp 0x1686a8
movq 0x28(%r8), %rax
movq (%rax,%rcx,8), %rdx
testl %edx, %edx
je 0x1684bc
movq %rdx, %rax
shrq $0x20, %rax
leaq (%rax,%rax,2), %rbp
shlq $0x4, %rbp
addq 0x10(%r8), %rbp
movl %edx, %eax
cmpq %rax, %rdi
movq %rcx, 0x10(%rsp)
jae 0x16855b
decq %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rbx
shrq $0x10, %rbx
orq %rax, %rbx
leaq 0x8(,%rbx,8), %rsi
incq %rbx
movq %r12, %rdi
movq %rdx, %r14
callq 0x2370
movq %r14, %rdx
movq %rbx, %rdi
movq %rax, %r12
cmpl $0x1, %edx
adcl $0x0, %edx
xorl %ebx, %ebx
movq 0x10(%r13), %rax
leaq (%rbx,%rbx,2), %rcx
shlq $0x4, %rcx
movl 0x14(%rbp,%rcx), %ecx
movq (%rax,%rcx,8), %r14
cmpq %rdi, %rbx
jne 0x1685ad
leaq (%rdi,%rdi), %r13
testq %rdi, %rdi
movl $0x2, %eax
cmoveq %rax, %r13
leaq (,%r13,8), %rsi
movq %r12, %rdi
movq %rdx, %r12
callq 0x2370
movq %r12, %rdx
movq %rax, %r12
movq %r13, %rdi
movq 0x18(%rsp), %r13
shlq $0x20, %r14
orq %rbx, %r14
movq %r14, (%r12,%rbx,8)
incq %rbx
cmpq %rdx, %rbx
jne 0x168563
movq %rdi, %r14
leaq (%r12,%rbx,8), %rsi
movq %r12, %rdi
callq 0x1604f0
xorl %edx, %edx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl $0x1, %ecx
movsd 0xbcf55(%rip), %xmm0    # 0x225538
movq 0x30(%rsp), %r8
movapd 0xc8490(%rip), %xmm3    # 0x230a80
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
cmpq %rcx, %rbx
je 0x168617
movl %edx, %esi
movq (%r12,%rsi,8), %rsi
shrq $0x20, %rsi
cmpq %r9, %rsi
je 0x168617
cmpl 0x4(%r12,%rcx,8), %esi
jne 0x168617
movapd %xmm0, %xmm1
jmp 0x168658
xorpd %xmm1, %xmm1
cmpl %ecx, %edx
jae 0x168643
movl %edx, %esi
movl (%r12,%rsi,8), %edi
leaq (%rdi,%rdi,2), %rdi
shlq $0x4, %rdi
movsd 0x20(%rbp,%rdi), %xmm2
andpd %xmm3, %xmm2
addsd %xmm2, %xmm1
incq %rsi
cmpq %rsi, %rcx
jne 0x168621
ucomisd %xmm0, %xmm1
jbe 0x168652
movl %edx, %eax
movl 0x4(%r12,%rax,8), %eax
jmp 0x168656
movapd %xmm0, %xmm1
movl %ecx, %edx
incq %rcx
movapd %xmm1, %xmm0
cmpl %ebx, %ecx
jbe 0x1685f6
cmpq %r9, %rax
movq 0x20(%rsp), %rsi
jne 0x16867a
movq %r14, %rdi
movq 0x10(%rsp), %rcx
jmp 0x1684bc
movq 0x10(%r13), %rcx
movq 0x10(%rsp), %rdx
movq %rax, (%rcx,%rdx,8)
movq %rdx, %rcx
movq %r14, %rdi
jmp 0x1684bc
xorl %ebx, %ebx
jmp 0x16897a
xorl %r12d, %r12d
xorl %edi, %edi
movq 0x18(%rsp), %r13
movq 0x30(%rsp), %r8
movq 0x30(%rsi), %rax
movq 0x10(%rax), %rax
movq 0x18(%rax), %rcx
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andl 0x14(%rcx), %eax
je 0x16884d
xorl %ebp, %ebp
movq 0x10(%r13), %rax
cmpq $-0x1, (%rax,%rbp,8)
jne 0x16882d
testq %rdi, %rdi
jne 0x1686f7
movl $0x10, %esi
movq %r12, %rdi
callq 0x2370
movq 0x30(%rsp), %r8
movq 0x20(%rsp), %rsi
movq %rax, %r12
movl $0x2, %edi
movq %rbp, (%r12)
movl %r15d, %r9d
movl $0x1, %ebx
movq 0x18(%rsp), %r13
subq $0x1, %rbx
jb 0x16882a
movl (%r12,%rbx,8), %eax
movq 0x10(%r13), %rcx
cmpq $-0x1, (%rcx,%rax,8)
jne 0x168708
movq %r9, (%rcx,%rax,8)
movq 0x28(%r8), %rcx
movq (%rcx,%rax,8), %rax
testl %eax, %eax
je 0x168708
movq 0x10(%r8), %rcx
movq %rax, %rdx
shrq $0x20, %rdx
leaq (%rdx,%rdx,2), %rdx
shlq $0x4, %rdx
leaq (%rcx,%rdx), %r10
movl %eax, %r11d
negq %r11
leaq (%rcx,%rdx), %r14
addq $0x44, %r14
movl $0x1, %r13d
xorl %eax, %eax
movq %r10, 0x48(%rsp)
movq %r9, 0x40(%rsp)
movq %r11, %rcx
addq %r13, %rcx
je 0x168786
movl (%r14), %ecx
leaq (%rax,%rax,2), %rdx
shlq $0x4, %rdx
cmpl 0x14(%r10,%rdx), %ecx
je 0x16880d
movq %r14, 0x10(%rsp)
movq 0x18(%rsp), %rcx
movq 0x10(%rcx), %rcx
leaq (%rax,%rax,2), %r14
shlq $0x4, %r14
movl 0x14(%r10,%r14), %eax
cmpq $-0x1, (%rcx,%rax,8)
jne 0x168805
cmpq %rdi, %rbx
jne 0x1687f4
leaq (%rdi,%rdi), %rcx
testq %rdi, %rdi
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x50(%rsp)
leaq (,%rcx,8), %rsi
movq %r12, %rdi
movq %r11, %r12
callq 0x2370
movq %r12, %r11
movq 0x48(%rsp), %r10
movq 0x40(%rsp), %r9
movq 0x30(%rsp), %r8
movq 0x20(%rsp), %rsi
movq %rax, %r12
movq 0x50(%rsp), %rdi
leaq (%r10,%r14), %rax
addq $0x14, %rax
movl (%rax), %eax
movq %rax, (%r12,%rbx,8)
incq %rbx
movq %r13, %rax
movq 0x10(%rsp), %r14
leaq (%r11,%r13), %rcx
incq %rcx
incq %r13
addq $0x30, %r14
cmpq $0x1, %rcx
jne 0x168768
jmp 0x168703
incl %r15d
incq %rbp
movq 0x30(%rsi), %rax
movq 0x10(%rax), %rax
movq 0x18(%rax), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpq %rax, %rbp
jb 0x1686c4
movl %eax, %eax
cmpq %rax, (%r13)
jne 0x16898c
movq 0x30(%rsi), %rcx
movq 0xc0(%rcx), %rax
cmpq $0x0, (%rax)
je 0x16890b
xorl %ebx, %ebx
leaq 0x38(%rsp), %r15
leaq 0x2c(%rsp), %r13
movq 0x10(%rax), %rax
leaq (%rbx,%rbx,4), %rcx
cmpl $0x0, 0x10(%rax,%rcx,8)
je 0x1688f5
leaq (%rax,%rcx,8), %r14
xorl %ebp, %ebp
movq 0x30(%rsi), %rdi
movq 0x18(%r14), %rax
movq (%rax,%rbp,8), %rsi
shrq $0x21, %rsi
movq $0x0, (%rsp)
xorl %edx, %edx
xorl %ecx, %ecx
movq %r15, %r8
movq %r13, %r9
callq 0x13812e
movl 0x2c(%rsp), %eax
testq %rax, %rax
je 0x1688e4
movq 0x18(%rsp), %rcx
movq 0x10(%rcx), %rcx
movq 0x38(%rsp), %rdx
xorl %esi, %esi
movl (%rdx,%rsi,4), %edi
shrl %edi
movq $-0x1, (%rcx,%rdi,8)
incq %rsi
cmpq %rsi, %rax
jne 0x1688cf
incq %rbp
movl 0x10(%r14), %eax
cmpq %rax, %rbp
movq 0x20(%rsp), %rsi
jb 0x16888f
incl %ebx
movq 0x30(%rsi), %rcx
movq 0xc0(%rcx), %rax
cmpq %rbx, (%rax)
ja 0x16887a
movq 0x18(%rsp), %rbx
movq $0x0, (%rbx)
movq 0x10(%rcx), %rax
movq 0x18(%rax), %rax
testl $0x7fffffff, 0x14(%rax) # imm = 0x7FFFFFFF
je 0x168962
movq 0x10(%rbx), %rcx
xorl %edx, %edx
movq (%rcx,%rdx,8), %rsi
cmpq $-0x1, %rsi
je 0x168951
shlq $0x20, %rsi
addq %rdx, %rsi
movq %rsi, (%rcx,%rdx,8)
movq (%rbx), %rdi
leaq 0x1(%rdi), %r8
movq %r8, (%rbx)
movq %rsi, (%rcx,%rdi,8)
incq %rdx
movl 0x14(%rax), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
cmpq %rsi, %rdx
jb 0x16892e
movq (%rbx), %rax
movq 0x10(%rbx), %rdi
leaq (%rdi,%rax,8), %rsi
callq 0x1604f0
movq %r12, %rdi
callq 0x2220
movq %rbx, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xc8722(%rip), %rdi     # 0x2310b5
leaq 0xc849e(%rip), %rsi     # 0x230e38
leaq 0xc8734(%rip), %rcx     # 0x2310d5
movl $0xd6a, %edx            # imm = 0xD6A
callq 0x2110