// File: /workspace/github_cpp_makefile_star2_O3/statgen[P]statgen/lib/samtools-0.1.7a-hybrid/bam_color.c
// Function: bam_aux_getCEi
char bam_aux_getCEi(bam1_t *b, int i)
{
	int cs_i;
	uint8_t *c = bam_aux_get(b, "CS");
	char *cs = NULL;
	char prev_b, cur_b;
	char cur_color, cor_color;

	// return the base if the tag was not found
	if(0 == c) return 0;
	
	cs = bam_aux2Z(c);

	// adjust for strandedness and leading adaptor
	if(bam1_strand(b)) { //reverse strand
		cs_i = strlen(cs) - 1 - i;
		// get current color
		cur_color = cs[cs_i];
		// get previous base.  Note: must rc adaptor
		prev_b = (cs_i == 1) ? "TGCAN"[(int)bam_aux_nt2int(cs[0])] : bam_nt16_rev_table[bam1_seqi(bam1_seq(b), i+1)];
		// get current base
		cur_b = bam_nt16_rev_table[bam1_seqi(bam1_seq(b), i)]; 
	}
	else {
		cs_i=i+1;
		// get current color
		cur_color = cs[cs_i];
		// get previous base
		prev_b = (0 == i) ? cs[0] : bam_nt16_rev_table[bam1_seqi(bam1_seq(b), i-1)];
		// get current base
		cur_b = bam_nt16_rev_table[bam1_seqi(bam1_seq(b), i)];
	}

	// corrected color
	cor_color = bam_aux_ntnt2cs(prev_b, cur_b);

	if(cur_color == cor_color) { 
		return '-';
	}
	else {
		return cur_color;
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl %esi, %ebx
movq %rdi, %r15
leaq 0x16915(%rip), %rsi     # 0x24cc6
callq 0x1175c
testq %rax, %rax
je 0xe439
movq %rax, %rdi
callq 0x12251
movq %rax, %r14
movq 0x8(%r15), %r12
btq $0x24, %r12
jb 0xe440
movslq %ebx, %r8
movq %r12, %rdi
shrq $0x2e, %rdi
andl $-0x4, %edi
leaq 0x20afb(%rip), %rax     # 0x2eee0
movq (%rax), %rax
movq 0x30(%r15), %rsi
testl %ebx, %ebx
je 0xe4ee
leaq (%rsi,%rdi), %rcx
shrl $0x18, %r12d
addq %r12, %rcx
leal -0x1(%rbx), %r9d
movl %r9d, %edx
shrl $0x1f, %edx
leal (%rbx,%rdx), %r10d
decl %r10d
movl %r10d, %edx
sarl %edx
movslq %edx, %rdx
movzbl (%rdx,%rcx), %edx
andl $0x3e, %r10d
subl %r10d, %r9d
shll $0x2, %r9d
movb $0x4, %cl
subb %r9b, %cl
shrl %cl, %edx
andl $0xf, %edx
addq %rax, %rdx
jmp 0xe4f5
xorl %eax, %eax
jmp 0xe53e
movq %r14, %rdi
callq 0x32d0
movl %ebx, %ecx
notl %ecx
addl %ecx, %eax
cltq
movb (%r14,%rax), %bpl
cmpl $0x1, %eax
jne 0xe48d
movsbl (%r14), %edi
callq 0xe323
movzbl %al, %eax
leaq 0x16865(%rip), %rdx     # 0x24cd1
addq %rax, %rdx
leaq 0x20a6a(%rip), %rax     # 0x2eee0
movq (%rax), %rax
movq 0x30(%r15), %r8
movq %r12, %rdi
shrq $0x2e, %rdi
andl $-0x4, %edi
shrl $0x18, %r12d
jmp 0xe4e3
leaq 0x20a4c(%rip), %rax     # 0x2eee0
movq (%rax), %rax
movq 0x30(%r15), %r8
movq %r12, %rdi
shrq $0x30, %rdi
leaq (%r8,%rdi,4), %rcx
shrl $0x18, %r12d
addq %r12, %rcx
leal 0x1(%rbx), %esi
movl %esi, %edx
shrl $0x1f, %edx
leal (%rbx,%rdx), %r9d
incl %r9d
movl %r9d, %edx
sarl %edx
movslq %edx, %rdx
movzbl (%rdx,%rcx), %edx
andl $0x3e, %r9d
subl %r9d, %esi
shll $0x2, %esi
movb $0x4, %cl
subb %sil, %cl
shrl %cl, %edx
shlq $0x2, %rdi
andl $0xf, %edx
addq %rax, %rdx
movq %r12, %rsi
addq %r8, %rsi
addq %rdi, %rsi
jmp 0xe500
shrl $0x18, %r12d
movq %r14, %rdx
movb 0x1(%r14,%r8), %bpl
addq %rdi, %rsi
addq %r12, %rsi
movl %ebx, %ecx
shrl $0x1f, %ecx
addl %ebx, %ecx
movl %ecx, %edi
sarl %edi
movslq %edi, %rdi
movzbl (%rsi,%rdi), %esi
andl $0x3e, %ecx
subl %ecx, %ebx
shll $0x2, %ebx
movb $0x4, %cl
subb %bl, %cl
shrl %cl, %esi
andl $0xf, %esi
movsbl (%rax,%rsi), %esi
movsbl (%rdx), %edi
callq 0xe361
cmpb %al, %bpl
movzbl %bpl, %ecx
movl $0x2d, %eax
cmovnel %ecx, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
nop