// File: /workspace/github_c_makefile_star2_O2/lh3[P]fermi-lite/mag.c
// Function: mag_vh_merge_try
int mag_vh_merge_try(mag_t *g, magv_t *p, int min_merge_len) // merge p's neighbor to the right-end of p
{
	magv_t *q;
	khint_t kp, kq;
	int i, j, new_l;
	hash64_t *h = (hash64_t*)g->h;

	// check if an unambiguous merge can be performed
	if (p->nei[1].n != 1) return -1; // multiple or no neighbor; do not merge
	if ((int64_t)p->nei[1].a[0].x < 0) return -2; // deleted neighbor
	if ((int)p->nei[1].a[0].y < min_merge_len) return -5;
	kq = kh_get(64, g->h, p->nei[1].a[0].x);
	assert(kq != kh_end(h)); // otherwise the neighbor is non-existant
	q = &g->v.a[kh_val((hash64_t*)g->h, kq)>>1];
	if (p == q) return -3; // we have a loop p->p. We cannot merge in this case
	if (q->nei[kh_val(h, kq)&1].n != 1) return -4; // the neighbor q has multiple neighbors. cannot be an unambiguous merge

	// we can perform a merge; do further consistency check (mostly check bugs)
	if (kh_val(h, kq)&1) mag_v_flip(g, q); // a "><" bidirectional arc; flip q
	kp = kh_get(64, g->h, p->k[1]); assert(kp != kh_end(h)); // get the iterator to p
	kh_del(64, g->h, kp); kh_del(64, g->h, kq); // remove the two ends of the arc in the hash table
	assert(p->k[1] == q->nei[0].a[0].x && q->k[0] == p->nei[1].a[0].x); // otherwise inconsistent topology
	assert(p->nei[1].a[0].y == q->nei[0].a[0].y); // the overlap length must be the same
	assert(p->len >= p->nei[1].a[0].y && q->len >= p->nei[1].a[0].y); // and the overlap is shorter than both vertices

	// update the read count and sequence length
	p->nsr += q->nsr;
	new_l = p->len + q->len - p->nei[1].a[0].y;
	if (new_l + 1 > p->max_len) { // then double p->seq and p->cov
		p->max_len = new_l + 1;
		kroundup32(p->max_len);
		p->seq = realloc(p->seq, p->max_len);
		p->cov = realloc(p->cov, p->max_len);
	}
	// merge seq and cov
	for (i = p->len - p->nei[1].a[0].y, j = 0; j < q->len; ++i, ++j) { // write seq and cov
		p->seq[i] = q->seq[j];
		if (i < p->len) {
			if ((int)p->cov[i] + (q->cov[j] - 33) > 126) p->cov[i] = 126;
			else p->cov[i] += q->cov[j] - 33;
		} else p->cov[i] = q->cov[j];
	}
	p->seq[new_l] = p->cov[new_l] = 0;
	p->len = new_l;
	// merge neighbors
	free(p->nei[1].a);
	p->nei[1] = q->nei[1]; p->k[1] = q->k[1];
	q->nei[1].a = 0; // to avoid freeing p->nei[1] by mag_v_destroy() below
	// update the hash table for the right end of p
	kp = kh_get(64, g->h, p->k[1]);
	assert(kp != kh_end((hash64_t*)g->h));
	kh_val(h, kp) = (p - g->v.a)<<1 | 1;
	// clean up q
	mag_v_destroy(q);
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
cmpq $0x1, 0x38(%rsi)
jne 0xdea7
movq %rsi, %rbx
movq 0x48(%rsi), %rax
movq (%rax), %rsi
testq %rsi, %rsi
js 0xdeae
cmpl %edx, 0x8(%rax)
jge 0xdeb5
pushq $-0x5
jmp 0xe074
pushq $-0x1
jmp 0xe074
pushq $-0x2
jmp 0xe074
movq %rdi, %r14
movq 0x20(%rdi), %r15
movq %r15, %rdi
callq 0xb01f
cmpl (%r15), %eax
je 0xe110
movl %eax, %ebp
movq 0x20(%r15), %rax
movl %ebp, %ecx
movq (%rax,%rcx,8), %rax
movq %rax, %rcx
shrq %rcx
imulq $0x68, %rcx, %r12
addq 0x10(%r14), %r12
cmpq %rbx, %r12
je 0xe06e
andl $0x1, %eax
imulq $0x18, %rax, %rcx
cmpq $0x1, 0x20(%r12,%rcx)
jne 0xe072
movq %r15, %r13
testq %rax, %rax
je 0xdf1a
movq %r14, %rdi
movq %r12, %rsi
callq 0xdd93
movq 0x20(%r14), %r13
movq 0x18(%rbx), %rsi
movq %r13, %rdi
callq 0xb01f
cmpl (%r15), %eax
je 0xe16d
movq %r13, %rdi
movl %eax, %esi
callq 0xb467
movq 0x20(%r14), %rdi
movl %ebp, %esi
callq 0xb467
movq 0x18(%rbx), %rcx
movq 0x30(%r12), %rax
cmpq (%rax), %rcx
jne 0xe12f
movq 0x10(%r12), %rdx
movq 0x48(%rbx), %rcx
cmpq (%rcx), %rdx
jne 0xe12f
movq 0x8(%rcx), %rcx
cmpq 0x8(%rax), %rcx
jne 0xe18c
movslq (%rbx), %rax
cmpq %rax, %rcx
ja 0xe14e
movslq (%r12), %rdx
cmpq %rdx, %rcx
ja 0xe14e
movl 0x4(%r12), %esi
addl %esi, 0x4(%rbx)
subl %ecx, %eax
leal (%rax,%rdx), %r8d
leal (%rax,%rdx), %ecx
incl %ecx
cmpl 0x8(%rbx), %ecx
jbe 0xdffc
movl %r8d, %eax
shrl %eax
orl %r8d, %eax
movl %eax, %ecx
shrl $0x2, %ecx
orl %eax, %ecx
movl %ecx, %eax
shrl $0x4, %eax
orl %ecx, %eax
movl %eax, %ecx
shrl $0x8, %ecx
orl %eax, %ecx
movl %ecx, %esi
shrl $0x10, %esi
orl %ecx, %esi
incl %esi
movl %esi, 0x8(%rbx)
movq 0x50(%rbx), %rdi
movl %r8d, %ebp
callq 0x21c0
movq %rax, 0x50(%rbx)
movq 0x58(%rbx), %rdi
movl 0x8(%rbx), %esi
callq 0x21c0
movl %ebp, %r8d
movq %rax, 0x58(%rbx)
movl (%rbx), %eax
movq 0x48(%rbx), %rcx
subl 0x8(%rcx), %eax
leaq 0x38(%rbx), %r13
cltq
xorl %ecx, %ecx
movslq (%r12), %rdx
cmpq %rdx, %rcx
jge 0xe086
leaq (%rax,%rcx), %rdx
movq 0x50(%r12), %rsi
movb (%rsi,%rcx), %sil
movq 0x50(%rbx), %rdi
addq %rax, %rdi
movb %sil, (%rcx,%rdi)
movslq (%rbx), %rsi
cmpq %rsi, %rdx
jge 0xe051
movq 0x58(%rbx), %rdx
addq %rax, %rdx
movsbl (%rcx,%rdx), %esi
movq 0x58(%r12), %rdi
movsbl (%rdi,%rcx), %edi
addl %edi, %esi
addl $-0x21, %esi
cmpl $0x7f, %esi
jl 0xe065
movb $0x7e, (%rdx,%rcx)
jmp 0xe069
movq 0x58(%r12), %rdx
movb (%rdx,%rcx), %dl
movq 0x58(%rbx), %rsi
addq %rax, %rsi
movb %dl, (%rcx,%rsi)
jmp 0xe069
movb %sil, (%rdx,%rcx)
incq %rcx
jmp 0xe004
pushq $-0x3
jmp 0xe074
pushq $-0x4
popq %rbp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x58(%rbx), %rax
movslq %r8d, %rcx
xorl %ebp, %ebp
movb %bpl, (%rax,%rcx)
movq 0x50(%rbx), %rax
movb %bpl, (%rax,%rcx)
movl %r8d, (%rbx)
movq 0x48(%rbx), %rdi
callq 0x2040
movq 0x48(%r12), %rax
movq %rax, 0x10(%r13)
movups 0x38(%r12), %xmm0
movups %xmm0, (%r13)
movq 0x18(%r12), %rsi
movq %rsi, 0x18(%rbx)
andq $0x0, 0x48(%r12)
movq 0x20(%r14), %r13
movq %r13, %rdi
callq 0xb01f
cmpl (%r13), %eax
je 0xe1ab
movl %eax, %ecx
subq 0x10(%r14), %rbx
pushq $0x68
popq %rsi
movq %rbx, %rax
cqto
idivq %rsi
leaq 0x1(,%rax,2), %rax
movq 0x20(%r15), %rdx
movl %ecx, %ecx
movq %rax, (%rdx,%rcx,8)
movq %r12, %rdi
callq 0xd887
jmp 0xe075
leaq 0x6a2d(%rip), %rdi      # 0x14b44
leaq 0x69fd(%rip), %rsi      # 0x14b1b
leaq 0x6a2f(%rip), %rcx      # 0x14b54
movl $0x142, %edx            # imm = 0x142
callq 0x20e0
leaq 0x6a5b(%rip), %rdi      # 0x14b91
leaq 0x69de(%rip), %rsi      # 0x14b1b
leaq 0x6a10(%rip), %rcx      # 0x14b54
movl $0x14b, %edx            # imm = 0x14B
callq 0x20e0
leaq 0x6a9c(%rip), %rdi      # 0x14bf1
leaq 0x69bf(%rip), %rsi      # 0x14b1b
leaq 0x69f1(%rip), %rcx      # 0x14b54
movl $0x14d, %edx            # imm = 0x14D
callq 0x20e0
leaq 0x6a0d(%rip), %rdi      # 0x14b81
leaq 0x69a0(%rip), %rsi      # 0x14b1b
leaq 0x69d2(%rip), %rcx      # 0x14b54
movl $0x149, %edx            # imm = 0x149
callq 0x20e0
leaq 0x6a39(%rip), %rdi      # 0x14bcc
leaq 0x6981(%rip), %rsi      # 0x14b1b
leaq 0x69b3(%rip), %rcx      # 0x14b54
movl $0x14c, %edx            # imm = 0x14C
callq 0x20e0
leaq 0x6a78(%rip), %rdi      # 0x14c2a
leaq 0x6962(%rip), %rsi      # 0x14b1b
leaq 0x6994(%rip), %rcx      # 0x14b54
movl $0x168, %edx            # imm = 0x168
callq 0x20e0