// File: 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
movq %rsp, %rbp
pushq %rbx
subq $0x98, %rsp
movl 0x38(%rbp), %eax
movq 0x30(%rbp), %rax
movq 0x28(%rbp), %rax
movl 0x20(%rbp), %eax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movss %xmm0, -0x1c(%rbp)
movq %rdx, -0x28(%rbp)
movq %rcx, -0x30(%rbp)
movl %r8d, -0x34(%rbp)
movl %r9d, -0x38(%rbp)
movl $0x0, -0x5c(%rbp)
movq $0x0, -0x68(%rbp)
movq $0x0, -0x70(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x78(%rbp)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x18(%rbp), %rax
movq (%rax), %rax
shlq $0x3, %rax
addq %rax, %rsi
callq 0xc90e0
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, %ecx
movq -0x18(%rbp), %rdx
xorl %eax, %eax
cmpq (%rdx), %rcx
movb %al, -0x79(%rbp)
jae 0x148c9b
movl -0x3c(%rbp), %eax
cmpl 0x38(%rbp), %eax
setb %al
movb %al, -0x79(%rbp)
movb -0x79(%rbp), %al
testb $0x1, %al
jne 0x148ca7
jmp 0x148f5d
movq -0x78(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x10(%rcx), %rcx
movl -0x3c(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
movl %ecx, %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x148cdf
jmp 0x148f4f
movq -0x68(%rbp), %rax
movq (%rax), %rax
shrq $0x20, %rax
movl %eax, -0x40(%rbp)
movq -0x68(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x4c(%rbp)
movq -0x78(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x40(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
jne 0x148d2a
movq -0x78(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x40(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movzbl 0x4(%rax,%rcx,8), %eax
cmpl $0x1, %eax
jne 0x148d2f
jmp 0x148f4f
movq -0x78(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x4c(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
jne 0x148d62
movq -0x78(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x4c(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movzbl 0x4(%rax,%rcx,8), %eax
cmpl $0x1, %eax
jne 0x148d67
jmp 0x148f4f
movq -0x78(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x40(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x50(%rbp)
cmpl $0x1, -0x50(%rbp)
ja 0x148d84
jmp 0x148f4f
movl $0x0, -0x54(%rbp)
movq -0x78(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x78(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x40(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x70(%rbp)
movl $0x0, -0x44(%rbp)
movl $0x0, -0x48(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x50(%rbp), %eax
jae 0x148e2d
movq -0x70(%rbp), %rax
movl -0x44(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x148de2
jmp 0x148e22
movl -0x54(%rbp), %eax
movq -0x70(%rbp), %rcx
movl -0x44(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movl 0xc(%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl %ecx, %eax
jae 0x148e19
movq -0x70(%rbp), %rax
movl -0x44(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, -0x54(%rbp)
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x148dbf
cmpl $0x1, -0x48(%rbp)
ja 0x148e38
jmp 0x148f4f
movq -0x68(%rbp), %rax
movl 0xc(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cvtsi2ss %eax, %xmm0
movl -0x54(%rbp), %eax
cvtsi2ss %rax, %xmm1
mulss -0x1c(%rbp), %xmm1
ucomiss %xmm1, %xmm0
jbe 0x148e5f
jmp 0x148f4f
movq -0x78(%rbp), %rdi
movl -0x40(%rbp), %esi
movl -0x4c(%rbp), %edx
movl $0x1, %ecx
callq 0xd6530
movq -0x78(%rbp), %rdi
movl -0x4c(%rbp), %esi
xorl $0x1, %esi
movl -0x40(%rbp), %edx
xorl $0x1, %edx
movl $0x1, %ecx
callq 0xd6530
movl -0x34(%rbp), %eax
xorl $0x1, %eax
movl %eax, -0x58(%rbp)
movq -0x78(%rbp), %rdi
movl -0x34(%rbp), %esi
movl -0x38(%rbp), %edx
movq 0x28(%rbp), %r9
movq 0x10(%rbp), %r11
movq 0x18(%rbp), %r10
movq -0x10(%rbp), %rax
leaq -0x58(%rbp), %rcx
movl $0x1, %r8d
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x147c90
cmpl $0x0, %eax
jne 0x148f03
movl $0x0, -0x5c(%rbp)
movq -0x78(%rbp), %rdi
movl -0x40(%rbp), %esi
movl -0x4c(%rbp), %edx
xorl %ecx, %ecx
callq 0xd6530
movq -0x78(%rbp), %rdi
movl -0x4c(%rbp), %esi
xorl $0x1, %esi
movl -0x40(%rbp), %edx
xorl $0x1, %edx
xorl %ecx, %ecx
callq 0xd6530
jmp 0x148f5d
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x30(%rbp), %rdx
movl -0x34(%rbp), %ecx
movl -0x38(%rbp), %r8d
movq 0x10(%rbp), %r9
movq 0x18(%rbp), %rbx
movl 0x20(%rbp), %r11d
movq 0x28(%rbp), %r10
movq 0x30(%rbp), %rax
movq %rbx, (%rsp)
movl %r11d, 0x8(%rsp)
movq %r10, 0x10(%rsp)
movq %rax, 0x18(%rsp)
callq 0x168be0
movl %eax, -0x5c(%rbp)
cmpl $0x1, -0x5c(%rbp)
jne 0x148f4d
jmp 0x148f5d
jmp 0x148f4f
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x148c7c
movl -0x5c(%rbp), %eax
addq $0x98, %rsp
popq %rbx
popq %rbp
retq
nopw (%rax,%rax)