// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/hic.cpp
// Function: identify_best_interval(block_phase_type*, unsigned char*, G_partition*, bubble_type*, ma_utg_t*, hc_links*, long long, long long, long long*, long long*)
int identify_best_interval(block_phase_type* i_buf, uint8_t* lock, G_partition* g_p, bubble_type* bub, 
ma_utg_t *u, hc_links* link, long long f_bid, long long f_uid, long long* l_bid, long long* l_uid)
{
    long long c_bid, c_uid, min_bid, min_uid;
    double w = 0, min_w = 1;
    uint32_t gid, val = 0;
    block_phase_type b;
    b.bid = f_bid; b.uid = f_uid;
    memset(i_buf->vis.a, 0, g_p->n);
    i_buf->weight = min_w = 1;  min_bid = min_uid = -1;
    (*l_bid) = (*l_uid) = -1;

    while (1)
    {
        gid = next_hap_label_id(&b, g_p, bub, u, 1, &c_bid, &c_uid);
        if(gid == (uint32_t)-1) break;
        if(i_buf->vis.a[gid] == 1) continue;
        w += get_new_weight(g_p, i_buf->vis.a, link, gid);
        i_buf->vis.a[gid] = 1;
        if(lock[gid] == 0) val = 1;
        if(val == 0) continue;

        if(min_w > w)
        {
            min_w = w;
            min_bid = c_bid;
            min_uid = c_uid;
        }
    }

    if(min_w < 0 && min_bid != -1 && min_uid != -1)
    {
        (*l_bid) = min_bid; (*l_uid) = min_uid;
        i_buf->weight = min_w;
        ///fprintf(stderr, "+min_w: %f, min_bid: %lld, min_uid: %lld\n", min_w, min_bid, min_uid);
    }

    if(val == 0) return 1;

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %r9, 0x30(%rsp)
movq %r8, %r15
movq %rcx, %r12
movq %rdx, %r13
movq %rsi, 0x28(%rsp)
movq %rdi, %rbx
movq 0xd8(%rsp), %r14
movq 0xd0(%rsp), %rbp
movaps 0xc0(%rsp), %xmm0
leaq 0x50(%rsp), %rax
movups %xmm0, 0x20(%rax)
movq 0x10(%rdi), %rdi
movq (%rdx), %rdx
movl $0x0, 0xc(%rsp)
xorl %esi, %esi
callq 0x20e0
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, 0x18(%rbx)
movq $-0x1, %rax
movq %rax, (%r14)
movq $-0x1, 0x20(%rsp)
movq %rax, (%rbp)
movsd 0xdbe88(%rip), %xmm0    # 0x231310
movsd %xmm0, 0x10(%rsp)
xorpd %xmm2, %xmm2
movq $-0x1, 0x18(%rsp)
movsd %xmm2, 0x38(%rsp)
leaq 0x40(%rsp), %rax
movq %rax, (%rsp)
leaq 0x50(%rsp), %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %r15, %rcx
movl $0x1, %r8d
leaq 0x48(%rsp), %r9
callq 0x15505a
cmpl $-0x1, %eax
je 0x155554
movq 0x10(%rbx), %r14
movl %eax, %ebp
cmpb $0x1, (%r14,%rbp)
je 0x1554a1
movq %r13, %rdi
movq %r14, %rsi
movq 0x30(%rsp), %rdx
movl %eax, %ecx
callq 0x1551ca
movsd 0x38(%rsp), %xmm2
addsd %xmm0, %xmm2
movb $0x1, (%r14,%rbp)
movq 0x28(%rsp), %rax
cmpb $0x0, (%rax,%rbp)
je 0x155519
cmpl $0x0, 0xc(%rsp)
movl $0x0, 0xc(%rsp)
je 0x15549b
movsd 0x10(%rsp), %xmm1
ucomisd %xmm2, %xmm1
jbe 0x155539
movq 0x48(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x40(%rsp), %rax
movq %rax, 0x18(%rsp)
movapd %xmm2, %xmm0
minsd %xmm1, %xmm0
movl $0x1, 0xc(%rsp)
movsd %xmm0, 0x10(%rsp)
jmp 0x15549b
xorpd %xmm0, %xmm0
movsd 0x10(%rsp), %xmm1
ucomisd %xmm1, %xmm0
seta %al
movq 0x20(%rsp), %rsi
cmpq $-0x1, %rsi
setne %cl
movq 0x18(%rsp), %rdi
cmpq $-0x1, %rdi
setne %dl
andb %cl, %dl
andb %al, %dl
cmpb $0x1, %dl
jne 0x1555a1
movq 0xd0(%rsp), %rax
movq %rsi, (%rax)
movq 0xd8(%rsp), %rax
movq %rdi, (%rax)
movsd %xmm1, 0x18(%rbx)
movl 0xc(%rsp), %eax
xorl $0x1, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq