// File: /workspace/github_cpp_makefile_star2_O2/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 %r9, %rbx
movq %r8, %r14
movq %rcx, %r15
movq %rdx, 0x10(%rsp)
movq %rdi, 0x8(%rsp)
movq 0x88(%rsp), %rax
movq 0x70(%rsp), %rcx
movq 0x68(%rsp), %rdx
movq 0x60(%rsp), %rbp
movq (%rax), %rax
movq %rax, 0x20(%rsp)
andq $0x0, (%rcx)
andq $0x0, (%rdx)
pushq $-0x1
popq %r12
movq %r9, 0x18(%rsp)
cmpq %rbp, %rbx
jae 0x1d0b5f
movq (%r15,%rbx,8), %r13
cmpb $0x0, (%r14,%r13)
jne 0x1d0a26
movq %r13, %rax
xorq $0x1, %rax
cmpb $0x0, (%r14,%rax)
je 0x1d0b57
pushq $-0x1
popq %rcx
cmpq $-0x1, %r12
je 0x1d0afe
movq %r13, %rax
xorq $0x1, %rax
cmpb $0x0, (%r14,%rax)
je 0x1d0afb
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rdx
movq %r15, %rcx
movq 0x18(%rsp), %r8
movq %rbp, %r9
movsd 0x12b36(%rip), %xmm0    # 0x1e3598
pushq 0x70(%rsp)
pushq 0x70(%rsp)
pushq 0x90(%rsp)
pushq 0x90(%rsp)
pushq %rax
pushq %rbx
callq 0x1d062a
movq 0xb8(%rsp), %rdi
addq $0x30, %rsp
pushq $-0x1
popq %rcx
testq %rax, %rax
je 0x1d0afe
movq (%rdi), %rcx
movq 0x10(%rdi), %rax
cmpq 0x20(%rsp), %rcx
jbe 0x1d0ab3
leaq (%rax,%rcx,8), %rdx
addq $-0x8, %rdx
je 0x1d0ab3
movl 0x4(%rdx), %edx
cmpq %r12, %rdx
je 0x1d0afb
cmpq 0x8(%rdi), %rcx
jne 0x1d0ae6
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%rdi)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movq 0x88(%rsp), %rdi
movq %rax, 0x10(%rdi)
movq (%rdi), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%rdi)
movq %r12, %rdx
shlq $0x20, %rdx
orq %rbx, %rdx
movq %rdx, (%rax,%rcx,8)
movq %r12, %rcx
cmpb $0x0, (%r14,%r13)
movq %rcx, %r12
je 0x1d0b57
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rdx
movq %r15, %rcx
movq 0x18(%rsp), %r8
movq %rbp, %r9
movsd 0x12a73(%rip), %xmm0    # 0x1e3598
pushq 0x70(%rsp)
pushq 0x70(%rsp)
pushq 0x90(%rsp)
pushq 0x90(%rsp)
pushq %r13
pushq %rbx
callq 0x1d062a
addq $0x30, %rsp
cmpq $0x1, %rax
movl $0x0, %r12d
sbbq %r12, %r12
orq %rbx, %r12
incq %rbx
jmp 0x1d0a00
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq