// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Overlaps.cpp
// Function: cal_self_close_tang_flank(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*)
uint64_t cal_self_close_tang_flank(asg_t *g, uint32_t *s, uint32_t *sd, uint32_t sn, uint32_t *e, uint32_t *ed, uint32_t en, asg32_v *b1, asg32_v *b2, asg32_v *b3, uint8_t *f, uint8_t *fs, uint8_t *fsk, uint64_t max_path, uint64_t *is_dip)
{
    (*is_dip) = 0;
    if((!sn) || (!en)) return (uint64_t)-1;

    uint64_t z, k, tot, sf = 1, ef = 2, s0, e0; 
    for (k = 0; k < sn; k++) {
        assert(!(fs[s[k]])); fs[s[k]] = sf;
    }
    s0 = s[0];

    for (k = 0; k < en; k++) {
        assert(!(fs[e[k]])); fs[e[k]] = ef;
    }
    e0 = e[en-1];

    b1->n = 0; b2->n = 0; tot = ((uint64_t)-1);
    for (k = 0; k < sn; k++) {
        if(fs[s[sn-k-1]] != sf) continue;
        tot = cal_self_close_tang_flank0(g, s[sn-k-1], s0, e0, sf, ef, b1, b2, f, fs, max_path); 
        if((tot == ((uint64_t)-1)) || (tot > max_path)) {
            tot = ((uint64_t)-1); break;
        } else {
            tot = trace_back_tangle_dis(g, s, sd, sn, e, ed, en, b3, b1, b2, f, fs, fsk, sf, ef, max_path, is_dip);
            if(tot != ((uint64_t)-1)) break;
        }

        ///reset s && e
        for (z = 0; z < sn; z++) fs[s[z]] = sf;
        for (z = 0; z < en; z++) fs[e[z]] = ef;
        for (z = 0; z < b2->n; z++) f[b2->a[z]] = 0;
    }

    for (k = 0; k < sn; k++) fs[s[k]] = 0;
    for (k = 0; k < en; k++) fs[e[k]] = 0;
    for (k = 0; k < b2->n; k++) f[b2->a[k]] = 0;
    
    return tot;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r9, 0x38(%rsp)
movq %rdx, 0x30(%rsp)
movq %rdi, 0x20(%rsp)
movq 0xc0(%rsp), %rax
movl 0x80(%rsp), %edx
andq $0x0, (%rax)
testl %ecx, %ecx
sete %al
testl %edx, %edx
sete %dl
orb %al, %dl
jne 0xa07d1
movq %r8, %rbx
movq %rsi, %r14
movq 0xb8(%rsp), %r11
movq 0xa8(%rsp), %r12
movq 0xa0(%rsp), %r10
movq 0x90(%rsp), %rbp
movl %ecx, %r13d
xorl %eax, %eax
cmpq %rax, %r13
je 0xa07d9
movl (%r14,%rax,4), %edx
cmpb $0x0, (%r12,%rdx)
jne 0xa09e9
movb $0x1, (%r12,%rdx)
incq %rax
jmp 0xa07b3
pushq $-0x1
popq %rax
jmp 0xa09da
movl %ecx, 0xc(%rsp)
movl (%r14), %eax
movl %eax, 0x14(%rsp)
movl 0x80(%rsp), %eax
movl %eax, %r15d
xorl %eax, %eax
cmpq %rax, %r15
je 0xa080d
movl (%rbx,%rax,4), %ecx
cmpb $0x0, (%r12,%rcx)
jne 0xa0a08
movb $0x2, (%r12,%rcx)
incq %rax
jmp 0xa07f0
movl 0x80(%rsp), %eax
decl %eax
movl (%rbx,%rax,4), %eax
movl %eax, 0x10(%rsp)
movq 0x88(%rsp), %rax
andq $0x0, (%rax)
andq $0x0, (%rbp)
leaq (%r14,%r13,4), %rdx
xorl %edi, %edi
pushq $-0x1
popq %rax
movq %rax, 0x18(%rsp)
movq %rdx, 0x28(%rsp)
cmpq %r13, %rdi
je 0xa0993
movq %rdi, %rax
notq %rax
movl (%rdx,%rax,4), %esi
cmpb $0x1, (%r12,%rsi)
jne 0xa096c
movq %rdi, 0x40(%rsp)
subq $0x8, %rsp
movq 0x28(%rsp), %rdi
movl 0x1c(%rsp), %edx
movl 0x18(%rsp), %ecx
pushq $0x1
popq %r8
pushq $0x2
popq %r9
pushq %r11
pushq %r12
pushq %r10
pushq %rbp
pushq 0xb0(%rsp)
movq %r11, %rbp
callq 0x9f91d
addq $0x30, %rsp
cmpq $-0x1, %rax
je 0xa0974
cmpq %rbp, %rax
ja 0xa0974
subq $0x8, %rsp
movq 0x28(%rsp), %rdi
movq %r14, %rsi
movq 0x38(%rsp), %rdx
movl 0x14(%rsp), %ecx
movq %rbx, %r8
movq 0x40(%rsp), %r9
pushq 0xc8(%rsp)
pushq %rbp
pushq $0x2
pushq $0x1
pushq 0xd8(%rsp)
pushq %r12
pushq 0xd8(%rsp)
movq 0xd0(%rsp), %rbp
pushq %rbp
pushq 0xd0(%rsp)
pushq 0xe8(%rsp)
movl 0xd8(%rsp), %eax
pushq %rax
callq 0xa0453
addq $0x60, %rsp
cmpq $-0x1, %rax
jne 0xa0986
xorl %eax, %eax
movq 0xa0(%rsp), %r10
movq 0xb8(%rsp), %r11
movq 0x28(%rsp), %rdx
movq 0x40(%rsp), %rdi
cmpq %rax, %r13
je 0xa093f
movl (%r14,%rax,4), %ecx
movb $0x1, (%r12,%rcx)
incq %rax
jmp 0xa092c
xorl %eax, %eax
cmpq %rax, %r15
je 0xa0953
movl (%rbx,%rax,4), %ecx
movb $0x2, (%r12,%rcx)
incq %rax
jmp 0xa0941
xorl %eax, %eax
cmpq (%rbp), %rax
jae 0xa096c
movq 0x10(%rbp), %rcx
movl (%rcx,%rax,4), %ecx
movb $0x0, (%r10,%rcx)
incq %rax
jmp 0xa0955
incq %rdi
jmp 0xa0841
movq 0xa0(%rsp), %r10
movq 0x90(%rsp), %rbp
jmp 0xa0993
movq %rax, 0x18(%rsp)
movq 0xa0(%rsp), %r10
xorl %eax, %eax
cmpq %rax, %r13
je 0xa09a8
movl (%r14,%rax,4), %ecx
movb $0x0, (%r12,%rcx)
incq %rax
jmp 0xa0995
xorl %eax, %eax
cmpq %rax, %r15
je 0xa09bc
movl (%rbx,%rax,4), %ecx
movb $0x0, (%r12,%rcx)
incq %rax
jmp 0xa09aa
xorl %eax, %eax
cmpq (%rbp), %rax
jae 0xa09d5
movq 0x10(%rbp), %rcx
movl (%rcx,%rax,4), %ecx
movb $0x0, (%r10,%rcx)
incq %rax
jmp 0xa09be
movq 0x18(%rsp), %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x148ea6(%rip), %rdi    # 0x1e9896
leaq 0x14739a(%rip), %rsi    # 0x1e7d91
leaq 0x148ea4(%rip), %rcx    # 0x1e98a2
movl $0x57df, %edx           # imm = 0x57DF
callq 0x2110
leaq 0x148f5b(%rip), %rdi    # 0x1e996a
leaq 0x14737b(%rip), %rsi    # 0x1e7d91
leaq 0x148e85(%rip), %rcx    # 0x1e98a2
movl $0x57e4, %edx           # imm = 0x57E4
callq 0x2110