// File: /workspace/github_cpp_makefile_star2_O3/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 0xee124
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 0xee41b
addq $0x10, %rsp
addl %ebx, %eax
jne 0x1063c4
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 0xeecfc
addq $0x10, %rsp
testl %eax, %eax
jne 0x1063c4
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %r15d, %edx
movl %edx, %ecx
cmpl %ebp, %edx
je 0x10650f
movq 0x8(%rsp), %rsi
movq 0x28(%rsi), %rsi
movl %ecx, %edi
movq (%rsi,%rdi,8), %r8
movq %r8, %r9
andq %rax, %r9
je 0x10650f
movq 0x8(%rsp), %rdi
movq 0x8(%rdi), %rdi
shrq $0x20, %r8
leaq (%r8,%r8,2), %r8
leaq (%rdi,%r8,8), %r8
addq $0xc, %r8
shlq $0x3, %r9
leaq (%r9,%r9,2), %r9
xorl %r10d, %r10d
xorl %r11d, %r11d
movl (%r8,%r10), %ebx
notl %ebx
shrl $0x1f, %ebx
addl %ebx, %r11d
addq $0x18, %r10
cmpq %r10, %r9
jne 0x106487
cmpl $0x1, %r11d
jne 0x10650f
xorl %r10d, %r10d
cmpl $0x0, (%r8,%r10)
js 0x1064b1
movl -0x4(%r8,%r10), %edx
addq $0x18, %r10
cmpq %r10, %r9
jne 0x1064a5
movl %edx, %r8d
xorl $0x1, %r8d
movq (%rsi,%r8,8), %rsi
movq %rsi, %r8
andq %rax, %r8
je 0x10650f
shrq $0x20, %rsi
leaq (%rsi,%rsi,2), %rsi
leaq (%rdi,%rsi,8), %rsi
addq $0xc, %rsi
shlq $0x3, %r8
leaq (%r8,%r8,2), %r8
xorl %r9d, %r9d
xorl %edi, %edi
movl (%rsi,%r9), %r10d
notl %r10d
shrl $0x1f, %r10d
addl %r10d, %edi
addq $0x18, %r9
cmpq %r9, %r8
jne 0x1064ea
cmpl %r15d, %edx
je 0x10650f
cmpl $0x1, %edi
je 0x10643b
xorl %eax, %eax
cmpl %ebp, %ecx
sete %al
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq