// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %r9, %r14
movq %r8, 0x30(%rsp)
movq %rdx, 0x28(%rsp)
movq %rsi, 0x20(%rsp)
movq %rdi, %rbp
movq 0xa0(%rsp), %rdx
leaq 0x50(%rsp), %rbx
movq %rcx, %rdi
movq %rbx, %rsi
callq 0x12607e
movq (%r14), %rdx
movq 0x10(%r14), %rdi
xorl %esi, %esi
callq 0x20e0
movsd 0xbd340(%rip), %xmm0    # 0x1e3580
movsd %xmm0, 0x8(%rsp)
xorpd %xmm2, %xmm2
movb $0x1, %cl
pushq $-0x1
popq %rax
movupd 0x8(%rbx), %xmm0
movapd %xmm0, 0x40(%rsp)
leaq 0x1c(%rsp), %r15
leaq 0x18(%rsp), %r12
movl %eax, 0x4(%rsp)
movl %eax, (%rsp)
movl %ecx, 0x14(%rsp)
movsd %xmm2, 0x38(%rsp)
leaq 0x50(%rsp), %rdi
movq %rbp, %rsi
movq %r15, %rdx
movq %r12, %rcx
callq 0x12e9df
cmpl $-0x1, %eax
je 0x126303
movq 0x10(%r14), %r13
movl %eax, %ebx
cmpb $0x0, (%r13,%rbx)
jne 0x126275
movq 0x28(%rsp), %rdi
movq 0x20(%rsp), %rsi
movq %r13, %rdx
movl %eax, %ecx
callq 0x126147
movb $0x1, (%r13,%rbx)
movq 0x30(%rsp), %rax
cmpb $0x0, (%rax,%rbx)
movsd 0x38(%rsp), %xmm2
addsd %xmm0, %xmm2
setne %al
testb %al, 0x14(%rsp)
movb $0x1, %cl
jne 0x12626b
movsd 0x8(%rsp), %xmm1
ucomisd %xmm1, %xmm2
jbe 0x1262ee
movl 0x18(%rsp), %eax
movl %eax, 0x4(%rsp)
movl 0x1c(%rsp), %eax
movl %eax, (%rsp)
movapd %xmm2, %xmm0
maxsd %xmm1, %xmm0
xorl %ecx, %ecx
movsd %xmm0, 0x8(%rsp)
jmp 0x12626b
xorpd %xmm0, %xmm0
movsd 0x8(%rsp), %xmm1
ucomisd %xmm1, %xmm0
setae %al
movl (%rsp), %edi
cmpl $-0x1, %edi
sete %cl
movl 0x4(%rsp), %esi
cmpl $-0x1, %esi
sete %dl
orb %cl, %dl
orb %al, %dl
jne 0x12637d
movq 0xa8(%rsp), %rax
ucomisd 0x18(%rax), %xmm1
ja 0x12634d
jne 0x12637d
jp 0x12637d
movl 0x14(%rax), %eax
cmpq 0xa0(%rsp), %rax
jbe 0x12637d
pshufd $0xe8, 0x40(%rsp), %xmm0 # xmm0 = mem[0,2,2,3]
movq 0xa8(%rsp), %rcx
movsd %xmm1, 0x18(%rcx)
movq 0xa0(%rsp), %rax
movl %eax, 0x14(%rcx)
movl 0x50(%rsp), %eax
movl %eax, (%rcx)
movl %edi, 0xc(%rcx)
movl %esi, 0x10(%rcx)
movq %xmm0, 0x4(%rcx)
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq