// File: /workspace/github_cpp_makefile_star2_O2/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 $0x38, %rsp
movl %r9d, 0xc(%rsp)
movl %r8d, %ebx
movq %rcx, 0x30(%rsp)
movq %rdx, 0x28(%rsp)
movss %xmm0, 0x18(%rsp)
movq %rsi, %r13
movq %rdi, 0x20(%rsp)
movl 0x98(%rsp), %r15d
movq 0x18(%rdi), %r14
movq (%rsi), %rax
movq 0x10(%rsi), %rdi
leaq (%rdi,%rax,8), %rsi
callq 0x66c25
movl %ebx, %eax
xorl $0x1, %eax
movl %eax, 0x14(%rsp)
movl $0x0, 0x4(%rsp)
xorl %r12d, %r12d
movl %ebx, 0x8(%rsp)
cmpl %r15d, %r12d
jae 0xb01e3
movl %r12d, %r12d
cmpq %r12, (%r13)
jbe 0xb01e3
movq 0x8(%r14), %rcx
movq 0x10(%r13), %rax
movl (%rax,%r12,8), %eax
imulq $0x18, %rax, %rsi
movl 0xc(%rcx,%rsi), %eax
testl %eax, %eax
js 0xb01db
addq %rcx, %rsi
movq (%rsi), %rbx
movq 0x20(%r14), %rdx
movq %rbx, %rdi
shrq $0x21, %rdi
cmpl $0x0, (%rdx,%rdi,8)
js 0xb01db
cmpb $0x1, 0x4(%rdx,%rdi,8)
je 0xb01db
movl 0x8(%rsi), %ebp
movl %ebp, %esi
shrl %esi
cmpl $0x0, (%rdx,%rsi,8)
js 0xb01db
cmpb $0x1, 0x4(%rdx,%rsi,8)
je 0xb01db
shrq $0x20, %rbx
movq 0x28(%r14), %rdx
movq (%rdx,%rbx,8), %rdx
testl $0xfffffffe, %edx       # imm = 0xFFFFFFFE
je 0xb01db
movq %rdx, %rsi
shrq $0x20, %rsi
movl %edx, %edx
imulq $0x18, %rdx, %rdx
imulq $0x18, %rsi, %rsi
addq %rcx, %rsi
addq $0xc, %rsi
xorl %edi, %edi
xorl %r8d, %r8d
xorl %ecx, %ecx
cmpq %rdi, %rdx
je 0xb00f7
movl (%rsi,%rdi), %r9d
cmpl %r9d, %ecx
movl %r9d, %r10d
cmoval %ecx, %r10d
xorl %r11d, %r11d
testl %r9d, %r9d
setns %r11b
cmovnsl %r10d, %ecx
addl %r11d, %r8d
addq $0x18, %rdi
jmp 0xb00cd
cmpl $0x2, %r8d
jb 0xb01db
cvtsi2ss %eax, %xmm0
cvtsi2ss %ecx, %xmm1
mulss 0x18(%rsp), %xmm1
ucomiss %xmm1, %xmm0
ja 0xb01db
movq %r14, %rdi
movl %ebx, %esi
movl %ebp, %edx
pushq $0x1
popq %rcx
callq 0x6db50
movl %ebp, %esi
xorl $0x1, %esi
movl %ebx, %edx
xorl $0x1, %edx
movq %r14, %rdi
movl %esi, 0x4(%rsp)
movl %edx, 0x10(%rsp)
pushq $0x1
popq %rcx
callq 0x6db50
movl 0x14(%rsp), %eax
movl %eax, 0x1c(%rsp)
subq $0x8, %rsp
movq %r14, %rdi
movl 0x10(%rsp), %esi
movl 0x14(%rsp), %edx
leaq 0x24(%rsp), %rcx
pushq $0x1
popq %r8
movq 0x90(%rsp), %r9
pushq 0x28(%rsp)
movq 0x88(%rsp), %rax
pushq %rax
movq 0x88(%rsp), %rax
pushq %rax
callq 0xaf676
addq $0x20, %rsp
testl %eax, %eax
je 0xb01fa
movq 0x20(%rsp), %rdi
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
movl 0x8(%rsp), %ecx
movl 0xc(%rsp), %r8d
movq 0x70(%rsp), %r9
pushq 0x90(%rsp)
pushq 0x90(%rsp)
movl 0x90(%rsp), %eax
pushq %rax
pushq 0x90(%rsp)
callq 0xc3e2a
addq $0x20, %rsp
movl %eax, 0x4(%rsp)
cmpl $0x1, %eax
je 0xb021f
incl %r12d
jmp 0xb0022
movl 0x4(%rsp), %r15d
movl %r15d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r15d, %r15d
movq %r14, %rdi
movl %ebx, %esi
movl %ebp, %edx
xorl %ecx, %ecx
callq 0x6db50
movq %r14, %rdi
movl 0x4(%rsp), %esi
movl 0x10(%rsp), %edx
xorl %ecx, %ecx
callq 0x6db50
jmp 0xb01e8
pushq $0x1
popq %r15
jmp 0xb01e8