// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/Overlaps.cpp
// Function: process_tangles(ma_ug_t*, unsigned long*, unsigned long, unsigned int, unsigned int, buf_t*, unsigned char*, unsigned int, long long, long long)
inline uint32_t process_tangles(ma_ug_t *ug, uint64_t* nodes, uint64_t nodes_n, uint32_t beg, uint32_t end,
buf_t* bb, uint8_t* visit, uint32_t trio_flag, long long totalNodeLen, long long totalBaseLen)
{
    uint32_t n_reduce = 1, v, w, kv, is_found = 0;
    asg_t* nsg = ug->g;

    while (n_reduce != 0)
    {
        while (n_reduce != 0)
        {
            n_reduce = 0;
            n_reduce += drop_tips_at_tangle(nsg, nodes, nodes_n, beg, end, bb);
            n_reduce += pop_bubble_at_tangle(ug, totalBaseLen, nodes, nodes_n, beg, end, trio_flag, DROP);
        }
        n_reduce = drop_useless_edges(ug, bb, visit, beg, end, nodes, nodes_n, totalNodeLen);
    }
    // if(pop_bubble_at_tangle(ug, 10000000, nodes, nodes_n, beg, end, trio_flag, DROP)!=0)
    // {
    //     fprintf(stderr, "false bubble popping: beg: %u, end: %u\n", beg>>1, end>>1);
    // }

    v = beg;
    is_found = 0;
    while (1)
    {
        if(v == end) is_found = 1;
        if(is_found == 1) break;

        kv = get_real_length(nsg, v, NULL);
        if(kv!=1) break;
        kv = get_real_length(nsg, v, &w);
        if(get_real_length(nsg, w^1, NULL)!=1) break;

        v = w;
        if(v == beg) break;
    }
    return is_found;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r9, 0x10(%rsp)
movl %r8d, %ebp
movl %ecx, %r15d
movq %rdx, %r12
movq %rsi, %r13
movq %rdi, %r14
movq 0x18(%rdi), %rax
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rdi
movq %r13, %rsi
movq %r12, %rdx
movl %r15d, %ecx
movl %ebp, %r8d
movq 0x10(%rsp), %r9
callq 0xec7f7
movl %eax, %ebx
movq %r14, %rdi
movq 0x68(%rsp), %rsi
movq %r13, %rdx
movq %r12, %rcx
movl %r15d, %r8d
movl %ebp, %r9d
pushq $0x5
movl 0x60(%rsp), %eax
pushq %rax
callq 0xecaf0
addq $0x10, %rsp
addl %ebx, %eax
jne 0x1020a1
movq %r14, %rdi
movq 0x10(%rsp), %rsi
movq 0x50(%rsp), %rdx
movl %r15d, %ecx
movl %ebp, %r8d
movq %r13, %r9
movl 0x60(%rsp), %eax
pushq %rax
pushq %r12
callq 0xed25a
addq $0x10, %rsp
testl %eax, %eax
jne 0x1020a1
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %r15d, %edx
movl %edx, %ecx
cmpl %ebp, %edx
je 0x10221f
movq 0x8(%rsp), %rsi
movq 0x28(%rsi), %rsi
movl %ecx, %edi
movq (%rsi,%rdi,8), %rdi
movq %rdi, %r8
andq %rax, %r8
je 0x10221f
movq 0x8(%rsp), %r9
movq 0x8(%r9), %r10
shrq $0x20, %rdi
leaq (%rdi,%rdi,2), %r9
leaq (%r10,%r9,8), %r10
addq $0xc, %r10
leaq (,%r8,8), %rdi
leaq (%rdi,%rdi,2), %rdi
xorl %r11d, %r11d
xorl %ebx, %ebx
movl (%r10,%r11), %r14d
notl %r14d
shrl $0x1f, %r14d
addl %r14d, %ebx
addq $0x18, %r11
cmpq %r11, %rdi
jne 0x102167
cmpl $0x1, %ebx
jne 0x10221f
testq %r8, %r8
je 0x1021b5
movq 0x8(%rsp), %r8
movq 0x8(%r8), %r8
leaq (%r8,%r9,8), %r8
addq $0xc, %r8
xorl %r9d, %r9d
cmpl $0x0, (%r8,%r9)
js 0x1021ac
movl -0x4(%r8,%r9), %edx
addq $0x18, %r9
cmpq %r9, %rdi
jne 0x1021a0
movl %edx, %edi
xorl $0x1, %edi
movq (%rsi,%rdi,8), %rsi
movq %rsi, %rdi
andq %rax, %rdi
je 0x10220e
movq 0x8(%rsp), %r8
movq 0x8(%r8), %r8
shrq $0x20, %rsi
leaq (%rsi,%rsi,2), %rsi
leaq (%r8,%rsi,8), %rsi
addq $0xc, %rsi
shlq $0x3, %rdi
leaq (%rdi,%rdi,2), %rdi
xorl %r8d, %r8d
xorl %r9d, %r9d
movl (%rsi,%r8), %r10d
notl %r10d
shrl $0x1f, %r10d
addl %r10d, %r9d
addq $0x18, %r8
cmpq %r8, %rdi
jne 0x1021ed
cmpl $0x1, %r9d
setne %sil
jmp 0x102211
movb $0x1, %sil
cmpl %r15d, %edx
je 0x10221f
testb %sil, %sil
je 0x102118
xorl %eax, %eax
cmpl %ebp, %ecx
sete %al
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq