// File: /workspace/github_c_makefile_star2_O1/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 0x10057
movq %rsi, %rbx
movq 0x48(%rsi), %rax
movq (%rax), %rsi
testq %rsi, %rsi
js 0x1004b
movl $0xfffffffb, %ebp       # imm = 0xFFFFFFFB
cmpl %edx, 0x8(%rax)
jl 0x10057
movq %rdi, %r14
movq 0x20(%rdi), %r15
movq %r15, %rdi
callq 0xc8d4
cmpl (%r15), %eax
je 0x10068
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 0x10052
andl $0x1, %eax
leaq (%rax,%rax,2), %rcx
movl $0xfffffffc, %ebp       # imm = 0xFFFFFFFC
cmpq $0x1, 0x20(%r12,%rcx,8)
jne 0x10057
testq %rax, %rax
je 0xfe70
movq %r14, %rdi
movq %r12, %rsi
callq 0xfce8
movq 0x20(%r14), %rbp
movq 0x18(%rbx), %rsi
movq %rbp, %rdi
callq 0xc8d4
cmpl (%r15), %eax
je 0x100c5
movq %rbp, %rdi
movl %eax, %esi
callq 0xcd36
movq 0x20(%r14), %rdi
movl %r13d, %esi
callq 0xcd36
movq 0x18(%rbx), %rcx
movq 0x30(%r12), %rax
cmpq (%rax), %rcx
jne 0x10087
movq 0x10(%r12), %rdx
movq 0x48(%rbx), %rcx
cmpq (%rcx), %rdx
jne 0x10087
movq 0x8(%rcx), %rcx
cmpq 0x8(%rax), %rcx
jne 0x100e4
movslq (%rbx), %rax
cmpq %rax, %rcx
ja 0x100a6
movslq (%r12), %rdx
cmpq %rdx, %rcx
ja 0x100a6
movl 0x4(%r12), %esi
addl %esi, 0x4(%rbx)
subl %ecx, %eax
leal (%rax,%rdx), %r8d
addl %edx, %eax
incl %eax
cmpl 0x8(%rbx), %eax
jbe 0xff4d
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 0x21d0
movq %rax, 0x50(%rbx)
movq 0x58(%rbx), %rdi
movl 0x8(%rbx), %esi
callq 0x21d0
movl %ebp, %r8d
movq %rax, 0x58(%rbx)
leaq 0x38(%rbx), %r13
cmpl $0x0, (%r12)
jle 0xffc1
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 0xff9d
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 0xffae
movb $0x7e, (%rdx,%rax)
jmp 0xffb2
movq 0x58(%r12), %rdx
movb (%rdx,%rcx), %dl
movq 0x58(%rbx), %rsi
movb %dl, (%rsi,%rax)
jmp 0xffb2
movb %sil, (%rdx,%rax)
incq %rax
incq %rcx
movslq (%r12), %rdx
cmpq %rdx, %rcx
jl 0xff65
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)
movq $0x0, 0x48(%r12)
movq 0x20(%r14), %r13
movq %r13, %rdi
callq 0xc8d4
cmpl (%r13), %eax
je 0x10103
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 0xf741
jmp 0x10057
movl $0xfffffffe, %ebp       # imm = 0xFFFFFFFE
jmp 0x10057
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 0x7a95(%rip), %rdi      # 0x17b04
leaq 0x7a65(%rip), %rsi      # 0x17adb
leaq 0x7a97(%rip), %rcx      # 0x17b14
movl $0x142, %edx            # imm = 0x142
callq 0x20e0
leaq 0x7ac3(%rip), %rdi      # 0x17b51
leaq 0x7a46(%rip), %rsi      # 0x17adb
leaq 0x7a78(%rip), %rcx      # 0x17b14
movl $0x14b, %edx            # imm = 0x14B
callq 0x20e0
leaq 0x7b04(%rip), %rdi      # 0x17bb1
leaq 0x7a27(%rip), %rsi      # 0x17adb
leaq 0x7a59(%rip), %rcx      # 0x17b14
movl $0x14d, %edx            # imm = 0x14D
callq 0x20e0
leaq 0x7a75(%rip), %rdi      # 0x17b41
leaq 0x7a08(%rip), %rsi      # 0x17adb
leaq 0x7a3a(%rip), %rcx      # 0x17b14
movl $0x149, %edx            # imm = 0x149
callq 0x20e0
leaq 0x7aa1(%rip), %rdi      # 0x17b8c
leaq 0x79e9(%rip), %rsi      # 0x17adb
leaq 0x7a1b(%rip), %rcx      # 0x17b14
movl $0x14c, %edx            # imm = 0x14C
callq 0x20e0
leaq 0x7ae0(%rip), %rdi      # 0x17bea
leaq 0x79ca(%rip), %rsi      # 0x17adb
leaq 0x79fc(%rip), %rcx      # 0x17b14
movl $0x168, %edx            # imm = 0x168
callq 0x20e0