// File: /workspace/github_c_makefile_star2_O1/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, 0x38(%rsp)
movl %esi, 0x4(%rsp)
cmpq $0x0, (%rdi)
movq %rdi, 0x18(%rsp)
je 0x118bd
xorl %ebx, %ebx
movl $0x2, %r14d
xorl %r15d, %r15d
xorl %r13d, %r13d
xorl %edx, %edx
xorl %eax, %eax
movq 0x10(%rdi), %r12
movl (%r12,%rbx), %ecx
testl %ecx, %ecx
js 0x118af
cmpq $0x0, 0x20(%r12,%rbx)
je 0x1186d
cmpl (%rsp), %ecx
jge 0x1187d
cmpq $0x0, 0x38(%r12,%rbx)
je 0x11872
jmp 0x1187d
cmpl (%rsp), %ecx
jge 0x1187d
movl 0x14(%rsp), %ecx
cmpl %ecx, 0x4(%r12,%rbx)
jl 0x118af
cmpq %rdx, %r13
jne 0x118a5
leaq (%rdx,%rdx), %rbp
testq %rdx, %rdx
cmoveq %r14, %rbp
leaq (,%rbp,8), %rsi
movq %rax, %rdi
callq 0x21d0
movq 0x18(%rsp), %rdi
movq %rbp, %rdx
addq %rbx, %r12
movq %r12, (%rax,%r13,8)
incq %r13
incq %r15
addq $0x68, %rbx
cmpq %r15, (%rdi)
ja 0x1184a
jmp 0x118c2
xorl %eax, %eax
xorl %r13d, %r13d
movq %r13, %rdi
movq %rax, 0x20(%rsp)
movq %rax, %rsi
callq 0x10791
decl %r13d
js 0x11ac0
movslq 0x4(%rsp), %rbx
movl %r13d, %ecx
xorl %r13d, %r13d
movq 0x18(%rsp), %r8
movq 0x20(%rsp), %rax
movq %rcx, 0x28(%rsp)
movq (%rax,%rcx,8), %rax
movq %rax, 0x40(%rsp)
leaq 0x20(%rax), %rdx
xorl %r14d, %r14d
movq %rdx, 0x30(%rsp)
leaq (%r14,%r14,2), %rcx
movq (%rdx,%rcx,8), %rax
testq %rax, %rax
je 0x11a94
leaq (%rdx,%rcx,8), %r15
movq 0x10(%r15), %rdx
addq $0x8, %rdx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
xorl %esi, %esi
movl 0x4(%rsp), %edi
movl %edi, %ebp
movslq %ebp, %rbp
movq (%rdx), %rdi
cmpq %rbp, %rdi
cmoval %edi, %ebp
cmoval %esi, %ecx
incq %rsi
addq $0x10, %rdx
cmpq %rsi, %rax
jne 0x11934
testl %ecx, %ecx
js 0x119e6
movq %r13, 0x8(%rsp)
movq %rbx, %r13
movq 0x20(%r8), %r12
movq 0x10(%r15), %rax
movl %ecx, %ecx
shlq $0x4, %rcx
movq (%rax,%rcx), %rsi
movq %r12, %rdi
movq %r8, %rbx
callq 0xc8d4
cmpl (%r12), %eax
je 0x11b15
movq 0x20(%r12), %rcx
movl %eax, %eax
movq (%rcx,%rax,8), %rcx
movq 0x10(%rbx), %rax
shrq %rcx
imulq $0x68, %rcx, %rdx
movl (%rax,%rdx), %ecx
testl %ecx, %ecx
movq %rbx, %r8
js 0x119c6
addq %rdx, %rax
cmpq $0x0, 0x20(%rax)
movq %r13, %rbx
je 0x119d0
cmpl (%rsp), %ecx
movq 0x8(%rsp), %r13
jge 0x119e6
cmpq $0x0, 0x38(%rax)
je 0x119da
jmp 0x119e6
movq %r13, %rbx
movq 0x8(%rsp), %r13
jmp 0x119e6
cmpl (%rsp), %ecx
movq 0x8(%rsp), %r13
jge 0x119e6
movl 0x14(%rsp), %ecx
cmpl %ecx, 0x4(%rax)
cmovll 0x4(%rsp), %ebp
cmpq $0x0, (%r15)
je 0x11a94
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
movsd %xmm0, 0x8(%rsp)
movl $0x8, %r12d
xorl %ebp, %ebp
movq 0x10(%r15), %rax
movq -0x8(%rax,%r12), %rsi
cmpq $-0x2, %rsi
je 0x11a84
movq (%rax,%r12), %rax
testq %rax, %rax
je 0x11a84
cmpq %rbx, %rax
jb 0x11a55
movq %rax, %xmm0
punpckldq 0x5951(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x5959(%rip), %xmm0     # 0x17390
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
divsd 0x8(%rsp), %xmm1
movsd 0x38(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x11a84
movq 0x40(%rsp), %rax
movq 0x10(%rax,%r14,8), %rdx
movq %r8, %rdi
callq 0xfa58
movq 0x18(%rsp), %r8
movq 0x10(%r15), %rax
movq $-0x2, -0x8(%rax,%r12)
movq $0x0, (%rax,%r12)
incq %r13
incq %rbp
addq $0x10, %r12
cmpq %rbp, (%r15)
ja 0x11a05
leaq 0x1(%r14), %rax
testq %r14, %r14
movq %rax, %r14
movq 0x30(%rsp), %rdx
je 0x1190a
movq 0x28(%rsp), %rcx
leaq -0x1(%rcx), %rax
testq %rcx, %rcx
movq %rax, %rcx
jg 0x118eb
jmp 0x11ac3
xorl %r13d, %r13d
movq 0x20(%rsp), %rdi
callq 0x2040
cmpl $0x3, 0xb79c(%rip)      # 0x1d270
jge 0x11ae5
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xb50c(%rip), %rax      # 0x1cff8
movq (%rax), %rdi
leaq 0x61e1(%rip), %rsi      # 0x17cd7
leaq 0x61f5(%rip), %rdx      # 0x17cf2
movq %r13, %rcx
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2160
leaq 0x58a3(%rip), %rdi      # 0x173bf
leaq 0x5fb8(%rip), %rsi      # 0x17adb
leaq 0x623e(%rip), %rcx      # 0x17d68
movl $0x70, %edx
callq 0x20e0