// File: chhylp123[P]hifiasm/rcut.cpp
// Function: select_min_bp(bubble_type*, mc_match_t*, mc_svaux_t*, mc_bp_t*, unsigned char*, bits_p*, unsigned long, mc_bp_res*)
void select_min_bp(bubble_type* bub, mc_match_t *ma, mc_svaux_t *b_aux, mc_bp_t* bp,
uint8_t *lock, bits_p *vis, uint64_t id, mc_bp_res* r)
{
	uint32_t uid, val = 0, max_bid, max_uid, c_bid, c_uid, f_bid, f_uid;
	t_w_t w = 0, max_w = -1;
	mc_bp_iter i;
	reset_mc_bp_iter(bp, &i, id);
	memset(vis->a, 0, vis->n);
	max_bid = max_uid = (uint32_t)-1;
	f_bid = i.bid; f_uid = i.uid;///f_bid::bubble id, f_uid::unitig id

	while (1)
	{
		uid = next_uid(&i, bub, &c_bid, &c_uid);
		if(uid == (uint32_t)-1) break;
		if(vis->a[uid]) continue; ///already flip uid
		///update w
		w += incre_weight(b_aux, ma, vis->a, uid);
		vis->a[uid] = 1;
		if(lock[uid] == 0) val = 1;
        if(val == 0) continue;
		///update max_w
		if(max_w < w)
		{
			max_w = w;
			max_bid = c_bid;
			max_uid = c_uid;
		}
	}

	if(max_w <= 0 || max_bid == (uint32_t)-1 || max_uid == (uint32_t)-1) return;
	if((max_w > r->w) || (max_w == r->w && id < r->id))
	{
		r->w = max_w;
		r->id = id;
		r->chain_id = i.chain_id;
		r->l_bid = max_bid;
		r->l_uid = max_uid;
		r->f_bid = f_bid;
		r->f_uid = f_uid;
	}
	///if((res->min_w > i_b->weight) || (res->min_w == i_b->weight && id < res->min_idx))
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movl $0x0, -0x38(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x58(%rbp)
movsd 0x164946(%rip), %xmm0   # 0x382278
movsd %xmm0, -0x60(%rbp)
movq -0x20(%rbp), %rdi
movq 0x10(%rbp), %rdx
leaq -0x78(%rbp), %rsi
callq 0x21d610
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x30(%rbp), %rax
movq (%rax), %rdx
xorl %esi, %esi
callq 0x2100
movl $0xffffffff, -0x40(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0x3c(%rbp) # imm = 0xFFFFFFFF
movq -0x70(%rbp), %rax
movl %eax, -0x4c(%rbp)
movq -0x68(%rbp), %rax
movl %eax, -0x50(%rbp)
movq -0x8(%rbp), %rsi
leaq -0x78(%rbp), %rdi
leaq -0x44(%rbp), %rdx
leaq -0x48(%rbp), %rcx
callq 0x22d230
movl %eax, -0x34(%rbp)
cmpl $-0x1, -0x34(%rbp)
jne 0x21d99d
jmp 0x21da2e
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x34(%rbp), %ecx
cmpb $0x0, (%rax,%rcx)
je 0x21d9b0
jmp 0x21d97a
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rdx
movl -0x34(%rbp), %ecx
callq 0x21d770
addsd -0x58(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x34(%rbp), %ecx
movb $0x1, (%rax,%rcx)
movq -0x28(%rbp), %rax
movl -0x34(%rbp), %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x21d9f8
movl $0x1, -0x38(%rbp)
cmpl $0x0, -0x38(%rbp)
jne 0x21da03
jmp 0x21d97a
movsd -0x60(%rbp), %xmm1
movsd -0x58(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x21da29
movsd -0x58(%rbp), %xmm0
movsd %xmm0, -0x60(%rbp)
movl -0x44(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x48(%rbp), %eax
movl %eax, -0x40(%rbp)
jmp 0x21d97a
xorps %xmm0, %xmm0
ucomisd -0x60(%rbp), %xmm0
jae 0x21da44
cmpl $-0x1, -0x3c(%rbp)
je 0x21da44
cmpl $-0x1, -0x40(%rbp)
jne 0x21da49
jmp 0x21daca
movsd -0x60(%rbp), %xmm0
movq 0x18(%rbp), %rax
ucomisd 0x18(%rax), %xmm0
ja 0x21da7b
movsd -0x60(%rbp), %xmm0
movq 0x18(%rbp), %rax
ucomisd 0x18(%rax), %xmm0
jne 0x21daca
jp 0x21daca
movq 0x10(%rbp), %rax
movq 0x18(%rbp), %rcx
movl 0x14(%rcx), %ecx
cmpq %rcx, %rax
jae 0x21daca
movsd -0x60(%rbp), %xmm0
movq 0x18(%rbp), %rax
movsd %xmm0, 0x18(%rax)
movq 0x10(%rbp), %rax
movl %eax, %ecx
movq 0x18(%rbp), %rax
movl %ecx, 0x14(%rax)
movq -0x78(%rbp), %rax
movl %eax, %ecx
movq 0x18(%rbp), %rax
movl %ecx, (%rax)
movl -0x3c(%rbp), %ecx
movq 0x18(%rbp), %rax
movl %ecx, 0xc(%rax)
movl -0x40(%rbp), %ecx
movq 0x18(%rbp), %rax
movl %ecx, 0x10(%rax)
movl -0x4c(%rbp), %ecx
movq 0x18(%rbp), %rax
movl %ecx, 0x4(%rax)
movl -0x50(%rbp), %ecx
movq 0x18(%rbp), %rax
movl %ecx, 0x8(%rax)
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)