// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Overlaps.cpp
// Function: trace_back_tangle_dis(asg_t*, unsigned int*, unsigned int*, unsigned int, unsigned int*, unsigned int*, unsigned int, asg32_v*, asg32_v*, asg32_v*, unsigned char*, unsigned char*, unsigned char*, unsigned long, unsigned long, unsigned long, unsigned long*)
uint64_t trace_back_tangle_dis(asg_t *g, uint32_t *s, uint32_t *sd, uint32_t sn, uint32_t *e, uint32_t *ed, uint32_t en, asg32_v *b, asg32_v *b1, asg32_v *b2, uint8_t *f, uint8_t *fs, uint8_t *fsk, uint64_t sf, uint64_t ef, uint64_t max_path, uint64_t *is_dip)
{
    uint64_t k, sk, sm, ek, em, s0, slen, e0, elen, tot; b->n = 0; (*is_dip) = 0;
    for (sk = sm = 0; sk < sn; sk++) {
        if((fs[s[sn-sk-1]] == sf) && (f[s[sn-sk-1]]) && (!f[s[sn-sk-1]^1])) {///a potiential 
            kv_push(uint32_t, *b, sn-sk-1); sm++;
        }
    }
    if(!sm) return ((uint64_t)-1);

    for (ek = em = 0; ek < en; ek++) {
        if((fs[e[ek]] == ef) && (!f[e[ek]]) && (f[e[ek]^1])) {///a potiential 
            kv_push(uint32_t, *b, ek); em++;
        }
    }
    if(!em) return ((uint64_t)-1);

    uint32_t *si = b->a, *ei = b->a + sm;
    for (sk = 0; sk < sm; sk++) {
        s0 = s[si[sk]]; slen = sd[si[sk]];
        for (ek = 0; ek < em; ek++) {
            e0 = e[ei[ek]]; elen = ed[ei[ek]];   
            for (k = 0; k < b2->n; k++) f[b2->a[k]] = 0;
            
            tot = cal_self_close_tang_flank1(g, s0, e0, b1, b2, f, fsk, max_path + slen + elen);
            if((tot != ((uint64_t)-1)) && (tot <= (max_path + slen + elen))) {
                if(fsk[s0>>1] && fsk[e0>>1]) {
                    (*is_dip) = 1;
                    return 0;
                } else {
                    return ((tot>=(slen + elen))?(tot-(slen + elen)):(0));
                }
            }
        }
    }
    return ((uint64_t)-1);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %r9, 0x60(%rsp)
movq %r8, %r12
movq %rdx, 0x38(%rsp)
movq %rdi, 0x58(%rsp)
movq 0xf0(%rsp), %rax
movq 0xe0(%rsp), %r8
movq 0xd8(%rsp), %r13
movq 0xc8(%rsp), %rbx
movq 0xc0(%rsp), %rbp
movq 0xb8(%rsp), %r15
movq 0xa8(%rsp), %r9
andq $0x0, (%r9)
andq $0x0, (%rax)
movl %ecx, %r14d
movq $0x0, (%rsp)
movq %rsi, 0x10(%rsp)
testq %r14, %r14
je 0xa054d
movl -0x4(%rsi,%r14,4), %eax
movzbl (%rbx,%rax), %ecx
cmpq %r13, %rcx
jne 0xa0545
cmpb $0x0, (%rbp,%rax)
je 0xa0545
xorq $0x1, %rax
cmpb $0x0, (%rbp,%rax)
jne 0xa0545
movq (%r9), %rcx
movq 0x10(%r9), %rax
cmpq 0x8(%r9), %rcx
jne 0xa0533
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r9)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq 0xa8(%rsp), %r9
movq 0xe0(%rsp), %r8
movq 0x10(%rsp), %rsi
movq %rax, 0x10(%r9)
movq (%r9), %rcx
leal -0x1(%r14), %edx
leaq 0x1(%rcx), %rdi
movq %rdi, (%r9)
movl %edx, (%rax,%rcx,4)
incq (%rsp)
decq %r14
jmp 0xa04c3
cmpq $0x0, (%rsp)
je 0xa06f3
movl 0xa0(%rsp), %r14d
movq $0x0, 0x8(%rsp)
xorl %r13d, %r13d
cmpq %r13, %r14
je 0xa05ec
movl (%r12,%r13,4), %eax
movzbl (%rbx,%rax), %ecx
cmpq %r8, %rcx
jne 0xa05e7
cmpb $0x0, (%rbp,%rax)
jne 0xa05e7
xorq $0x1, %rax
cmpb $0x0, (%rbp,%rax)
je 0xa05e7
movq (%r9), %rcx
movq 0x10(%r9), %rax
cmpq 0x8(%r9), %rcx
jne 0xa05d7
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r9)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq 0xa8(%rsp), %r9
movq 0xe0(%rsp), %r8
movq 0x10(%rsp), %rsi
movq %rax, 0x10(%r9)
movq (%r9), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%r9)
movl %r13d, (%rax,%rcx,4)
incq 0x8(%rsp)
incq %r13
jmp 0xa056c
cmpq $0x0, 0x8(%rsp)
je 0xa06f3
movq 0x10(%r9), %rcx
movq (%rsp), %rax
leaq (%rcx,%rax,4), %rdx
movq %rdx, 0x40(%rsp)
xorl %edx, %edx
movq %r12, 0x48(%rsp)
movq %rcx, 0x20(%rsp)
cmpq %rax, %rdx
je 0xa06f3
movq %rdx, 0x30(%rsp)
movl (%rcx,%rdx,4), %eax
movl (%rsi,%rax,4), %ecx
movq %rcx, 0x18(%rsp)
movq 0x38(%rsp), %rcx
movl (%rcx,%rax,4), %ecx
movq 0xe8(%rsp), %rax
movq %rcx, 0x28(%rsp)
addq %rcx, %rax
movq %rax, 0x50(%rsp)
xorl %ebx, %ebx
cmpq 0x8(%rsp), %rbx
je 0xa06dd
movq 0x40(%rsp), %rax
movl (%rax,%rbx,4), %eax
movq 0x48(%rsp), %rcx
movl (%rcx,%rax,4), %r13d
movq 0x60(%rsp), %rcx
movl (%rcx,%rax,4), %r12d
xorl %eax, %eax
cmpq (%r15), %rax
jae 0xa068a
movq 0x10(%r15), %rcx
movl (%rcx,%rax,4), %ecx
movb $0x0, (%rbp,%rcx)
incq %rax
jmp 0xa0674
movq 0x50(%rsp), %rax
leaq (%rax,%r12), %r14
movq 0x58(%rsp), %rdi
movq 0x18(%rsp), %rsi
movl %r13d, %edx
movq 0xb0(%rsp), %rcx
movq %r15, %r8
movq %rbp, %r9
pushq %r14
pushq 0xd8(%rsp)
callq 0x9ffe0
movq 0x20(%rsp), %rsi
addq $0x10, %rsp
incq %rbx
cmpq $-0x1, %rax
je 0xa064d
cmpq %r14, %rax
ja 0xa064d
jmp 0xa06f8
movq 0x30(%rsp), %rdx
incq %rdx
movq (%rsp), %rax
movq 0x20(%rsp), %rcx
jmp 0xa0615
pushq $-0x1
popq %rax
jmp 0xa073b
movq 0x18(%rsp), %rdx
shrl %edx
movq 0xd0(%rsp), %rcx
cmpb $0x0, (%rcx,%rdx)
je 0xa072a
shrl %r13d
cmpb $0x0, (%rcx,%r13)
je 0xa072a
movq 0xf0(%rsp), %rax
movq $0x1, (%rax)
xorl %eax, %eax
jmp 0xa073b
addq 0x28(%rsp), %r12
xorl %ecx, %ecx
subq %r12, %rax
cmovaeq %rax, %rcx
movq %rcx, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq