// File: chhylp123[P]hifiasm/hic.cpp
// Function: identify_best_interval_debug(block_phase_type*, G_partition*, bubble_type*, ma_utg_t*, hc_links*, long long, long long, long long*, long long*)
void identify_best_interval_debug(block_phase_type* i_buf, 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;
    block_phase_type b;
    b.bid = f_bid; b.uid = f_uid;
    memset(i_buf->vis.a, 0, g_p->n);
    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);
        if(f_bid == 689 && f_uid == 1)
        {
            fprintf(stderr, "gid: %u, w: %f\n", gid, w);
        }
        
        if(min_w > w)
        {
            min_w = w;
            min_bid = c_bid;
            min_uid = c_uid;
        }
        i_buf->vis.a[gid] = 1;
    }

    if(min_w < 0 && min_bid != -1 && min_uid != -1)
    {
        (*l_bid) = min_bid; (*l_uid) = min_uid;
        i_buf->weight = min_w;
        b.bid = min_bid; b.uid = min_uid;


        gid = next_hap_label_id(&b, g_p, bub, u, 1, &c_bid, &c_uid);
        fprintf(stderr, "-min_w: %f, f_bid: %lld, f_uid: %lld, min_bid: %lld, min_uid: %lld, gid: %u\n", 
                                                        min_w, f_bid, f_uid, min_bid, min_uid, gid);
        
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq 0x20(%rbp), %rax
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)
xorps %xmm0, %xmm0
movsd %xmm0, -0x58(%rbp)
movsd 0x190b51(%rip), %xmm0   # 0x382000
movsd %xmm0, -0x60(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x80(%rbp)
movq 0x10(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rdx
xorl %esi, %esi
callq 0x2100
movsd 0x190b1e(%rip), %xmm0   # 0x382000
movsd %xmm0, -0x60(%rbp)
movq $-0x1, -0x50(%rbp)
movq $-0x1, -0x48(%rbp)
movq 0x20(%rbp), %rax
movq $-0x1, (%rax)
movq 0x18(%rbp), %rax
movq $-0x1, (%rax)
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
leaq -0xa0(%rbp), %rdi
movl $0x1, %r8d
leaq -0x38(%rbp), %r9
leaq -0x40(%rbp), %rax
movq %rax, (%rsp)
callq 0x1f0aa0
movl %eax, -0x64(%rbp)
cmpl $-0x1, -0x64(%rbp)
jne 0x1f1545
jmp 0x1f15e8
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x64(%rbp), %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x1, %eax
jne 0x1f155b
jmp 0x1f150d
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x28(%rbp), %rdx
movl -0x64(%rbp), %ecx
callq 0x1f0d10
addsd -0x58(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
cmpq $0x2b1, -0x30(%rbp)     # imm = 0x2B1
jne 0x1f15ae
cmpq $0x1, 0x10(%rbp)
jne 0x1f15ae
movq 0x1d2a4b(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movl -0x64(%rbp), %edx
movsd -0x58(%rbp), %xmm0
leaq 0x19b73b(%rip), %rsi    # 0x38cce2
movb $0x1, %al
callq 0x22a0
movsd -0x60(%rbp), %xmm0
ucomisd -0x58(%rbp), %xmm0
jbe 0x1f15d4
movsd -0x58(%rbp), %xmm0
movsd %xmm0, -0x60(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x64(%rbp), %ecx
movb $0x1, (%rax,%rcx)
jmp 0x1f150d
xorps %xmm0, %xmm0
ucomisd -0x60(%rbp), %xmm0
jbe 0x1f16a0
cmpq $-0x1, -0x48(%rbp)
je 0x1f16a0
cmpq $-0x1, -0x50(%rbp)
je 0x1f16a0
movq -0x48(%rbp), %rcx
movq 0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x50(%rbp), %rcx
movq 0x20(%rbp), %rax
movq %rcx, (%rax)
movsd -0x60(%rbp), %xmm0
movq -0x8(%rbp), %rax
movsd %xmm0, 0x18(%rax)
movq -0x48(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
leaq -0xa0(%rbp), %rdi
movl $0x1, %r8d
leaq -0x38(%rbp), %r9
leaq -0x40(%rbp), %rax
movq %rax, (%rsp)
callq 0x1f0aa0
movl %eax, -0x64(%rbp)
movq 0x1d296c(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movsd -0x60(%rbp), %xmm0
movq -0x30(%rbp), %rdx
movq 0x10(%rbp), %rcx
movq -0x48(%rbp), %r8
movq -0x50(%rbp), %r9
movl -0x64(%rbp), %eax
leaq 0x19b65c(%rip), %rsi    # 0x38ccf2
movl %eax, (%rsp)
movb $0x1, %al
callq 0x22a0
addq $0xb0, %rsp
popq %rbp
retq
nopl (%rax)