// File: 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
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movq 0x50(%rbp), %rax
movq 0x48(%rbp), %rax
movq 0x40(%rbp), %rax
movq 0x38(%rbp), %rax
movq 0x30(%rbp), %rax
movq 0x28(%rbp), %rax
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movl 0x10(%rbp), %eax
movq %rdi, -0x38(%rbp)
movq %rsi, -0x40(%rbp)
movq %rdx, -0x48(%rbp)
movl %ecx, -0x4c(%rbp)
movq %r8, -0x58(%rbp)
movq %r9, -0x60(%rbp)
movq 0x50(%rbp), %rax
movq $0x0, (%rax)
cmpl $0x0, -0x4c(%rbp)
je 0x12c505
cmpl $0x0, 0x10(%rbp)
jne 0x12c512
movq $-0x1, -0x30(%rbp)
jmp 0x12c955
movq $0x1, -0x80(%rbp)
movq $0x2, -0x88(%rbp)
movq $0x0, -0x70(%rbp)
movq -0x70(%rbp), %rax
movl -0x4c(%rbp), %ecx
cmpq %rcx, %rax
jae 0x12c59e
movq 0x38(%rbp), %rax
movq -0x40(%rbp), %rcx
movq -0x70(%rbp), %rdx
movl (%rcx,%rdx,4), %ecx
cmpb $0x0, (%rax,%rcx)
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x12c557
jmp 0x12c559
jmp 0x12c578
leaq 0x25c021(%rip), %rdi    # 0x388581
leaq 0x25a356(%rip), %rsi    # 0x3868bd
movl $0x57df, %edx           # imm = 0x57DF
leaq 0x25c01a(%rip), %rcx    # 0x38858d
callq 0x2130
movq -0x80(%rbp), %rax
movb %al, %dl
movq 0x38(%rbp), %rax
movq -0x40(%rbp), %rcx
movq -0x70(%rbp), %rsi
movl (%rcx,%rsi,4), %ecx
movb %dl, (%rax,%rcx)
movq -0x70(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x70(%rbp)
jmp 0x12c52d
movq -0x40(%rbp), %rax
movl (%rax), %eax
movq %rax, -0x90(%rbp)
movq $0x0, -0x70(%rbp)
movq -0x70(%rbp), %rax
movl 0x10(%rbp), %ecx
cmpq %rcx, %rax
jae 0x12c627
movq 0x38(%rbp), %rax
movq -0x58(%rbp), %rcx
movq -0x70(%rbp), %rdx
movl (%rcx,%rdx,4), %ecx
cmpb $0x0, (%rax,%rcx)
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x12c5dd
jmp 0x12c5df
jmp 0x12c5fe
leaq 0x25c06f(%rip), %rdi    # 0x388655
leaq 0x25a2d0(%rip), %rsi    # 0x3868bd
movl $0x57e4, %edx           # imm = 0x57E4
leaq 0x25bf94(%rip), %rcx    # 0x38858d
callq 0x2130
movq -0x88(%rbp), %rax
movb %al, %dl
movq 0x38(%rbp), %rax
movq -0x58(%rbp), %rcx
movq -0x70(%rbp), %rsi
movl (%rcx,%rsi,4), %ecx
movb %dl, (%rax,%rcx)
movq -0x70(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x70(%rbp)
jmp 0x12c5b3
movq -0x58(%rbp), %rax
movl 0x10(%rbp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
movq %rax, -0x98(%rbp)
movq 0x18(%rbp), %rax
movq $0x0, (%rax)
movq 0x20(%rbp), %rax
movq $0x0, (%rax)
movq $-0x1, -0x78(%rbp)
movq $0x0, -0x70(%rbp)
movq -0x70(%rbp), %rax
movl -0x4c(%rbp), %ecx
cmpq %rcx, %rax
jae 0x12c8a9
movq 0x38(%rbp), %rax
movq -0x40(%rbp), %rcx
movl -0x4c(%rbp), %edx
subq -0x70(%rbp), %rdx
subq $0x1, %rdx
movl (%rcx,%rdx,4), %ecx
movzbl (%rax,%rcx), %eax
cmpq -0x80(%rbp), %rax
je 0x12c698
jmp 0x12c898
movq -0x38(%rbp), %rdi
movq -0x40(%rbp), %rax
movl -0x4c(%rbp), %ecx
subq -0x70(%rbp), %rcx
subq $0x1, %rcx
movl (%rax,%rcx,4), %esi
movq -0x90(%rbp), %rax
movl %eax, %edx
movq -0x98(%rbp), %rax
movl %eax, %ecx
movq -0x80(%rbp), %r8
movq -0x88(%rbp), %r9
movq 0x18(%rbp), %r14
movq 0x20(%rbp), %rbx
movq 0x30(%rbp), %r11
movq 0x38(%rbp), %r10
movq 0x48(%rbp), %rax
movq %r14, (%rsp)
movq %rbx, 0x8(%rsp)
movq %r11, 0x10(%rsp)
movq %r10, 0x18(%rsp)
movq %rax, 0x20(%rsp)
callq 0x12aa00
movq %rax, -0x78(%rbp)
cmpq $-0x1, -0x78(%rbp)
je 0x12c711
movq -0x78(%rbp), %rax
cmpq 0x48(%rbp), %rax
jbe 0x12c71e
movq $-0x1, -0x78(%rbp)
jmp 0x12c8a9
movq -0x38(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x48(%rbp), %rdx
movl -0x4c(%rbp), %ecx
movq -0x58(%rbp), %r8
movq -0x60(%rbp), %r9
movl 0x10(%rbp), %eax
movl %eax, -0xb4(%rbp)
movq 0x28(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq 0x18(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq 0x20(%rbp), %r13
movq 0x30(%rbp), %r12
movq 0x38(%rbp), %r15
movq 0x40(%rbp), %r14
movq -0x80(%rbp), %rbx
movq -0x88(%rbp), %r11
movq 0x48(%rbp), %r10
movq 0x50(%rbp), %rax
movq %rax, -0xa0(%rbp)
movl -0xb4(%rbp), %eax
movl %eax, (%rsp)
movq -0xb0(%rbp), %rax
movq %rax, 0x8(%rsp)
movq -0xa8(%rbp), %rax
movq %rax, 0x10(%rsp)
movq -0xa0(%rbp), %rax
movq %r13, 0x18(%rsp)
movq %r12, 0x20(%rsp)
movq %r15, 0x28(%rsp)
movq %r14, 0x30(%rsp)
movq %rbx, 0x38(%rsp)
movq %r11, 0x40(%rsp)
movq %r10, 0x48(%rsp)
movq %rax, 0x50(%rsp)
callq 0x12bf90
movq %rax, -0x78(%rbp)
cmpq $-0x1, -0x78(%rbp)
je 0x12c7e3
jmp 0x12c8a9
jmp 0x12c7e5
movq $0x0, -0x68(%rbp)
movq -0x68(%rbp), %rax
movl -0x4c(%rbp), %ecx
cmpq %rcx, %rax
jae 0x12c81f
movq -0x80(%rbp), %rax
movb %al, %dl
movq 0x38(%rbp), %rax
movq -0x40(%rbp), %rcx
movq -0x68(%rbp), %rsi
movl (%rcx,%rsi,4), %ecx
movb %dl, (%rax,%rcx)
movq -0x68(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x68(%rbp)
jmp 0x12c7ed
movq $0x0, -0x68(%rbp)
movq -0x68(%rbp), %rax
movl 0x10(%rbp), %ecx
cmpq %rcx, %rax
jae 0x12c85c
movq -0x88(%rbp), %rax
movb %al, %dl
movq 0x38(%rbp), %rax
movq -0x58(%rbp), %rcx
movq -0x68(%rbp), %rsi
movl (%rcx,%rsi,4), %ecx
movb %dl, (%rax,%rcx)
movq -0x68(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x68(%rbp)
jmp 0x12c827
movq $0x0, -0x68(%rbp)
movq -0x68(%rbp), %rax
movq 0x20(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x12c896
movq 0x30(%rbp), %rax
movq 0x20(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq -0x68(%rbp), %rdx
movl (%rcx,%rdx,4), %ecx
movb $0x0, (%rax,%rcx)
movq -0x68(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x68(%rbp)
jmp 0x12c864
jmp 0x12c898
movq -0x70(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x70(%rbp)
jmp 0x12c663
movq $0x0, -0x70(%rbp)
movq -0x70(%rbp), %rax
movl -0x4c(%rbp), %ecx
cmpq %rcx, %rax
jae 0x12c8de
movq 0x38(%rbp), %rax
movq -0x40(%rbp), %rcx
movq -0x70(%rbp), %rdx
movl (%rcx,%rdx,4), %ecx
movb $0x0, (%rax,%rcx)
movq -0x70(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x70(%rbp)
jmp 0x12c8b1
movq $0x0, -0x70(%rbp)
movq -0x70(%rbp), %rax
movl 0x10(%rbp), %ecx
cmpq %rcx, %rax
jae 0x12c913
movq 0x38(%rbp), %rax
movq -0x58(%rbp), %rcx
movq -0x70(%rbp), %rdx
movl (%rcx,%rdx,4), %ecx
movb $0x0, (%rax,%rcx)
movq -0x70(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x70(%rbp)
jmp 0x12c8e6
movq $0x0, -0x70(%rbp)
movq -0x70(%rbp), %rax
movq 0x20(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x12c94d
movq 0x30(%rbp), %rax
movq 0x20(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq -0x70(%rbp), %rdx
movl (%rcx,%rdx,4), %ecx
movb $0x0, (%rax,%rcx)
movq -0x70(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x70(%rbp)
jmp 0x12c91b
movq -0x78(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax,%rax)