// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/Overlaps.cpp
// Function: cal_self_close_tang_flank1(asg_t*, unsigned int, unsigned int, asg32_v*, asg32_v*, unsigned char*, unsigned char*, unsigned long)
uint64_t cal_self_close_tang_flank1(asg_t *g, uint32_t s0, uint32_t e0, asg32_v *b1, asg32_v *b2, uint8_t *f, uint8_t *fsk, uint64_t max_path)
{
    uint64_t se = 0, k, v, o, o0, o1, nv, tot = 0; asg_arc_t *av;
        
    b1->n = b2->n = 0; kv_push(uint32_t, *b1, s0);
    while(b1->n) {
        v = b1->a[--b1->n];
        if(f[v] && f[v^1]) continue;

        v = v; 
        if((!f[v]) && (v!=(s0^1)) && (v!=e0)) {
            f[v] = 1; kv_push(uint32_t, *b2, v);
            av = asg_arc_a(g, v); nv = asg_arc_n(g, v); 
            for (k = 0; k < nv; k++) {
                if(av[k].del) continue;
                if((av[k].v == s0) || (av[k].v == (e0^1))) {
                    se = 1; break;
                }
                if((!f[av[k].v])) kv_push(uint32_t, *b1, av[k].v);
            }
            if(se) break;
        }

        v = v^1; 
        if((!f[v]) && (v!=(s0^1)) && (v!=e0)) {
            f[v] = 1; kv_push(uint32_t, *b2, v);
            av = asg_arc_a(g, v); nv = asg_arc_n(g, v); 
            for (k = 0; k < nv; k++) {
                if(av[k].del) continue;
                if((av[k].v == s0) || (av[k].v == (e0^1))) {
                    se = 1; break;
                }
                if((!f[av[k].v])) kv_push(uint32_t, *b1, av[k].v);
            }
            if(se) break;
        }

        if(f[v] && f[v^1] && (!fsk[v>>1])) {
            av = asg_arc_a(g, v); nv = asg_arc_n(g, v); 
            for (k = o = 0; k < nv; k++) {
                if(av[k].del) continue;
                if((f[av[k].v^1]) && (f[av[k].v]) && (!fsk[av[k].v>>1]) && (o < av[k].ol)) o = av[k].ol;
            }
            o0 = o;

            av = asg_arc_a(g, (v^1)); nv = asg_arc_n(g, (v^1)); 
            for (k = o = 0; k < nv; k++) {
                if(av[k].del) continue;
                if((f[av[k].v^1]) && (f[av[k].v]) && (!fsk[av[k].v>>1]) && (o < av[k].ol)) o = av[k].ol;
            }
            o1 = o;

            if(o0 + o1 < g->seq[v>>1].len) tot += g->seq[v>>1].len - o0 - o1;
        }

        if(tot > max_path) break;
    }

    if((!se) && (tot <= max_path)) return tot;
    return (uint64_t)-1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r9, %rbx
movq %rcx, %r15
movl %edx, %r9d
movl %esi, %ebp
movq %rdi, 0x18(%rsp)
xorl %eax, %eax
movq %r8, 0x20(%rsp)
movq %rax, (%r8)
movq %rax, (%rcx)
cmpq %rax, 0x8(%rcx)
movl %edx, 0x8(%rsp)
jne 0xdc4a5
movq $0x2, 0x8(%r15)
movq 0x10(%r15), %rdi
movl $0x8, %esi
callq 0x2370
movl 0x8(%rsp), %r9d
movq %rax, 0x10(%r15)
movq 0x88(%rsp), %r13
movq (%r15), %rax
movq 0x10(%r15), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%r15)
movl %ebp, (%rcx,%rax,4)
movl %ebp, %eax
xorl $0x1, %eax
movq %rax, 0x38(%rsp)
movl %r9d, %eax
movq %rax, 0x40(%rsp)
xorl %eax, %eax
movl %ebp, %edi
movl %ebp, 0xc(%rsp)
movq (%r15), %rsi
decq %rsi
cmpq $-0x1, %rsi
je 0xdc923
movq 0x10(%r15), %rcx
movq %rsi, (%r15)
movl (%rcx,%rsi,4), %r12d
movb (%rbx,%r12), %cl
testb %cl, %cl
je 0xdc50b
movq %r12, %rdx
xorq $0x1, %rdx
decq %rsi
cmpb $0x0, (%rbx,%rdx)
jne 0xdc4de
movq %rax, 0x10(%rsp)
cmpl %r9d, %r12d
je 0xdc648
testb %cl, %cl
jne 0xdc648
movl %r12d, %eax
xorl %edi, %eax
cmpl $0x1, %eax
je 0xdc648
movb $0x1, (%rbx,%r12)
movq 0x20(%rsp), %r14
movq 0x8(%r14), %rax
cmpq %rax, (%r14)
jne 0xdc570
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r14)
movq 0x10(%r14), %rdi
shlq $0x2, %rsi
callq 0x2370
movl 0xc(%rsp), %edi
movl 0x8(%rsp), %r9d
movq %rax, 0x10(%r14)
movq (%r14), %rax
movq 0x10(%r14), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%r14)
movl %r12d, (%rcx,%rax,4)
movq 0x18(%rsp), %rax
movq 0x28(%rax), %rax
movq (%rax,%r12,8), %rax
movq %rax, %rcx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
andq %rdx, %rcx
je 0xdc648
movq 0x18(%rsp), %rdx
movq 0x8(%rdx), %rdx
shrq $0x20, %rax
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %r14
leaq (%rax,%rax,2), %rax
leaq (%rdx,%rax,8), %r13
addq $0x8, %r13
xorl %ebp, %ebp
cmpl $0x0, 0x4(%r13,%rbp)
js 0xdc63b
movl (%r13,%rbp), %eax
movb $0x1, %cl
cmpl %edi, %eax
je 0xdc948
movl %eax, %edx
xorl %r9d, %edx
cmpl $0x1, %edx
je 0xdc948
cmpb $0x0, (%rbx,%rax)
jne 0xdc63b
movq 0x8(%r15), %rax
cmpq %rax, (%r15)
jne 0xdc625
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r15)
movq 0x10(%r15), %rdi
shlq $0x2, %rsi
callq 0x2370
movl 0xc(%rsp), %edi
movl 0x8(%rsp), %r9d
movq %rax, 0x10(%r15)
movl (%r13,%rbp), %eax
movq (%r15), %rcx
movq 0x10(%r15), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, (%r15)
movl %eax, (%rdx,%rcx,4)
addq $0x18, %rbp
cmpq %rbp, %r14
jne 0xdc5c3
movq %r12, %rbp
xorq $0x1, %rbp
cmpq 0x40(%rsp), %rbp
je 0xdc7ae
cmpl 0x38(%rsp), %ebp
je 0xdc7ae
cmpb $0x0, (%rbx,%rbp)
jne 0xdc7ae
movb $0x1, (%rbx,%rbp)
movq 0x20(%rsp), %r14
movq 0x8(%r14), %rax
cmpq %rax, (%r14)
jne 0xdc6ae
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r14)
movq 0x10(%r14), %rdi
shlq $0x2, %rsi
callq 0x2370
movl 0xc(%rsp), %edi
movl 0x8(%rsp), %r9d
movq %rax, 0x10(%r14)
movq (%r14), %rax
movq 0x10(%r14), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%r14)
movl %ebp, (%rcx,%rax,4)
movq 0x18(%rsp), %rdx
movq 0x28(%rdx), %rax
movq %rbp, 0x28(%rsp)
movq (%rax,%rbp,8), %rcx
movq %rcx, %rbp
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
andq %rax, %rbp
setne %al
je 0xdc79f
movq 0x8(%rdx), %rdx
shrq $0x20, %rcx
movq %rbp, %r8
negq %r8
leaq (%rcx,%rcx,2), %rcx
leaq (%rdx,%rcx,8), %r14
addq $0x8, %r14
movl $0x1, %r13d
movq %r8, 0x30(%rsp)
cmpl $0x0, 0x4(%r14)
js 0xdc781
movl (%r14), %edx
movl $0x1, %ecx
cmpl %edi, %edx
je 0xdc7a1
movl %edx, %esi
xorl %r9d, %esi
cmpl $0x1, %esi
je 0xdc7a1
cmpb $0x0, (%rbx,%rdx)
jne 0xdc781
movq 0x8(%r15), %rax
cmpq %rax, (%r15)
jne 0xdc76d
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r15)
movq 0x10(%r15), %rdi
shlq $0x2, %rsi
callq 0x2370
movq 0x30(%rsp), %r8
movl 0xc(%rsp), %edi
movl 0x8(%rsp), %r9d
movq %rax, 0x10(%r15)
movl (%r14), %eax
movq (%r15), %rcx
movq 0x10(%r15), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, (%r15)
movl %eax, (%rdx,%rcx,4)
cmpq %rbp, %r13
setb %al
leaq (%r8,%r13), %rcx
incq %rcx
incq %r13
addq $0x18, %r14
cmpq $0x1, %rcx
jne 0xdc70a
xorl %ecx, %ecx
testb $0x1, %al
movq 0x28(%rsp), %rbp
jne 0xdc948
cmpb $0x0, (%rbx,%rbp)
movq 0x88(%rsp), %r13
je 0xdc86d
cmpb $0x0, (%rbx,%r12)
movq 0x10(%rsp), %rax
je 0xdc91a
movq %rbp, %r8
movl %r12d, %ebp
shrl %ebp
movq 0x80(%rsp), %rcx
cmpb $0x0, (%rcx,%rbp)
jne 0xdc91a
movq 0x18(%rsp), %rcx
movq 0x8(%rcx), %rdx
movq 0x28(%rcx), %rsi
movq (%rsi,%r8,8), %rcx
movq %rcx, %rdi
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
andq %r8, %rdi
je 0xdc877
shrq $0x20, %rcx
shlq $0x3, %rdi
leaq (%rdi,%rdi,2), %rdi
leaq (%rcx,%rcx,2), %rcx
leaq (%rdx,%rcx,8), %r8
addq $0xc, %r8
xorl %r9d, %r9d
xorl %ecx, %ecx
movslq (%r8,%r9), %r10
testq %r10, %r10
js 0xdc862
movl -0x4(%r8,%r9), %r11d
movq %r11, %r14
xorq $0x1, %r14
cmpb $0x0, (%rbx,%r14)
je 0xdc862
cmpb $0x0, (%rbx,%r11)
je 0xdc862
shrl %r11d
movq 0x80(%rsp), %r14
cmpb $0x0, (%r14,%r11)
jne 0xdc862
cmpq %r10, %rcx
cmovbeq %r10, %rcx
addq $0x18, %r9
cmpq %r9, %rdi
jne 0xdc826
jmp 0xdc879
movq 0x10(%rsp), %rax
jmp 0xdc91a
xorl %ecx, %ecx
movq (%rsi,%r12,8), %rdi
movq %rdi, %rsi
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
andq %r8, %rsi
je 0xdc8ef
shrq $0x20, %rdi
shlq $0x3, %rsi
leaq (%rsi,%rsi,2), %rsi
leaq (%rdi,%rdi,2), %rdi
leaq (%rdx,%rdi,8), %rdi
addq $0xc, %rdi
xorl %r8d, %r8d
xorl %edx, %edx
movslq (%rdi,%r8), %r9
testq %r9, %r9
js 0xdc8e4
movl -0x4(%rdi,%r8), %r10d
movq %r10, %r11
xorq $0x1, %r11
cmpb $0x0, (%rbx,%r11)
je 0xdc8e4
cmpb $0x0, (%rbx,%r10)
je 0xdc8e4
shrl %r10d
movq 0x80(%rsp), %r11
cmpb $0x0, (%r11,%r10)
jne 0xdc8e4
cmpq %r9, %rdx
cmovbeq %r9, %rdx
addq $0x18, %r8
cmpq %r8, %rsi
jne 0xdc8a8
jmp 0xdc8f1
xorl %edx, %edx
addq %rcx, %rdx
movq 0x18(%rsp), %rcx
movq 0x20(%rcx), %rcx
movl (%rcx,%rbp,8), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpq %rcx, %rdx
jae 0xdc911
subq %rdx, %rax
addq %rcx, %rax
movl 0x8(%rsp), %r9d
movl 0xc(%rsp), %edi
cmpq %r13, %rax
jbe 0xdc4d8
xorl %ecx, %ecx
cmpq %r13, %rax
movq $-0x1, %rdx
cmovaq %rdx, %rax
testb %cl, %cl
cmovneq %rdx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x88(%rsp), %r13
movq 0x10(%rsp), %rax
jmp 0xdc925