// File: /workspace/github_c_makefile_star2_O0/skoren[P]bacValidation/bamcat.c
// Function: bam_calend
uint32_t bam_calend(const bam1_core_t *c, const uint32_t *cigar)
{
	int k, end = c->pos;
	for (k = 0; k < c->n_cigar; ++k) {
		int op  = bam_cigar_op(cigar[k]);
		int len = bam_cigar_oplen(cigar[k]);
		if (op == BAM_CBACK) { // move backward
			int l, u, v;
			if (k == c->n_cigar - 1) break; // skip trailing 'B'
			for (l = k - 1, u = v = 0; l >= 0; --l) {
				int op1  = bam_cigar_op(cigar[l]);
				int len1 = bam_cigar_oplen(cigar[l]);
				if (bam_cigar_type(op1)&1) { // consume query
					if (u + len1 >= len) { // stop
						if (bam_cigar_type(op1)&2) v += len - u;
						break;
					} else u += len1;
				}
				if (bam_cigar_type(op1)&2) v += len1;
			}
			end = l < 0? c->pos : end - v;
		} else if (bam_cigar_type(op)&2) end += bam_cigar_oplen(cigar[k]);
	}
	return end;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x18(%rbp)
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jae 0x65b4
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movl (%rax,%rcx,4), %eax
andl $0xf, %eax
movl %eax, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movl (%rax,%rcx,4), %eax
shrl $0x4, %eax
movl %eax, -0x20(%rbp)
cmpl $0x9, -0x1c(%rbp)
jne 0x6577
movl -0x14(%rbp), %eax
movq -0x8(%rbp), %rcx
movl 0x10(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jne 0x648f
jmp 0x65b4
movl -0x14(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x24(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x28(%rbp)
cmpl $0x0, -0x24(%rbp)
jl 0x6554
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movl (%rax,%rcx,4), %eax
andl $0xf, %eax
movl %eax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movl (%rax,%rcx,4), %eax
shrl $0x4, %eax
movl %eax, -0x34(%rbp)
movl -0x30(%rbp), %ecx
shll %ecx
movl $0x3c1a7, %eax          # imm = 0x3C1A7
sarl %cl, %eax
andl $0x3, %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x6524
movl -0x28(%rbp), %eax
addl -0x34(%rbp), %eax
cmpl -0x20(%rbp), %eax
jl 0x6519
movl -0x30(%rbp), %ecx
shll %ecx
movl $0x3c1a7, %eax          # imm = 0x3C1A7
sarl %cl, %eax
andl $0x3, %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x6517
movl -0x20(%rbp), %eax
subl -0x28(%rbp), %eax
addl -0x2c(%rbp), %eax
movl %eax, -0x2c(%rbp)
jmp 0x6554
movl -0x34(%rbp), %eax
addl -0x28(%rbp), %eax
movl %eax, -0x28(%rbp)
jmp 0x6524
movl -0x30(%rbp), %ecx
shll %ecx
movl $0x3c1a7, %eax          # imm = 0x3C1A7
sarl %cl, %eax
andl $0x3, %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x6544
movl -0x34(%rbp), %eax
addl -0x2c(%rbp), %eax
movl %eax, -0x2c(%rbp)
jmp 0x6546
movl -0x24(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x64a6
cmpl $0x0, -0x24(%rbp)
jge 0x6566
movq -0x8(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x38(%rbp)
jmp 0x656f
movl -0x18(%rbp), %eax
subl -0x2c(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
movl %eax, -0x18(%rbp)
jmp 0x65a4
movl -0x1c(%rbp), %ecx
shll %ecx
movl $0x3c1a7, %eax          # imm = 0x3C1A7
sarl %cl, %eax
andl $0x3, %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x65a2
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movl (%rax,%rcx,4), %eax
shrl $0x4, %eax
addl -0x18(%rbp), %eax
movl %eax, -0x18(%rbp)
jmp 0x65a4
jmp 0x65a6
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x643d
movl -0x18(%rbp), %eax
popq %rbp
retq
nopl (%rax)