// File: /workspace/github_cpp_makefile_star2_O1/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 $0x68, %rsp
movsd %xmm0, 0x30(%rsp)
movq %r8, %rsi
movq %rdx, 0x58(%rsp)
movq %rdi, %r15
movq 0xc0(%rsp), %r14
movq 0xa8(%rsp), %r12
movq 0xa0(%rsp), %r13
movq 0xb8(%rsp), %rbx
movq %rcx, 0x60(%rsp)
movq %rcx, %rdi
movq %r9, %rdx
movq %r13, %rcx
movq %r12, %r8
movq %r14, %r9
callq 0x213edc
andq $-0x2, %r12
movq (%rbx,%r12,4), %rdx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
andq %rdx, %rsi
je 0x21433c
movq %r15, 0x50(%rsp)
shrq $0x1d, %rdx
andq $-0x8, %rdx
addq 0xb0(%rsp), %rdx
movq 0xc8(%rsp), %r15
movl $0x1, %eax
movq %rax, 0x8(%rsp)
movq $0x0, 0x18(%rsp)
movq $0x0, 0x48(%rsp)
movq $-0x1, 0x10(%rsp)
movq $-0x1, %rbp
xorl %ebx, %ebx
movq %rdx, 0x40(%rsp)
movq %rsi, 0x38(%rsp)
movq (%rdx,%rbx,8), %rax
movl %eax, %ecx
cmpq %r13, %rcx
je 0x21431a
shrq $0x20, %rax
movq 0x58(%rsp), %rdx
movq (%rdx,%rax,8), %rsi
movl %esi, %edx
shrq $0x20, %rsi
addq %rsi, %rdx
movq 0x60(%rsp), %rdi
movq 0xa8(%rsp), %r8
movq %r15, %r9
callq 0x213edc
movq (%r14), %rdx
movq (%r15), %r12
cmpq %r12, %rdx
cmovbq %rdx, %r12
testq %r12, %r12
je 0x214185
movq 0x10(%r14), %rax
movq 0x10(%r15), %rcx
xorl %r15d, %r15d
movq (%rax,%r15,8), %rsi
cmpq (%rcx,%r15,8), %rsi
jne 0x214188
incq %r15
cmpq %r15, %r12
jne 0x21416e
movq %r12, %r15
jmp 0x214188
xorl %r15d, %r15d
testq %r15, %r15
je 0x2143e3
movq $-0x1, %rax
movq %rax, 0x20(%rsp)
movq %rax, 0x28(%rsp)
cmpq %rdx, %r15
jae 0x2143cf
movq %rbp, %r13
incq 0x48(%rsp)
movq 0x10(%r14), %rsi
leaq -0x1(%r15), %rbp
leaq 0x28(%rsp), %rax
movq %rax, (%rsp)
movq 0x50(%rsp), %r14
movq %r14, %rdi
movq %rbp, %rcx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x2034cf
movq 0xc8(%rsp), %rax
movq (%rax), %rdx
cmpq %rdx, %r15
jae 0x2142fa
movq 0x10(%rax), %rsi
leaq 0x20(%rsp), %rax
movq %rax, (%rsp)
movq %r14, %rdi
movq %rbp, %rcx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x2034cf
movq 0x28(%rsp), %rax
cmpq $-0x1, %rax
movl $0x0, %esi
cmoveq %rsi, %rax
movq %rax, 0x28(%rsp)
movq 0x20(%rsp), %rcx
cmpq $-0x1, %rcx
movl $0x0, %edx
movq %rdx, 0x18(%rsp)
cmoveq %rsi, %rcx
movq %rcx, 0x20(%rsp)
cmpq %rcx, %rax
jbe 0x2143cf
movq %rcx, %xmm0
movq 0x10feb(%rip), %xmm2    # 0x225240
punpckldq %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
movapd 0x10fef(%rip), %xmm3    # 0x225250
subpd %xmm3, %xmm0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movq %rax, %xmm0
punpckldq %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
subpd %xmm3, %xmm0
movapd %xmm0, %xmm2
unpckhpd %xmm0, %xmm2            # xmm2 = xmm2[1],xmm0[1]
addsd %xmm0, %xmm2
mulsd 0x30(%rsp), %xmm2
ucomisd %xmm2, %xmm1
ja 0x2143cf
movq %r13, %rbp
cmpq $-0x1, %r13
sete %dl
cmpq %r12, %r15
sete %sil
orb %dl, %sil
cmpq %rax, %r13
seta %dl
orb %sil, %dl
movq 0xc0(%rsp), %r14
movq 0xa0(%rsp), %r13
movq 0x40(%rsp), %rdx
movq 0x38(%rsp), %rsi
movq 0xc8(%rsp), %r15
jne 0x2142e7
cmpq %rax, %rbp
jne 0x2142ef
cmpq %rcx, 0x10(%rsp)
jae 0x2142ef
movq %rax, %rbp
movq %rcx, 0x10(%rsp)
movq $0x0, 0x8(%rsp)
jmp 0x21431a
movq %r13, %rbp
movq 0xc0(%rsp), %r14
movq 0xa0(%rsp), %r13
movq 0x40(%rsp), %rdx
movq 0x38(%rsp), %rsi
movq %rax, %r15
incq %rbx
cmpq %rsi, %rbx
jne 0x214117
cmpq $0x0, 0x48(%rsp)
setne %cl
cmpq $0x0, 0x8(%rsp)
sete %al
andb %cl, %al
jmp 0x21434e
xorl %eax, %eax
movq $-0x1, %rbp
movq $-0x1, 0x10(%rsp)
movl $0x1, %ecx
movq %rcx, 0x18(%rsp)
testb %al, %al
je 0x2143cf
xorl %eax, %eax
cmpq $-0x1, %rbp
cmoveq %rax, %rbp
movq 0x10(%rsp), %rcx
cmpq $-0x1, %rcx
cmoveq %rax, %rcx
cmpq %rcx, %rbp
jbe 0x2143c6
movq %rcx, %xmm0
movq 0x10ebb(%rip), %xmm1    # 0x225240
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x10ebf(%rip), %xmm2    # 0x225250
subpd %xmm2, %xmm0
movapd %xmm0, %xmm3
unpckhpd %xmm0, %xmm3            # xmm3 = xmm3[1],xmm0[1]
addsd %xmm0, %xmm3
movq %rbp, %xmm0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
subpd %xmm2, %xmm0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x30(%rsp), %xmm1
ucomisd %xmm3, %xmm1
jae 0x2143cf
movq $0x0, 0x18(%rsp)
movq 0x18(%rsp), %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x27acf(%rip), %rdi     # 0x23beb9
leaq 0x24f34(%rip), %rsi     # 0x239325
leaq 0x28d77(%rip), %rcx     # 0x23d16f
movl $0x370d, %edx           # imm = 0x370D
callq 0x2110