// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: is_best_path(ul_resolve_t*, usg_t*, unsigned long*, unsigned long*, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long*, unsigned long*, asg64_v*, asg64_v*, double)
uint64_t is_best_path(ul_resolve_t *uidx, usg_t *ng, uint64_t *int_idx, uint64_t *int_a, 
uint64_t s, uint64_t e, uint64_t it, uint64_t v, uint64_t *ridx_a, uint64_t *ridx, 
asg64_v *b0, asg64_v *b1, double cutoff)
{
    uint64_t *arc_a, arc_n, k, is, ie, z, zn, w0, w1, min_w0, min_w1, alt_n = 0, is_contain = 1;
    gen_sub_integer_path(int_a, s, e, it, v, b0);

    arc_a = ridx_a + (ridx[v>>1]>>32); 
    arc_n = (uint32_t)ridx[v>>1];


    // uint64_t is_debug = 0;
    // if((((v>>1) == 2736) && (v&1))/** && (b0->n > 1 && (b0->a[b0->n-1]>>1) == 34944)**/) {
    //     // is_debug = 1;
    //     fprintf(stderr, "[M::%s::] utg%.6dl(%c)\n", __func__, 
    //                 (int32_t)(v>>1)+1, "+-"[v&1]);
    //     prt_sub_integer_path(b0, it, (uint64_t)-1, (uint64_t)-1, (uint64_t)-1, (uint64_t)-1);
    // }


    for (k = 0, min_w0 = min_w1 = (uint64_t)-1, is_contain = 1; k < arc_n; k++) {
        if(it == ((uint32_t)arc_a[k])) continue;
        is = int_idx[arc_a[k]>>32]>>32; alt_n++;
        ie = is + ((uint32_t)(int_idx[arc_a[k]>>32])); 
        gen_sub_integer_path(int_a, is, ie, ((uint32_t)arc_a[k]), v, b1);
        zn = MIN(b0->n, b1->n);
        for (z = 0; z < zn && b0->a[z] == b1->a[z]; z++); ///z: first raw unitig that is different between two paths
        assert(z > 0); w0 = w1 = (uint64_t)-1;
        if(z < b0->n) get_integer_seq_ovlps(uidx, b0->a, b0->n, z - 1, 0, NULL, &w0);
        else return 0;///b0 is contained
        if(z < b1->n) get_integer_seq_ovlps(uidx, b1->a, b1->n, z - 1, 0, NULL, &w1);
        else continue;///b1 is contained
        // if(((v>>1) == 2736) && (v&1)) {
        //     prt_sub_integer_path(b0, it, w0, w1, zn, z);
        //     prt_sub_integer_path(b1, it, w0, w1, zn, z);
        // }
        if(w0 == (uint64_t)-1) w0 = 0;
        if(w1 == (uint64_t)-1) w1 = 0;
        if((w0 <= w1) || (w1 > (w0*cutoff))) return 0;
        // if(b0->n == zn) return 0;///b0 is shorter
        // if(b1->n == zn) continue;///b1 is shorter
        if((min_w0 == (uint64_t)-1) || (z == zn) || (min_w0 > w0) || (min_w0 == w0 && min_w1 < w1)) {
            min_w0 = w0; min_w1 = w1;
        }
        is_contain = 0;
    }

    // if(((v>>1) == 2736) && (v&1)) {
    //     fprintf(stderr, "[M::%s::] min_w0::%lu, min_w1::%lu\n\n", __func__, min_w0, min_w1);
    // }
    // fprintf(stderr, "[M::%s::] utg%.6dl(%c)->utg%.6dl(%c)\n", __func__, 
    //                 (int32_t)(v>>1)+1, "+-"[v&1], (int32_t)(int_a[k]>>1)+1, "+-"[int_a[k]&1]);
    if(alt_n == 0) return 1;
    if(is_contain) return 1;
    
    if(min_w0 == (uint64_t)-1) min_w0 = 0;
    if(min_w1 == (uint64_t)-1) min_w1 = 0;
    if((min_w0 > min_w1) && (min_w1 <= (min_w0*cutoff))) return 1;
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movsd %xmm0, 0x40(%rsp)
movq %r8, %rsi
movq %rdx, 0x68(%rsp)
movq %rdi, 0x60(%rsp)
movq 0xd8(%rsp), %r13
movq 0xd0(%rsp), %r15
movq 0xb8(%rsp), %r14
movq 0xb0(%rsp), %r12
movq 0xc8(%rsp), %rbx
movq %rcx, 0x70(%rsp)
movq %rcx, %rdi
movq %r9, %rdx
movq %r12, %rcx
movq %r14, %r8
movq %r15, %r9
callq 0x1d043b
andq $-0x2, %r14
movq (%rbx,%r14,4), %rax
movl %eax, %edx
movq %rax, %rsi
shrq $0x1d, %rsi
andq $-0x8, %rsi
addq 0xc0(%rsp), %rsi
pushq $0x1
popq %rax
movq %rax, 0x10(%rsp)
pushq $-0x1
popq %rdi
movq $0x0, 0x18(%rsp)
xorl %ebx, %ebx
movq %rdi, %r9
xorl %r8d, %r8d
movq %rdx, 0x20(%rsp)
movq %rsi, 0x48(%rsp)
movq 0x60(%rsp), %rbp
cmpq %rdx, %rbx
je 0x1d08f0
movq (%rsi,%rbx,8), %rax
movl %eax, %ecx
cmpq %r12, %rcx
jne 0x1d06f3
movq %rdi, %rax
movq %r9, %rcx
jmp 0x1d08e2
movq %r9, 0x50(%rsp)
movq %rdi, 0x58(%rsp)
shrq $0x20, %rax
movq 0x68(%rsp), %rdx
movq (%rdx,%rax,8), %rsi
movl %esi, %edx
shrq $0x20, %rsi
incq %r8
movq %r8, 0x28(%rsp)
addq %rsi, %rdx
movq 0x70(%rsp), %rdi
movq 0xb8(%rsp), %r8
movq %r13, %r9
callq 0x1d043b
movq (%r15), %rdx
movq (%r13), %r12
cmpq %r12, %rdx
cmovbq %rdx, %r12
xorl %r14d, %r14d
cmpq %r14, %r12
je 0x1d075d
movq 0x10(%r15), %rax
movq (%rax,%r14,8), %rax
movq 0x10(%r13), %rcx
cmpq (%rcx,%r14,8), %rax
jne 0x1d0760
incq %r14
jmp 0x1d0741
movq %r12, %r14
testq %r14, %r14
je 0x1d0990
orq $-0x1, 0x30(%rsp)
orq $-0x1, 0x38(%rsp)
cmpq %rdx, %r14
jae 0x1d097c
movq 0x10(%r15), %rsi
leaq -0x1(%r14), %r15
leaq 0x38(%rsp), %rax
movq %rax, (%rsp)
movq %rbp, %rdi
movq %r15, %rcx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x1c1c92
movq (%r13), %rdx
cmpq %rdx, %r14
jae 0x1d08b9
movq 0x10(%r13), %rsi
leaq 0x30(%rsp), %rax
movq %rax, (%rsp)
movq %rbp, %rdi
movq %r15, %rcx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x1c1c92
movq 0x38(%rsp), %rax
cmpq $-0x1, %rax
movq %rax, %rdx
movl $0x0, %edi
cmoveq %rdi, %rdx
movq %rdx, 0x38(%rsp)
movq 0x30(%rsp), %rcx
cmpq $-0x1, %rcx
movl $0x0, %esi
movq %rsi, 0x18(%rsp)
cmoveq %rdi, %rcx
movq %rcx, 0x30(%rsp)
cmpq %rcx, %rdx
movq 0x58(%rsp), %r8
movq 0x50(%rsp), %r9
jbe 0x1d097c
movq %rcx, %xmm0
movq 0x12a4f(%rip), %xmm3    # 0x1e3270
punpckldq %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
movapd 0x12a53(%rip), %xmm2    # 0x1e3280
subpd %xmm2, %xmm0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movq %rdx, %xmm0
punpckldq %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
subpd %xmm2, %xmm0
movapd %xmm0, %xmm2
unpckhpd %xmm0, %xmm2            # xmm2 = xmm2[1],xmm0[1]
addsd %xmm0, %xmm2
mulsd 0x40(%rsp), %xmm2
ucomisd %xmm2, %xmm1
ja 0x1d097c
cmpq $-0x1, %r8
sete %sil
cmpq %r12, %r14
sete %dil
orb %sil, %dil
cmpq %rdx, %r8
seta %sil
orb %dil, %sil
movq 0xd0(%rsp), %r15
movq 0xb0(%rsp), %r12
movq 0x48(%rsp), %rsi
jne 0x1d08a9
cmpq %rdx, %r8
jne 0x1d08a3
cmpq %rcx, %r9
jb 0x1d08a9
movq %r8, %rax
movq %r9, %rcx
movq $0x0, 0x10(%rsp)
movq 0x20(%rsp), %rdx
jmp 0x1d08dd
movq 0x58(%rsp), %rax
movq 0x50(%rsp), %rcx
movq 0xd0(%rsp), %r15
movq 0xb0(%rsp), %r12
movq 0x20(%rsp), %rdx
movq 0x48(%rsp), %rsi
movq 0x28(%rsp), %r8
incq %rbx
movq %rax, %rdi
movq %rcx, %r9
jmp 0x1d06d4
testq %r8, %r8
setne %al
cmpq $0x0, 0x10(%rsp)
sete %cl
andb %al, %cl
pushq $0x1
popq %rax
movq %rax, 0x18(%rsp)
cmpb $0x1, %cl
jne 0x1d097c
xorl %eax, %eax
cmpq $-0x1, %rdi
cmoveq %rax, %rdi
cmpq $-0x1, %r9
cmoveq %rax, %r9
cmpq %r9, %rdi
jbe 0x1d0973
movq %r9, %xmm0
movq 0x1293e(%rip), %xmm3    # 0x1e3270
punpckldq %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
movapd 0x12942(%rip), %xmm2    # 0x1e3280
subpd %xmm2, %xmm0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movq %rdi, %xmm0
punpckldq %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
subpd %xmm2, %xmm0
movapd %xmm0, %xmm2
unpckhpd %xmm0, %xmm2            # xmm2 = xmm2[1],xmm0[1]
addsd %xmm0, %xmm2
mulsd 0x40(%rsp), %xmm2
ucomisd %xmm1, %xmm2
jae 0x1d097c
movq $0x0, 0x18(%rsp)
movq 0x18(%rsp), %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x297c5(%rip), %rdi     # 0x1fa15c
leaq 0x26b3b(%rip), %rsi     # 0x1f74d9
leaq 0x2aa6d(%rip), %rcx     # 0x1fb412
movl $0x370d, %edx           # imm = 0x370D
callq 0x2110