// File: /workspace/github_c_makefile_star2_O3/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
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpq $0x1, 0x38(%rsi)
jne 0x10658
movq %rsi, %rbx
movq 0x48(%rsi), %rax
movq (%rax), %rsi
testq %rsi, %rsi
js 0x1064c
movl $0xfffffffb, %ebp       # imm = 0xFFFFFFFB
cmpl %edx, 0x8(%rax)
jl 0x10658
movq %rdi, %r14
movq 0x20(%rdi), %r15
movq %r15, %rdi
callq 0xce10
cmpl (%r15), %eax
je 0x10669
movl %eax, %r13d
movq 0x20(%r15), %rax
movl %r13d, %ecx
movq (%rax,%rcx,8), %rax
movq %rax, %rcx
shrq %rcx
imulq $0x68, %rcx, %r12
addq 0x10(%r14), %r12
cmpq %rbx, %r12
je 0x10653
andl $0x1, %eax
leaq (%rax,%rax,2), %rcx
movl $0xfffffffc, %ebp       # imm = 0xFFFFFFFC
cmpq $0x1, 0x20(%r12,%rcx,8)
jne 0x10658
movq %r15, %rbp
testq %rax, %rax
je 0x10471
movq %r14, %rdi
movq %r12, %rsi
callq 0x102e2
movq 0x20(%r14), %rbp
movq 0x18(%rbx), %rsi
movq %rbp, %rdi
callq 0xce10
cmpl (%r15), %eax
je 0x106c6
movq %rbp, %rdi
movl %eax, %esi
callq 0xd27b
movq 0x20(%r14), %rdi
movl %r13d, %esi
callq 0xd27b
movq 0x18(%rbx), %rcx
movq 0x30(%r12), %rax
cmpq (%rax), %rcx
jne 0x10688
movq 0x10(%r12), %rdx
movq 0x48(%rbx), %rcx
cmpq (%rcx), %rdx
jne 0x10688
movq 0x8(%rcx), %rcx
cmpq 0x8(%rax), %rcx
jne 0x106e5
movslq (%rbx), %rdx
cmpq %rdx, %rcx
ja 0x106a7
movslq (%r12), %rax
cmpq %rax, %rcx
ja 0x106a7
movl 0x4(%r12), %esi
addl %esi, 0x4(%rbx)
subl %ecx, %edx
movl %edx, %r13d
addl %eax, %r13d
leal (%rdx,%rax), %ecx
incl %ecx
cmpl 0x8(%rbx), %ecx
jbe 0x1054b
movl %r13d, %eax
shrl %eax
orl %r13d, %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
callq 0x21c0
movq %rax, 0x50(%rbx)
movq 0x58(%rbx), %rdi
movl 0x8(%rbx), %esi
callq 0x21c0
movq %rax, 0x58(%rbx)
movl (%r12), %eax
leaq 0x38(%rbx), %rcx
movq %rcx, (%rsp)
testl %eax, %eax
jle 0x105c0
movl (%rbx), %eax
movq 0x48(%rbx), %rcx
subl 0x8(%rcx), %eax
cltq
xorl %ecx, %ecx
movq 0x50(%r12), %rdx
movb (%rdx,%rcx), %dl
movq 0x50(%rbx), %rsi
movb %dl, (%rsi,%rax)
movslq (%rbx), %rdx
cmpq %rdx, %rax
jge 0x1059c
movq 0x58(%rbx), %rdx
movsbl (%rdx,%rax), %esi
movq 0x58(%r12), %rdi
movsbl (%rdi,%rcx), %edi
addl %edi, %esi
addl $-0x21, %esi
cmpl $0x7f, %esi
jl 0x105ad
movb $0x7e, (%rdx,%rax)
jmp 0x105b1
movq 0x58(%r12), %rdx
movb (%rdx,%rcx), %dl
movq 0x58(%rbx), %rsi
movb %dl, (%rsi,%rax)
jmp 0x105b1
movb %sil, (%rdx,%rax)
incq %rax
incq %rcx
movslq (%r12), %rdx
cmpq %rdx, %rcx
jl 0x10564
movq 0x58(%rbx), %rax
movslq %r13d, %rcx
xorl %ebp, %ebp
movb %bpl, (%rax,%rcx)
movq 0x50(%rbx), %rax
movb %bpl, (%rax,%rcx)
movl %r13d, (%rbx)
movq 0x48(%rbx), %rdi
callq 0x2040
movq 0x48(%r12), %rax
movq (%rsp), %rcx
movq %rax, 0x10(%rcx)
movups 0x38(%r12), %xmm0
movups %xmm0, (%rcx)
movq 0x18(%r12), %rsi
movq %rsi, 0x18(%rbx)
movq $0x0, 0x48(%r12)
movq 0x20(%r14), %r13
movq %r13, %rdi
callq 0xce10
cmpl (%r13), %eax
je 0x10704
subq 0x10(%r14), %rbx
sarq $0x3, %rbx
movabsq $-0x6276276276276276, %rcx # imm = 0x9D89D89D89D89D8A
imulq %rbx, %rcx
incq %rcx
movq 0x20(%r15), %rdx
movl %eax, %eax
movq %rcx, (%rdx,%rax,8)
movq %r12, %rdi
callq 0xfd00
jmp 0x10658
movl $0xfffffffe, %ebp       # imm = 0xFFFFFFFE
jmp 0x10658
movl $0xfffffffd, %ebp       # imm = 0xFFFFFFFD
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x7524(%rip), %rdi      # 0x17b94
leaq 0x74f4(%rip), %rsi      # 0x17b6b
leaq 0x7526(%rip), %rcx      # 0x17ba4
movl $0x142, %edx            # imm = 0x142
callq 0x20e0
leaq 0x7552(%rip), %rdi      # 0x17be1
leaq 0x74d5(%rip), %rsi      # 0x17b6b
leaq 0x7507(%rip), %rcx      # 0x17ba4
movl $0x14b, %edx            # imm = 0x14B
callq 0x20e0
leaq 0x7593(%rip), %rdi      # 0x17c41
leaq 0x74b6(%rip), %rsi      # 0x17b6b
leaq 0x74e8(%rip), %rcx      # 0x17ba4
movl $0x14d, %edx            # imm = 0x14D
callq 0x20e0
leaq 0x7504(%rip), %rdi      # 0x17bd1
leaq 0x7497(%rip), %rsi      # 0x17b6b
leaq 0x74c9(%rip), %rcx      # 0x17ba4
movl $0x149, %edx            # imm = 0x149
callq 0x20e0
leaq 0x7530(%rip), %rdi      # 0x17c1c
leaq 0x7478(%rip), %rsi      # 0x17b6b
leaq 0x74aa(%rip), %rcx      # 0x17ba4
movl $0x14c, %edx            # imm = 0x14C
callq 0x20e0
leaq 0x756f(%rip), %rdi      # 0x17c7a
leaq 0x7459(%rip), %rsi      # 0x17b6b
leaq 0x748b(%rip), %rcx      # 0x17ba4
movl $0x168, %edx            # imm = 0x168
callq 0x20e0