// File: /workspace/github_c_makefile_star2_O3/xiongxu[P]bam2bedGraph2/samtools-0.1.19/padding.c
// Function: unpad_seq
static void unpad_seq(bam1_t *b, kstring_t *s)
{
	int k, j, i;
	int length;
	uint32_t *cigar = bam1_cigar(b);
	uint8_t *seq = bam1_seq(b);
	// b->core.l_qseq gives length of the SEQ entry (including soft clips, S)
	// We need the padded length after alignment from the CIGAR (excluding
	// soft clips S, but including pads from CIGAR D operations)
	length = 0;
	for (k = 0; k < b->core.n_cigar; ++k) {
		int op, ol;
		op= bam_cigar_op(cigar[k]);
		ol = bam_cigar_oplen(cigar[k]);
		if (op == BAM_CMATCH || op == BAM_CEQUAL || op == BAM_CDIFF || op == BAM_CDEL)
			length += ol;
	}
	ks_resize(s, length);
	for (k = 0, s->l = 0, j = 0; k < b->core.n_cigar; ++k) {
		int op, ol;
		op = bam_cigar_op(cigar[k]);
		ol = bam_cigar_oplen(cigar[k]);
		if (op == BAM_CMATCH || op == BAM_CEQUAL || op == BAM_CDIFF) {
			for (i = 0; i < ol; ++i, ++j) s->s[s->l++] = bam1_seqi(seq, j);
		} else if (op == BAM_CSOFT_CLIP) {
			j += ol;
		} else if (op == BAM_CHARD_CLIP) {
			/* do nothing */
		} else if (op == BAM_CDEL) {
			for (i = 0; i < ol; ++i) s->s[s->l++] = 0;
                } else {
			fprintf(stderr, "[depad] ERROR: Didn't expect CIGAR op %c in read %s\n", BAM_CIGAR_STR[op], bam1_qname(b));
                        assert(-1);
		}
	}
	assert(length == s->l);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r9
movabsq $0x1000000000000, %r15  # imm = 0x1000000000000
movq 0x8(%rdi), %r14
movl %r14d, %r13d
shrl $0x18, %r13d
xorl %r12d, %r12d
addq 0x30(%rdi), %r13
shrq $0x30, %r14
je 0x1c83a
xorl %eax, %eax
movl (%r13,%rax,4), %ecx
movl %ecx, %edx
andl $0xf, %edx
movl %ecx, %esi
shrl $0x4, %esi
cmpl $0x7, %edx
movl $0x0, %edi
cmovel %esi, %edi
testb $0x7, %cl
cmovel %esi, %edi
cmpl $0x2, %edx
cmovel %esi, %edi
addl %edi, %r12d
incq %rax
cmpq %rax, %r14
jne 0x1c7b0
movl %r12d, %r12d
cmpq %r12, 0x8(%rbx)
jae 0x1c83a
leaq -0x1(%r12), %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rsi
shrq $0x10, %rsi
orq %rax, %rsi
incq %rsi
movq %rsi, 0x8(%rbx)
movq 0x10(%rbx), %rdi
movq %r9, %rbp
callq 0x3720
movq %rbp, %r9
movq %rax, 0x10(%rbx)
movq $0x0, (%rbx)
xorl %eax, %eax
cmpq %r15, 0x8(%r9)
jb 0x1c94e
leaq (,%r14,4), %rbp
addq %r13, %rbp
movq 0x33789(%rip), %r10     # 0x4ffe8
leaq 0x24a0a(%rip), %r11     # 0x41270
xorl %r15d, %r15d
xorl %r14d, %r14d
movl (%r13,%r15,4), %ecx
movl %ecx, %edx
andl $0xf, %edx
movl %ecx, %eax
shrl $0x4, %eax
cmpq $0x7, %rdx
setne %sil
testb $0x7, %cl
setne %dil
testb %sil, %dil
jne 0x1c8d4
cmpl $0x10, %ecx
jb 0x1c906
leal (,%r14,4), %edx
movl %r14d, %ecx
sarl %ecx
movslq %ecx, %rcx
movzbl (%rbp,%rcx), %esi
movl %edx, %ecx
notb %cl
andb $0x4, %cl
shrl %cl, %esi
andb $0xf, %sil
movq (%rbx), %rcx
movq 0x10(%rbx), %rdi
leaq 0x1(%rcx), %r8
movq %r8, (%rbx)
movb %sil, (%rdi,%rcx)
incl %r14d
addl $0x4, %edx
decl %eax
jne 0x1c89c
jmp 0x1c906
cmpl $0x5, %edx
je 0x1c906
cmpl $0x4, %edx
je 0x1c900
cmpl $0x2, %edx
jne 0x1c919
cmpl $0x10, %ecx
jb 0x1c906
movq (%rbx), %rcx
movq 0x10(%rbx), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, (%rbx)
movb $0x0, (%rdx,%rcx)
decl %eax
jne 0x1c8e8
jmp 0x1c906
addl %r14d, %eax
movl %eax, %r14d
incq %r15
movzwl 0xe(%r9), %eax
cmpq %rax, %r15
jb 0x1c86c
jmp 0x1c94b
movq (%r10), %rdi
movsbl (%rdx,%r11), %edx
movq 0x30(%r9), %rcx
leaq 0x262b7(%rip), %rsi     # 0x42be3
xorl %eax, %eax
movq %r9, (%rsp)
callq 0x3750
leaq 0x24932(%rip), %r11     # 0x41270
movq 0x336a3(%rip), %r10     # 0x4ffe8
movq (%rsp), %r9
jmp 0x1c906
movq (%rbx), %rax
cmpq %r12, %rax
jne 0x1c962
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x262af(%rip), %rdi     # 0x42c18
leaq 0x25c64(%rip), %rsi     # 0x425d4
leaq 0x262b0(%rip), %rcx     # 0x42c27
movl $0x47, %edx
callq 0x31b0