// File: /workspace/github_cpp_makefile_star2_O3/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 %rdi, 0x58(%rsp)
movq 0xf0(%rsp), %rdi
movq 0xa8(%rsp), %r13
xorl %eax, %eax
movq %rax, (%r13)
movq %rax, (%rdi)
movq $-0x1, %rax
testl %ecx, %ecx
je 0xddff3
movq %rdx, 0x40(%rsp)
movq 0xe0(%rsp), %rbp
movq 0xd8(%rsp), %r15
movq 0xc8(%rsp), %r10
movq 0xc0(%rsp), %r12
movq 0xb8(%rsp), %rbx
movl %ecx, %r14d
xorl %r9d, %r9d
movq %r8, 0x10(%rsp)
movq %rsi, (%rsp)
movl -0x4(%rsi,%r14,4), %eax
movzbl (%r10,%rax), %ecx
cmpq %r15, %rcx
jne 0xdde3d
cmpb $0x0, (%r12,%rax)
je 0xdde3d
xorq $0x1, %rax
cmpb $0x0, (%r12,%rax)
jne 0xdde3d
movq (%r13), %rcx
movq 0x10(%r13), %rax
cmpq 0x8(%r13), %rcx
jne 0xdde2b
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r13)
shlq $0x2, %rsi
movq %rax, %rdi
movq %r9, %r13
movq %r10, %rbp
callq 0x2370
movq %rbp, %r10
movq %r13, %r9
movq 0xa8(%rsp), %r13
movq 0xe0(%rsp), %rbp
movq (%rsp), %rsi
movq 0x10(%rsp), %r8
movq %rax, 0x10(%r13)
movq (%r13), %rcx
leal -0x1(%r14), %edx
leaq 0x1(%rcx), %rdi
movq %rdi, (%r13)
movl %edx, (%rax,%rcx,4)
incq %r9
decq %r14
jne 0xdddaf
testq %r9, %r9
je 0xddfec
movl 0xa0(%rsp), %eax
testl %eax, %eax
je 0xddfec
movl %eax, %r14d
xorl %r15d, %r15d
movq $0x0, 0x8(%rsp)
movq %r9, 0x18(%rsp)
movl (%r8,%r15,4), %eax
movzbl (%r10,%rax), %ecx
cmpq %rbp, %rcx
jne 0xddeef
cmpb $0x0, (%r12,%rax)
jne 0xddeef
xorq $0x1, %rax
cmpb $0x0, (%r12,%rax)
je 0xddeef
movq (%r13), %rcx
movq 0x10(%r13), %rax
cmpq 0x8(%r13), %rcx
jne 0xddede
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r13)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq 0xc8(%rsp), %r10
movq 0x18(%rsp), %r9
movq (%rsp), %rsi
movq 0x10(%rsp), %r8
movq %rax, 0x10(%r13)
movq (%r13), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%r13)
movl %r15d, (%rax,%rcx,4)
incq 0x8(%rsp)
incq %r15
cmpq %r15, %r14
jne 0xdde72
cmpq $0x0, 0x8(%rsp)
je 0xddfec
movq 0x10(%r13), %rax
leaq (%rax,%r9,4), %rcx
movq %rcx, 0x48(%rsp)
xorl %ecx, %ecx
movq %rax, 0x28(%rsp)
movq %rcx, 0x38(%rsp)
movl (%rax,%rcx,4), %eax
movl (%rsi,%rax,4), %ecx
movq %rcx, 0x20(%rsp)
movq 0x40(%rsp), %rcx
movl (%rcx,%rax,4), %ecx
movq 0xe8(%rsp), %rax
movq %rcx, 0x30(%rsp)
addq %rcx, %rax
movq %rax, 0x50(%rsp)
xorl %r14d, %r14d
movq 0x48(%rsp), %rax
movl (%rax,%r14,4), %eax
movl (%r8,%rax,4), %ebp
movq 0x60(%rsp), %rcx
movl (%rcx,%rax,4), %r15d
cmpq $0x0, (%rbx)
je 0xddf7d
xorl %eax, %eax
movq 0x10(%rbx), %rcx
movl (%rcx,%rax,4), %ecx
movb $0x0, (%r12,%rcx)
incq %rax
cmpq (%rbx), %rax
jb 0xddf69
movq 0x50(%rsp), %rax
leaq (%rax,%r15), %r13
movq 0x58(%rsp), %rdi
movq 0x20(%rsp), %rsi
movl %ebp, %edx
movq 0xb0(%rsp), %rcx
movq %rbx, %r8
movq %r12, %r9
pushq %r13
pushq 0xd8(%rsp)
callq 0xdd827
addq $0x10, %rsp
cmpq $-0x1, %rax
je 0xddfbd
cmpq %r13, %rax
jbe 0xde002
incq %r14
cmpq 0x8(%rsp), %r14
movq 0x10(%rsp), %r8
jne 0xddf4b
movq 0x38(%rsp), %rcx
incq %rcx
cmpq 0x18(%rsp), %rcx
movq (%rsp), %rsi
movq 0x28(%rsp), %rax
jne 0xddf1b
movq $-0x1, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x20(%rsp), %rdx
shrl %edx
movq 0xd0(%rsp), %rcx
cmpb $0x0, (%rcx,%rdx)
je 0xde032
shrl %ebp
cmpb $0x0, (%rcx,%rbp)
je 0xde032
movq 0xf0(%rsp), %rax
movq $0x1, (%rax)
xorl %eax, %eax
jmp 0xddff3
addq 0x30(%rsp), %r15
xorl %ecx, %ecx
subq %r15, %rax
cmovaeq %rax, %rcx
movq %rcx, %rax
jmp 0xddff3