// File: /workspace/github_c_makefile_star2_O0/lh3[P]fermi-lite/ksw.c
// Function: ksw_align
kswr_t ksw_align(int qlen, uint8_t *query, int tlen, uint8_t *target, int m, const int8_t *mat, int gapo, int gape, 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);

	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, gapo, gape, 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, gapo, gape, 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
subq $0xb0, %rsp
movq %rdi, -0xa0(%rbp)
movq %rdi, -0x98(%rbp)
movq 0x30(%rbp), %rax
movl 0x28(%rbp), %eax
movl 0x20(%rbp), %eax
movl 0x18(%rbp), %eax
movq 0x10(%rbp), %rax
movl %esi, -0x4(%rbp)
movq %rdx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movq %r8, -0x20(%rbp)
movl %r9d, -0x24(%rbp)
cmpq $0x0, 0x30(%rbp)
je 0x20bad
movq 0x30(%rbp), %rax
cmpq $0x0, (%rax)
je 0x20bad
movq 0x30(%rbp), %rax
movq (%rax), %rax
movq %rax, -0xa8(%rbp)
jmp 0x20be0
movl 0x28(%rbp), %ecx
andl $0x10000, %ecx          # imm = 0x10000
movl $0x2, %edi
movl $0x1, %eax
cmpl $0x0, %ecx
cmovnel %eax, %edi
movl -0x4(%rbp), %esi
movq -0x10(%rbp), %rdx
movl -0x24(%rbp), %ecx
movq 0x10(%rbp), %r8
callq 0x1e720
movq %rax, -0xa8(%rbp)
movq -0xa8(%rbp), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, 0x30(%rbp)
je 0x20c07
movq 0x30(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x20c07
movq -0x30(%rbp), %rcx
movq 0x30(%rbp), %rax
movq %rcx, (%rax)
movq -0x30(%rbp), %rax
movzbl 0xb(%rax), %edx
leaq -0x2166(%rip), %rax     # 0x1eab0
leaq -0xf9d(%rip), %rcx      # 0x1fc80
cmpl $0x2, %edx
cmoveq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x30(%rbp), %rax
movzbl 0xb(%rax), %eax
movl %eax, -0x28(%rbp)
movq -0x58(%rbp), %rax
movq -0x30(%rbp), %rsi
movl -0x14(%rbp), %edx
movq -0x20(%rbp), %rcx
movl 0x18(%rbp), %r8d
movl 0x20(%rbp), %r9d
movl 0x28(%rbp), %r10d
leaq -0x74(%rbp), %rdi
movl %r10d, (%rsp)
callq *%rax
movq -0xa0(%rbp), %rax
movq -0x74(%rbp), %rcx
movq %rcx, (%rax)
movq -0x6c(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x64(%rbp), %rcx
movq %rcx, 0x10(%rax)
movl -0x5c(%rbp), %ecx
movl %ecx, 0x18(%rax)
cmpq $0x0, 0x30(%rbp)
jne 0x20c8c
movq -0x30(%rbp), %rdi
callq 0x2040
movl 0x28(%rbp), %eax
andl $0x80000, %eax          # imm = 0x80000
cmpl $0x0, %eax
je 0x20cbc
movl 0x28(%rbp), %eax
andl $0x40000, %eax          # imm = 0x40000
cmpl $0x0, %eax
je 0x20cc1
movq -0xa0(%rbp), %rax
movl (%rax), %eax
movl 0x28(%rbp), %ecx
andl $0xffff, %ecx           # imm = 0xFFFF
cmpl %ecx, %eax
jge 0x20cc1
jmp 0x20dc8
movq -0xa0(%rbp), %rax
movl 0x8(%rax), %edi
addl $0x1, %edi
movq -0x10(%rbp), %rsi
callq 0x20de0
movq -0xa0(%rbp), %rax
movl 0x4(%rax), %edi
addl $0x1, %edi
movq -0x20(%rbp), %rsi
callq 0x20de0
movq -0xa0(%rbp), %rax
movl -0x28(%rbp), %edi
movl 0x8(%rax), %esi
addl $0x1, %esi
movq -0x10(%rbp), %rdx
movl -0x24(%rbp), %ecx
movq 0x10(%rbp), %r8
callq 0x1e720
movq -0xa0(%rbp), %rdi
movq %rax, -0x30(%rbp)
movq -0x58(%rbp), %rax
movq -0x30(%rbp), %rsi
movl -0x14(%rbp), %edx
movq -0x20(%rbp), %rcx
movl 0x18(%rbp), %r8d
movl 0x20(%rbp), %r9d
movl (%rdi), %r10d
orl $0x20000, %r10d         # imm = 0x20000
leaq -0x90(%rbp), %rdi
movl %r10d, (%rsp)
callq *%rax
movq -0xa0(%rbp), %rax
movq -0x90(%rbp), %rcx
movq %rcx, -0x4c(%rbp)
movq -0x88(%rbp), %rcx
movq %rcx, -0x44(%rbp)
movq -0x80(%rbp), %rcx
movq %rcx, -0x3c(%rbp)
movl -0x78(%rbp), %ecx
movl %ecx, -0x34(%rbp)
movl 0x8(%rax), %edi
addl $0x1, %edi
movq -0x10(%rbp), %rsi
callq 0x20de0
movq -0xa0(%rbp), %rax
movl 0x4(%rax), %edi
addl $0x1, %edi
movq -0x20(%rbp), %rsi
callq 0x20de0
movq -0x30(%rbp), %rdi
callq 0x2040
movq -0xa0(%rbp), %rax
movl (%rax), %eax
cmpl -0x4c(%rbp), %eax
jne 0x20dc6
movq -0xa0(%rbp), %rax
movl 0x4(%rax), %ecx
subl -0x48(%rbp), %ecx
movl %ecx, 0x14(%rax)
movl 0x8(%rax), %ecx
subl -0x44(%rbp), %ecx
movl %ecx, 0x18(%rax)
jmp 0x20dc8
movq -0x98(%rbp), %rax
addq $0xb0, %rsp
popq %rbp
retq
nopl (%rax,%rax)