// File: /workspace/github_c_makefile_star2_O0/ToniWestbrook[P]paladin/bwamem.c
// Function: test_and_merge
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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movl %r8d, -0x2c(%rbp)
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x20(%rbp), %rcx
movl (%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x58(%rbp), %rcx
addl 0xc(%rcx), %eax
cltq
movq %rax, -0x38(%rbp)
movq -0x58(%rbp), %rax
movq (%rax), %rax
movq -0x58(%rbp), %rcx
movslq 0xc(%rcx), %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movl -0x2c(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0xc(%rcx), %eax
je 0x1dfad
movl $0x0, -0x4(%rbp)
jmp 0x1e18a
movq -0x28(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x20(%rbp), %rcx
movq 0x20(%rcx), %rcx
cmpl 0x8(%rcx), %eax
jl 0x1e00f
movq -0x28(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x28(%rbp), %rcx
addl 0xc(%rcx), %eax
cltq
cmpq -0x38(%rbp), %rax
jg 0x1e00f
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq -0x20(%rbp), %rcx
movq 0x20(%rcx), %rcx
cmpq (%rcx), %rax
jl 0x1e00f
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq -0x28(%rbp), %rcx
movslq 0xc(%rcx), %rcx
addq %rcx, %rax
cmpq -0x40(%rbp), %rax
jg 0x1e00f
movl $0x1, -0x4(%rbp)
jmp 0x1e18a
movq -0x58(%rbp), %rax
movq (%rax), %rax
cmpq -0x18(%rbp), %rax
jl 0x1e02d
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rax
movq (%rax), %rax
cmpq -0x18(%rbp), %rax
jge 0x1e046
movq -0x28(%rbp), %rax
movq (%rax), %rax
cmpq -0x18(%rbp), %rax
jl 0x1e046
movl $0x0, -0x4(%rbp)
jmp 0x1e18a
movq -0x28(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x58(%rbp), %rcx
subl 0x8(%rcx), %eax
cltq
movq %rax, -0x48(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq -0x58(%rbp), %rcx
subq (%rcx), %rax
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
jl 0x1e183
movq -0x48(%rbp), %rax
subq -0x50(%rbp), %rax
movq -0x10(%rbp), %rcx
movslq 0x24(%rcx), %rcx
cmpq %rcx, %rax
jg 0x1e183
movq -0x50(%rbp), %rax
subq -0x48(%rbp), %rax
movq -0x10(%rbp), %rcx
movslq 0x24(%rcx), %rcx
cmpq %rcx, %rax
jg 0x1e183
movq -0x48(%rbp), %rax
movq -0x58(%rbp), %rcx
movslq 0xc(%rcx), %rcx
subq %rcx, %rax
movq -0x10(%rbp), %rcx
movslq 0x90(%rcx), %rcx
cmpq %rcx, %rax
jge 0x1e183
movq -0x50(%rbp), %rax
movq -0x58(%rbp), %rcx
movslq 0xc(%rcx), %rcx
subq %rcx, %rax
movq -0x10(%rbp), %rcx
movslq 0x90(%rcx), %rcx
cmpq %rcx, %rax
jge 0x1e183
movq -0x20(%rbp), %rax
movl (%rax), %eax
movq -0x20(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jne 0x1e141
movq -0x20(%rbp), %rax
movl 0x4(%rax), %ecx
shll %ecx
movl %ecx, 0x4(%rax)
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x20(%rbp), %rax
movslq 0x4(%rax), %rax
imulq $0x18, %rax, %rsi
leaq 0x1c593(%rip), %rdx     # 0x3a6b8
movl $0x11a, %ecx            # imm = 0x11A
leaq 0x1ce6a(%rip), %r8      # 0x3af9b
callq 0x31d40
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x20(%rbp), %rdx
movl (%rdx), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, (%rdx)
movslq %ecx, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq -0x28(%rbp), %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rax)
movq 0x10(%rcx), %rcx
movq %rcx, 0x10(%rax)
movl $0x1, -0x4(%rbp)
jmp 0x1e18a
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)