// File: /workspace/github_cpp_makefile_star2_O1/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)
testq %rdx, %rdx
je 0x1772a9
xorl %eax, %eax
xorl %r8d, %r8d
movq %rax, %r9
shlq $0x4, %r9
movq (%rsi,%r9), %r15
cmpq $-0x1, %r15
je 0x17726b
addq %rsi, %r9
movq 0x10(%rsp), %rcx
movq (%rcx), %rdi
movq 0x8(%rdi), %r14
shlq $0x5, %r15
cmpl $0x0, 0x8(%r14,%r15)
js 0x177264
leaq (%r14,%r15), %r10
movl (%r10), %r11d
movl 0x4(%r10), %ecx
movq 0x20(%rdi), %rdi
movq (%rdi,%rcx,8), %r13
movl %r13d, %ebp
movq (%rdi,%r11,8), %r12
movl %r12d, %ebx
cmpq $0x1, %rbp
ja 0x177123
cmpl $0x1, %ebx
jbe 0x177264
shrq $0x20, %r12
shlq $0x5, %r12
testq %rbx, %rbx
je 0x177145
leaq (%r14,%r12), %r11
movq %rbx, %rdi
cmpl %ecx, (%r11)
je 0x177148
addq $0x20, %r11
decq %rdi
jne 0x177137
xorl %r11d, %r11d
testq %r11, %r11
je 0x1772bb
movl 0x8(%r11), %ecx
testl %ecx, %ecx
js 0x1772bb
movl %ecx, 0x4(%rsp)
testq %rbp, %rbp
je 0x1771ab
shrq $0x20, %r13
shlq $0x5, %rbp
shlq $0x5, %r13
leaq (%r14,%r13), %rcx
addq $0x18, %rcx
xorpd %xmm1, %xmm1
xorl %edi, %edi
xorl %r13d, %r13d
cmpl $0x0, -0x10(%rcx,%rdi)
js 0x177198
incq %r13
movsd (%rcx,%rdi), %xmm2
ucomisd %xmm1, %xmm2
ja 0x17719c
movapd %xmm1, %xmm2
addq $0x20, %rdi
movapd %xmm2, %xmm1
cmpq %rdi, %rbp
jne 0x177183
jmp 0x1771b2
xorpd %xmm2, %xmm2
xorl %r13d, %r13d
testq %r13, %r13
je 0x177264
movsd 0x18(%r14,%r15), %xmm1
cmpq $0x0, 0x8(%rsp)
jne 0x1771de
cmpq $0x1, %r13
je 0x1771de
mulsd %xmm0, %xmm2
ucomisd %xmm2, %xmm1
ja 0x17726e
testq %rbx, %rbx
je 0x177220
shlq $0x5, %rbx
leaq (%r14,%r12), %rcx
addq $0x18, %rcx
xorpd %xmm3, %xmm3
xorl %edi, %edi
xorl %r14d, %r14d
cmpl $0x0, -0x10(%rcx,%rdi)
js 0x17720d
incq %r14
movsd (%rcx,%rdi), %xmm2
ucomisd %xmm3, %xmm2
ja 0x177211
movapd %xmm3, %xmm2
addq $0x20, %rdi
movapd %xmm2, %xmm3
cmpq %rdi, %rbx
jne 0x1771f8
jmp 0x177227
xorpd %xmm2, %xmm2
xorl %r14d, %r14d
testq %r14, %r14
je 0x177264
cmpq $0x0, 0x8(%rsp)
jne 0x177244
cmpq $0x1, %r14
je 0x177244
mulsd %xmm0, %xmm2
ucomisd %xmm2, %xmm1
ja 0x17726e
xorq $0x1, %r14
xorq $0x1, %r13
orq %r14, %r13
je 0x177264
movl 0x4(%rsp), %ecx
orl $0x80000000, %ecx       # imm = 0x80000000
movl %ecx, 0x8(%r11)
orb $-0x80, 0xb(%r10)
movq $-0x1, (%r9)
incq %r8
incq %rax
cmpq %rdx, %rax
jne 0x1770c3
testq %r8, %r8
je 0x1772a9
xorl %eax, %eax
movq %rsi, %rcx
cmpq $-0x1, (%rcx)
je 0x17729e
leaq 0x1(%rax), %rdi
shlq $0x4, %rax
movupd (%rcx), %xmm0
movupd %xmm0, (%rsi,%rax)
movq %rdi, %rax
addq $0x10, %rcx
decq %rdx
jne 0x177284
jmp 0x1772ac
movq %rdx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xba7ff(%rip), %rdi     # 0x231ac1
leaq 0xba312(%rip), %rsi     # 0x2315db
leaq 0xba806(%rip), %rcx     # 0x231ad6
movl $0xfe2, %edx            # imm = 0xFE2
callq 0x2110