// File: /workspace/github_cpp_makefile_star2_O1/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 $0x88, %rsp
movq %r9, %rbx
movq %r8, 0x48(%rsp)
movq %rcx, %r15
movq %rdx, %r12
movq %rsi, %rbp
movq %rdi, %r14
movq 0xc0(%rsp), %r13
leaq 0x50(%rsp), %rax
movq %r9, 0x20(%rax)
movq %r13, 0x28(%rax)
movq 0x10(%rdi), %rdi
movq (%rsi), %rdx
xorl %esi, %esi
callq 0x20e0
movq $-0x1, %rax
movq 0xd0(%rsp), %rcx
movq %rax, (%rcx)
movq $-0x1, 0x28(%rsp)
movq 0xc8(%rsp), %rcx
movq %rax, (%rcx)
movq %rbx, 0x40(%rsp)
xorq $0x2b1, %rbx            # imm = 0x2B1
movq %r13, %rcx
xorq $0x1, %rcx
orq %rbx, %rcx
sete 0xf(%rsp)
movsd 0xd6173(%rip), %xmm0    # 0x225270
movsd %xmm0, 0x10(%rsp)
xorpd %xmm0, %xmm0
movsd %xmm0, 0x18(%rsp)
movq $-0x1, 0x20(%rsp)
leaq 0x30(%rsp), %rax
movq %rax, (%rsp)
leaq 0x50(%rsp), %rdi
movq %rbp, %rsi
movq %r12, %rdx
movq %r15, %rcx
movl $0x1, %r8d
leaq 0x38(%rsp), %r9
callq 0x14eb12
cmpl $-0x1, %eax
je 0x14f1e0
movl %eax, %ebx
movq 0x10(%r14), %rsi
movl %eax, %r13d
cmpb $0x1, (%rsi,%r13)
je 0x14f116
movq %rbp, %rdi
movq 0x48(%rsp), %rdx
movl %ebx, %ecx
callq 0x14ec71
movsd 0x18(%rsp), %xmm1
addsd %xmm0, %xmm1
movapd %xmm1, %xmm0
cmpb $0x0, 0xf(%rsp)
movsd %xmm1, 0x18(%rsp)
jne 0x14f1b8
movsd 0x10(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x14f1a0
movq 0x38(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x30(%rsp), %rax
movq %rax, 0x20(%rsp)
minsd %xmm1, %xmm0
movq 0x10(%r14), %rax
movb $0x1, (%rax,%r13)
movsd %xmm0, 0x10(%rsp)
jmp 0x14f116
movq 0x13ae21(%rip), %rax    # 0x289fe0
movq (%rax), %rdi
leaq 0xe0cac(%rip), %rsi     # 0x22fe75
movl %ebx, %edx
movsd 0x18(%rsp), %xmm0
movb $0x1, %al
callq 0x22b0
movsd 0x18(%rsp), %xmm0
jmp 0x14f180
xorpd %xmm0, %xmm0
movsd 0x10(%rsp), %xmm1
ucomisd %xmm1, %xmm0
seta %al
movq 0x28(%rsp), %rbx
cmpq $-0x1, %rbx
setne %cl
movq 0x20(%rsp), %r13
cmpq $-0x1, %r13
setne %dl
andb %cl, %dl
andb %al, %dl
cmpb $0x1, %dl
je 0x14f224
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xc8(%rsp), %rax
movq %rbx, (%rax)
movq 0xd0(%rsp), %rax
movq %r13, (%rax)
movsd %xmm1, 0x18(%r14)
leaq 0x50(%rsp), %rdi
movq %rbx, 0x20(%rdi)
movq %r13, 0x28(%rdi)
leaq 0x30(%rsp), %rax
movq %rax, (%rsp)
leaq 0x38(%rsp), %r9
movq %rbp, %rsi
movq %r12, %rdx
movq %r15, %rcx
movl $0x1, %r8d
movsd %xmm1, 0x10(%rsp)
callq 0x14eb12
movq 0x13ad64(%rip), %rcx    # 0x289fe0
movq (%rcx), %rdi
movl %eax, (%rsp)
leaq 0xe0bfc(%rip), %rsi     # 0x22fe85
movsd 0x10(%rsp), %xmm0
movq 0x40(%rsp), %rdx
movq 0xc0(%rsp), %rcx
movq %rbx, %r8
movq %r13, %r9
movb $0x1, %al
callq 0x22b0
jmp 0x14f212