// File: 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
movq %rsp, %rbp
subq $0xb0, %rsp
movq 0x28(%rbp), %rax
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x60(%rbp)
movsd 0x190d3d(%rip), %xmm0   # 0x382000
movsd %xmm0, -0x68(%rbp)
movl $0x0, -0x70(%rbp)
movq 0x10(%rbp), %rax
movq %rax, -0x88(%rbp)
movq 0x18(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x20(%rbp), %rax
movq (%rax), %rdx
xorl %esi, %esi
callq 0x2100
movsd 0x190d00(%rip), %xmm0   # 0x382000
movsd %xmm0, -0x68(%rbp)
movq -0x10(%rbp), %rax
movsd 0x190cef(%rip), %xmm0   # 0x382000
movsd %xmm0, 0x18(%rax)
movq $-0x1, -0x58(%rbp)
movq $-0x1, -0x50(%rbp)
movq 0x28(%rbp), %rax
movq $-0x1, (%rax)
movq 0x20(%rbp), %rax
movq $-0x1, (%rax)
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x30(%rbp), %rcx
leaq -0xa8(%rbp), %rdi
movl $0x1, %r8d
leaq -0x40(%rbp), %r9
leaq -0x48(%rbp), %rax
movq %rax, (%rsp)
callq 0x1f0aa0
movl %eax, -0x6c(%rbp)
cmpl $-0x1, -0x6c(%rbp)
jne 0x1f1374
jmp 0x1f1408
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x6c(%rbp), %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x1, %eax
jne 0x1f138a
jmp 0x1f133c
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x38(%rbp), %rdx
movl -0x6c(%rbp), %ecx
callq 0x1f0d10
addsd -0x60(%rbp), %xmm0
movsd %xmm0, -0x60(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x6c(%rbp), %ecx
movb $0x1, (%rax,%rcx)
movq -0x18(%rbp), %rax
movl -0x6c(%rbp), %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x1f13d2
movl $0x1, -0x70(%rbp)
cmpl $0x0, -0x70(%rbp)
jne 0x1f13dd
jmp 0x1f133c
movsd -0x68(%rbp), %xmm0
ucomisd -0x60(%rbp), %xmm0
jbe 0x1f1403
movsd -0x60(%rbp), %xmm0
movsd %xmm0, -0x68(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x58(%rbp)
jmp 0x1f133c
xorps %xmm0, %xmm0
ucomisd -0x68(%rbp), %xmm0
jbe 0x1f1444
cmpq $-0x1, -0x50(%rbp)
je 0x1f1444
cmpq $-0x1, -0x58(%rbp)
je 0x1f1444
movq -0x50(%rbp), %rcx
movq 0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0x58(%rbp), %rcx
movq 0x28(%rbp), %rax
movq %rcx, (%rax)
movsd -0x68(%rbp), %xmm0
movq -0x10(%rbp), %rax
movsd %xmm0, 0x18(%rax)
cmpl $0x0, -0x70(%rbp)
jne 0x1f1453
movl $0x1, -0x4(%rbp)
jmp 0x1f145a
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xb0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)