// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/horder.cpp
// Function: mc_clus_cut(scg_t*, mc_edge_t*, unsigned long, double, unsigned long)
uint64_t mc_clus_cut(scg_t *sg, mc_edge_t *sa, uint64_t sn, double cut_rate, uint64_t force_cut)
{
    uint64_t i, k, kv, kw, v, w, nv, nw, cnt = 0, m = sn; double mm_ol, ol_max;
    osg_arc_t *av, *aw, *ve, *we; 
    for (k = 0; k < sn; k++) {
        if(sa[k].x == ((uint64_t)-1)) {
            cnt++; continue;
        }
        if(sg->g->arc[sa[k].x].del) {
            sa[k].x = ((uint64_t)-1); cnt++;
            continue;
        }

        v = sg->g->arc[sa[k].x].u;
        w = sg->g->arc[sa[k].x].v;

        nv = asg_arc_n(sg->g, v); nw = asg_arc_n(sg->g, w);
        if(nv<=1 && nw <= 1) {
            sa[k].x = ((uint64_t)-1); cnt++;
            continue;
        }
        av = asg_arc_a(sg->g, v); aw = asg_arc_a(sg->g, w);

        ve = &(sg->g->arc[sa[k].x]); we = NULL;
        for (i = 0; i < nw; ++i) {
            if (aw[i].v == v) {
                we = &(aw[i]);
                break;
            }
        }
        // if(!((!we) && (!(we->del)))) {
        //     fprintf(stderr, "[M::%s] sn::%lu, sg->g->n_arc::%u, sg->g->n_seq::%u, cut_rate::%f, v::%lu, w::%lu, x::%lu, v_beg::%lu, nv::%lu, w_beg::%lu, nw::%lu\n", __func__, 
	    //     sn, sg->g->n_arc, sg->g->n_seq, cut_rate, v, w, sa[k].x, 
        //     (sg->g)->idx[(v)]>>32, nv, (sg->g)->idx[(w)]>>32, nw);
        //     prt_scg_t_arc(sg);
        // }
        assert((we) && (!(we->del)));
        mm_ol = sg->g->arc[sa[k].x].nw;

        for (i = kv = ol_max = 0; i < nv; ++i) {
            if(av[i].del) continue;
            kv++;
            if(ol_max < av[i].nw) ol_max = av[i].nw;
        }
        if (kv < 1) {
            sa[k].x = ((uint64_t)-1); cnt++;
            continue;
        }
        if (kv >= 2) {
            if ((!force_cut) && (mm_ol > (ol_max*cut_rate))) continue;
        }
        

        for (i = kw = ol_max = 0; i < nw; ++i) {
            if(aw[i].del) continue;
            kw++;
            if(ol_max < aw[i].nw) ol_max = aw[i].nw;
        }
        if (kw < 1) {
            sa[k].x = ((uint64_t)-1); cnt++;
            continue;
        }
        if (kw >= 2) {
            if ((!force_cut) && (mm_ol > (ol_max*cut_rate))) continue;
        }

        if (kv <= 1 && kw <= 1) {
            sa[k].x = ((uint64_t)-1); cnt++;
            continue;
        }

        ve->del = we->del = 1;
        sa[k].x = ((uint64_t)-1); cnt++; 
    }

    m = sn;
    if(cnt) {
        for (k = m = 0; k < sn; k++) {
            if(sa[k].x == ((uint64_t)-1)) continue;
            sa[m++] = sa[k];
        }
    }
    return m;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rcx, 0x8(%rsp)
movq %rdi, 0x10(%rsp)
xorl %eax, %eax
testq %rdx, %rdx
je 0x17de32
xorl %r8d, %r8d
movq %rax, %r9
shlq $0x4, %r9
movq (%rsi,%r9), %r12
cmpq $-0x1, %r12
je 0x17ddf1
addq %rsi, %r9
movq 0x10(%rsp), %rcx
movq (%rcx), %rcx
movq 0x8(%rcx), %r15
shlq $0x5, %r12
cmpl $0x0, 0x8(%r15,%r12)
js 0x17ddea
leaq (%r15,%r12), %r10
movl (%r10), %r11d
movl 0x4(%r10), %edi
movq 0x20(%rcx), %rbx
movq (%rbx,%rdi,8), %rcx
movl %ecx, %ebp
movq (%rbx,%r11,8), %r13
movl %r13d, %r14d
cmpq $0x1, %rbp
ja 0x17dcc3
cmpl $0x1, %r14d
jbe 0x17ddea
testq %r14, %r14
je 0x17de41
shrq $0x20, %rcx
shrq $0x20, %r13
shlq $0x5, %r14
shlq $0x5, %r13
leaq (%r15,%r13), %r11
addq $0x8, %r11
xorl %ebx, %ebx
cmpl %edi, -0x8(%r11,%rbx)
je 0x17dcfb
addq $0x20, %rbx
cmpq %rbx, %r14
jne 0x17dce6
jmp 0x17de41
leaq (%r15,%r13), %rdi
movl 0x8(%rbx,%rdi), %edi
movl %edi, 0x4(%rsp)
testl %edi, %edi
js 0x17de41
testq %rbp, %rbp
je 0x17ddea
movsd 0x18(%r15,%r12), %xmm1
shlq $0x5, %rbp
shlq $0x5, %rcx
addq %r15, %rcx
addq $0x18, %rcx
xorpd %xmm2, %xmm2
xorl %edi, %edi
xorl %r12d, %r12d
cmpl $0x0, -0x10(%rcx,%rdi)
js 0x17dd50
incq %r12
movsd (%rcx,%rdi), %xmm3
ucomisd %xmm2, %xmm3
jbe 0x17dd50
movapd %xmm3, %xmm2
addq $0x20, %rdi
cmpq %rdi, %rbp
jne 0x17dd37
testq %r12, %r12
je 0x17ddea
cmpq $0x0, 0x8(%rsp)
jne 0x17dd7a
cmpq $0x1, %r12
je 0x17dd7a
mulsd %xmm0, %xmm2
ucomisd %xmm2, %xmm1
ja 0x17ddf4
addq %r13, %r15
addq $0x18, %r15
xorpd %xmm2, %xmm2
xorl %edi, %edi
xorl %ecx, %ecx
cmpl $0x0, -0x10(%r15,%rdi)
js 0x17dda4
incq %rcx
movsd (%r15,%rdi), %xmm3
ucomisd %xmm2, %xmm3
jbe 0x17dda4
movapd %xmm3, %xmm2
addq $0x20, %rdi
cmpq %rdi, %r14
jne 0x17dd89
testq %rcx, %rcx
je 0x17ddea
cmpq $0x0, 0x8(%rsp)
jne 0x17ddca
cmpq $0x1, %rcx
je 0x17ddca
mulsd %xmm0, %xmm2
ucomisd %xmm2, %xmm1
ja 0x17ddf4
xorq $0x1, %rcx
xorq $0x1, %r12
orq %rcx, %r12
je 0x17ddea
movl 0x4(%rsp), %ecx
orl $0x80000000, %ecx       # imm = 0x80000000
movl %ecx, (%r11,%rbx)
orb $-0x80, 0xb(%r10)
movq $-0x1, (%r9)
incq %r8
incq %rax
cmpq %rdx, %rax
jne 0x17dc63
testq %r8, %r8
je 0x17de2f
xorl %eax, %eax
movq %rsi, %rcx
cmpq $-0x1, (%rcx)
je 0x17de24
leaq 0x1(%rax), %rdi
shlq $0x4, %rax
movupd (%rcx), %xmm0
movupd %xmm0, (%rsi,%rax)
movq %rdi, %rax
addq $0x10, %rcx
decq %rdx
jne 0x17de0a
jmp 0x17de32
movq %rdx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xbfec9(%rip), %rdi     # 0x23dd11
leaq 0xbf9dc(%rip), %rsi     # 0x23d82b
leaq 0xbfed0(%rip), %rcx     # 0x23dd26
movl $0xfe2, %edx            # imm = 0xFE2
callq 0x2110