// File: /workspace/github_cpp_makefile_star2_O1/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 0x50(%rsp), %r10
movq $0x0, (%r9)
movq (%rbx,%rsi,8), %rax
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movl (%r10,%rax,4), %edx
andl %ecx, %edx
cmpl $0x1, %edx
jne 0x2102c9
movq (%rbx,%r12,8), %rdx
xorq $0x1, %rdx
andl (%r10,%rdx,4), %ecx
cmpl $0x1, %ecx
jne 0x2102e8
movq %rsi, %rbp
movq 0x58(%rsp), %r14
cmpq $0x0, (%r14,%rax,8)
jns 0x210136
incq %rbp
cmpq %r12, %rbp
jae 0x21012f
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq (%rbx,%rbp,8), %rcx
cmpq $0x0, (%r14,%rcx,8)
js 0x210127
movl (%r10,%rcx,4), %ecx
andl %eax, %ecx
cmpl $0x1, %ecx
je 0x210136
incq %rbp
cmpq %rbp, %r12
jne 0x210111
movq $-0x1, %rbp
cmpq %r12, %rbp
jae 0x210144
leaq 0x1(%rbp), %r15
cmpq %r12, %r15
jbe 0x210153
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movq %r9, 0x10(%rsp)
movq %r8, 0x8(%rsp)
movq %rdi, (%rsp)
movq $-0x1, %r13
cmpq $-0x1, %rbp
jne 0x2101ab
cmpq %r12, %r15
jae 0x21019e
movq (%rbx,%r15,8), %rax
cmpq $0x0, (%r14,%rax,8)
js 0x210197
cmpq $-0x1, %r13
jne 0x21019e
movl (%r10,%rax,4), %eax
andl %edx, %eax
movq %r15, %r13
cmpl $0x1, %eax
je 0x21019e
movq $-0x1, %r13
incq %r15
movq %r13, %rbp
cmpq %r12, %r15
jbe 0x210166
jmp 0x210144
movq (%rbx,%r15,8), %rax
movq %rax, %rcx
xorq $0x1, %rcx
cmpq $0x0, (%r14,%rcx,8)
js 0x210173
testl $0x7fffffff, (%r10,%rax,4) # imm = 0x7FFFFFFF
je 0x2101cc
movq %rbp, %r13
jmp 0x210173
cmpq %rbp, %r15
jbe 0x210173
movq %rbx, %rsi
movq %rbp, %rdx
movq %r15, %rcx
movq 0x68(%rsp), %rax
pushq %rax
pushq 0x68(%rsp)
callq 0x20fb6b
addq $0x10, %rsp
cmpq 0x68(%rsp), %rax
jae 0x21020f
movq 0x70(%rsp), %r11
movq (%r11), %rcx
testq %rcx, %rcx
je 0x210227
movq 0x10(%r11), %rax
leaq (%rax,%rcx,8), %rax
addq $-0x8, %rax
jmp 0x210229
movq 0x10(%rsp), %r9
movq 0x8(%rsp), %r8
movq (%rsp), %rdi
movq 0x50(%rsp), %r10
jmp 0x2102bf
xorl %eax, %eax
movq 0x10(%rsp), %r9
movq 0x8(%rsp), %r8
movq (%rsp), %rdi
movq 0x50(%rsp), %r10
testq %rax, %rax
je 0x21025d
movq (%rax), %rdx
movl %edx, %esi
cmpq %rbp, %rsi
jne 0x21025d
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
andq %rcx, %rdx
movq %rdx, %rbp
jmp 0x2102b9
movq 0x8(%r11), %rax
cmpq %rax, %rcx
jne 0x2102a3
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r11)
movq 0x10(%r11), %rdi
shlq $0x3, %rsi
callq 0x2370
movq 0x70(%rsp), %r11
movq 0x50(%rsp), %r10
movq (%rsp), %rdi
movq 0x8(%rsp), %r8
movq 0x10(%rsp), %r9
movq %rax, 0x10(%r11)
movq (%r11), %rax
leaq 0x1(%rax), %rcx
movq %rcx, (%r11)
shlq $0x3, %rax
addq 0x10(%r11), %rax
shlq $0x20, %rbp
orq %r15, %rbp
movq %rbp, (%rax)
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
jmp 0x210173
leaq 0x2c6b6(%rip), %rdi     # 0x23c986
leaq 0x2904e(%rip), %rsi     # 0x239325
leaq 0x2c6cb(%rip), %rcx     # 0x23c9a9
movl $0x3267, %edx           # imm = 0x3267
callq 0x2110
leaq 0x2c750(%rip), %rdi     # 0x23ca3f
leaq 0x2902f(%rip), %rsi     # 0x239325
leaq 0x2c6ac(%rip), %rcx     # 0x23c9a9
movl $0x3268, %edx           # imm = 0x3268
callq 0x2110