// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movsd %xmm0, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl %ecx, -0x20(%rbp)
leaq -0x48(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x2110
movq $0x0, -0x50(%rbp)
movl $0x0, -0x24(%rbp)
movslq -0x24(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x1be8d
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x24(%rbp), %rcx
imulq $0x68, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
cmpl $0x0, (%rax)
jge 0x1bde2
jmp 0x1be7f
movq -0x58(%rbp), %rax
cmpq $0x0, 0x20(%rax)
je 0x1bdf8
movq -0x58(%rbp), %rax
cmpq $0x0, 0x38(%rax)
jne 0x1be11
movq -0x58(%rbp), %rax
movl (%rax), %eax
cmpl -0x1c(%rbp), %eax
jge 0x1be11
movq -0x58(%rbp), %rax
movl 0x4(%rax), %eax
cmpl -0x20(%rbp), %eax
jge 0x1be11
jmp 0x1be7f
jmp 0x1be13
movq -0x48(%rbp), %rax
cmpq -0x40(%rbp), %rax
jne 0x1be62
cmpq $0x0, -0x40(%rbp)
je 0x1be34
movq -0x40(%rbp), %rax
shlq %rax
movq %rax, -0x88(%rbp)
jmp 0x1be42
movl $0x2, %eax
movq %rax, -0x88(%rbp)
jmp 0x1be42
movq -0x88(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rdi
movq -0x40(%rbp), %rsi
shlq $0x3, %rsi
callq 0x21e0
movq %rax, -0x38(%rbp)
movq -0x58(%rbp), %rdx
movq -0x38(%rbp), %rax
movq -0x48(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x48(%rbp)
movq %rdx, (%rax,%rcx,8)
jmp 0x1be7f
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x1bdac
movq -0x48(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x19b90
movq -0x48(%rbp), %rax
subq $0x1, %rax
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jl 0x1c13f
movq -0x38(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x60(%rbp)
movl $0x0, -0x28(%rbp)
cmpl $0x2, -0x28(%rbp)
jge 0x1c12f
movq -0x60(%rbp), %rax
addq $0x20, %rax
movslq -0x28(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x6c(%rbp)
movl $0xffffffff, -0x70(%rbp) # imm = 0xFFFFFFFF
movq -0x68(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x1bf03
jmp 0x1c121
movl $0x0, -0x2c(%rbp)
movslq -0x2c(%rbp), %rax
movq -0x68(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x1bf61
movslq -0x6c(%rbp), %rax
movq -0x68(%rbp), %rcx
movq 0x10(%rcx), %rcx
movslq -0x2c(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
cmpq 0x8(%rcx), %rax
jae 0x1bf54
movq -0x68(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x2c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movl %eax, -0x6c(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, -0x70(%rbp)
jmp 0x1bf56
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x1bf0a
cmpl $0x0, -0x70(%rbp)
jl 0x1bfe6
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x68(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x70(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rsi
callq 0x16e60
movq %rax, -0x78(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x78(%rbp), %rcx
shrq %rcx
imulq $0x68, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
cmpl $0x0, (%rax)
jl 0x1bfe4
movq -0x80(%rbp), %rax
cmpq $0x0, 0x20(%rax)
je 0x1bfc7
movq -0x80(%rbp), %rax
cmpq $0x0, 0x38(%rax)
jne 0x1bfe4
movq -0x80(%rbp), %rax
movl (%rax), %eax
cmpl -0x1c(%rbp), %eax
jge 0x1bfe4
movq -0x80(%rbp), %rax
movl 0x4(%rax), %eax
cmpl -0x20(%rbp), %eax
jge 0x1bfe4
movl -0xc(%rbp), %eax
movl %eax, -0x6c(%rbp)
jmp 0x1bfe6
movl $0x0, -0x2c(%rbp)
movslq -0x2c(%rbp), %rax
movq -0x68(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x1c11f
movq -0x68(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x2c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
cmpq $-0x2, (%rax)
je 0x1c031
movq -0x68(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x2c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
cmpq $0x0, 0x8(%rax)
jne 0x1c036
jmp 0x1c111
movq -0x68(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x2c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movslq -0xc(%rbp), %rcx
cmpq %rcx, %rax
jb 0x1c0a2
movq -0x68(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x2c(%rbp), %rcx
shlq $0x4, %rcx
movq 0x8(%rax,%rcx), %xmm1
movaps 0x92bd(%rip), %xmm0     # 0x25330
punpckldq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
movapd 0x92c1(%rip), %xmm0     # 0x25340
subpd %xmm0, %xmm1
movaps %xmm1, %xmm0
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm0, %xmm1
cvtsi2sdl -0x6c(%rbp), %xmm0
divsd %xmm0, %xmm1
movsd -0x18(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x1c10f
movq -0x8(%rbp), %rdi
movq -0x68(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x2c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rsi
movq -0x60(%rbp), %rax
movslq -0x28(%rbp), %rcx
movq 0x10(%rax,%rcx,8), %rdx
callq 0x183b0
movq -0x68(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x2c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq $-0x2, (%rax)
movq -0x68(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x2c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq $0x0, 0x8(%rax)
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x1c111
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x1bfed
jmp 0x1c121
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x1bec6
jmp 0x1c131
movl -0x24(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x1bea5
movq -0x38(%rbp), %rdi
callq 0x2040
cmpl $0x3, 0xe161(%rip)      # 0x2a2b0
jl 0x1c174
movq 0xdea0(%rip), %rax      # 0x29ff8
movq (%rax), %rdi
movq -0x50(%rbp), %rcx
leaq 0x9aa5(%rip), %rsi      # 0x25c0b
leaq 0x9ab9(%rip), %rdx      # 0x25c26
movb $0x0, %al
callq 0x2170
addq $0x90, %rsp
popq %rbp
retq
nopl (%rax)