// File: chhylp123[P]hifiasm/rcut.cpp
// Function: gen_best_clus(mc_clus_t*, unsigned int*, unsigned int*, double*)
uint32_t gen_best_clus(mc_clus_t *bc, uint32_t *off, uint32_t *occ, double *rw)
{
	uint32_t i; (*off) = (*occ) = (uint32_t)-1; (*rw) = -1;
	for (i = 0; i < bc->n_thread; i++) clean_clus_flip_aux(&(bc->aux[i]));
	
	kt_for(bc->n_thread, worker_cal_clus_sc, bc, bc->cc.nn.n);
	
	for (i = 0; i < bc->n_thread; i++) {
		if(bc->aux[i].off == (uint32_t)-1) continue;
		if(bc->aux[i].w < 0) continue;

		if((bc->aux[i].w > (*rw)) || (bc->aux[i].w == (*rw) && bc->aux[i].off < (*off))) {
			(*off) = bc->aux[i].off; (*occ) = bc->aux[i].occ; (*rw) = bc->aux[i].w;
		}
	}
	if((*off) != (uint32_t)-1) return 1;
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x20(%rbp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movq -0x18(%rbp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movq -0x28(%rbp), %rax
movsd 0x160200(%rip), %xmm0   # 0x382278
movsd %xmm0, (%rax)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x58(%rcx), %eax
jae 0x2220b1
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rdi
movl -0x2c(%rbp), %eax
imulq $0x28, %rax, %rax
addq %rax, %rdi
callq 0x221bf0
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x222083
movq -0x10(%rbp), %rax
movl 0x58(%rax), %edi
movq -0x10(%rbp), %rdx
movq -0x10(%rbp), %rax
movq (%rax), %rcx
leaq 0x146(%rip), %rsi       # 0x222210
callq 0x16d710
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x58(%rcx), %eax
jae 0x2221ea
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rax
movl -0x2c(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
cmpl $-0x1, 0x20(%rax)
jne 0x222103
jmp 0x2221dc
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rax
movl -0x2c(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
xorps %xmm0, %xmm0
ucomisd 0x18(%rax), %xmm0
jbe 0x222124
jmp 0x2221dc
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rax
movl -0x2c(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movsd 0x18(%rax), %xmm0
movq -0x28(%rbp), %rax
ucomisd (%rax), %xmm0
ja 0x222185
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rax
movl -0x2c(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movsd 0x18(%rax), %xmm0
movq -0x28(%rbp), %rax
ucomisd (%rax), %xmm0
jne 0x2221da
jp 0x2221da
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rax
movl -0x2c(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x20(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl (%rcx), %eax
jae 0x2221da
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rax
movl -0x2c(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x20(%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rax
movl -0x2c(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x24(%rax), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rax
movl -0x2c(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movsd 0x18(%rax), %xmm0
movq -0x28(%rbp), %rax
movsd %xmm0, (%rax)
jmp 0x2221dc
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x2220d6
movq -0x18(%rbp), %rax
cmpl $-0x1, (%rax)
je 0x2221fc
movl $0x1, -0x4(%rbp)
jmp 0x222203
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)