// File: 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
movq %rsp, %rbp
subq $0x70, %rsp
movq 0x30(%rbp), %rax
movq 0x28(%rbp), %rax
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq $-0x1, -0x40(%rbp)
movq $-0x1, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
movq -0x28(%rbp), %rax
movq $0x0, (%rax)
movq 0x10(%rbp), %rax
movq -0x30(%rbp), %rcx
movq -0x10(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movl (%rax,%rcx,4), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpl $0x1, %eax
jne 0x35b606
jmp 0x35b625
leaq 0x3e34d(%rip), %rdi     # 0x39995a
leaq 0x3aba5(%rip), %rsi     # 0x3961b9
movl $0x3267, %edx           # imm = 0x3267
leaq 0x3e35d(%rip), %rcx     # 0x39997d
callq 0x2130
movq 0x10(%rbp), %rax
movq -0x30(%rbp), %rcx
movq -0x18(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
xorq $0x1, %rcx
movl (%rax,%rcx,4), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpl $0x1, %eax
jne 0x35b648
jmp 0x35b667
leaq 0x3e3c4(%rip), %rdi     # 0x399a13
leaq 0x3ab63(%rip), %rsi     # 0x3961b9
movl $0x3268, %edx           # imm = 0x3268
leaq 0x3e31b(%rip), %rcx     # 0x39997d
callq 0x2130
movq 0x18(%rbp), %rcx
movq -0x30(%rbp), %rax
movq -0x10(%rbp), %rdx
movq (%rax,%rdx,8), %rdx
movabsq $-0x8000000000000000, %rax # imm = 0x8000000000000000
andq (%rcx,%rdx,8), %rax
cmpq $0x0, %rax
jne 0x35b695
movq -0x10(%rbp), %rax
movq %rax, -0x40(%rbp)
jmp 0x35b708
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x18(%rbp), %rax
jae 0x35b706
movq 0x18(%rbp), %rcx
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rdx
movq (%rax,%rdx,8), %rdx
movabsq $-0x8000000000000000, %rax # imm = 0x8000000000000000
andq (%rcx,%rdx,8), %rax
cmpq $0x0, %rax
jne 0x35b6f6
movq 0x10(%rbp), %rax
movq -0x30(%rbp), %rcx
movq -0x38(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movl (%rax,%rcx,4), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpl $0x1, %eax
jne 0x35b6f6
movq -0x38(%rbp), %rax
movq %rax, -0x40(%rbp)
jmp 0x35b706
jmp 0x35b6f8
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x35b6a1
jmp 0x35b708
cmpq $-0x1, -0x40(%rbp)
je 0x35b719
movq -0x40(%rbp), %rax
cmpq -0x18(%rbp), %rax
jb 0x35b71e
jmp 0x35b9bc
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x18(%rbp), %rax
ja 0x35b9bc
cmpq $-0x1, -0x40(%rbp)
je 0x35b93b
movq 0x18(%rbp), %rcx
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rdx
movq (%rax,%rdx,8), %rdx
xorq $0x1, %rdx
movabsq $-0x8000000000000000, %rax # imm = 0x8000000000000000
andq (%rcx,%rdx,8), %rax
cmpq $0x0, %rax
jne 0x35b929
movq 0x10(%rbp), %rax
movq -0x30(%rbp), %rcx
movq -0x38(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movl (%rax,%rcx,4), %eax
xorl $0x1, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpl $0x1, %eax
jne 0x35b927
movq -0x38(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
cmpq -0x40(%rbp), %rax
jbe 0x35b917
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq -0x48(%rbp), %rcx
movq -0x20(%rbp), %r8
movq -0x28(%rbp), %r9
movq 0x20(%rbp), %r10
movq 0x28(%rbp), %rax
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x35aa50
cmpq 0x28(%rbp), %rax
jae 0x35b917
movq 0x30(%rbp), %rax
cmpq $0x0, (%rax)
jbe 0x35b80b
movq 0x30(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x30(%rbp), %rcx
movq (%rcx), %rcx
subq $0x1, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
jmp 0x35b813
xorl %eax, %eax
movq %rax, -0x58(%rbp)
jmp 0x35b813
movq -0x58(%rbp), %rax
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
je 0x35b860
movq -0x50(%rbp), %rax
movq (%rax), %rax
movl %eax, %eax
cmpq -0x40(%rbp), %rax
jne 0x35b860
movq -0x50(%rbp), %rax
movq (%rax), %rcx
shrq $0x20, %rcx
movq %rcx, (%rax)
movq -0x50(%rbp), %rax
movq (%rax), %rcx
shlq $0x20, %rcx
movq %rcx, (%rax)
movq -0x48(%rbp), %rcx
movq -0x50(%rbp), %rax
orq (%rax), %rcx
movq %rcx, (%rax)
jmp 0x35b915
jmp 0x35b862
movq 0x30(%rbp), %rax
movq (%rax), %rax
movq 0x30(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x35b8ca
movq 0x30(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x35b88f
movq 0x30(%rbp), %rax
movq 0x8(%rax), %rax
shlq %rax
movq %rax, -0x60(%rbp)
jmp 0x35b89a
movl $0x2, %eax
movq %rax, -0x60(%rbp)
jmp 0x35b89a
movq -0x60(%rbp), %rcx
movq 0x30(%rbp), %rax
movq %rcx, 0x8(%rax)
movq 0x30(%rbp), %rax
movq 0x10(%rax), %rdi
movq 0x30(%rbp), %rax
movq 0x8(%rax), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq 0x30(%rbp), %rax
movq %rcx, 0x10(%rax)
movq 0x30(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x30(%rbp), %rdx
movq (%rdx), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, (%rdx)
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x40(%rbp), %rcx
movq -0x50(%rbp), %rax
movq %rcx, (%rax)
movq -0x50(%rbp), %rax
movq (%rax), %rcx
shlq $0x20, %rcx
movq %rcx, (%rax)
movq -0x48(%rbp), %rcx
movq -0x50(%rbp), %rax
orq (%rax), %rcx
movq %rcx, (%rax)
jmp 0x35b917
movq $-0x1, -0x48(%rbp)
movq $-0x1, -0x40(%rbp)
jmp 0x35b939
movq $-0x1, -0x48(%rbp)
movq $-0x1, -0x40(%rbp)
jmp 0x35b93b
movq -0x38(%rbp), %rax
cmpq -0x18(%rbp), %rax
jae 0x35b9a9
movq 0x18(%rbp), %rcx
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rdx
movq (%rax,%rdx,8), %rdx
movabsq $-0x8000000000000000, %rax # imm = 0x8000000000000000
andq (%rcx,%rdx,8), %rax
cmpq $0x0, %rax
je 0x35b97b
movq $-0x1, -0x48(%rbp)
movq $-0x1, -0x40(%rbp)
jmp 0x35b9ab
cmpq $-0x1, -0x40(%rbp)
jne 0x35b9a7
movq 0x10(%rbp), %rax
movq -0x30(%rbp), %rcx
movq -0x38(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movl (%rax,%rcx,4), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpl $0x1, %eax
jne 0x35b9a7
movq -0x38(%rbp), %rax
movq %rax, -0x40(%rbp)
jmp 0x35b9a9
jmp 0x35b9ab
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x35b72a
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)