// File: /workspace/github_cpp_makefile_star2_O3/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, 0x58(%rsp)
movq %r8, %rsi
movq %rdx, 0x68(%rsp)
movq %rdi, 0x60(%rsp)
movq 0xd0(%rsp), %rbp
movq 0xb8(%rsp), %r14
movq 0xb0(%rsp), %r15
movq 0xc8(%rsp), %rbx
movq %rcx, 0x70(%rsp)
movq %rcx, %rdi
movq %r9, %rdx
movq %r15, %rcx
movq %r14, %r8
movq %rbp, %r9
callq 0x21f346
andq $-0x2, %r14
movq (%rbx,%r14,4), %rdx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
andq %rdx, %rsi
je 0x21f826
shrq $0x1d, %rdx
andq $-0x8, %rdx
addq 0xc0(%rsp), %rdx
movq 0xd8(%rsp), %r9
movl $0x1, %eax
movq %rax, 0x18(%rsp)
movq $0x0, 0x10(%rsp)
movq $0x0, 0x40(%rsp)
movq $-0x1, 0x30(%rsp)
movq $-0x1, 0x38(%rsp)
xorl %ebx, %ebx
movq %rdx, 0x28(%rsp)
movq %rsi, 0x20(%rsp)
movq 0x60(%rsp), %r12
movq (%rdx,%rbx,8), %rax
movl %eax, %ecx
cmpq %r15, %rcx
je 0x21f779
shrq $0x20, %rax
movq 0x68(%rsp), %rdx
movq (%rdx,%rax,8), %rsi
movl %esi, %edx
shrq $0x20, %rsi
addq %rsi, %rdx
movq 0x70(%rsp), %rdi
movq 0xb8(%rsp), %r8
movq %r9, %r14
callq 0x21f346
movq (%rbp), %rdx
movq (%r14), %r15
cmpq %r15, %rdx
cmovbq %rdx, %r15
testq %r15, %r15
movq 0x40(%rsp), %rdi
je 0x21f844
incq %rdi
movq 0x10(%rbp), %rax
movq 0x10(%r14), %rcx
xorl %r13d, %r13d
movq (%rax,%r13,8), %rsi
cmpq (%rcx,%r13,8), %rsi
jne 0x21f600
incq %r13
cmpq %r13, %r15
jne 0x21f5e9
movq %r15, %r13
jmp 0x21f609
testq %r13, %r13
je 0x21f844
movq $-0x1, %rax
movq %rax, 0x48(%rsp)
movq %rax, 0x50(%rsp)
cmpq %rdx, %r13
jae 0x21f830
movq %rdi, 0x40(%rsp)
movq 0x10(%rbp), %rsi
leaq -0x1(%r13), %rbp
leaq 0x50(%rsp), %rax
movq %rax, (%rsp)
movq %r12, %rdi
movq %rbp, %rcx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x20eadf
movq %r14, %r9
movq (%r14), %rdx
cmpq %rdx, %r13
jae 0x21f75f
movq 0x10(%r9), %rsi
leaq 0x48(%rsp), %rax
movq %rax, (%rsp)
movq %r12, %rdi
movq %rbp, %rcx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x20eadf
movq 0x50(%rsp), %rax
cmpq $-0x1, %rax
movq %rax, %rdx
movl $0x0, %edi
cmoveq %rdi, %rdx
movq %rdx, 0x50(%rsp)
movq 0x48(%rsp), %rcx
cmpq $-0x1, %rcx
movl $0x0, %esi
movq %rsi, 0x10(%rsp)
cmoveq %rdi, %rcx
movq %rcx, 0x48(%rsp)
cmpq %rcx, %rdx
movq 0x38(%rsp), %r8
jbe 0x21f830
movq %rcx, %xmm0
movq 0x11bb8(%rip), %xmm3    # 0x231280
punpckldq %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
movapd 0x11bbc(%rip), %xmm2    # 0x231290
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 0x58(%rsp), %xmm2
ucomisd %xmm2, %xmm1
ja 0x21f830
cmpq $-0x1, %r8
sete %sil
cmpq %r15, %r13
sete %dil
orb %sil, %dil
cmpq %rdx, %r8
seta %sil
orb %dil, %sil
movq 0xd0(%rsp), %rbp
movq 0xb0(%rsp), %r15
movq %r14, %r9
jne 0x21f74a
cmpq %rdx, %r8
jne 0x21f754
cmpq %rcx, 0x30(%rsp)
jae 0x21f754
movq %rax, 0x38(%rsp)
movq %rcx, 0x30(%rsp)
movq $0x0, 0x18(%rsp)
jmp 0x21f76f
movq 0xd0(%rsp), %rbp
movq 0xb0(%rsp), %r15
movq 0x28(%rsp), %rdx
movq 0x20(%rsp), %rsi
incq %rbx
cmpq %rsi, %rbx
jne 0x21f585
cmpq $0x0, 0x40(%rsp)
setne %al
cmpq $0x0, 0x18(%rsp)
sete %cl
andb %al, %cl
movl $0x1, %eax
movq %rax, 0x10(%rsp)
cmpb $0x1, %cl
jne 0x21f830
xorl %eax, %eax
movq 0x38(%rsp), %rcx
cmpq $-0x1, %rcx
cmoveq %rax, %rcx
movq 0x30(%rsp), %rdx
cmpq $-0x1, %rdx
cmoveq %rax, %rdx
cmpq %rdx, %rcx
jbe 0x21f81b
movq %rdx, %xmm0
movq 0x11aa6(%rip), %xmm3    # 0x231280
punpckldq %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
movapd 0x11aaa(%rip), %xmm2    # 0x231290
subpd %xmm2, %xmm0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movq %rcx, %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 0x58(%rsp), %xmm2
ucomisd %xmm1, %xmm2
jae 0x21f830
movq $0x0, 0x10(%rsp)
jmp 0x21f830
movl $0x1, %eax
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x28952(%rip), %rdi     # 0x24819d
leaq 0x25db7(%rip), %rsi     # 0x245609
leaq 0x29bfa(%rip), %rcx     # 0x249453
movl $0x370d, %edx           # imm = 0x370D
callq 0x2110