// File: /workspace/github_c_makefile_star2_O0/lh3[P]minimap2/align.c
// Function: mm_fix_cigar
static void mm_fix_cigar(mm_reg1_t *r, const uint8_t *qseq, const uint8_t *tseq, int *qshift, int *tshift)
{
	mm_extra_t *p = r->p;
	int32_t toff = 0, qoff = 0, to_shrink = 0;
	uint32_t k;
	*qshift = *tshift = 0;
	if (p->n_cigar <= 1) return;
	for (k = 0; k < p->n_cigar; ++k) { // indel left alignment
		uint32_t op = p->cigar[k]&0xf, len = p->cigar[k]>>4;
		if (len == 0) to_shrink = 1;
		if (op == MM_CIGAR_MATCH) {
			toff += len, qoff += len;
		} else if (op == MM_CIGAR_INS || op == MM_CIGAR_DEL) {
			if (k > 0 && k < p->n_cigar - 1 && (p->cigar[k-1]&0xf) == 0 && (p->cigar[k+1]&0xf) == 0) {
				int l, prev_len = p->cigar[k-1] >> 4;
				if (op == MM_CIGAR_INS) {
					for (l = 0; l < prev_len; ++l)
						if (qseq[qoff - 1 - l] != qseq[qoff + len - 1 - l])
							break;
				} else {
					for (l = 0; l < prev_len; ++l)
						if (tseq[toff - 1 - l] != tseq[toff + len - 1 - l])
							break;
				}
				if (l > 0)
					p->cigar[k-1] -= l<<4, p->cigar[k+1] += l<<4, qoff -= l, toff -= l;
				if (l == prev_len) to_shrink = 1;
			}
			if (op == MM_CIGAR_INS) qoff += len;
			else toff += len;
		} else if (op == MM_CIGAR_N_SKIP) {
			toff += len;
		}
	}
	assert(qoff == r->qe - r->qs && toff == r->re - r->rs);
	for (k = 0; k < p->n_cigar - 2; ++k) { // fix CIGAR like 5I6D7I
		if ((p->cigar[k]&0xf) > 0 && (p->cigar[k]&0xf) + (p->cigar[k+1]&0xf) == 3) {
			uint32_t l, s[3] = {0,0,0};
			for (l = k; l < p->n_cigar; ++l) { // count number of adjacent I and D
				uint32_t op = p->cigar[l]&0xf;
				if (op == MM_CIGAR_INS || op == MM_CIGAR_DEL || p->cigar[l]>>4 == 0)
					s[op] += p->cigar[l] >> 4;
				else break;
			}
			if (s[1] > 0 && s[2] > 0 && l - k > 2) { // turn to a single I and a single D
				p->cigar[k]   = s[1]<<4|MM_CIGAR_INS;
				p->cigar[k+1] = s[2]<<4|MM_CIGAR_DEL;
				for (k += 2; k < l; ++k)
					p->cigar[k] &= 0xf;
				to_shrink = 1;
			}
			k = l;
		}
	}
	if (to_shrink) { // squeeze out zero-length operations
		int32_t l = 0;
		for (k = 0; k < p->n_cigar; ++k) // squeeze out zero-length operations
			if (p->cigar[k]>>4 != 0)
				p->cigar[l++] = p->cigar[k];
		p->n_cigar = l;
		for (k = l = 0; k < p->n_cigar; ++k) // merge two adjacent operations if they are the same
			if (k == p->n_cigar - 1 || (p->cigar[k]&0xf) != (p->cigar[k+1]&0xf))
				p->cigar[l++] = p->cigar[k];
			else p->cigar[k+1] += p->cigar[k]>>4<<4; // add length to the next CIGAR operator
		p->n_cigar = l;
	}
	if ((p->cigar[0]&0xf) == MM_CIGAR_INS || (p->cigar[0]&0xf) == MM_CIGAR_DEL) { // get rid of leading I or D
		int32_t l = p->cigar[0] >> 4;
		if ((p->cigar[0]&0xf) == MM_CIGAR_INS) {
			if (r->rev) r->qe -= l;
			else r->qs += l;
			*qshift = l;
		} else r->rs += l, *tshift = l;
		--p->n_cigar;
		memmove(p->cigar, p->cigar + 1, p->n_cigar * 4);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
movq %rax, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movq -0x28(%rbp), %rax
movl $0x0, (%rax)
movq -0x20(%rbp), %rax
movl $0x0, (%rax)
movq -0x30(%rbp), %rax
cmpl $0x1, 0x18(%rax)
ja 0x290e0
jmp 0x296a1
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
movq -0x30(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jae 0x29304
movq -0x30(%rbp), %rax
movl -0x40(%rbp), %ecx
movl 0x1c(%rax,%rcx,4), %eax
andl $0xf, %eax
movl %eax, -0x44(%rbp)
movq -0x30(%rbp), %rax
movl -0x40(%rbp), %ecx
movl 0x1c(%rax,%rcx,4), %eax
shrl $0x4, %eax
movl %eax, -0x48(%rbp)
cmpl $0x0, -0x48(%rbp)
jne 0x29126
movl $0x1, -0x3c(%rbp)
cmpl $0x0, -0x44(%rbp)
jne 0x29143
movl -0x48(%rbp), %eax
addl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x48(%rbp), %eax
addl -0x38(%rbp), %eax
movl %eax, -0x38(%rbp)
jmp 0x292f4
cmpl $0x1, -0x44(%rbp)
je 0x29153
cmpl $0x2, -0x44(%rbp)
jne 0x292e1
cmpl $0x0, -0x40(%rbp)
jbe 0x292c5
movl -0x40(%rbp), %eax
movq -0x30(%rbp), %rcx
movl 0x18(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jae 0x292c5
movq -0x30(%rbp), %rax
movl -0x40(%rbp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
movl 0x1c(%rax,%rcx,4), %eax
andl $0xf, %eax
cmpl $0x0, %eax
jne 0x292c5
movq -0x30(%rbp), %rax
movl -0x40(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movl 0x1c(%rax,%rcx,4), %eax
andl $0xf, %eax
cmpl $0x0, %eax
jne 0x292c5
movq -0x30(%rbp), %rax
movl -0x40(%rbp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
movl 0x1c(%rax,%rcx,4), %eax
shrl $0x4, %eax
movl %eax, -0x50(%rbp)
cmpl $0x1, -0x44(%rbp)
jne 0x29214
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x50(%rbp), %eax
jge 0x29212
movq -0x10(%rbp), %rax
movl -0x38(%rbp), %ecx
subl $0x1, %ecx
subl -0x4c(%rbp), %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
movq -0x10(%rbp), %rcx
movl -0x38(%rbp), %edx
addl -0x48(%rbp), %edx
subl $0x1, %edx
subl -0x4c(%rbp), %edx
movl %edx, %edx
movzbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
je 0x29205
jmp 0x29212
jmp 0x29207
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x291cd
jmp 0x29262
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x50(%rbp), %eax
jge 0x29260
movq -0x18(%rbp), %rax
movl -0x34(%rbp), %ecx
subl $0x1, %ecx
subl -0x4c(%rbp), %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
movq -0x18(%rbp), %rcx
movl -0x34(%rbp), %edx
addl -0x48(%rbp), %edx
subl $0x1, %edx
subl -0x4c(%rbp), %edx
movl %edx, %edx
movzbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
je 0x29253
jmp 0x29260
jmp 0x29255
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x2921b
jmp 0x29262
cmpl $0x0, -0x4c(%rbp)
jle 0x292b4
movl -0x4c(%rbp), %esi
shll $0x4, %esi
movq -0x30(%rbp), %rax
movl -0x40(%rbp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
movl 0x1c(%rax,%rcx,4), %edx
subl %esi, %edx
movl %edx, 0x1c(%rax,%rcx,4)
movl -0x4c(%rbp), %edx
shll $0x4, %edx
movq -0x30(%rbp), %rax
movl -0x40(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, %ecx
addl 0x1c(%rax,%rcx,4), %edx
movl %edx, 0x1c(%rax,%rcx,4)
movl -0x4c(%rbp), %ecx
movl -0x38(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x38(%rbp)
movl -0x4c(%rbp), %ecx
movl -0x34(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x34(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x50(%rbp), %eax
jne 0x292c3
movl $0x1, -0x3c(%rbp)
jmp 0x292c5
cmpl $0x1, -0x44(%rbp)
jne 0x292d6
movl -0x48(%rbp), %eax
addl -0x38(%rbp), %eax
movl %eax, -0x38(%rbp)
jmp 0x292df
movl -0x48(%rbp), %eax
addl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
jmp 0x292f2
cmpl $0x3, -0x44(%rbp)
jne 0x292f0
movl -0x48(%rbp), %eax
addl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
jmp 0x292f2
jmp 0x292f4
jmp 0x292f6
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x290e7
movl -0x38(%rbp), %eax
movq -0x8(%rbp), %rcx
movl 0x14(%rcx), %ecx
movq -0x8(%rbp), %rdx
subl 0x10(%rdx), %ecx
cmpl %ecx, %eax
jne 0x29330
movl -0x34(%rbp), %eax
movq -0x8(%rbp), %rcx
movl 0x1c(%rcx), %ecx
movq -0x8(%rbp), %rdx
subl 0x18(%rdx), %ecx
cmpl %ecx, %eax
jne 0x29330
jmp 0x2934f
leaq 0x2f115(%rip), %rdi     # 0x5844c
leaq 0x2ee71(%rip), %rsi     # 0x581af
movl $0x8b, %edx
leaq 0x2f19f(%rip), %rcx     # 0x584e9
callq 0x21a0
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
movq -0x30(%rbp), %rcx
movl 0x18(%rcx), %ecx
subl $0x2, %ecx
cmpl %ecx, %eax
jae 0x294b9
movq -0x30(%rbp), %rax
movl -0x40(%rbp), %ecx
movl 0x1c(%rax,%rcx,4), %eax
andl $0xf, %eax
cmpl $0x0, %eax
jbe 0x294a9
movq -0x30(%rbp), %rax
movl -0x40(%rbp), %ecx
movl 0x1c(%rax,%rcx,4), %eax
andl $0xf, %eax
movq -0x30(%rbp), %rcx
movl -0x40(%rbp), %edx
addl $0x1, %edx
movl %edx, %edx
movl 0x1c(%rcx,%rdx,4), %ecx
andl $0xf, %ecx
addl %ecx, %eax
cmpl $0x3, %eax
jne 0x294a9
leaq -0x60(%rbp), %rdi
xorl %esi, %esi
movl $0xc, %edx
callq 0x21b0
movl -0x40(%rbp), %eax
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %eax
movq -0x30(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jae 0x2942a
movq -0x30(%rbp), %rax
movl -0x54(%rbp), %ecx
movl 0x1c(%rax,%rcx,4), %eax
andl $0xf, %eax
movl %eax, -0x64(%rbp)
cmpl $0x1, -0x64(%rbp)
je 0x29400
cmpl $0x2, -0x64(%rbp)
je 0x29400
movq -0x30(%rbp), %rax
movl -0x54(%rbp), %ecx
movl 0x1c(%rax,%rcx,4), %eax
shrl $0x4, %eax
cmpl $0x0, %eax
jne 0x2941b
movq -0x30(%rbp), %rax
movl -0x54(%rbp), %ecx
movl 0x1c(%rax,%rcx,4), %ecx
shrl $0x4, %ecx
movl -0x64(%rbp), %eax
addl -0x60(%rbp,%rax,4), %ecx
movl %ecx, -0x60(%rbp,%rax,4)
jmp 0x2941d
jmp 0x2942a
jmp 0x2941f
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x293c4
cmpl $0x0, -0x5c(%rbp)
jbe 0x294a3
cmpl $0x0, -0x58(%rbp)
jbe 0x294a3
movl -0x54(%rbp), %eax
subl -0x40(%rbp), %eax
cmpl $0x2, %eax
jbe 0x294a3
movl -0x5c(%rbp), %edx
shll $0x4, %edx
orl $0x1, %edx
movq -0x30(%rbp), %rax
movl -0x40(%rbp), %ecx
movl %edx, 0x1c(%rax,%rcx,4)
movl -0x58(%rbp), %edx
shll $0x4, %edx
orl $0x2, %edx
movq -0x30(%rbp), %rax
movl -0x40(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movl %edx, 0x1c(%rax,%rcx,4)
movl -0x40(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x54(%rbp), %eax
jae 0x2949c
movq -0x30(%rbp), %rax
movl -0x40(%rbp), %ecx
movl 0x1c(%rax,%rcx,4), %edx
andl $0xf, %edx
movl %edx, 0x1c(%rax,%rcx,4)
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x29477
movl $0x1, -0x3c(%rbp)
movl -0x54(%rbp), %eax
movl %eax, -0x40(%rbp)
jmp 0x294ab
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x29356
cmpl $0x0, -0x3c(%rbp)
je 0x295de
movl $0x0, -0x68(%rbp)
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
movq -0x30(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jae 0x2951e
movq -0x30(%rbp), %rax
movl -0x40(%rbp), %ecx
movl 0x1c(%rax,%rcx,4), %eax
shrl $0x4, %eax
cmpl $0x0, %eax
je 0x29511
movq -0x30(%rbp), %rax
movl -0x40(%rbp), %ecx
movl 0x1c(%rax,%rcx,4), %edx
movq -0x30(%rbp), %rax
movl -0x68(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x68(%rbp)
movslq %ecx, %rcx
movl %edx, 0x1c(%rax,%rcx,4)
jmp 0x29513
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x294d1
movl -0x68(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x18(%rax)
movl $0x0, -0x68(%rbp)
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
movq -0x30(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jae 0x295d4
movl -0x40(%rbp), %eax
movq -0x30(%rbp), %rcx
movl 0x18(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
je 0x2957c
movq -0x30(%rbp), %rax
movl -0x40(%rbp), %ecx
movl 0x1c(%rax,%rcx,4), %eax
andl $0xf, %eax
movq -0x30(%rbp), %rcx
movl -0x40(%rbp), %edx
addl $0x1, %edx
movl %edx, %edx
movl 0x1c(%rcx,%rdx,4), %ecx
andl $0xf, %ecx
cmpl %ecx, %eax
je 0x2959f
movq -0x30(%rbp), %rax
movl -0x40(%rbp), %ecx
movl 0x1c(%rax,%rcx,4), %edx
movq -0x30(%rbp), %rax
movl -0x68(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x68(%rbp)
movslq %ecx, %rcx
movl %edx, 0x1c(%rax,%rcx,4)
jmp 0x295c4
movq -0x30(%rbp), %rax
movl -0x40(%rbp), %ecx
movl 0x1c(%rax,%rcx,4), %edx
shrl $0x4, %edx
shll $0x4, %edx
movq -0x30(%rbp), %rax
movl -0x40(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, %ecx
addl 0x1c(%rax,%rcx,4), %edx
movl %edx, 0x1c(%rax,%rcx,4)
jmp 0x295c6
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x29536
movl -0x68(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x18(%rax)
movq -0x30(%rbp), %rax
movl 0x1c(%rax), %eax
andl $0xf, %eax
cmpl $0x1, %eax
je 0x29600
movq -0x30(%rbp), %rax
movl 0x1c(%rax), %eax
andl $0xf, %eax
cmpl $0x2, %eax
jne 0x296a1
movq -0x30(%rbp), %rax
movl 0x1c(%rax), %eax
shrl $0x4, %eax
movl %eax, -0x6c(%rbp)
movq -0x30(%rbp), %rax
movl 0x1c(%rax), %eax
andl $0xf, %eax
cmpl $0x1, %eax
jne 0x29657
movq -0x8(%rbp), %rax
movl 0x3c(%rax), %eax
shrl $0xa, %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x2963f
movl -0x6c(%rbp), %edx
movq -0x8(%rbp), %rax
movl 0x14(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x14(%rax)
jmp 0x2964c
movl -0x6c(%rbp), %ecx
movq -0x8(%rbp), %rax
addl 0x10(%rax), %ecx
movl %ecx, 0x10(%rax)
movl -0x6c(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
jmp 0x2966d
movl -0x6c(%rbp), %ecx
movq -0x8(%rbp), %rax
addl 0x18(%rax), %ecx
movl %ecx, 0x18(%rax)
movl -0x6c(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movq -0x30(%rbp), %rax
movl 0x18(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x18(%rax)
movq -0x30(%rbp), %rdi
addq $0x1c, %rdi
movq -0x30(%rbp), %rsi
addq $0x1c, %rsi
addq $0x4, %rsi
movq -0x30(%rbp), %rax
movl 0x18(%rax), %eax
shll $0x2, %eax
movl %eax, %eax
movl %eax, %edx
callq 0x2330
addq $0x70, %rsp
popq %rbp
retq
nopw (%rax,%rax)