// File: /workspace/github_cpp_makefile_star2_O3/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 $0x68, %rsp
movl %r9d, %r14d
movl %r8d, %r15d
movq %rcx, %r12
movq %rdx, 0x58(%rsp)
movss %xmm0, 0x28(%rsp)
movq %rsi, %r13
movl 0xc8(%rsp), %ebp
movq %rdi, 0x60(%rsp)
movq 0x18(%rdi), %rbx
movq (%rsi), %rax
movq 0x10(%rsi), %rdi
leaq (%rdi,%rax,8), %rsi
callq 0x9dc69
movq (%r13), %rcx
testq %rcx, %rcx
sete %al
testl %ebp, %ebp
sete %dl
orb %al, %dl
jne 0xefca9
movq %r12, 0x38(%rsp)
movl %r14d, 0x24(%rsp)
movl %r15d, 0x8(%rsp)
xorl $0x1, %r15d
movl %r15d, 0x20(%rsp)
movl %ebp, %r9d
xorl %r12d, %r12d
xorl %eax, %eax
movq %r9, 0x18(%rsp)
movq 0x8(%rbx), %rdx
movq 0x10(%r13), %rsi
movl (%rsi,%r12,8), %esi
leaq (%rsi,%rsi,2), %rdi
movl 0xc(%rdx,%rdi,8), %esi
testl %esi, %esi
js 0xefbe4
leaq (%rdx,%rdi,8), %rdi
movq (%rdi), %r14
movq 0x20(%rbx), %r11
movq %r14, %r8
shrq $0x21, %r8
cmpl $0x0, (%r11,%r8,8)
js 0xefbe4
cmpb $0x1, 0x4(%r11,%r8,8)
je 0xefbe4
movl 0x8(%rdi), %r8d
movq %r8, %r10
movl %r10d, %edi
shrl %edi
cmpl $0x0, (%r11,%rdi,8)
js 0xefbe4
cmpb $0x1, 0x4(%r11,%rdi,8)
je 0xefbe4
shrq $0x20, %r14
movq 0x28(%rbx), %rdi
movq (%rdi,%r14,8), %r11
testl $0xfffffffe, %r11d      # imm = 0xFFFFFFFE
je 0xefbe4
movq %rdi, 0x50(%rsp)
movl %eax, 0xc(%rsp)
movq %r10, 0x30(%rsp)
movq %r8, 0x10(%rsp)
movl %r14d, 0x4(%rsp)
movq %r11, %rax
shrq $0x20, %rax
movq %r11, 0x48(%rsp)
movl %r11d, %r10d
leaq (%rax,%rax,2), %rax
leaq (%rdx,%rax,8), %rax
addq $0xc, %rax
xorl %r11d, %r11d
movq %r10, 0x40(%rsp)
movq %rax, %r8
xorl %edi, %edi
movl %r11d, %r9d
movl (%r8), %r15d
cmpl %r15d, %r11d
movl %r15d, %r11d
cmoval %r9d, %r11d
xorl %ebp, %ebp
testl %r15d, %r15d
cmovsl %r9d, %r11d
setns %bpl
addl %ebp, %edi
addq $0x18, %r8
decq %r10
jne 0xefa4e
cmpl $0x2, %edi
jae 0xefa89
movq 0x18(%rsp), %r9
movl 0xc(%rsp), %eax
jmp 0xefbe4
movq %rax, %r10
cvtsi2ss %esi, %xmm0
cvtsi2ss %r11d, %xmm1
mulss 0x28(%rsp), %xmm1
ucomiss %xmm1, %xmm0
movq 0x18(%rsp), %r9
movl 0xc(%rsp), %eax
ja 0xefbe4
cmpl $0x0, 0x48(%rsp)
movl 0x4(%rsp), %edi
movq 0x10(%rsp), %r8
movq 0x50(%rsp), %rax
je 0xefaef
movq 0x40(%rsp), %rax
shlq $0x3, %rax
leaq (%rax,%rax,2), %rcx
xorl %edx, %edx
cmpl %r8d, -0x4(%r10,%rdx)
jne 0xefade
orb $-0x80, 0x3(%r10,%rdx)
addq $0x18, %rdx
cmpq %rdx, %rcx
jne 0xefad1
movq 0x8(%rbx), %rdx
movq 0x28(%rbx), %rax
xorq $0x1, %r8
xorl $0x1, %edi
movq (%rax,%r8,8), %rcx
movq %rcx, %rax
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
andq %rsi, %rax
je 0xefb35
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 0xefb2c
orb $-0x80, 0x3(%rcx,%rdx)
addq $0x18, %rdx
cmpq %rdx, %rax
jne 0xefb21
movq %r8, 0x10(%rsp)
movl %edi, 0x4(%rsp)
movl 0x20(%rsp), %eax
movl %eax, 0x2c(%rsp)
subq $0x8, %rsp
movq %rbx, %rdi
movl 0x10(%rsp), %esi
movl 0x2c(%rsp), %ebp
movl %ebp, %edx
leaq 0x34(%rsp), %rcx
movl $0x1, %r8d
movq 0xc0(%rsp), %r9
movq 0x68(%rsp), %r15
pushq %r15
movq 0xb8(%rsp), %rax
pushq %rax
movq 0xb8(%rsp), %rax
pushq %rax
callq 0xee7a2
addq $0x20, %rsp
testl %eax, %eax
je 0xefbfe
movq %r15, %rdi
movq 0x58(%rsp), %rsi
movq 0x38(%rsp), %rdx
movl 0x8(%rsp), %ecx
movl %ebp, %r8d
movq 0xa0(%rsp), %r9
pushq 0xc0(%rsp)
pushq 0xc0(%rsp)
movl 0xc0(%rsp), %eax
pushq %rax
pushq 0xc0(%rsp)
callq 0x106399
addq $0x20, %rsp
cmpl $0x1, %eax
je 0xefc5e
movq (%r13), %rcx
movq 0x18(%rsp), %r9
incq %r12
cmpq %r9, %r12
jae 0xefcab
cmpq %r12, %rcx
ja 0xef98d
jmp 0xefcab
movq 0x8(%rbx), %rcx
movq 0x28(%rbx), %rdx
movq (%rdx,%r14,8), %rsi
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rsi, %rdi
andq %rax, %rdi
je 0xefc65
shrq $0x20, %rsi
shlq $0x3, %rdi
leaq (%rdi,%rdi,2), %rdx
leaq (%rsi,%rsi,2), %rsi
leaq (%rcx,%rsi,8), %rcx
addq $0xc, %rcx
xorl %esi, %esi
movl 0x4(%rsp), %edi
movq 0x10(%rsp), %r8
movq 0x30(%rsp), %r9
cmpl %r9d, -0x4(%rcx,%rsi)
jne 0xefc4b
andb $0x7f, 0x3(%rcx,%rsi)
addq $0x18, %rsi
cmpq %rsi, %rdx
jne 0xefc3f
movq 0x8(%rbx), %rcx
movq 0x28(%rbx), %rdx
jmp 0xefc6e
movl $0x1, %eax
jmp 0xefcab
movl 0x4(%rsp), %edi
movq 0x10(%rsp), %r8
movq (%rdx,%r8,8), %rdx
andq %rdx, %rax
je 0xefca9
shrq $0x20, %rdx
shlq $0x3, %rax
leaq (%rax,%rax,2), %rsi
leaq (%rdx,%rdx,2), %rdx
leaq (%rcx,%rdx,8), %rcx
addq $0xc, %rcx
xorl %edx, %edx
xorl %eax, %eax
cmpl %edi, -0x4(%rcx,%rdx)
jne 0xefc9e
andb $0x7f, 0x3(%rcx,%rdx)
addq $0x18, %rdx
cmpq %rdx, %rsi
jne 0xefc93
jmp 0xefcab
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq