// File: /workspace/github_c_makefile_star2_O2/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 $0x48, %rsp
movl %ecx, 0x14(%rsp)
movl %edx, (%rsp)
movsd %xmm0, 0x30(%rsp)
movl %esi, 0x4(%rsp)
xorl %ebx, %ebx
pushq $0x2
popq %r14
xorl %r12d, %r12d
movq $0x0, 0x8(%rsp)
xorl %edx, %edx
xorl %r13d, %r13d
movq %rdi, 0x18(%rsp)
cmpq %r12, (%rdi)
jbe 0xf725
movq 0x10(%rdi), %r15
movl (%r15,%rbx), %ecx
testl %ecx, %ecx
js 0xf719
cmpq $0x0, 0x20(%r15,%rbx)
je 0xf6c9
cmpl (%rsp), %ecx
jge 0xf6d9
cmpq $0x0, 0x38(%r15,%rbx)
je 0xf6ce
jmp 0xf6d9
cmpl (%rsp), %ecx
jge 0xf6d9
movl 0x14(%rsp), %ecx
cmpl %ecx, 0x4(%r15,%rbx)
jl 0xf719
cmpq %rdx, %r13
jne 0xf705
leaq (%rdx,%rdx), %rbp
testq %rdx, %rdx
cmoveq %r14, %rbp
leaq (,%rbp,8), %rsi
movq 0x8(%rsp), %rdi
callq 0x21c0
movq 0x18(%rsp), %rdi
movq %rbp, %rdx
jmp 0xf70a
movq 0x8(%rsp), %rax
addq %rbx, %r15
movq %rax, 0x8(%rsp)
movq %r15, (%rax,%r13,8)
incq %r13
incq %r12
addq $0x68, %rbx
jmp 0xf6a1
movq %r13, %rdi
movq 0x8(%rsp), %rbx
movq %rbx, %rsi
callq 0xe716
movslq 0x4(%rsp), %r12
movl %r13d, %eax
xorl %r13d, %r13d
decq %rax
testl %eax, %eax
js 0xf8dc
movq %rax, 0x20(%rsp)
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq (%rbx,%rax,8), %rax
movq %rax, 0x40(%rsp)
leaq 0x20(%rax), %rcx
xorl %r14d, %r14d
movq %rcx, 0x28(%rsp)
cmpq $0x2, %r14
je 0xf8cd
imulq $0x18, %r14, %rbx
movq (%rcx,%rbx), %rax
testq %rax, %rax
je 0xf8b7
addq %rcx, %rbx
movq 0x10(%rbx), %rcx
addq $0x8, %rcx
xorl %esi, %esi
movl 0x4(%rsp), %edx
movl %edx, %r15d
pushq $-0x1
popq %rdx
cmpq %rsi, %rax
je 0xf7ba
movslq %r15d, %r15
movq (%rcx), %rdi
cmpq %r15, %rdi
cmoval %edi, %r15d
cmoval %esi, %edx
incq %rsi
addq $0x10, %rcx
jmp 0xf79c
testl %edx, %edx
js 0xf813
movq 0x18(%rsp), %rbp
movq 0x20(%rbp), %rdi
movq 0x10(%rbx), %rax
movl %edx, %ecx
shlq $0x4, %rcx
movq (%rax,%rcx), %rsi
callq 0xd0f6
movq 0x10(%rbp), %rcx
shrq %rax
imulq $0x68, %rax, %rdx
movl (%rcx,%rdx), %eax
testl %eax, %eax
js 0xf813
addq %rdx, %rcx
cmpq $0x0, 0x20(%rcx)
je 0xf8bf
cmpl (%rsp), %eax
jge 0xf813
cmpq $0x0, 0x38(%rcx)
jne 0xf813
movl 0x14(%rsp), %eax
cmpl %eax, 0x4(%rcx)
cmovll 0x4(%rsp), %r15d
cvtsi2sd %r15d, %xmm0
movsd %xmm0, 0x38(%rsp)
pushq $0x8
popq %r15
xorl %ebp, %ebp
cmpq %rbp, (%rbx)
jbe 0xf8b2
movq 0x10(%rbx), %rax
movq -0x8(%rax,%r15), %rsi
cmpq $-0x2, %rsi
je 0xf8a6
movq (%rax,%r15), %rax
testq %rax, %rax
je 0xf8a6
cmpq %r12, %rax
jb 0xf87d
movq %rax, %xmm0
punpckldq 0x4b29(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x4b31(%rip), %xmm0     # 0x14390
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
divsd 0x38(%rsp), %xmm1
movsd 0x30(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0xf8a6
movq 0x40(%rsp), %rax
movq 0x10(%rax,%r14,8), %rdx
movq 0x18(%rsp), %rdi
callq 0xdb4b
movq 0x10(%rbx), %rax
movq $-0x2, -0x8(%rax,%r15)
andq $0x0, (%rax,%r15)
incq %r13
incq %rbp
addq $0x10, %r15
jmp 0xf824
movq 0x28(%rsp), %rcx
incq %r14
jmp 0xf76a
cmpl (%rsp), %eax
jl 0xf806
jmp 0xf813
movq 0x8(%rsp), %rbx
movq 0x20(%rsp), %rax
jmp 0xf740
movq %rbx, %rdi
callq 0x2040
cmpl $0x3, 0xb985(%rip)      # 0x1b270
jge 0xf8fc
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xb6f5(%rip), %rax      # 0x1aff8
movq (%rax), %rdi
leaq 0x540a(%rip), %rsi      # 0x14d17
leaq 0x541e(%rip), %rdx      # 0x14d32
movq %r13, %rcx
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2150