// File: /workspace/github_c_makefile_star2_O0/lh3[P]fermi-lite/bubble.c
// Function: mag_v_pop_open
void mag_v_pop_open(mag_t *g, magv_t *p, int min_elen)
{
	int i, j, k, l, dir, max_l, l_qry;
	magv_t *q, *t;
	ku128_v *r, *s;
	uint8_t *seq;
	int8_t mat[16];

	if (p->len < 0 || p->len >= min_elen) return;
	//if (p->nei[0].n && p->nei[1].n) return; // FIXME: between this and the next line, which is better?
	if (p->nei[0].n + p->nei[1].n != 1) return;
	dir = p->nei[0].n? 0 : 1;
	// initialize the scoring system
	for (i = k = 0; i < 4; ++i)
		for (j = 0; j < 4; ++j)
			mat[k++] = i == j? 5 : -4;
	
	s = &p->nei[dir];
	for (l = 0; l < s->n; ++l) { // if we use "if (p->nei[0].n + p->nei[1].n != 1)", s->n == 1
		uint64_t v;
		kswq_t *qry;
		if ((int64_t)s->a[l].x < 0) continue;
		v = mag_tid2idd(g->h, s->a[l].x);
		q = &g->v.a[v>>1];
		if (q == p || q->nei[v&1].n == 1) continue;
		// get the query ready
		max_l = (p->len - s->a[l].y) * 2;
		seq = malloc(max_l + 1);
		if (dir == 0) { // forward strand
			for (j = s->a[l].y, k = 0; j < p->len; ++j)
				seq[k++] = p->seq[j] - 1;
		} else { // reverse
			for (j = p->len - s->a[l].y - 1, k = 0; j >= 0; --j)
				seq[k++] = 4 - p->seq[j];
		}
		l_qry = k;
		qry = ksw_qinit(2, l_qry, seq, 4, mat);
		//fprintf(stderr, "===> %lld:%lld:%d[%d], %d, %ld <===\n", p->k[0], p->k[1], s->n, l, p->nsr, q->nei[v&1].n);
		//for (j = 0; j < k; ++j) fputc("ACGTN"[(int)seq[j]], stderr); fputc('\n', stderr);

		r = &q->nei[v&1];
		for (i = 0; i < r->n; ++i) {
			uint64_t w;
			kswr_t aln;
			if (r->a[i].x == p->k[dir] || (int64_t)r->a[i].x < 0) continue;
			w = mag_tid2idd(g->h, r->a[i].x);
			// get the target sequence
			t = &g->v.a[w>>1];
			if (w&1) { // reverse strand
				for (j = t->len - r->a[i].y - 1, k = 0; j >= 0 && k < max_l; --j)
					seq[k++] = 4 - t->seq[j];
			} else {
				for (j = r->a[i].y, k = 0; j < t->len && k < max_l; ++j)
					seq[k++] = t->seq[j] - 1;
			}
			aln = ksw_align(0, 0, k, seq, 4, mat, 5, 2, 0, &qry);
			//for (j = 0; j < k; ++j) fputc("ACGTN"[(int)seq[j]], stderr); fprintf(stderr, "\t%d\t%f\n", aln.score, (l_qry * 5. - aln.score) / (5. + 4.));
			if (aln.score >= l_qry * 5 / 2) {
				double r_diff, n_diff;
				n_diff = (l_qry * 5. - aln.score) / (5. + 4.); // 5: matching score; -4: mismatchig score
				r_diff = n_diff / l_qry;
				if (n_diff < MAX_N_DIFF || r_diff < MAX_R_DIFF) break;
			}
		}

		if (i != r->n) {
			// mark delete in p and delete in q
			edge_mark_del(s->a[l]);
			for (i = 0; i < r->n; ++i)
				if (r->a[i].x == p->k[dir])
					edge_mark_del(r->a[i]);
		}
		free(seq); free(qry);
	}

	for (i = 0; i < s->n; ++i)
		if (!edge_is_del(s->a[i])) break;
	if (i == s->n) mag_v_del(g, p); // p is not connected to any other vertices
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, (%rax)
jl 0x1df7a
movq -0x10(%rbp), %rax
movl (%rax), %eax
cmpl -0x14(%rbp), %eax
jl 0x1df7f
jmp 0x1e67b
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x10(%rbp), %rcx
addq 0x38(%rcx), %rax
cmpq $0x1, %rax
je 0x1df9a
jmp 0x1e67b
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdx
movl $0x1, %eax
xorl %ecx, %ecx
cmpq $0x0, %rdx
cmovnel %ecx, %eax
movl %eax, -0x28(%rbp)
movl $0x0, -0x20(%rbp)
movl $0x0, -0x18(%rbp)
cmpl $0x4, -0x18(%rbp)
jge 0x1e014
movl $0x0, -0x1c(%rbp)
cmpl $0x4, -0x1c(%rbp)
jge 0x1e007
movl -0x18(%rbp), %edx
movl -0x1c(%rbp), %esi
movl $0xfffffffc, %eax       # imm = 0xFFFFFFFC
movl $0x5, %ecx
cmpl %esi, %edx
cmovel %ecx, %eax
movb %al, %cl
movl -0x20(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x20(%rbp)
cltq
movb %cl, -0x70(%rbp,%rax)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x1dfce
jmp 0x1e009
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x1dfc1
movq -0x10(%rbp), %rax
addq $0x20, %rax
movslq -0x28(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movl $0x0, -0x24(%rbp)
movslq -0x24(%rbp), %rax
movq -0x50(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x1e60b
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x24(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
cmpq $0x0, (%rax)
jge 0x1e061
jmp 0x1e5fd
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x24(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rsi
callq 0x16e30
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, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x10(%rbp), %rax
je 0x1e0c9
movq -0x38(%rbp), %rax
addq $0x20, %rax
movq -0x78(%rbp), %rcx
andq $0x1, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
cmpq $0x1, (%rax)
jne 0x1e0ce
jmp 0x1e5fd
movq -0x10(%rbp), %rax
movslq (%rax), %rax
movq -0x50(%rbp), %rcx
movq 0x10(%rcx), %rcx
movslq -0x24(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
subq 0x8(%rcx), %rax
shlq %rax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rdi
callq 0x21c0
movq %rax, -0x58(%rbp)
cmpl $0x0, -0x28(%rbp)
jne 0x1e16d
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x24(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movl %eax, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
movl -0x1c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x1e16b
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movslq -0x1c(%rbp), %rcx
movsbl (%rax,%rcx), %eax
subl $0x1, %eax
movb %al, %dl
movq -0x58(%rbp), %rax
movl -0x20(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x20(%rbp)
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x1e12b
jmp 0x1e1da
movq -0x10(%rbp), %rax
movslq (%rax), %rax
movq -0x50(%rbp), %rcx
movq 0x10(%rcx), %rcx
movslq -0x24(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
subq 0x8(%rcx), %rax
subq $0x1, %rax
movl %eax, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
cmpl $0x0, -0x1c(%rbp)
jl 0x1e1d8
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movslq -0x1c(%rbp), %rcx
movsbl (%rax,%rcx), %ecx
movl $0x4, %eax
subl %ecx, %eax
movb %al, %dl
movq -0x58(%rbp), %rax
movl -0x20(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x20(%rbp)
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movl -0x1c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x1e199
jmp 0x1e1da
movl -0x20(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %esi
movq -0x58(%rbp), %rdx
leaq -0x70(%rbp), %r8
movl $0x2, %edi
movl $0x4, %ecx
callq 0x1e720
movq %rax, -0x80(%rbp)
movq -0x38(%rbp), %rax
addq $0x20, %rax
movq -0x78(%rbp), %rcx
andq $0x1, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movl $0x0, -0x18(%rbp)
movslq -0x18(%rbp), %rax
movq -0x48(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x1e528
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x18(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq -0x10(%rbp), %rcx
movslq -0x28(%rbp), %rdx
cmpq 0x10(%rcx,%rdx,8), %rax
je 0x1e26f
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x18(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
cmpq $0x0, (%rax)
jge 0x1e274
jmp 0x1e51a
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x18(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rsi
callq 0x16e30
movq %rax, -0x88(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x88(%rbp), %rcx
shrq %rcx
imulq $0x68, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x88(%rbp), %rax
andq $0x1, %rax
cmpq $0x0, %rax
je 0x1e363
movq -0x40(%rbp), %rax
movslq (%rax), %rax
movq -0x48(%rbp), %rcx
movq 0x10(%rcx), %rcx
movslq -0x18(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
subq 0x8(%rcx), %rax
subq $0x1, %rax
movl %eax, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
xorl %eax, %eax
cmpl $0x0, -0x1c(%rbp)
movb %al, -0xd1(%rbp)
jl 0x1e319
movl -0x20(%rbp), %eax
cmpl -0x2c(%rbp), %eax
setl %al
movb %al, -0xd1(%rbp)
movb -0xd1(%rbp), %al
testb $0x1, %al
jne 0x1e325
jmp 0x1e35e
movq -0x40(%rbp), %rax
movq 0x50(%rax), %rax
movslq -0x1c(%rbp), %rcx
movsbl (%rax,%rcx), %ecx
movl $0x4, %eax
subl %ecx, %eax
movb %al, %dl
movq -0x58(%rbp), %rax
movl -0x20(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x20(%rbp)
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movl -0x1c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x1e2fc
jmp 0x1e3e9
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x18(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movl %eax, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
movl -0x1c(%rbp), %ecx
movq -0x40(%rbp), %rdx
xorl %eax, %eax
cmpl (%rdx), %ecx
movb %al, -0xd2(%rbp)
jge 0x1e3a6
movl -0x20(%rbp), %eax
cmpl -0x2c(%rbp), %eax
setl %al
movb %al, -0xd2(%rbp)
movb -0xd2(%rbp), %al
testb $0x1, %al
jne 0x1e3b2
jmp 0x1e3e7
movq -0x40(%rbp), %rax
movq 0x50(%rax), %rax
movslq -0x1c(%rbp), %rcx
movsbl (%rax,%rcx), %eax
subl $0x1, %eax
movb %al, %dl
movq -0x58(%rbp), %rax
movl -0x20(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x20(%rbp)
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x1e384
jmp 0x1e3e9
movl -0x20(%rbp), %ecx
movq -0x58(%rbp), %r8
leaq -0x70(%rbp), %r10
leaq -0xc0(%rbp), %rdi
xorl %esi, %esi
xorl %eax, %eax
movl %eax, %edx
movl $0x4, %r9d
leaq -0x80(%rbp), %rax
movq %r10, (%rsp)
movl $0x5, 0x8(%rsp)
movl $0x2, 0x10(%rsp)
movl $0x0, 0x18(%rsp)
movq %rax, 0x20(%rsp)
callq 0x20b50
movq -0xc0(%rbp), %rax
movq %rax, -0xa4(%rbp)
movq -0xb8(%rbp), %rax
movq %rax, -0x9c(%rbp)
movq -0xb0(%rbp), %rax
movq %rax, -0x94(%rbp)
movl -0xa8(%rbp), %eax
movl %eax, -0x8c(%rbp)
movl -0xa4(%rbp), %eax
movl %eax, -0xd8(%rbp)
imull $0x5, -0x30(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0xd8(%rbp), %eax
cmpl %ecx, %eax
jl 0x1e518
cvtsi2sdl -0x30(%rbp), %xmm0
cvtsi2sdl -0xa4(%rbp), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
movsd 0x7835(%rip), %xmm2     # 0x25cf0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd 0x781d(%rip), %xmm1     # 0x25ce8
divsd %xmm1, %xmm0
movsd %xmm0, -0xd0(%rbp)
movsd -0xd0(%rbp), %xmm0
cvtsi2sdl -0x30(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0xc8(%rbp)
movsd 0x77d8(%rip), %xmm0     # 0x25cd0
ucomisd -0xd0(%rbp), %xmm0
ja 0x1e514
movsd 0x6e1e(%rip), %xmm0     # 0x25328
ucomisd -0xc8(%rbp), %xmm0
jbe 0x1e516
jmp 0x1e528
jmp 0x1e518
jmp 0x1e51a
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x1e220
movslq -0x18(%rbp), %rax
movq -0x48(%rbp), %rcx
cmpq (%rcx), %rax
je 0x1e5eb
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x24(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq $-0x2, (%rax)
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x24(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq $0x0, 0x8(%rax)
movl $0x0, -0x18(%rbp)
movslq -0x18(%rbp), %rax
movq -0x48(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x1e5e9
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x18(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq -0x10(%rbp), %rcx
movslq -0x28(%rbp), %rdx
cmpq 0x10(%rcx,%rdx,8), %rax
jne 0x1e5dc
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x18(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq $-0x2, (%rax)
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x18(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq $0x0, 0x8(%rax)
jmp 0x1e5de
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x1e575
jmp 0x1e5eb
movq -0x58(%rbp), %rdi
callq 0x2040
movq -0x80(%rbp), %rdi
callq 0x2040
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x1e032
movl $0x0, -0x18(%rbp)
movslq -0x18(%rbp), %rax
movq -0x50(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x1e661
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x18(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
cmpq $-0x2, (%rax)
je 0x1e654
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x18(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
cmpq $0x0, 0x8(%rax)
je 0x1e654
jmp 0x1e661
jmp 0x1e656
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x1e612
movslq -0x18(%rbp), %rax
movq -0x50(%rbp), %rcx
cmpq (%rcx), %rax
jne 0x1e67b
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x18490
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
nopw %cs:(%rax,%rax)