// File: /workspace/github_cpp_makefile_star2_O2/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 $0x28, %rsp
movq %rcx, 0x8(%rsp)
xorl %r11d, %r11d
xorl %ebx, %ebx
movq %rdi, 0x10(%rsp)
cmpq %rdx, %rbx
je 0x13b1ad
movq %rbx, %r9
shlq $0x4, %r9
movq (%rsi,%r9), %r12
cmpq $-0x1, %r12
je 0x13b1a2
addq %rsi, %r9
movq (%rdi), %rcx
movq 0x8(%rcx), %r15
shlq $0x5, %r12
cmpl $0x0, 0x8(%r15,%r12)
js 0x13b04c
leaq (%r15,%r12), %r8
movl (%r8), %eax
movq %r8, 0x20(%rsp)
movl 0x4(%r8), %r8d
movq 0x20(%rcx), %r10
movq (%r10,%r8,8), %rcx
movl %ecx, %ebp
movq (%r10,%rax,8), %r13
movl %r13d, %r14d
cmpq $0x1, %rbp
ja 0x13b055
cmpl $0x1, %r14d
ja 0x13b055
orq $-0x1, (%r9)
jmp 0x13b1a2
movq %rbx, 0x18(%rsp)
movq %r11, (%rsp)
shrq $0x20, %rcx
shrq $0x20, %r13
shlq $0x5, %r14
leaq 0x20(%r14), %r10
shlq $0x5, %r13
leaq (%r15,%r13), %r11
addq $-0x18, %r11
xorl %ebx, %ebx
leaq 0x20(%rbx), %rax
cmpq %rax, %r10
je 0x13b1f2
cmpl %r8d, 0x18(%r11,%rbx)
movq %rax, %rbx
jne 0x13b07c
leaq (%r15,%r13), %rdi
movl -0x18(%rax,%rdi), %r10d
testl %r10d, %r10d
js 0x13b1f2
movsd 0x18(%r15,%r12), %xmm1
shlq $0x5, %rbp
shlq $0x5, %rcx
addq %r15, %rcx
addq $0x18, %rcx
xorpd %xmm2, %xmm2
xorl %r8d, %r8d
xorl %r12d, %r12d
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rbx
cmpq %r8, %rbp
je 0x13b0f9
cmpl $0x0, -0x10(%rcx,%r8)
js 0x13b0eb
incq %r12
movsd (%rcx,%r8), %xmm3
ucomisd %xmm2, %xmm3
ja 0x13b0ef
movapd %xmm2, %xmm3
addq $0x20, %r8
movapd %xmm3, %xmm2
jmp 0x13b0cf
testq %r12, %r12
je 0x13b19a
cmpq $0x0, 0x8(%rsp)
jne 0x13b11a
cmpq $0x1, %r12
je 0x13b11a
mulsd %xmm0, %xmm2
ucomisd %xmm2, %xmm1
ja 0x13b173
leaq (%r15,%r13), %rcx
addq $0x18, %rcx
xorpd %xmm2, %xmm2
xorl %r8d, %r8d
xorl %r15d, %r15d
cmpq %r8, %r14
je 0x13b156
cmpl $0x0, -0x10(%rcx,%r8)
js 0x13b148
incq %r15
movsd (%rcx,%r8), %xmm3
ucomisd %xmm2, %xmm3
ja 0x13b14c
movapd %xmm2, %xmm3
addq $0x20, %r8
movapd %xmm3, %xmm2
jmp 0x13b12c
testq %r15, %r15
je 0x13b19a
cmpq $0x0, 0x8(%rsp)
jne 0x13b179
cmpq $0x1, %r15
je 0x13b179
mulsd %xmm0, %xmm2
ucomisd %xmm2, %xmm1
jbe 0x13b179
movq (%rsp), %r11
jmp 0x13b1a5
xorq $0x1, %r15
xorq $0x1, %r12
orq %r15, %r12
je 0x13b19a
orl $0x80000000, %r10d      # imm = 0x80000000
movl %r10d, (%r11,%rax)
movq 0x20(%rsp), %rax
orb $-0x80, 0xb(%rax)
orq $-0x1, (%r9)
movq (%rsp), %r11
incq %r11
incq %rbx
jmp 0x13afeb
testq %r11, %r11
je 0x13b1e0
xorl %eax, %eax
movq %rsi, %rcx
subq $0x1, %rdx
jb 0x13b1dd
cmpq $-0x1, (%rcx)
je 0x13b1d7
leaq 0x1(%rax), %rdi
shlq $0x4, %rax
movupd (%rcx), %xmm0
movupd %xmm0, (%rsi,%rax)
movq %rdi, %rax
addq $0x10, %rcx
jmp 0x13b1b7
movq %rax, %rdx
movq %rdx, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xb49d8(%rip), %rdi     # 0x1efbd1
leaq 0xb44eb(%rip), %rsi     # 0x1ef6eb
leaq 0xb49df(%rip), %rcx     # 0x1efbe6
movl $0xfe2, %edx            # imm = 0xFE2
callq 0x2110