// File: /workspace/github_c_makefile_star2_O0/ToniWestbrook[P]paladin/bwamem.c
// Function: mem_seed_sw
int mem_seed_sw(const mem_opt_t *opt, const bntseq_t *bns, const uint8_t *pac, int l_query, const uint8_t *query, const mem_seed_t *s)
{
	int qb, qe, rid;
	int64_t rb, re, mid, l_pac = bns->l_pac;
	uint8_t *rseq = 0;
	kswr_t x;

	if (s->len >= MEM_SHORT_LEN) return -1; // the seed is longer than the max-extend; no need to do SW
	qb = s->qbeg, qe = s->qbeg + s->len;
	rb = s->rbeg, re = s->rbeg + s->len;
	mid = (rb + re) >> 1;
	qb -= MEM_SHORT_EXT; qb = qb > 0? qb : 0;
	qe += MEM_SHORT_EXT; qe = qe < l_query? qe : l_query;
	rb -= MEM_SHORT_EXT; rb = rb > 0? rb : 0;
	re += MEM_SHORT_EXT; re = re < l_pac<<1? re : l_pac<<1;
	if (rb < l_pac && l_pac < re) {
		if (mid < l_pac) re = l_pac;
		else rb = l_pac;
	}
	if (qe - qb >= MEM_SHORT_LEN || re - rb >= MEM_SHORT_LEN) return -1; // the seed seems good enough; no need to do SW

	rseq = bns_fetch_seq(bns, pac, &rb, mid, &re, &rid);
	x = ksw_align2(qe - qb, (uint8_t*)query + qb, re - rb, rseq, VALUE_DEFINED, opt->mat, opt->o_del, opt->e_del, opt->o_ins, opt->e_ins, KSW_XSTART, 0);
	free(rseq);
	return x.score;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0xf8, %rsp
movq %rdi, -0x28(%rbp)
movq %rsi, -0x30(%rbp)
movq %rdx, -0x38(%rbp)
movl %ecx, -0x3c(%rbp)
movq %r8, -0x48(%rbp)
movq %r9, -0x50(%rbp)
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x80(%rbp)
movq $0x0, -0x88(%rbp)
movq -0x50(%rbp), %rax
cmpl $0xc8, 0xc(%rax)
jl 0x278f6
movl $0xffffffff, -0x1c(%rbp) # imm = 0xFFFFFFFF
jmp 0x27b65
movq -0x50(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x54(%rbp)
movq -0x50(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x50(%rbp), %rcx
addl 0xc(%rcx), %eax
movl %eax, -0x58(%rbp)
movq -0x50(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x68(%rbp)
movq -0x50(%rbp), %rax
movq (%rax), %rax
movq -0x50(%rbp), %rcx
movslq 0xc(%rcx), %rcx
addq %rcx, %rax
movq %rax, -0x70(%rbp)
movq -0x68(%rbp), %rax
addq -0x70(%rbp), %rax
sarq %rax
movq %rax, -0x78(%rbp)
movl -0x54(%rbp), %eax
subl $0x32, %eax
movl %eax, -0x54(%rbp)
cmpl $0x0, -0x54(%rbp)
jle 0x2795b
movl -0x54(%rbp), %eax
movl %eax, -0xc4(%rbp)
jmp 0x27965
xorl %eax, %eax
movl %eax, -0xc4(%rbp)
jmp 0x27965
movl -0xc4(%rbp), %eax
movl %eax, -0x54(%rbp)
movl -0x58(%rbp), %eax
addl $0x32, %eax
movl %eax, -0x58(%rbp)
movl -0x58(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jge 0x2798a
movl -0x58(%rbp), %eax
movl %eax, -0xc8(%rbp)
jmp 0x27993
movl -0x3c(%rbp), %eax
movl %eax, -0xc8(%rbp)
movl -0xc8(%rbp), %eax
movl %eax, -0x58(%rbp)
movq -0x68(%rbp), %rax
subq $0x32, %rax
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x68(%rbp)
jle 0x279bc
movq -0x68(%rbp), %rax
movq %rax, -0xd0(%rbp)
jmp 0x279c7
xorl %eax, %eax
movq %rax, -0xd0(%rbp)
jmp 0x279c7
movq -0xd0(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x70(%rbp), %rax
addq $0x32, %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
movq -0x80(%rbp), %rcx
shlq %rcx
cmpq %rcx, %rax
jge 0x279fb
movq -0x70(%rbp), %rax
movq %rax, -0xd8(%rbp)
jmp 0x27a09
movq -0x80(%rbp), %rax
shlq %rax
movq %rax, -0xd8(%rbp)
movq -0xd8(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x68(%rbp), %rax
cmpq -0x80(%rbp), %rax
jge 0x27a46
movq -0x80(%rbp), %rax
cmpq -0x70(%rbp), %rax
jge 0x27a46
movq -0x78(%rbp), %rax
cmpq -0x80(%rbp), %rax
jge 0x27a3c
movq -0x80(%rbp), %rax
movq %rax, -0x70(%rbp)
jmp 0x27a44
movq -0x80(%rbp), %rax
movq %rax, -0x68(%rbp)
jmp 0x27a46
movl -0x58(%rbp), %eax
subl -0x54(%rbp), %eax
cmpl $0xc8, %eax
jge 0x27a63
movq -0x70(%rbp), %rax
subq -0x68(%rbp), %rax
cmpq $0xc8, %rax
jl 0x27a6f
movl $0xffffffff, -0x1c(%rbp) # imm = 0xFFFFFFFF
jmp 0x27b65
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x78(%rbp), %rcx
leaq -0x68(%rbp), %rdx
leaq -0x70(%rbp), %r8
leaq -0x5c(%rbp), %r9
callq 0x17fd0
movq %rax, -0x88(%rbp)
movl -0x58(%rbp), %esi
subl -0x54(%rbp), %esi
movq -0x48(%rbp), %rdx
movslq -0x54(%rbp), %rax
addq %rax, %rdx
movq -0x70(%rbp), %rax
subq -0x68(%rbp), %rax
movl %eax, %ecx
movq -0x88(%rbp), %r8
movq -0x28(%rbp), %r14
addq $0xc4, %r14
movq -0x28(%rbp), %rax
movl 0x8(%rax), %ebx
movq -0x28(%rbp), %rax
movl 0xc(%rax), %r11d
movq -0x28(%rbp), %rax
movl 0x10(%rax), %r10d
movq -0x28(%rbp), %rax
movl 0x14(%rax), %eax
leaq -0xc0(%rbp), %rdi
movl $0x16, %r9d
xorl %r15d, %r15d
movq %r14, (%rsp)
movl %ebx, 0x8(%rsp)
movl %r11d, 0x10(%rsp)
movl %r10d, 0x18(%rsp)
movl %eax, 0x20(%rsp)
movl $0x80000, 0x28(%rsp)    # imm = 0x80000
movq $0x0, 0x30(%rsp)
callq 0x34880
movq -0xc0(%rbp), %rax
movq %rax, -0xa4(%rbp)
movq -0xb8(%rbp), %rax
movq %rax, -0x9c(%rbp)
movq -0xb0(%rbp), %rax
movq %rax, -0x94(%rbp)
movl -0xa8(%rbp), %eax
movl %eax, -0x8c(%rbp)
movq -0x88(%rbp), %rdi
callq 0x3380
movl -0xa4(%rbp), %eax
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
addq $0xf8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nopw %cs:(%rax,%rax)