// File: /workspace/github_cpp_makefile_star2_O3/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 $0x38, %rsp
movq %r9, 0x30(%rsp)
movq %rdx, 0x28(%rsp)
movq %rsi, %r14
movq %rdi, 0x18(%rsp)
movq 0xb0(%rsp), %rax
movl 0x70(%rsp), %edx
movq $0x0, (%rax)
testl %ecx, %ecx
sete %sil
testl %edx, %edx
sete %dl
movq $-0x1, %rax
orb %sil, %dl
jne 0xde2c0
movq %r8, %rbx
movq 0x98(%rsp), %r12
movq 0x90(%rsp), %r10
movq 0x80(%rsp), %r11
movl %ecx, %r13d
xorl %eax, %eax
movl (%r14,%rax,4), %edx
cmpb $0x0, (%r12,%rdx)
jne 0xde2cf
movb $0x1, (%r12,%rdx)
incq %rax
cmpq %rax, %r13
jne 0xde0b3
movl (%r14), %eax
movl %eax, 0x14(%rsp)
movl 0x70(%rsp), %eax
movl %eax, %r15d
xorl %eax, %eax
movl (%rbx,%rax,4), %edx
cmpb $0x0, (%r12,%rdx)
jne 0xde2ee
movb $0x2, (%r12,%rdx)
incq %rax
cmpq %rax, %r15
jne 0xde0df
movl %ecx, 0xc(%rsp)
movl 0x70(%rsp), %eax
decl %eax
movl (%rbx,%rax,4), %eax
movl %eax, 0x10(%rsp)
xorl %ebp, %ebp
movq 0x78(%rsp), %rax
movq %rbp, (%rax)
movq %rbp, (%r11)
leaq (%r14,%r13,4), %rdx
movq %rdx, 0x20(%rsp)
movq %rbp, %rax
notq %rax
movl (%rdx,%rax,4), %esi
cmpb $0x1, (%r12,%rsi)
jne 0xde25a
subq $0x8, %rsp
movl $0x1, %r8d
movl $0x2, %r9d
movq 0x20(%rsp), %rdi
movl 0x1c(%rsp), %edx
movl 0x18(%rsp), %ecx
movq 0xb0(%rsp), %rax
pushq %rax
pushq %r12
pushq %r10
pushq %r11
pushq 0xa0(%rsp)
callq 0xdd07a
addq $0x30, %rsp
movq %rax, %rcx
movq $-0x1, %rax
cmpq $-0x1, %rcx
je 0xde26f
movq 0xa8(%rsp), %rdx
cmpq %rdx, %rcx
movq 0x90(%rsp), %r10
movq 0x80(%rsp), %r11
ja 0xde27f
subq $0x8, %rsp
movq 0x20(%rsp), %rdi
movq %rdx, %rax
movq %r14, %rsi
movq 0x30(%rsp), %rdx
movl 0x14(%rsp), %ecx
movq %rbx, %r8
movq 0x38(%rsp), %r9
pushq 0xb8(%rsp)
pushq %rax
pushq $0x2
pushq $0x1
pushq 0xc8(%rsp)
pushq %r12
pushq %r10
pushq %r11
pushq 0xc0(%rsp)
pushq 0xd8(%rsp)
movl 0xc8(%rsp), %eax
pushq %rax
callq 0xddd33
addq $0x60, %rsp
cmpq $-0x1, %rax
jne 0xde26f
xorl %eax, %eax
movl (%r14,%rax,4), %ecx
movb $0x1, (%r12,%rcx)
incq %rax
cmpq %rax, %r13
jne 0xde206
xorl %eax, %eax
movq 0x90(%rsp), %r10
movq 0x80(%rsp), %r11
movq 0x20(%rsp), %rdx
movl (%rbx,%rax,4), %ecx
movb $0x2, (%r12,%rcx)
incq %rax
cmpq %rax, %r15
jne 0xde22e
cmpq $0x0, (%r11)
je 0xde25a
xorl %eax, %eax
movq 0x10(%r11), %rcx
movl (%rcx,%rax,4), %ecx
movb $0x0, (%r10,%rcx)
incq %rax
cmpq (%r11), %rax
jb 0xde246
incq %rbp
cmpq %r13, %rbp
jne 0xde121
movq $-0x1, %rax
jmp 0xde27f
movq 0x90(%rsp), %r10
movq 0x80(%rsp), %r11
xorl %ecx, %ecx
movl (%r14,%rcx,4), %edx
movb $0x0, (%r12,%rdx)
incq %rcx
cmpq %rcx, %r13
jne 0xde281
xorl %ecx, %ecx
movl (%rbx,%rcx,4), %edx
movb $0x0, (%r12,%rdx)
incq %rcx
cmpq %rcx, %r15
jne 0xde294
cmpq $0x0, (%r11)
je 0xde2c0
xorl %ecx, %ecx
movq 0x10(%r11), %rdx
movl (%rdx,%rcx,4), %edx
movb $0x0, (%r10,%rdx)
incq %rcx
cmpq (%r11), %rcx
jb 0xde2ac
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1596c0(%rip), %rdi    # 0x237996
leaq 0x157bb4(%rip), %rsi    # 0x235e91
leaq 0x1596be(%rip), %rcx    # 0x2379a2
movl $0x57df, %edx           # imm = 0x57DF
callq 0x2110
leaq 0x159775(%rip), %rdi    # 0x237a6a
leaq 0x157b95(%rip), %rsi    # 0x235e91
leaq 0x15969f(%rip), %rcx    # 0x2379a2
movl $0x57e4, %edx           # imm = 0x57E4
callq 0x2110