// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: get_best_path(ul_resolve_t*, usg_t*, unsigned long*, unsigned long*, unsigned char*, unsigned long, unsigned long, asg64_v*, asg64_v*, unsigned long*, unsigned long*, asg64_v*)
void get_best_path(ul_resolve_t *uidx, usg_t *ng, uint64_t *int_idx, uint64_t *int_a, 
uint8_t *f, uint64_t s, uint64_t e, asg64_v *b0, asg64_v *b1, uint64_t *ridx_a, 
uint64_t *ridx, asg64_v *res)
{
    uint64_t pi, v, k, res_n = res->n, *pz;
    b0->n = b1->n = 0; 
    for (k = s, pi = (uint64_t)-1; k < e; k++) {
        v = int_a[k]; 
        if((!f[v])&&(!f[v^1])) continue;
        if((pi != (uint64_t)-1) && (f[v^1])) {
            // if(((v>>1) == 2736)) {
            //     fprintf(stderr, "+[M::%s::ii[%lu, %lu)] utg%.6dl(%c), f[v^1]::%u, v^1::%lu, putg%.6dl(%c), f[pv]::%u, pv::%lu\n", 
            //     __func__, s, e, (int32_t)(int_a[k]>>1)+1, "+-"[int_a[k]&1], f[v^1], v^1, 
            //     (int32_t)(int_a[pi]>>1)+1, "+-"[int_a[pi]&1], f[int_a[pi]], int_a[pi]);
            // }
            if(is_best_path(uidx, ng, int_idx, int_a, s, e, k, v^1, ridx_a, ridx, b0, b1, 0.51)) {
                // if(((v>>1) == 2736)) {
                //     fprintf(stderr, "-[M::%s::ii[%lu, %lu)] utg%.6dl(%c), f[v^1]::%u, v^1::%lu, putg%.6dl(%c), f[pv]::%u, pv::%lu\n", 
                //     __func__, s, e, (int32_t)(int_a[k]>>1)+1, "+-"[int_a[k]&1], f[v^1], v^1, 
                //     (int32_t)(int_a[pi]>>1)+1, "+-"[int_a[pi]&1], f[int_a[pi]], int_a[pi]);
                // }
                // fprintf(stderr, "[M::%s::] utg%.6dl(%c)->utg%.6dl(%c)\n", __func__, 
                //     (int32_t)(int_a[pi]>>1)+1, "+-"[int_a[pi]&1], (int32_t)(int_a[k]>>1)+1, "+-"[int_a[k]&1]);
                pz = (res->n > res_n)? &(res->a[res->n-1]):(NULL);
                if((!pz) || (((*pz)>>32) != pi)) {//keep the shortest pi<->k 
                    kv_pushp(uint64_t, *res, &pz); 
                    *pz = pi; (*pz) <<= 32; (*pz) |= k;
                }
            } else {
                pi = (uint64_t)-1;
            }            
        }
        if(f[v]) {
            // fprintf(stderr, "-[M::%s::] utg%.6dl(%c), f[v]::%u, v::%lu\n", 
            // __func__, (int32_t)(int_a[k]>>1)+1, "+-"[int_a[k]&1], f[v], v);
            if(is_best_path(uidx, ng, int_idx, int_a, s, e, k, v, ridx_a, ridx, b0, b1, 0.51)) {
                pi = k;//keep the shortest pi<->k
            } else {
                pi = (uint64_t)-1;
            }
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rcx, %r15
movq %rdx, 0x18(%rsp)
movq %rdi, 0x10(%rsp)
movq 0x88(%rsp), %rax
movq 0x70(%rsp), %rcx
movq 0x68(%rsp), %rdx
movq 0x60(%rsp), %rsi
movq (%rax), %rax
movq %rax, 0x20(%rsp)
xorl %eax, %eax
movq %rax, (%rcx)
movq %rax, (%rdx)
movq %r9, 0x8(%rsp)
cmpq %rsi, %r9
jae 0x21fa34
movq %r8, %r14
movq $-0x1, %r13
movq 0x8(%rsp), %rbx
movq (%r15,%rbx,8), %r12
cmpb $0x0, (%r14,%r12)
jne 0x21f8df
movq %r12, %rax
xorq $0x1, %rax
cmpb $0x0, (%r14,%rax)
je 0x21fa28
movq $-0x1, %rbp
cmpq $-0x1, %r13
je 0x21f9c7
movq %r12, %rax
xorq $0x1, %rax
cmpb $0x0, (%r14,%rax)
je 0x21f9c4
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rdx
movq %r15, %rcx
movq 0x8(%rsp), %r8
movq %rsi, %r9
movsd 0x11d29(%rip), %xmm0    # 0x231648
pushq 0x70(%rsp)
pushq 0x70(%rsp)
pushq 0x90(%rsp)
pushq 0x90(%rsp)
pushq %rax
pushq %rbx
callq 0x21f4be
movq 0x90(%rsp), %rsi
movq 0xb8(%rsp), %rdi
addq $0x30, %rsp
testq %rax, %rax
je 0x21f9c7
movq (%rdi), %rcx
movq 0x10(%rdi), %rax
cmpq 0x20(%rsp), %rcx
jbe 0x21f975
leaq (%rax,%rcx,8), %rdx
addq $-0x8, %rdx
je 0x21f975
movl 0x4(%rdx), %edx
cmpq %r13, %rdx
je 0x21f9c4
cmpq 0x8(%rdi), %rcx
jne 0x21f9af
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%rdi)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movq 0x60(%rsp), %rsi
movq 0x88(%rsp), %rdi
movq %rax, 0x10(%rdi)
movq (%rdi), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%rdi)
movq %r13, %rdx
shlq $0x20, %rdx
orq %rbx, %rdx
movq %rdx, (%rax,%rcx,8)
movq %r13, %rbp
cmpb $0x0, (%r14,%r12)
movq %rbp, %r13
je 0x21fa28
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rdx
movq %r15, %rcx
movq 0x8(%rsp), %r8
movq %rsi, %r9
movsd 0x11c5a(%rip), %xmm0    # 0x231648
pushq 0x70(%rsp)
pushq 0x70(%rsp)
pushq 0x90(%rsp)
pushq 0x90(%rsp)
pushq %r12
pushq %rbx
callq 0x21f4be
movq 0x90(%rsp), %rsi
addq $0x30, %rsp
cmpq $0x1, %rax
movl $0x0, %r13d
sbbq %r13, %r13
orq %rbx, %r13
incq %rbx
cmpq %rbx, %rsi
jne 0x21f8c2
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq