// File: /workspace/github_c_makefile_star2_O0/lh3[P]minimap2/align.c
// Function: mm_test_zdrop
static int mm_test_zdrop(void *km, const mm_mapopt_t *opt, const uint8_t *qseq, const uint8_t *tseq, uint32_t n_cigar, uint32_t *cigar, const int8_t *mat)
{
	uint32_t k;
	int32_t score = 0, max = INT32_MIN, max_i = -1, max_j = -1, i = 0, j = 0, max_zdrop = 0;
	int pos[2][2] = {{-1, -1}, {-1, -1}}, q_len, t_len;

	// find the score and the region where score drops most along diagonal
	for (k = 0, score = 0; k < n_cigar; ++k) {
		uint32_t l, op = cigar[k]&0xf, len = cigar[k]>>4;
		if (op == MM_CIGAR_MATCH) {
			for (l = 0; l < len; ++l) {
				score += mat[tseq[i + l] * 5 + qseq[j + l]];
				update_max_zdrop(score, i+l, j+l, &max, &max_i, &max_j, opt->e, &max_zdrop, pos);
			}
			i += len, j += len;
		} else if (op == MM_CIGAR_INS || op == MM_CIGAR_DEL || op == MM_CIGAR_N_SKIP) {
			score -= opt->q + opt->e * len;
			if (op == MM_CIGAR_INS) j += len;
			else i += len;
			update_max_zdrop(score, i, j, &max, &max_i, &max_j, opt->e, &max_zdrop, pos);
		}
	}

	// test if there is an inversion in the most dropped region
	q_len = pos[1][1] - pos[1][0], t_len = pos[0][1] - pos[0][0];
	if (!(opt->flag&(MM_F_SPLICE|MM_F_SR|MM_F_FOR_ONLY|MM_F_REV_ONLY)) && max_zdrop > opt->zdrop_inv && q_len < opt->max_gap && t_len < opt->max_gap) {
		uint8_t *qseq2;
		void *qp;
		int q_off, t_off;
		qseq2 = (uint8_t*)kmalloc(km, q_len);
		for (i = 0; i < q_len; ++i) {
			int c = qseq[pos[1][1] - i - 1];
			qseq2[i] = c >= 4? 4 : 3 - c;
		}
		qp = ksw_ll_qinit(km, 2, q_len, qseq2, 5, mat);
		score = ksw_ll_i16(qp, t_len, tseq + pos[0][0], opt->q, opt->e, &q_off, &t_off);
		kfree(km, qseq2);
		kfree(km, qp);
		if (score >= opt->min_chain_score * opt->a && score >= opt->min_dp_max)
			return 2; // there is a potential inversion
	}
	return max_zdrop > opt->zdrop? 1 : 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movl %r8d, -0x2c(%rbp)
movq %r9, -0x38(%rbp)
movl $0x0, -0x40(%rbp)
movl $0x80000000, -0x44(%rbp) # imm = 0x80000000
movl $0xffffffff, -0x48(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0x4c(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x50(%rbp)
movl $0x0, -0x54(%rbp)
movl $0x0, -0x58(%rbp)
movq 0x30531(%rip), %rax     # 0x58540
movq %rax, -0x70(%rbp)
movq 0x3052e(%rip), %rax     # 0x58548
movq %rax, -0x68(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jae 0x281b5
movq -0x38(%rbp), %rax
movl -0x3c(%rbp), %ecx
movl (%rax,%rcx,4), %eax
andl $0xf, %eax
movl %eax, -0x80(%rbp)
movq -0x38(%rbp), %rax
movl -0x3c(%rbp), %ecx
movl (%rax,%rcx,4), %eax
shrl $0x4, %eax
movl %eax, -0x84(%rbp)
cmpl $0x0, -0x80(%rbp)
jne 0x2811a
movl $0x0, -0x7c(%rbp)
movl -0x7c(%rbp), %eax
cmpl -0x84(%rbp), %eax
jae 0x280fd
movq 0x10(%rbp), %rax
movq -0x28(%rbp), %rcx
movl -0x50(%rbp), %edx
addl -0x7c(%rbp), %edx
movl %edx, %edx
movzbl (%rcx,%rdx), %ecx
imull $0x5, %ecx, %ecx
movq -0x20(%rbp), %rdx
movl -0x54(%rbp), %esi
addl -0x7c(%rbp), %esi
movl %esi, %esi
movzbl (%rdx,%rsi), %edx
addl %edx, %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
addl -0x40(%rbp), %eax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %edi
movl -0x50(%rbp), %esi
addl -0x7c(%rbp), %esi
movl -0x54(%rbp), %edx
addl -0x7c(%rbp), %edx
movq -0x18(%rbp), %rax
movl 0x70(%rax), %r11d
leaq -0x70(%rbp), %rax
leaq -0x44(%rbp), %rcx
leaq -0x48(%rbp), %r8
leaq -0x4c(%rbp), %r9
leaq -0x58(%rbp), %r10
movl %r11d, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x28f90
movl -0x7c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x7c(%rbp)
jmp 0x2806c
movl -0x84(%rbp), %eax
addl -0x50(%rbp), %eax
movl %eax, -0x50(%rbp)
movl -0x84(%rbp), %eax
addl -0x54(%rbp), %eax
movl %eax, -0x54(%rbp)
jmp 0x281a5
cmpl $0x1, -0x80(%rbp)
je 0x2812c
cmpl $0x2, -0x80(%rbp)
je 0x2812c
cmpl $0x3, -0x80(%rbp)
jne 0x281a3
movq -0x18(%rbp), %rax
movl 0x6c(%rax), %ecx
movq -0x18(%rbp), %rax
movl 0x70(%rax), %eax
imull -0x84(%rbp), %eax
addl %eax, %ecx
movl -0x40(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x40(%rbp)
cmpl $0x1, -0x80(%rbp)
jne 0x2815f
movl -0x84(%rbp), %eax
addl -0x54(%rbp), %eax
movl %eax, -0x54(%rbp)
jmp 0x2816b
movl -0x84(%rbp), %eax
addl -0x50(%rbp), %eax
movl %eax, -0x50(%rbp)
movl -0x40(%rbp), %edi
movl -0x50(%rbp), %esi
movl -0x54(%rbp), %edx
movq -0x18(%rbp), %rax
movl 0x70(%rax), %r11d
leaq -0x70(%rbp), %rax
leaq -0x44(%rbp), %rcx
leaq -0x48(%rbp), %r8
leaq -0x4c(%rbp), %r9
leaq -0x58(%rbp), %r10
movl %r11d, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x28f90
jmp 0x281a5
jmp 0x281a7
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x2802c
movl -0x64(%rbp), %eax
subl -0x68(%rbp), %eax
movl %eax, -0x74(%rbp)
movl -0x6c(%rbp), %eax
subl -0x70(%rbp), %eax
movl %eax, -0x78(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
andq $0x301080, %rax         # imm = 0x301080
cmpq $0x0, %rax
jne 0x2834d
movl -0x58(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x94(%rcx), %eax
jle 0x2834d
movl -0x74(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x1c(%rcx), %eax
jge 0x2834d
movl -0x78(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x1c(%rcx), %eax
jge 0x2834d
movq -0x10(%rbp), %rdi
movslq -0x74(%rbp), %rsi
callq 0x1aae0
movq %rax, -0x90(%rbp)
movl $0x0, -0x50(%rbp)
movl -0x50(%rbp), %eax
cmpl -0x74(%rbp), %eax
jge 0x28296
movq -0x20(%rbp), %rax
movl -0x64(%rbp), %ecx
subl -0x50(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
movl %eax, -0xa4(%rbp)
cmpl $0x4, -0xa4(%rbp)
jl 0x28264
movl $0x4, %eax
movl %eax, -0xa8(%rbp)
jmp 0x28275
movl $0x3, %eax
subl -0xa4(%rbp), %eax
movl %eax, -0xa8(%rbp)
movl -0xa8(%rbp), %eax
movb %al, %dl
movq -0x90(%rbp), %rax
movslq -0x50(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x2822c
movq -0x10(%rbp), %rdi
movl -0x74(%rbp), %edx
movq -0x90(%rbp), %rcx
movq 0x10(%rbp), %r9
movl $0x2, %esi
movl $0x5, %r8d
callq 0x2e8f0
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rdi
movl -0x78(%rbp), %esi
movq -0x28(%rbp), %rdx
movslq -0x70(%rbp), %rax
addq %rax, %rdx
movq -0x18(%rbp), %rax
movl 0x6c(%rax), %ecx
movq -0x18(%rbp), %rax
movl 0x70(%rax), %r8d
leaq -0x9c(%rbp), %r9
leaq -0xa0(%rbp), %rax
movq %rax, (%rsp)
callq 0x2eca0
movl %eax, -0x40(%rbp)
movq -0x10(%rbp), %rdi
movq -0x90(%rbp), %rsi
callq 0x1a8c0
movq -0x10(%rbp), %rdi
movq -0x98(%rbp), %rsi
callq 0x1a8c0
movl -0x40(%rbp), %eax
movq -0x18(%rbp), %rcx
movl 0x34(%rcx), %ecx
movq -0x18(%rbp), %rdx
imull 0x64(%rdx), %ecx
cmpl %ecx, %eax
jl 0x2834b
movl -0x40(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x9c(%rcx), %eax
jl 0x2834b
movl $0x2, -0x4(%rbp)
jmp 0x28369
jmp 0x2834d
movl -0x58(%rbp), %edx
movq -0x18(%rbp), %rax
movl 0x90(%rax), %esi
xorl %eax, %eax
movl $0x1, %ecx
cmpl %esi, %edx
cmovgl %ecx, %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xc0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)