// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/Overlaps.cpp
// Function: cut_edges_progressive(ma_ug_t*, kvec_t_u64_warp*, float, unsigned long*, unsigned long, unsigned int, unsigned int, buf_t*, unsigned char*, unsigned int, long long, long long, unsigned int)
uint32_t cut_edges_progressive(ma_ug_t *ug, kvec_t_u64_warp* edges, float drop_ratio,
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 max_arc_n)
{
    uint32_t k, v, i, kv, w, nv, ov_max, ban, is_found = 0;
    asg_arc_t *a = NULL, *av = NULL;
    asg_t* nsg = ug->g;
    radix_sort_arch64(edges->a.a, edges->a.a + edges->a.n);
    for (k = 0; k < edges->a.n && k < max_arc_n; k++)
    {
        a = &nsg->arc[(uint32_t)edges->a.a[k]];
        if(a->del) continue;
        v = (a->ul)>>32; w = a->v;
        if(nsg->seq[v>>1].del || nsg->seq[v>>1].c == ALTER_LABLE) continue;
        if(nsg->seq[w>>1].del || nsg->seq[w>>1].c == ALTER_LABLE) continue;

        nv = asg_arc_n(nsg, v);
        if(nv<=1) continue;

        ov_max = 0;
        av = asg_arc_a(nsg, v);
        for(i = 0, kv = 0; i < nv; ++i) 
        {
            if(av[i].del) continue;
            if(ov_max < av[i].ol) ov_max = av[i].ol;
            ++kv;
        }

        if(kv<=1) continue;
        if(a->ol > ov_max * drop_ratio) continue;
        asg_arc_del(nsg, v, w, 1);
        asg_arc_del(nsg, w^1, v^1, 1);

        ban = beg^1;
        if(find_spec_node(nsg, beg, end, &ban, 1, totalNodeLen, bb, visit, ug) == 0)
        {
            is_found = 0;
            asg_arc_del(nsg, v, w, 0);
            asg_arc_del(nsg, w^1, v^1, 0);
            break;
        }

        is_found = process_tangles(ug, nodes, nodes_n, beg, end, bb, visit, trio_flag, totalNodeLen,
        totalBaseLen);
        if(is_found == 1) break;
    }

    return is_found;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %r9d, %r14d
movl %r8d, %r15d
movq %rcx, %r12
movq %rdx, 0x40(%rsp)
movss %xmm0, 0x20(%rsp)
movq %rsi, %r13
movl 0xa8(%rsp), %ebp
movq %rdi, 0x28(%rsp)
movq 0x18(%rdi), %rbx
movq (%rsi), %rax
movq 0x10(%rsi), %rdi
leaq (%rdi,%rax,8), %rsi
callq 0x9d53f
xorl %eax, %eax
testl %ebp, %ebp
je 0xeddff
movq %r12, 0x38(%rsp)
movl %r15d, 0x4(%rsp)
movl %r14d, 0x1c(%rsp)
cmpq $0x0, (%r13)
je 0xeddff
movl 0x4(%rsp), %eax
xorl $0x1, %eax
movl %eax, 0x18(%rsp)
movl %ebp, %r15d
xorl %r14d, %r14d
xorl %eax, %eax
movq 0x8(%rbx), %rbp
movq 0x10(%r13), %rcx
movl (%rcx,%r14,8), %ecx
leaq (%rcx,%rcx,2), %rdx
movl 0xc(%rbp,%rdx,8), %ecx
testl %ecx, %ecx
js 0xedded
leaq (,%rdx,8), %rsi
addq %rbp, %rsi
movq (%rsi), %r12
movq 0x20(%rbx), %rdx
movq %r12, %rdi
shrq $0x21, %rdi
cmpl $0x0, (%rdx,%rdi,8)
js 0xedded
cmpb $0x1, 0x4(%rdx,%rdi,8)
je 0xedded
movl 0x8(%rsi), %edi
movq %rdi, %r8
movl %r8d, %esi
shrl %esi
cmpl $0x0, (%rdx,%rsi,8)
js 0xedded
cmpb $0x1, 0x4(%rdx,%rsi,8)
je 0xedded
shrq $0x20, %r12
movq 0x28(%rbx), %rdx
movq (%rdx,%r12,8), %rsi
testl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
je 0xedded
movq %rdx, 0x8(%rsp)
movq %r8, 0x30(%rsp)
movq %rdi, 0x10(%rsp)
movq %rsi, %rdi
shrq $0x20, %rdi
movl %esi, %esi
leaq (%rdi,%rdi,2), %rdi
leaq 0xc(,%rdi,8), %rdi
addq %rbp, %rdi
xorl %r8d, %r8d
xorl %r9d, %r9d
movl %r8d, %r10d
movl (%rdi), %r11d
cmpl %r11d, %r8d
movl %r11d, %r8d
cmoval %r10d, %r8d
xorl %edx, %edx
testl %r11d, %r11d
cmovsl %r10d, %r8d
setns %dl
addl %edx, %r9d
addq $0x18, %rdi
decq %rsi
jne 0xedc62
cmpl $0x2, %r9d
jb 0xedded
cvtsi2ss %ecx, %xmm0
cvtsi2ss %r8d, %xmm1
mulss 0x20(%rsp), %xmm1
ucomiss %xmm1, %xmm0
movq 0x28(%rsp), %r10
ja 0xedded
movq 0x8(%rsp), %rax
movq (%rax,%r12,8), %rdx
movq %rdx, %rcx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
andq %rsi, %rcx
movq 0x98(%rsp), %r9
movq 0x10(%rsp), %rsi
je 0xedd05
shrq $0x20, %rdx
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rdx,%rdx,2), %rdx
leaq 0xc(,%rdx,8), %rax
addq %rbp, %rax
xorl %edx, %edx
cmpl %esi, -0x4(%rax,%rdx)
jne 0xedcfc
orb $-0x80, 0x3(%rax,%rdx)
addq $0x18, %rdx
cmpq %rdx, %rcx
jne 0xedcf1
xorq $0x1, %rsi
movl %r12d, %edi
xorl $0x1, %edi
movq 0x28(%rbx), %rax
movq (%rax,%rsi,8), %rcx
movq %rcx, %rax
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
andq %rdx, %rax
je 0xedd56
movq 0x8(%rbx), %rdx
shrq $0x20, %rcx
shlq $0x3, %rax
leaq (%rax,%rax,2), %rax
leaq (%rcx,%rcx,2), %rcx
leaq (%rdx,%rcx,8), %rcx
addq $0xc, %rcx
xorl %edx, %edx
cmpl %edi, -0x4(%rcx,%rdx)
jne 0xedd4d
orb $-0x80, 0x3(%rcx,%rdx)
addq $0x18, %rdx
cmpq %rdx, %rax
jne 0xedd42
movl %edi, 0x8(%rsp)
movq %rsi, 0x10(%rsp)
movl 0x18(%rsp), %eax
movl %eax, 0x24(%rsp)
subq $0x8, %rsp
movq %rbx, %rdi
movl 0xc(%rsp), %esi
movl 0x24(%rsp), %edx
movl %edx, %ebp
leaq 0x2c(%rsp), %rcx
movl $0x1, %r8d
pushq %r10
movq 0x98(%rsp), %rax
pushq %rax
movq 0x98(%rsp), %rax
pushq %rax
callq 0xece7c
addq $0x20, %rsp
testl %eax, %eax
je 0xede0e
movq 0x28(%rsp), %rdi
movq 0x40(%rsp), %rsi
movq 0x38(%rsp), %rdx
movl 0x4(%rsp), %ecx
movl %ebp, %r8d
movq 0x80(%rsp), %r9
pushq 0xa0(%rsp)
pushq 0xa0(%rsp)
movl 0xa0(%rsp), %eax
pushq %rax
pushq 0xa0(%rsp)
callq 0x102076
addq $0x20, %rsp
cmpl $0x1, %eax
je 0xede37
incq %r14
cmpq %r15, %r14
jae 0xeddff
cmpq %r14, (%r13)
ja 0xedbb3
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
movl %r12d, %esi
movq 0x30(%rsp), %rdx
xorl %ecx, %ecx
callq 0xa5255
movq %rbx, %rdi
movq 0x10(%rsp), %rsi
movl 0x8(%rsp), %edx
xorl %ecx, %ecx
callq 0xa5255
xorl %eax, %eax
jmp 0xeddff
movl $0x1, %eax
jmp 0xeddff