// File: /workspace/github_cpp_makefile_star2_O3/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 %r12d, %r12d
testq %rsi, %rsi
je 0x16f2b1
movq %rdi, %rax
movq %rsi, 0x30(%rsp)
movl $0x1, %edi
movq %rax, 0x18(%rsp)
movl $0x18, %esi
callq 0x2120
movq %rax, %rbx
movq 0x18(%rsp), %rax
movl 0x54(%rax), %r13d
movq %r13, 0x8(%rbx)
movq %r13, (%rbx)
shlq $0x3, %r13
movq %r13, %rdi
callq 0x2280
movq %rax, %r15
movq %rbx, 0x10(%rsp)
movq %rax, 0x10(%rbx)
movq %rax, %rdi
movl $0xff, %esi
movq %r13, %rdx
callq 0x20e0
movq 0x18(%rsp), %rsi
movq 0x30(%rsi), %rax
movq 0xc0(%rax), %rcx
cmpq $0x0, (%rcx)
je 0x16eef0
xorl %edi, %edi
leaq 0x40(%rsp), %r13
leaq 0x24(%rsp), %rbp
xorl %r12d, %r12d
movq 0x10(%rcx), %rcx
leaq (%rdi,%rdi,4), %rdx
cmpl $0x0, 0x10(%rcx,%rdx,8)
je 0x16eede
movq %rdi, 0x28(%rsp)
leaq (%rcx,%rdx,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 0x13df01
movl 0x24(%rsp), %eax
testq %rax, %rax
je 0x16eec1
movl %r12d, %ecx
movq 0x40(%rsp), %rdx
xorl %esi, %esi
movl (%rdx,%rsi,4), %edi
shrl %edi
movq %rcx, (%r15,%rdi,8)
incq %rsi
cmpq %rsi, %rax
jne 0x16eeb0
incq %rbx
incl %r12d
movl 0x10(%r14), %eax
cmpq %rax, %rbx
movq 0x18(%rsp), %rsi
jb 0x16ee76
movq 0x30(%rsi), %rax
movq 0x28(%rsp), %rdi
incl %edi
movq 0xc0(%rax), %rcx
cmpq %rdi, (%rcx)
ja 0x16ee5c
movq 0x10(%rax), %rcx
movq 0x18(%rcx), %rcx
testl $0x7fffffff, 0x14(%rcx) # imm = 0x7FFFFFFF
je 0x16f2b8
xorl %r8d, %r8d
xorl %r9d, %r9d
xorl %edi, %edi
movq 0x10(%rsp), %rdx
movq 0x30(%rsp), %r13
movq 0x10(%rdx), %rax
cmpq $-0x1, (%rax,%r8,8)
jne 0x16f0e3
movq 0x28(%r13), %rax
movq (%rax,%r8,8), %rcx
testl %ecx, %ecx
je 0x16f0e3
movq %rcx, %rax
shrq $0x20, %rax
leaq (%rax,%rax,2), %rbx
shlq $0x4, %rbx
addq 0x10(%r13), %rbx
movl %ecx, %eax
cmpq %rax, %r9
movq %rcx, %r13
movq %r8, 0x28(%rsp)
jae 0x16efa7
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, %r14
shrq $0x10, %r14
orq %rax, %r14
leaq 0x8(,%r14,8), %rsi
incq %r14
callq 0x2370
movq %r14, %r9
movq 0x10(%rsp), %rdx
movq %rax, %rdi
movq %r13, 0x38(%rsp)
movl %r13d, %ebp
xorl %r14d, %r14d
movq 0x10(%rdx), %rax
leaq (%r14,%r14,2), %rcx
shlq $0x4, %rcx
movl 0x14(%rbx,%rcx), %ecx
movq (%rax,%rcx,8), %r13
cmpq %r9, %r14
jne 0x16efff
movq %r12, %r15
movq %rbp, %r12
leaq (%r14,%r14), %rbp
testq %r14, %r14
movl $0x2, %eax
cmoveq %rax, %rbp
leaq (,%rbp,8), %rsi
callq 0x2370
movq %rbp, %r9
movq %r12, %rbp
movq %r15, %r12
movq 0x10(%rsp), %rdx
movq %rax, %rdi
shlq $0x20, %r13
orq %r14, %r13
movq %r13, (%rdi,%r14,8)
incq %r14
cmpq %rbp, %r14
jne 0x16efb2
movq %r9, %r14
leaq (%rdi,%rbp,8), %rsi
movq %rdi, %r15
callq 0x166e19
movq %r15, %rdi
xorl %edx, %edx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl $0x1, %ecx
movsd 0xc2600(%rip), %xmm0    # 0x231638
movq 0x28(%rsp), %r8
movapd 0xcdc4b(%rip), %xmm3    # 0x23cc90
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
movq 0x38(%rsp), %r10
cmpq %rbp, %rcx
je 0x16f070
movl %edx, %esi
movq (%rdi,%rsi,8), %rsi
shrq $0x20, %rsi
cmpq %r9, %rsi
je 0x16f070
cmpl 0x4(%rdi,%rcx,8), %esi
jne 0x16f070
movapd %xmm0, %xmm1
jmp 0x16f0b1
xorpd %xmm1, %xmm1
cmpl %ecx, %edx
jae 0x16f09d
movl %edx, %esi
movl (%rdi,%rsi,8), %r11d
leaq (%r11,%r11,2), %r11
shlq $0x4, %r11
movsd 0x20(%rbx,%r11), %xmm2
andpd %xmm3, %xmm2
addsd %xmm2, %xmm1
incq %rsi
cmpq %rsi, %rcx
jne 0x16f07a
ucomisd %xmm0, %xmm1
jbe 0x16f0ab
movl %edx, %eax
movl 0x4(%rdi,%rax,8), %eax
jmp 0x16f0af
movapd %xmm0, %xmm1
movl %ecx, %edx
incq %rcx
movapd %xmm1, %xmm0
cmpl %r10d, %ecx
jbe 0x16f050
cmpq %r9, %rax
movq 0x18(%rsp), %rsi
movq 0x30(%rsp), %r13
jne 0x16f0d3
movq 0x10(%rsp), %rdx
jmp 0x16f0e0
movq 0x10(%rsp), %rdx
movq 0x10(%rdx), %rcx
movq %rax, (%rcx,%r8,8)
movq %r14, %r9
incq %r8
movq 0x30(%rsi), %rax
movq 0x10(%rax), %rcx
movq 0x18(%rcx), %rcx
movl 0x14(%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpq %rcx, %r8
jb 0x16ef17
testl %ecx, %ecx
je 0x16f2c3
xorl %ebp, %ebp
movq 0x10(%rdx), %rcx
cmpq $-0x1, (%rcx,%rbp,8)
jne 0x16f290
testq %r9, %r9
jne 0x16f13f
movl $0x10, %esi
callq 0x2370
movq 0x18(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq %rax, %rdi
movl $0x2, %r9d
movq %rbp, (%rdi)
movl %r12d, %r8d
movl $0x1, %ebx
subq $0x1, %rbx
jb 0x16f289
movl (%rdi,%rbx,8), %eax
movq 0x10(%rdx), %rcx
cmpq $-0x1, (%rcx,%rax,8)
jne 0x16f14a
movq %r8, (%rcx,%rax,8)
movq 0x28(%r13), %rcx
movq (%rcx,%rax,8), %rax
testl %eax, %eax
je 0x16f14a
movq 0x10(%r13), %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
movq 0x10(%rsp), %rdx
movl $0x1, %r15d
xorl %eax, %eax
movq %r8, 0x50(%rsp)
movq %r11, 0x48(%rsp)
movq %r11, %rcx
addq %r15, %rcx
je 0x16f1cd
leaq (%rax,%rax,2), %rcx
shlq $0x4, %rcx
movl 0x14(%r10,%rcx), %ecx
cmpl %ecx, (%r14)
jne 0x16f1da
jmp 0x16f26c
leaq (%rax,%rax,2), %rcx
shlq $0x4, %rcx
movl 0x14(%r10,%rcx), %ecx
movq 0x10(%rdx), %rdx
movl %ecx, %ecx
cmpq $-0x1, (%rdx,%rcx,8)
je 0x16f1f1
movq %r15, %rax
movq 0x10(%rsp), %rdx
jmp 0x16f26c
cmpq %r9, %rbx
jne 0x16f25d
leaq (%rax,%rax,2), %rax
shlq $0x4, %rax
addq %r10, %rax
addq $0x14, %rax
movq %rax, 0x30(%rsp)
movq %r14, 0x28(%rsp)
leaq (%rbx,%rbx), %r14
testq %rbx, %rbx
movl $0x2, %eax
cmoveq %rax, %r14
leaq (,%r14,8), %rsi
movq %r15, 0x38(%rsp)
movq %r10, %r15
callq 0x2370
movq 0x48(%rsp), %r11
movq %r15, %r10
movq 0x38(%rsp), %r15
movq 0x50(%rsp), %r8
movq %r14, %r9
movq 0x28(%rsp), %r14
movq 0x18(%rsp), %rsi
movq %rax, %rdi
movq 0x30(%rsp), %rax
movl (%rax), %ecx
movq 0x10(%rsp), %rdx
movq %rcx, (%rdi,%rbx,8)
incq %rbx
movq %r15, %rax
leaq (%r11,%r15), %rcx
incq %rcx
incq %r15
addq $0x30, %r14
cmpq $0x1, %rcx
jne 0x16f1ae
jmp 0x16f14a
incl %r12d
movq 0x30(%rsi), %rax
incq %rbp
movq 0x10(%rax), %rcx
movq 0x18(%rcx), %rcx
movl 0x14(%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpq %rcx, %rbp
jb 0x16f10e
movl %ecx, %ecx
jmp 0x16f2c5
xorl %eax, %eax
jmp 0x16f3f9
xorl %edi, %edi
xorl %ecx, %ecx
movq 0x10(%rsp), %rdx
jmp 0x16f2c5
xorl %ecx, %ecx
cmpq %rcx, (%rdx)
jne 0x16f408
movq 0xc0(%rax), %rcx
cmpq $0x0, (%rcx)
movq %rdi, %r15
je 0x16f37f
xorl %ebx, %ebx
leaq 0x40(%rsp), %r12
leaq 0x24(%rsp), %r13
movq 0x10(%rcx), %rcx
leaq (%rbx,%rbx,4), %rdx
cmpl $0x0, 0x10(%rcx,%rdx,8)
je 0x16f36d
leaq (%rcx,%rdx,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 %r12, %r8
movq %r13, %r9
callq 0x13df01
movl 0x24(%rsp), %eax
testq %rax, %rax
je 0x16f358
movq 0x10(%rsp), %rcx
movq 0x10(%rcx), %rcx
movq 0x40(%rsp), %rdx
xorl %esi, %esi
movl (%rdx,%rsi,4), %edi
shrl %edi
movq $-0x1, (%rcx,%rdi,8)
incq %rsi
cmpq %rsi, %rax
jne 0x16f343
incq %rbp
movl 0x10(%r14), %eax
cmpq %rax, %rbp
movq 0x18(%rsp), %rsi
jb 0x16f303
movq 0x30(%rsi), %rax
incl %ebx
movq 0xc0(%rax), %rcx
cmpq %rbx, (%rcx)
ja 0x16f2ee
movq 0x10(%rsp), %rcx
movq $0x0, (%rcx)
movq 0x10(%rax), %rax
movq 0x18(%rax), %rax
movl 0x14(%rax), %edx
movq 0x10(%rcx), %rdi
xorl %ecx, %ecx
testl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
je 0x16f3e3
xorl %esi, %esi
movq (%rdi,%rsi,8), %r8
cmpq $-0x1, %r8
je 0x16f3d1
shlq $0x20, %r8
addq %rsi, %r8
movq %r8, (%rdi,%rsi,8)
leaq 0x1(%rcx), %r9
movq 0x10(%rsp), %rdx
movq %r9, (%rdx)
movq %r8, (%rdi,%rcx,8)
movl 0x14(%rax), %edx
movq %r9, %rcx
incq %rsi
movl %edx, %r8d
andl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
cmpq %r8, %rsi
jb 0x16f3a6
leaq (%rdi,%rcx,8), %rsi
callq 0x166e19
movq %r15, %rdi
callq 0x2220
movq 0x10(%rsp), %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xcdef6(%rip), %rdi     # 0x23d305
leaq 0xcdc72(%rip), %rsi     # 0x23d088
leaq 0xcdf08(%rip), %rcx     # 0x23d325
movl $0xd6a, %edx            # imm = 0xD6A
callq 0x2110