// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %r9, %rbx
movq %r8, 0x58(%rsp)
movq %rcx, 0x38(%rsp)
movq %rdx, %r12
movq %rsi, %rbp
movq %rdi, %r14
movq 0xe0(%rsp), %r13
movq 0xd0(%rsp), %r15
leaq 0x60(%rsp), %rax
movq %r9, 0x20(%rax)
movq %r15, 0x28(%rax)
movq 0x10(%rdi), %rdi
movq (%rsi), %rdx
xorl %esi, %esi
callq 0x20e0
movq $-0x1, %rax
movq %rax, (%r13)
movq $-0x1, 0x30(%rsp)
movq 0xd8(%rsp), %rcx
movq %rax, (%rcx)
movq %rbx, 0x50(%rsp)
xorq $0x2b1, %rbx            # imm = 0x2B1
movq %r15, %rcx
xorq $0x1, %rcx
orq %rbx, %rcx
sete 0x17(%rsp)
movsd 0xdbcc2(%rip), %xmm0    # 0x231310
movsd %xmm0, 0x18(%rsp)
xorpd %xmm0, %xmm0
movsd %xmm0, 0x20(%rsp)
movq $-0x1, 0x28(%rsp)
leaq 0x40(%rsp), %rax
movq %rax, (%rsp)
leaq 0x60(%rsp), %rdi
movq %rbp, %rsi
movq %r12, %rdx
movq 0x38(%rsp), %rcx
movl $0x1, %r8d
leaq 0x48(%rsp), %r9
callq 0x15505a
cmpl $-0x1, %eax
je 0x155739
movl %eax, %r13d
movq 0x10(%r14), %rbx
movl %eax, %r15d
cmpb $0x1, (%rbx,%r15)
je 0x155667
movq %rbp, %rdi
movq %rbx, %rsi
movq 0x58(%rsp), %rdx
movl %r13d, %ecx
callq 0x1551ca
movsd 0x20(%rsp), %xmm1
addsd %xmm0, %xmm1
movapd %xmm1, %xmm0
cmpb $0x0, 0x17(%rsp)
movsd %xmm1, 0x20(%rsp)
jne 0x15570c
movsd 0x18(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x1556f8
movq 0x48(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x40(%rsp), %rax
movq %rax, 0x28(%rsp)
minsd %xmm1, %xmm0
movb $0x1, (%rbx,%r15)
movsd %xmm0, 0x18(%rsp)
jmp 0x155667
movq 0x13f8cd(%rip), %rax    # 0x294fe0
movq (%rax), %rdi
leaq 0xe6964(%rip), %rsi     # 0x23c081
movl %r13d, %edx
movsd 0x20(%rsp), %xmm0
movb $0x1, %al
callq 0x22b0
movsd 0x20(%rsp), %xmm0
movq 0x10(%r14), %rbx
jmp 0x1556d8
xorpd %xmm0, %xmm0
movsd 0x18(%rsp), %xmm1
ucomisd %xmm1, %xmm0
seta %al
movq 0x30(%rsp), %rbx
cmpq $-0x1, %rbx
setne %cl
movq 0x28(%rsp), %r15
cmpq $-0x1, %r15
setne %dl
andb %cl, %dl
andb %al, %dl
cmpb $0x1, %dl
je 0x15577d
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xd8(%rsp), %rax
movq %rbx, (%rax)
movq 0xe0(%rsp), %rax
movq %r15, (%rax)
movsd %xmm1, 0x18(%r14)
leaq 0x60(%rsp), %rdi
movq %rbx, 0x20(%rdi)
movq %r15, 0x28(%rdi)
leaq 0x40(%rsp), %rax
movq %rax, (%rsp)
leaq 0x48(%rsp), %r9
movq %rbp, %rsi
movq %r12, %rdx
movq 0x38(%rsp), %rcx
movl $0x1, %r8d
movsd %xmm1, 0x18(%rsp)
callq 0x15505a
movq 0x13f809(%rip), %rcx    # 0x294fe0
movq (%rcx), %rdi
movl %eax, (%rsp)
leaq 0xe68ad(%rip), %rsi     # 0x23c091
movsd 0x18(%rsp), %xmm0
movq 0x50(%rsp), %rdx
movq 0xd0(%rsp), %rcx
movq %rbx, %r8
movq %r15, %r9
movb $0x1, %al
callq 0x22b0
jmp 0x15576b