// File: /workspace/github_c_makefile_star2_O1/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
movq 0x8(%rdi), %r14
movl %r14d, %r12d
shrl $0x18, %r12d
xorl %r13d, %r13d
addq 0x30(%rdi), %r12
shrq $0x30, %r14
je 0x1c28b
xorl %eax, %eax
movl (%r12,%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, %r13d
incq %rax
cmpq %rax, %r14
jne 0x1c258
movl %r13d, %r13d
movabsq $0x1000000000000, %r15  # imm = 0x1000000000000
cmpq %r13, 0x8(%rbx)
jae 0x1c2ea
leaq -0x1(%r13), %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)
cmpq %r15, 0x8(%r9)
jae 0x1c30f
cmpq %r13, (%rbx)
jne 0x1c408
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq (%r12,%r14,4), %rbp
movq 0x32cce(%rip), %r10     # 0x4efe8
leaq 0x23f0f(%rip), %r11     # 0x40230
xorl %r15d, %r15d
xorl %r14d, %r14d
movl (%r12,%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 0x1c38e
cmpl $0x10, %ecx
jb 0x1c3c0
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 0x1c356
jmp 0x1c3c0
cmpl $0x5, %edx
je 0x1c3c0
cmpl $0x4, %edx
je 0x1c3ba
cmpl $0x2, %edx
jne 0x1c3d6
cmpl $0x10, %ecx
jb 0x1c3c0
movq (%rbx), %rcx
movq 0x10(%rbx), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, (%rbx)
movb $0x0, (%rdx,%rcx)
decl %eax
jne 0x1c3a2
jmp 0x1c3c0
addl %r14d, %eax
movl %eax, %r14d
incq %r15
movzwl 0xe(%r9), %eax
cmpq %rax, %r15
jb 0x1c327
jmp 0x1c2f7
movq (%r10), %rdi
movsbl (%rdx,%r11), %edx
movq 0x30(%r9), %rcx
leaq 0x257aa(%rip), %rsi     # 0x41b93
xorl %eax, %eax
movq %r9, (%rsp)
callq 0x3750
leaq 0x23e35(%rip), %r11     # 0x40230
movq 0x32be6(%rip), %r10     # 0x4efe8
movq (%rsp), %r9
jmp 0x1c3c0
leaq 0x257b9(%rip), %rdi     # 0x41bc8
leaq 0x2516e(%rip), %rsi     # 0x41584
leaq 0x257ba(%rip), %rcx     # 0x41bd7
movl $0x47, %edx
callq 0x31b0