// File: /workspace/github_cpp_makefile_star2_O1/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 0x2145ee
movq %r8, %r14
movq $-0x1, %r13
movq 0x8(%rsp), %rbx
movq (%r15,%rbx,8), %r12
cmpb $0x0, (%r14,%r12)
jne 0x21447e
movq %r12, %rax
xorq $0x1, %rax
cmpb $0x0, (%r14,%rax)
je 0x2145e2
movq $-0x1, %rbp
cmpq $-0x1, %r13
je 0x214581
movq %r12, %rax
xorq $0x1, %rax
cmpb $0x0, (%r14,%rax)
je 0x21457e
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rdx
movq %r15, %rcx
movq 0x8(%rsp), %r8
movq %rsi, %r9
movsd 0x1108a(%rip), %xmm0    # 0x225548
pushq 0x70(%rsp)
pushq 0x70(%rsp)
pushq 0x90(%rsp)
pushq 0x90(%rsp)
pushq %rax
pushq %rbx
callq 0x214054
movq 0x90(%rsp), %rsi
movq 0xb8(%rsp), %rdi
addq $0x30, %rsp
testq %rax, %rax
je 0x214581
movq (%rdi), %rax
cmpq 0x20(%rsp), %rax
jbe 0x214510
movq 0x10(%rdi), %rcx
leaq (%rcx,%rax,8), %rcx
addq $-0x8, %rcx
jmp 0x214512
xorl %ecx, %ecx
testq %rcx, %rcx
je 0x21451f
movl 0x4(%rcx), %ecx
cmpq %r13, %rcx
je 0x21457e
movq 0x8(%rdi), %rcx
cmpq %rcx, %rax
jne 0x214562
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%rdi)
movq 0x88(%rsp), %rax
movq 0x10(%rax), %rdi
shlq $0x3, %rsi
callq 0x2370
movq 0x60(%rsp), %rsi
movq 0x88(%rsp), %rdi
movq %rax, 0x10(%rdi)
movq (%rdi), %rax
movq 0x10(%rdi), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%rdi)
movq %r13, %rdx
shlq $0x20, %rdx
orq %rbx, %rdx
movq %rdx, (%rcx,%rax,8)
movq %r13, %rbp
cmpb $0x0, (%r14,%r12)
movq %rbp, %r13
je 0x2145e2
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rdx
movq %r15, %rcx
movq 0x8(%rsp), %r8
movq %rsi, %r9
movsd 0x10fa0(%rip), %xmm0    # 0x225548
pushq 0x70(%rsp)
pushq 0x70(%rsp)
pushq 0x90(%rsp)
pushq 0x90(%rsp)
pushq %r12
pushq %rbx
callq 0x214054
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 0x214461
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq