// File: /workspace/github_c_makefile_star2_O1/ToniWestbrook[P]paladin/bwamem.c
// Function: _kb_putp_aux_chn
static int test_and_merge(const mem_opt_t *opt, int64_t l_pac, mem_chain_t *c, const mem_seed_t *p, int seed_rid)
{
	int64_t qend, rend, x, y;
	const mem_seed_t *last = &c->seeds[c->n-1];
	qend = last->qbeg + last->len;
	rend = last->rbeg + last->len;
	if (seed_rid != c->rid) return 0; // different chr; request a new chain
	if (p->qbeg >= c->seeds[0].qbeg && p->qbeg + p->len <= qend && p->rbeg >= c->seeds[0].rbeg && p->rbeg + p->len <= rend)
		return 1; // contained seed; do nothing
	if ((last->rbeg < l_pac || c->seeds[0].rbeg < l_pac) && p->rbeg >= l_pac) return 0; // don't chain if on different strand
	x = p->qbeg - last->qbeg; // always non-negtive
	y = p->rbeg - last->rbeg;
	if (y >= 0 && x - y <= opt->w && y - x <= opt->w && x - last->len < opt->max_chain_gap && y - last->len < opt->max_chain_gap) { // grow the chain
		if (c->n == c->m) {
			c->m <<= 1;
			c->seeds = realloc(c->seeds, c->m * sizeof(mem_seed_t));
		}
		c->seeds[c->n++] = *p;
		return 1;
	}
	return 0; // request to add a new chain
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %r14
movq %rsi, %rbx
movq %rdi, %r15
movl (%rbx), %eax
testb $0x1, %al
je 0x1f3a8
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
cmpl $0x2, %eax
jb 0x1f33f
sarl %eax
testl %eax, %eax
jle 0x1f318
movq 0x18(%r14), %rcx
leaq 0x4(%rbx), %rdx
xorl %r12d, %r12d
movl %eax, %esi
leal (%r12,%rsi), %edi
sarl %edi
movslq %edi, %r8
leaq (%r8,%r8,4), %r8
cmpq %rcx, 0x18(%rdx,%r8,8)
jl 0x1f30c
movl %edi, %esi
jmp 0x1f311
incl %edi
movl %edi, %r12d
cmpl %esi, %r12d
jl 0x1f2f4
jmp 0x1f31b
xorl %r12d, %r12d
cmpl %eax, %r12d
jne 0x1f327
decl %eax
movl %eax, %r12d
jmp 0x1f33f
movslq %r12d, %rax
leaq (%rax,%rax,4), %rax
movq 0x18(%r14), %rcx
xorl %edx, %edx
cmpq 0x1c(%rbx,%rax,8), %rcx
setl %dl
subl %edx, %r12d
movslq %r12d, %r13
incl %r12d
movslq 0xc(%r15), %rax
addq %rbx, %rax
movq 0x8(%rax,%r13,8), %rcx
movl (%rcx), %eax
sarl %eax
movl 0x1c(%r15), %edx
leal -0x1(,%rdx,2), %edx
cmpl %edx, %eax
jne 0x1f395
leaq 0x1(%r13), %rbp
movq %r15, %rdi
movq %rbx, %rsi
movl %r12d, %edx
callq 0x1f14f
leaq (,%rbp,4), %rax
addq %rbp, %rax
movq 0x1c(%rbx,%rax,8), %rax
addl $0x2, %r13d
cmpq 0x18(%r14), %rax
cmovgel %r12d, %r13d
movl %r13d, %r12d
movslq 0xc(%r15), %rax
addq %rax, %rbx
movslq %r12d, %rax
movq (%rbx,%rax,8), %rbx
jmp 0x1f2cc
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpl $0x2, %eax
jb 0x1f412
movl %eax, %ecx
sarl %ecx
testl %ecx, %ecx
jle 0x1f3ee
movq 0x18(%r14), %rsi
leaq 0x4(%rbx), %rdi
xorl %edx, %edx
movl %ecx, %r8d
leal (%rdx,%r8), %r9d
sarl %r9d
movslq %r9d, %r10
leaq (%r10,%r10,4), %r10
cmpq %rsi, 0x18(%rdi,%r10,8)
jl 0x1f3e1
movl %r9d, %r8d
jmp 0x1f3e7
incl %r9d
movl %r9d, %edx
cmpl %r8d, %edx
jl 0x1f3c7
jmp 0x1f3f0
xorl %edx, %edx
cmpl %ecx, %edx
jne 0x1f3f8
decl %ecx
jmp 0x1f412
movslq %edx, %rcx
leaq (%rcx,%rcx,4), %rcx
movq 0x18(%r14), %rsi
xorl %edi, %edi
cmpq 0x1c(%rbx,%rcx,8), %rsi
setl %dil
subl %edi, %edx
movl %edx, %ecx
sarl %eax
leal -0x1(%rax), %edx
movslq %ecx, %r15
cmpl %edx, %ecx
je 0x1f448
leaq (%r15,%r15,4), %rcx
leaq (%rbx,%rcx,8), %rdi
addq $0x54, %rdi
leaq (%rbx,%rcx,8), %rsi
addq $0x2c, %rsi
movl %r15d, %ecx
notl %ecx
addl %ecx, %eax
cltq
shlq $0x3, %rax
leaq (%rax,%rax,4), %rdx
callq 0x3600
leaq (%r15,%r15,4), %rax
movq 0x20(%r14), %rcx
movq %rcx, 0x4c(%rbx,%rax,8)
movups (%r14), %xmm0
movups 0x10(%r14), %xmm1
movups %xmm1, 0x3c(%rbx,%rax,8)
movups %xmm0, 0x2c(%rbx,%rax,8)
addl $0x2, (%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop