// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: select_unqiue_path_on_fly(usg_t*, unsigned long, unsigned long, asg64_v*, asg64_v*, unsigned long*, unsigned int*, unsigned long*, unsigned char*, unsigned long, asg64_v*)
void select_unqiue_path_on_fly(usg_t *g, uint64_t s, uint64_t e, asg64_v *b64, asg64_v *ub64,
uint64_t *integer_seq, uint32_t *ng_occ, uint64_t *is_reli, uint8_t *f, uint64_t max_ext, asg64_v *res)
{
    uint64_t k, sk = (uint64_t)-1, ek = (uint64_t)-1, *p = NULL; ub64->n = 0;
    assert(occ_m(ng_occ[integer_seq[s]]) == 1);
    assert(occ_m(ng_occ[integer_seq[e]^1]) == 1);
    
    if(reli_pass(is_reli[integer_seq[s]])) {
        sk = s; 
    } else {
        for (k = s + 1; k < e; k++) {
            if((reli_pass(is_reli[integer_seq[k]])) && (occ_m(ng_occ[integer_seq[k]]) == 1)) {
                sk = k;
                break;
            }
        }
    }
    if((sk == ((uint64_t)-1)) || (sk >= e)) return;

    for (k = sk + 1; k <= e; k++) {
        if(sk != ((uint64_t)-1)) {
            if(reli_pass(is_reli[(integer_seq[k]^1)])) {
                if(occ_m((ng_occ[integer_seq[k]]^1)) == 1) {
                    ek = k; ///check and extend [sk, ek]
                    if((ek > sk) && (get_ext_tip(g, integer_seq, sk, ek, b64, ub64, f, max_ext) < max_ext)) {
                        p = ((res->n > 0)? (&(res->a[res->n-1])):NULL);
                        if(p && (((uint32_t)(*p)) == sk)) {
                            (*p) >>= 32; (*p) <<= 32; (*p) |= ek;
                        } else {
                            kv_pushp(uint64_t, *res, &p); *p = sk; (*p) <<= 32; (*p) |= ek;
                        }
                    }
                    sk = ek = ((uint64_t)-1);
                }
            } else {
                sk = ek = ((uint64_t)-1);
            }
        }

        ///case2: sk != (uint64_t)-1 && ek == (uint64_t)-1 -> wait for an available ek
        ///case3: sk == (uint64_t)-1 && ek == (uint64_t)-1 -> not available
        if(k < e) {
            if((!(reli_pass(is_reli[integer_seq[k]])))) {
                sk = ek = (uint64_t)-1; continue;
            }
            if((sk == (uint64_t)-1) && (occ_m(ng_occ[integer_seq[k]]) == 1)) {
                sk = k;
            }
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r9, %rbx
movq %r8, %r9
movq %rcx, %r8
movq %rdx, %r12
movq %rsi, %rbp
movq 0x50(%rsp), %rsi
movq $0x0, (%r9)
movq (%rbx,%rbp,8), %rax
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movl (%rsi,%rax,4), %edx
andl %ecx, %edx
cmpl $0x1, %edx
jne 0x21b6d0
movq (%rbx,%r12,8), %rdx
xorq $0x1, %rdx
andl (%rsi,%rdx,4), %ecx
cmpl $0x1, %ecx
jne 0x21b6ef
movq 0x58(%rsp), %r14
cmpq $0x0, (%r14,%rax,8)
js 0x21b693
cmpq %r12, %rbp
jae 0x21b6c1
leaq 0x1(%rbp), %r15
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movq %r9, 0x10(%rsp)
movq %r8, 0x8(%rsp)
movq %rdi, (%rsp)
movq $-0x1, %r13
cmpq $-0x1, %rbp
jne 0x21b588
cmpq %r12, %r15
jae 0x21b578
movq (%rbx,%r15,8), %rax
cmpq $0x0, (%r14,%rax,8)
js 0x21b571
cmpq $-0x1, %r13
jne 0x21b578
movl (%rsi,%rax,4), %eax
andl %edx, %eax
movq %r15, %r13
cmpl $0x1, %eax
je 0x21b578
movq $-0x1, %r13
incq %r15
movq %r13, %rbp
cmpq %r12, %r15
jbe 0x21b541
jmp 0x21b6c1
movq (%rbx,%r15,8), %rax
movq %rax, %rcx
xorq $0x1, %rcx
cmpq $0x0, (%r14,%rcx,8)
js 0x21b54e
testl $0x7fffffff, (%rsi,%rax,4) # imm = 0x7FFFFFFF
je 0x21b5a8
movq %rbp, %r13
jmp 0x21b54e
cmpq %rbp, %r15
jbe 0x21b54e
movq %rbx, %rsi
movq %rbp, %rdx
movq %r15, %rcx
movq 0x68(%rsp), %rax
pushq %rax
pushq 0x68(%rsp)
callq 0x21af98
addq $0x10, %rsp
cmpq 0x68(%rsp), %rax
jae 0x21b61a
movq 0x70(%rsp), %r10
movq (%r10), %rcx
movq 0x10(%r10), %rax
testq %rcx, %rcx
je 0x21b62f
leaq (%rax,%rcx,8), %rdx
addq $-0x8, %rdx
je 0x21b62f
movq (%rdx), %rsi
movl %esi, %edi
cmpq %rbp, %rdi
jne 0x21b62f
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
andq %rax, %rsi
movq %rsi, %rbp
movq 0x10(%rsp), %r9
movq 0x8(%rsp), %r8
movq (%rsp), %rdi
movq 0x50(%rsp), %rsi
jmp 0x21b683
movq 0x10(%rsp), %r9
movq 0x8(%rsp), %r8
movq (%rsp), %rdi
movq 0x50(%rsp), %rsi
jmp 0x21b689
cmpq 0x8(%r10), %rcx
jne 0x21b661
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r10)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movq 0x70(%rsp), %r10
movq %rax, 0x10(%r10)
movq (%r10), %rcx
movq 0x10(%rsp), %r9
movq 0x8(%rsp), %r8
movq (%rsp), %rdi
movq 0x50(%rsp), %rsi
leaq 0x1(%rcx), %rdx
movq %rdx, (%r10)
leaq (%rax,%rcx,8), %rdx
shlq $0x20, %rbp
orq %r15, %rbp
movq %rbp, (%rdx)
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
jmp 0x21b54e
incq %rbp
cmpq %r12, %rbp
jae 0x21b6c1
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq (%rbx,%rbp,8), %rcx
cmpq $0x0, (%r14,%rcx,8)
js 0x21b6b9
movl (%rsi,%rcx,4), %ecx
andl %eax, %ecx
cmpl $0x1, %ecx
je 0x21b521
incq %rbp
cmpq %rbp, %r12
jne 0x21b6a0
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2d593(%rip), %rdi     # 0x248c6a
leaq 0x29f2b(%rip), %rsi     # 0x245609
leaq 0x2d5a8(%rip), %rcx     # 0x248c8d
movl $0x3267, %edx           # imm = 0x3267
callq 0x2110
leaq 0x2d62d(%rip), %rdi     # 0x248d23
leaq 0x29f0c(%rip), %rsi     # 0x245609
leaq 0x2d589(%rip), %rcx     # 0x248c8d
movl $0x3268, %edx           # imm = 0x3268
callq 0x2110