// File: /workspace/github_c_makefile_star2_O0/ToniWestbrook[P]paladin/ksw.c
// Function: ksw_align2
kswr_t ksw_align2(int qlen, uint8_t *query, int tlen, uint8_t *target, int m, const int8_t *mat, int o_del, int e_del, int o_ins, int e_ins, int xtra, kswq_t **qry)
{
	int size;
	kswq_t *q;
	kswr_t r, rr;
	kswr_t (*func)(kswq_t*, int, const uint8_t*, int, int, int, int, int);

	q = (qry && *qry)? *qry : ksw_qinit((xtra&KSW_XBYTE)? 1 : 2, qlen, query, m, mat);
	if (qry && *qry == 0) *qry = q;
	func = q->size == 2? ksw_i16 : ksw_u8;
	size = q->size;
	r = func(q, tlen, target, o_del, e_del, o_ins, e_ins, xtra);
	if (qry == 0) free(q);
	if ((xtra&KSW_XSTART) == 0 || ((xtra&KSW_XSUBO) && r.score < (xtra&0xffff))) return r;
	revseq(r.qe + 1, query); revseq(r.te + 1, target); // +1 because qe/te points to the exact end, not the position after the end
	q = ksw_qinit(size, r.qe + 1, query, m, mat);
	rr = func(q, tlen, target, o_del, e_del, o_ins, e_ins, KSW_XSTOP | r.score);
	revseq(r.qe + 1, query); revseq(r.te + 1, target);
	free(q);
	if (r.score == rr.score)
		r.tb = r.te - rr.te, r.qb = r.qe - rr.qe;
	return r;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
subq $0xc8, %rsp
movq %rdi, -0xa8(%rbp)
movq %rdi, -0xa0(%rbp)
movq 0x40(%rbp), %rax
movl 0x38(%rbp), %eax
movl 0x30(%rbp), %eax
movl 0x28(%rbp), %eax
movl 0x20(%rbp), %eax
movl 0x18(%rbp), %eax
movq 0x10(%rbp), %rax
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq %r8, -0x28(%rbp)
movl %r9d, -0x2c(%rbp)
cmpq $0x0, 0x40(%rbp)
je 0x348e4
movq 0x40(%rbp), %rax
cmpq $0x0, (%rax)
je 0x348e4
movq 0x40(%rbp), %rax
movq (%rax), %rax
movq %rax, -0xb0(%rbp)
jmp 0x34917
movl 0x38(%rbp), %ecx
andl $0x10000, %ecx          # imm = 0x10000
movl $0x2, %edi
movl $0x1, %eax
cmpl $0x0, %ecx
cmovnel %eax, %edi
movl -0xc(%rbp), %esi
movq -0x18(%rbp), %rdx
movl -0x2c(%rbp), %ecx
movq 0x10(%rbp), %r8
callq 0x31ea0
movq %rax, -0xb0(%rbp)
movq -0xb0(%rbp), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, 0x40(%rbp)
je 0x3493e
movq 0x40(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x3493e
movq -0x38(%rbp), %rcx
movq 0x40(%rbp), %rax
movq %rcx, (%rax)
movq -0x38(%rbp), %rax
movzbl 0xb(%rax), %edx
leaq -0x270d(%rip), %rax     # 0x32240
leaq -0x11d4(%rip), %rcx     # 0x33780
cmpl $0x2, %edx
cmoveq %rcx, %rax
movq %rax, -0x60(%rbp)
movq -0x38(%rbp), %rax
movzbl 0xb(%rax), %eax
movl %eax, -0x30(%rbp)
movq -0x60(%rbp), %rax
movq -0x38(%rbp), %rsi
movl -0x1c(%rbp), %edx
movq -0x28(%rbp), %rcx
movl 0x18(%rbp), %r8d
movl 0x20(%rbp), %r9d
movl 0x28(%rbp), %ebx
movl 0x30(%rbp), %r11d
movl 0x38(%rbp), %r10d
leaq -0x7c(%rbp), %rdi
movl %ebx, (%rsp)
movl %r11d, 0x8(%rsp)
movl %r10d, 0x10(%rsp)
callq *%rax
movq -0xa8(%rbp), %rax
movq -0x7c(%rbp), %rcx
movq %rcx, (%rax)
movq -0x74(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x6c(%rbp), %rcx
movq %rcx, 0x10(%rax)
movl -0x64(%rbp), %ecx
movl %ecx, 0x18(%rax)
cmpq $0x0, 0x40(%rbp)
jne 0x349d3
movq -0x38(%rbp), %rdi
callq 0x3380
movl 0x38(%rbp), %eax
andl $0x80000, %eax          # imm = 0x80000
cmpl $0x0, %eax
je 0x34a03
movl 0x38(%rbp), %eax
andl $0x40000, %eax          # imm = 0x40000
cmpl $0x0, %eax
je 0x34a08
movq -0xa8(%rbp), %rax
movl (%rax), %eax
movl 0x38(%rbp), %ecx
andl $0xffff, %ecx           # imm = 0xFFFF
cmpl %ecx, %eax
jge 0x34a08
jmp 0x34b22
movq -0xa8(%rbp), %rax
movl 0x8(%rax), %edi
addl $0x1, %edi
movq -0x18(%rbp), %rsi
callq 0x34b40
movq -0xa8(%rbp), %rax
movl 0x4(%rax), %edi
addl $0x1, %edi
movq -0x28(%rbp), %rsi
callq 0x34b40
movq -0xa8(%rbp), %rax
movl -0x30(%rbp), %edi
movl 0x8(%rax), %esi
addl $0x1, %esi
movq -0x18(%rbp), %rdx
movl -0x2c(%rbp), %ecx
movq 0x10(%rbp), %r8
callq 0x31ea0
movq -0xa8(%rbp), %rdi
movq %rax, -0x38(%rbp)
movq -0x60(%rbp), %rax
movq -0x38(%rbp), %rsi
movl -0x1c(%rbp), %edx
movq -0x28(%rbp), %rcx
movl 0x18(%rbp), %r8d
movl 0x20(%rbp), %r9d
movl 0x28(%rbp), %ebx
movl 0x30(%rbp), %r11d
movl (%rdi), %r10d
orl $0x20000, %r10d         # imm = 0x20000
leaq -0x98(%rbp), %rdi
movl %ebx, (%rsp)
movl %r11d, 0x8(%rsp)
movl %r10d, 0x10(%rsp)
callq *%rax
movq -0xa8(%rbp), %rax
movq -0x98(%rbp), %rcx
movq %rcx, -0x54(%rbp)
movq -0x90(%rbp), %rcx
movq %rcx, -0x4c(%rbp)
movq -0x88(%rbp), %rcx
movq %rcx, -0x44(%rbp)
movl -0x80(%rbp), %ecx
movl %ecx, -0x3c(%rbp)
movl 0x8(%rax), %edi
addl $0x1, %edi
movq -0x18(%rbp), %rsi
callq 0x34b40
movq -0xa8(%rbp), %rax
movl 0x4(%rax), %edi
addl $0x1, %edi
movq -0x28(%rbp), %rsi
callq 0x34b40
movq -0x38(%rbp), %rdi
callq 0x3380
movq -0xa8(%rbp), %rax
movl (%rax), %eax
cmpl -0x54(%rbp), %eax
jne 0x34b20
movq -0xa8(%rbp), %rax
movl 0x4(%rax), %ecx
subl -0x50(%rbp), %ecx
movl %ecx, 0x14(%rax)
movl 0x8(%rax), %ecx
subl -0x4c(%rbp), %ecx
movl %ecx, 0x18(%rax)
jmp 0x34b22
movq -0xa0(%rbp), %rax
addq $0xc8, %rsp
popq %rbx
popq %rbp
retq
nopw %cs:(%rax,%rax)