// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rax
cmpq $0x1, 0x38(%rax)
je 0x18a16
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x18f5d
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rax
cmpq $0x0, (%rax)
jge 0x18a30
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x18f5d
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rax
movq 0x8(%rax), %rax
cmpl -0x1c(%rbp), %eax
jge 0x18a4d
movl $0xfffffffb, -0x4(%rbp) # imm = 0xFFFFFFFB
jmp 0x18f5d
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rax
movq (%rax), %rsi
callq 0x12560
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
movq -0x48(%rbp), %rcx
cmpl (%rcx), %eax
je 0x18a75
jmp 0x18a94
leaq 0xcfbc(%rip), %rdi      # 0x25a38
leaq 0xcf8c(%rip), %rsi      # 0x25a0f
movl $0x142, %edx            # imm = 0x142
leaq 0xcfb9(%rip), %rcx      # 0x25a48
callq 0x20f0
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x20(%rcx), %rcx
movq 0x20(%rcx), %rcx
movl -0x30(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq %rcx
imulq $0x68, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rax
cmpq -0x28(%rbp), %rax
jne 0x18ad3
movl $0xfffffffd, -0x4(%rbp) # imm = 0xFFFFFFFD
jmp 0x18f5d
movq -0x28(%rbp), %rax
addq $0x20, %rax
movq -0x48(%rbp), %rcx
movq 0x20(%rcx), %rcx
movl -0x30(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
andq $0x1, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
cmpq $0x1, (%rax)
je 0x18b07
movl $0xfffffffc, -0x4(%rbp) # imm = 0xFFFFFFFC
jmp 0x18f5d
movq -0x48(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x30(%rbp), %ecx
movq (%rax,%rcx,8), %rax
andq $0x1, %rax
cmpq $0x0, %rax
je 0x18b2d
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x18850
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rsi
callq 0x12560
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movq -0x48(%rbp), %rcx
cmpl (%rcx), %eax
je 0x18b52
jmp 0x18b71
leaq 0xcf1c(%rip), %rdi      # 0x25a75
leaq 0xceaf(%rip), %rsi      # 0x25a0f
movl $0x149, %edx            # imm = 0x149
leaq 0xcedc(%rip), %rcx      # 0x25a48
callq 0x20f0
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
movl -0x2c(%rbp), %esi
callq 0x12ea0
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
movl -0x30(%rbp), %esi
callq 0x12ea0
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x28(%rbp), %rcx
movq 0x30(%rcx), %rcx
cmpq (%rcx), %rax
jne 0x18bbd
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x48(%rcx), %rcx
cmpq (%rcx), %rax
jne 0x18bbd
jmp 0x18bdc
leaq 0xcec1(%rip), %rdi      # 0x25a85
leaq 0xce44(%rip), %rsi      # 0x25a0f
movl $0x14b, %edx            # imm = 0x14B
leaq 0xce71(%rip), %rcx      # 0x25a48
callq 0x20f0
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rax
movq 0x8(%rax), %rax
movq -0x28(%rbp), %rcx
movq 0x30(%rcx), %rcx
cmpq 0x8(%rcx), %rax
jne 0x18bf8
jmp 0x18c17
leaq 0xcec1(%rip), %rdi      # 0x25ac0
leaq 0xce09(%rip), %rsi      # 0x25a0f
movl $0x14c, %edx            # imm = 0x14C
leaq 0xce36(%rip), %rcx      # 0x25a48
callq 0x20f0
movq -0x18(%rbp), %rax
movslq (%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x48(%rcx), %rcx
cmpq 0x8(%rcx), %rax
jb 0x18c43
movq -0x28(%rbp), %rax
movslq (%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x48(%rcx), %rcx
cmpq 0x8(%rcx), %rax
jb 0x18c43
jmp 0x18c62
leaq 0xce9b(%rip), %rdi      # 0x25ae5
leaq 0xcdbe(%rip), %rsi      # 0x25a0f
movl $0x14d, %edx            # imm = 0x14D
leaq 0xcdeb(%rip), %rcx      # 0x25a48
callq 0x20f0
movq -0x28(%rbp), %rax
movl 0x4(%rax), %ecx
movq -0x18(%rbp), %rax
addl 0x4(%rax), %ecx
movl %ecx, 0x4(%rax)
movq -0x18(%rbp), %rax
movl (%rax), %eax
movq -0x28(%rbp), %rcx
addl (%rcx), %eax
cltq
movq -0x18(%rbp), %rcx
movq 0x48(%rcx), %rcx
subq 0x8(%rcx), %rax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movq -0x18(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jbe 0x18d6f
movl -0x3c(%rbp), %ecx
addl $0x1, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x18(%rbp), %rax
movl 0x8(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x8(%rax)
movq -0x18(%rbp), %rax
movl 0x8(%rax), %ecx
shrl %ecx
movq -0x18(%rbp), %rax
orl 0x8(%rax), %ecx
movl %ecx, 0x8(%rax)
movq -0x18(%rbp), %rax
movl 0x8(%rax), %ecx
shrl $0x2, %ecx
movq -0x18(%rbp), %rax
orl 0x8(%rax), %ecx
movl %ecx, 0x8(%rax)
movq -0x18(%rbp), %rax
movl 0x8(%rax), %ecx
shrl $0x4, %ecx
movq -0x18(%rbp), %rax
orl 0x8(%rax), %ecx
movl %ecx, 0x8(%rax)
movq -0x18(%rbp), %rax
movl 0x8(%rax), %ecx
shrl $0x8, %ecx
movq -0x18(%rbp), %rax
orl 0x8(%rax), %ecx
movl %ecx, 0x8(%rax)
movq -0x18(%rbp), %rax
movl 0x8(%rax), %ecx
shrl $0x10, %ecx
movq -0x18(%rbp), %rax
orl 0x8(%rax), %ecx
movl %ecx, 0x8(%rax)
movq -0x18(%rbp), %rax
movl 0x8(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x8(%rax)
movq -0x18(%rbp), %rax
movq 0x50(%rax), %rdi
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, %esi
callq 0x21e0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x50(%rax)
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rdi
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, %esi
callq 0x21e0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x58(%rax)
movq -0x18(%rbp), %rax
movslq (%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x48(%rcx), %rcx
subq 0x8(%rcx), %rax
movl %eax, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x18e61
movq -0x28(%rbp), %rax
movq 0x50(%rax), %rax
movslq -0x38(%rbp), %rcx
movb (%rax,%rcx), %dl
movq -0x18(%rbp), %rax
movq 0x50(%rax), %rax
movslq -0x34(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x34(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x18e2a
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rax
movslq -0x34(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movq -0x28(%rbp), %rcx
movq 0x58(%rcx), %rcx
movslq -0x38(%rbp), %rdx
movsbl (%rcx,%rdx), %ecx
subl $0x21, %ecx
addl %ecx, %eax
cmpl $0x7e, %eax
jle 0x18e00
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rax
movslq -0x34(%rbp), %rcx
movb $0x7e, (%rax,%rcx)
jmp 0x18e28
movq -0x28(%rbp), %rax
movq 0x58(%rax), %rax
movslq -0x38(%rbp), %rcx
movsbl (%rax,%rcx), %esi
subl $0x21, %esi
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rax
movslq -0x34(%rbp), %rcx
movsbl (%rax,%rcx), %edx
addl %esi, %edx
movb %dl, (%rax,%rcx)
jmp 0x18e48
movq -0x28(%rbp), %rax
movq 0x58(%rax), %rax
movslq -0x38(%rbp), %rcx
movb (%rax,%rcx), %dl
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rax
movslq -0x34(%rbp), %rcx
movb %dl, (%rax,%rcx)
jmp 0x18e4a
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x18d8c
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rax
movslq -0x3c(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x18(%rbp), %rax
movq 0x50(%rax), %rax
movslq -0x3c(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movl -0x3c(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rdi
callq 0x2040
movq -0x18(%rbp), %rax
movq -0x28(%rbp), %rcx
movq 0x38(%rcx), %rdx
movq %rdx, 0x38(%rax)
movq 0x40(%rcx), %rdx
movq %rdx, 0x40(%rax)
movq 0x48(%rcx), %rcx
movq %rcx, 0x48(%rax)
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x28(%rbp), %rax
movq $0x0, 0x48(%rax)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rsi
callq 0x12560
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movq -0x10(%rbp), %rcx
movq 0x20(%rcx), %rcx
cmpl (%rcx), %eax
je 0x18efc
jmp 0x18f1b
leaq 0xcc1b(%rip), %rdi      # 0x25b1e
leaq 0xcb05(%rip), %rsi      # 0x25a0f
movl $0x168, %edx            # imm = 0x168
leaq 0xcb32(%rip), %rcx      # 0x25a48
callq 0x20f0
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x10(%rcx), %rcx
subq %rcx, %rax
movl $0x68, %ecx
cqto
idivq %rcx
movq %rax, %rdx
shlq %rdx
orq $0x1, %rdx
movq -0x48(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x2c(%rbp), %ecx
movq %rdx, (%rax,%rcx,8)
movq -0x28(%rbp), %rdi
callq 0x17db0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)