// File: /workspace/github_c_makefile_star2_O3/sc932[P]ALE/src/ALElike.c
// Function: recordSNPPhase
void recordSNPPhase(FILE *snpPhaseFile, int *printedHeader, bam1_t *bam, alignSet_t *aln, assemblyT *theAssembly) {
	if (bam == NULL || (bam->core.flag & BAM_FUNMAP) == BAM_FUNMAP)
		return;

	contig_t *contig = theAssembly->contigs[ bam->core.tid ];
	if (contig->ambiguousBaseCount == 0)
		return;

	int32_t startPos = bam->core.pos;
	int32_t endPos;

	uint32_t idx = binary_search_lower_bound(contig->ambiguousBasePositions, 0, contig->ambiguousBaseCount - 1, startPos);
	uint8_t *seq = NULL;
	unsigned char *qual = NULL;
	while(idx < contig->ambiguousBaseCount) {
		int32_t pos = contig->ambiguousBasePositions[idx++];
		if (pos < startPos) {
			continue;
		}
		if (seq == NULL) {
			endPos = bam_calend(&bam->core, bam1_cigar(bam));
			seq = bam1_seq(bam);
			qual = bam1_qual(bam);
		}
		if (pos >= endPos)
			break;
		int32_t seqPos = calcRefPos2SeqPos(bam, pos);
		if (seqPos >= 0) {
			assert(seqPos < bam->core.l_qseq);
			if (*printedHeader != bam->core.tid) {
				fprintf(snpPhaseFile, "\n%s\t%0.1e\t%0.1e\t%d", bam1_qname(bam), aln->likelihood, aln->likelihoodInsert, bam->core.tid);
				*printedHeader = bam->core.tid;
			}
			fprintf(snpPhaseFile, "\t%d\t%c\t%c", pos, bam_nt16_rev_table[ bam1_seqi(seq, seqPos) ], qual[seqPos]+33);
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rcx, 0x20(%rsp)
movq %rsi, 0x18(%rsp)
movq %rdi, 0x10(%rsp)
testq %rdx, %rdx
je 0x7fee
movq %rdx, %r14
testb $0x4, 0xc(%rdx)
jne 0x7fee
movq 0xa0(%r8), %rax
movslq (%r14), %rcx
movq (%rax,%rcx,8), %rbx
movl 0x20(%rbx), %eax
testl %eax, %eax
je 0x7fee
movl 0x4(%r14), %r12d
leal -0x1(%rax), %ecx
testl %eax, %eax
jle 0x7eac
movq 0x28(%rbx), %rsi
xorl %edx, %edx
movl %ecx, %r8d
movl %r8d, %edi
shrl $0x1f, %edi
addl %r8d, %edi
sarl %edi
movslq %edi, %r8
cmpl %r12d, (%rsi,%r8,4)
jge 0x7e9c
incl %edi
movl %edi, %edx
jmp 0x7ea2
je 0x7eae
decl %edi
movl %edi, %ecx
leal (%rcx,%rdx), %r8d
cmpl %ecx, %edx
jle 0x7e82
jmp 0x7eae
xorl %edx, %edx
cmpl %ecx, %edx
cmovll %edx, %ecx
cmpl %eax, %ecx
jae 0x7fee
movl %ecx, %ebp
movq $0x0, 0x8(%rsp)
xorl %r15d, %r15d
movl %r12d, (%rsp)
movq 0x28(%rbx), %rax
movl (%rax,%rbp,4), %r13d
cmpl %r12d, %r13d
jl 0x7fdf
testq %r15, %r15
jne 0x7f24
movzbl 0xb(%r14), %esi
addq 0x30(%r14), %rsi
movq %r14, %rdi
callq 0xf6d8
movq 0x8(%r14), %r15
movq %r15, %rcx
shrq $0x30, %rcx
shlq $0x2, %rcx
addq 0x30(%r14), %rcx
movl %eax, 0x4(%rsp)
shrl $0x18, %r15d
addq %rcx, %r15
movl 0x10(%r14), %eax
incl %eax
sarl %eax
cltq
addq %r15, %rax
movq %rax, 0x8(%rsp)
cmpl 0x4(%rsp), %r13d
jge 0x7fee
movq %rbx, %r12
movq %r14, %rdi
movl %r13d, %esi
callq 0x7d66
testl %eax, %eax
js 0x7fd8
movl %eax, %ebx
cmpl 0x10(%r14), %eax
jge 0x7ffd
movl (%r14), %ecx
movq 0x18(%rsp), %rax
cmpl %ecx, (%rax)
je 0x7f8c
movq 0x30(%r14), %rdx
movq 0x20(%rsp), %rax
movsd (%rax), %xmm0
movsd 0x8(%rax), %xmm1
movq 0x10(%rsp), %rdi
leaq 0x1a4a4(%rip), %rsi     # 0x2241f
movb $0x2, %al
callq 0x3350
movl (%r14), %eax
movq 0x18(%rsp), %rcx
movl %eax, (%rcx)
leaq 0x2487d(%rip), %rax     # 0x2c810
movq (%rax), %rax
movl %ebx, %edx
movl %ebx, %ecx
shrl %ecx
movzbl (%r15,%rcx), %esi
shll $0x2, %ebx
notb %bl
andb $0x4, %bl
movl %ebx, %ecx
shrl %cl, %esi
andl $0xf, %esi
movsbl (%rax,%rsi), %ecx
movq 0x8(%rsp), %rax
movzbl (%rax,%rdx), %r8d
addl $0x21, %r8d
movq 0x10(%rsp), %rdi
leaq 0x1a464(%rip), %rsi     # 0x22432
movl %r13d, %edx
xorl %eax, %eax
callq 0x3350
movq %r12, %rbx
movl (%rsp), %r12d
incq %rbp
movl 0x20(%rbx), %eax
cmpq %rax, %rbp
jb 0x7ecd
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1a3b9(%rip), %rdi     # 0x223bd
leaq 0x19d5a(%rip), %rsi     # 0x21d65
leaq 0x1a3c5(%rip), %rcx     # 0x223d7
movl $0x53a, %edx            # imm = 0x53A
callq 0x3230