// File: /workspace/github_c_makefile_star2_O3/lh3[P]fermi-lite/mag.c
// Function: mag_g_rm_edge
void mag_g_rm_edge(mag_t *g, int min_ovlp, double min_ratio, int min_len, int min_nsr)
{
	int i, j, k;
	kvec_t(magv_p) a = {0,0,0};
	uint64_t n_marked = 0;

	for (i = 0; i < g->v.n; ++i) {
		magv_t *p = &g->v.a[i];
		if (p->len < 0) continue;
		if ((p->nei[0].n == 0 || p->nei[1].n == 0) && p->len < min_len && p->nsr < min_nsr)
			continue; // skip tips
		kv_push(magv_p, a, p);
	}
	ks_introsort(vlt1, a.n, a.a);

	for (i = a.n - 1; i >= 0; --i) {
		magv_t *p = a.a[i];
		for (j = 0; j < 2; ++j) {
			ku128_v *r = &p->nei[j];
			int max_ovlp = min_ovlp, max_k = -1;
			if (r->n == 0) continue; // no overlapping reads
			for (k = 0; k < r->n; ++k) // get the max overlap length
				if (max_ovlp < r->a[k].y)
					max_ovlp = r->a[k].y, max_k = k;
			if (max_k >= 0) { // test if max_k is a tip
				uint64_t x = tid2idd(g->h, r->a[max_k].x);
				magv_t *q = &g->v.a[x>>1];
				if (q->len >= 0 && (q->nei[0].n == 0 || q->nei[1].n == 0) && q->len < min_len && q->nsr < min_nsr)
					max_ovlp = min_ovlp;
			}
			for (k = 0; k < r->n; ++k) {
				if (edge_is_del(r->a[k])) continue;
				if (r->a[k].y < min_ovlp || (double)r->a[k].y / max_ovlp < min_ratio) {
					mag_eh_markdel(g, r->a[k].x, p->k[j]); // FIXME: should we check if r->a[k] is p itself?
					edge_mark_del(r->a[k]);
					++n_marked;
				}
			}
		}
	}
	free(a.a);
	if (fm_verbose >= 3)
		fprintf(stderr, "[M::%s] removed %ld edges\n", __func__, (long)n_marked);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %ecx, 0x14(%rsp)
movl %edx, 0xc(%rsp)
movsd %xmm0, 0x48(%rsp)
movl %esi, 0x10(%rsp)
movq (%rdi), %rdx
testq %rdx, %rdx
je 0x12118
xorl %ebx, %ebx
movl $0x2, %r14d
xorl %r15d, %r15d
xorl %r13d, %r13d
xorl %r12d, %r12d
xorl %eax, %eax
movq %rdi, 0x28(%rsp)
movq 0x10(%rdi), %rbp
movl (%rbp,%rbx), %ecx
testl %ecx, %ecx
js 0x11f0a
cmpq $0x0, 0x20(%rbp,%rbx)
je 0x11ec4
cmpl 0xc(%rsp), %ecx
jge 0x11ed4
cmpq $0x0, 0x38(%rbp,%rbx)
je 0x11eca
jmp 0x11ed4
cmpl 0xc(%rsp), %ecx
jge 0x11ed4
movl 0x14(%rsp), %ecx
cmpl %ecx, 0x4(%rbp,%rbx)
jl 0x11f0a
cmpq %r12, %r13
jne 0x11f00
leaq (,%r13,2), %r12
testq %r13, %r13
cmoveq %r14, %r12
movq %rax, %rdi
leaq (,%r12,8), %rsi
callq 0x21c0
movq 0x28(%rsp), %rdi
movq (%rdi), %rdx
addq %rbx, %rbp
movq %rbp, (%rax,%r13,8)
incq %r13
incq %r15
addq $0x68, %rbx
cmpq %r15, %rdx
ja 0x11ea0
movq %r13, %rdi
movq %rax, 0x20(%rsp)
movq %rax, %rsi
callq 0x10d90
decl %r13d
js 0x12128
movslq 0x10(%rsp), %rax
movq %rax, 0x60(%rsp)
movl %r13d, %eax
xorl %r12d, %r12d
movq 0x20(%rsp), %rdi
movq 0x28(%rsp), %r8
movq %rax, 0x38(%rsp)
movq (%rdi,%rax,8), %rax
movq %rax, 0x50(%rsp)
leaq 0x20(%rax), %rcx
movb $0x1, %dil
xorl %edx, %edx
movq %rcx, 0x40(%rsp)
leaq (%rdx,%rdx,2), %rax
movq (%rcx,%rax,8), %r14
testq %r14, %r14
movl %edi, 0x34(%rsp)
je 0x120e5
movq %rdx, 0x58(%rsp)
leaq (%rcx,%rax,8), %r15
movq 0x10(%r15), %rbp
leaq 0x8(%rbp), %rcx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
xorl %edx, %edx
movl 0x10(%rsp), %esi
movl %esi, %r13d
movslq %r13d, %r13
movq (%rcx), %rsi
cmpq %r13, %rsi
cmoval %esi, %r13d
cmoval %edx, %eax
incq %rdx
addq $0x10, %rcx
cmpq %rdx, %r14
jne 0x11f99
testl %eax, %eax
js 0x12038
movq %r12, 0x18(%rsp)
movq 0x20(%r8), %rbx
movl %eax, %eax
shlq $0x4, %rax
movq (%rbp,%rax), %rsi
movq %rbx, %rdi
movq %r8, %r12
callq 0xce10
cmpl (%rbx), %eax
je 0x1217d
movq 0x20(%rbx), %rcx
movl %eax, %eax
movq (%rcx,%rax,8), %rcx
movq 0x10(%r12), %rax
shrq %rcx
imulq $0x68, %rcx, %rdx
movl (%rax,%rdx), %ecx
testl %ecx, %ecx
movq %r12, %r8
js 0x1201e
addq %rdx, %rax
cmpq $0x0, 0x20(%rax)
movq 0x18(%rsp), %r12
je 0x12025
cmpl 0xc(%rsp), %ecx
jge 0x12038
cmpq $0x0, 0x38(%rax)
je 0x1202b
jmp 0x12038
movq 0x18(%rsp), %r12
jmp 0x12038
cmpl 0xc(%rsp), %ecx
jge 0x12038
movl 0x14(%rsp), %ecx
cmpl %ecx, 0x4(%rax)
cmovll 0x10(%rsp), %r13d
xorps %xmm0, %xmm0
cvtsi2sd %r13d, %xmm0
movsd %xmm0, 0x18(%rsp)
movl $0x8, %ebx
xorl %r13d, %r13d
movq -0x8(%rbp,%rbx), %rsi
cmpq $-0x2, %rsi
je 0x120d5
movq (%rbp,%rbx), %rax
testq %rax, %rax
je 0x120d5
cmpq 0x60(%rsp), %rax
jb 0x1209d
movq %rax, %xmm0
punpckldq 0x5309(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x5311(%rip), %xmm0     # 0x17390
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
divsd 0x18(%rsp), %xmm1
movsd 0x48(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x120d5
movq 0x50(%rsp), %rax
movq 0x58(%rsp), %rcx
movq 0x10(%rax,%rcx,8), %rdx
movq %r8, %rdi
callq 0x1001a
movq 0x28(%rsp), %r8
movq 0x10(%r15), %rbp
movq $-0x2, -0x8(%rbp,%rbx)
movq $0x0, (%rbp,%rbx)
incq %r12
movq (%r15), %r14
incq %r13
addq $0x10, %rbx
cmpq %r13, %r14
ja 0x1204e
movl $0x1, %edx
testb $0x1, 0x34(%rsp)
movl $0x0, %edi
movq 0x40(%rsp), %rcx
jne 0x11f65
movq 0x38(%rsp), %rcx
leaq -0x1(%rcx), %rax
testq %rcx, %rcx
movq 0x20(%rsp), %rdi
jg 0x11f49
jmp 0x12130
xorl %edi, %edi
xorl %esi, %esi
callq 0x10d90
xorl %edi, %edi
xorl %r12d, %r12d
jmp 0x12130
xorl %r12d, %r12d
movq 0x20(%rsp), %rdi
callq 0x2040
cmpl $0x3, 0xb134(%rip)      # 0x1d270
jge 0x1214d
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xaea4(%rip), %rax      # 0x1cff8
movq (%rax), %rdi
leaq 0x5c09(%rip), %rsi      # 0x17d67
leaq 0x5c1d(%rip), %rdx      # 0x17d82
movq %r12, %rcx
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2150
leaq 0x523b(%rip), %rdi      # 0x173bf
leaq 0x59e0(%rip), %rsi      # 0x17b6b
leaq 0x5c66(%rip), %rcx      # 0x17df8
movl $0x70, %edx
callq 0x20e0