// File: /workspace/github_c_makefile_star2_O1/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, 0x10(%rsp)
movq %rdi, 0x18(%rsp)
testq %rdx, %rdx
je 0x7caf
movq %rdx, %r14
testb $0x4, 0xc(%rdx)
jne 0x7caf
movq 0xa0(%r8), %rax
movslq (%r14), %rcx
movq (%rax,%rcx,8), %r15
movl 0x20(%r15), %eax
testl %eax, %eax
je 0x7caf
movl 0x4(%r14), %edi
leal -0x1(%rax), %ebp
testl %eax, %eax
jle 0x7b68
movq 0x28(%r15), %rcx
xorl %eax, %eax
movl %ebp, %esi
movl %esi, %edx
shrl $0x1f, %edx
addl %esi, %edx
sarl %edx
movslq %edx, %rsi
cmpl %edi, (%rcx,%rsi,4)
jge 0x7b59
incl %edx
movl %edx, %eax
jmp 0x7b5f
je 0x7b6a
decl %edx
movl %edx, %ebp
leal (%rax,%rbp), %esi
cmpl %ebp, %eax
jle 0x7b42
jmp 0x7b6a
xorl %eax, %eax
cmpl %ebp, %eax
cmovll %eax, %ebp
xorl %r12d, %r12d
movq $0x0, 0x8(%rsp)
movl %edi, (%rsp)
cmpl 0x20(%r15), %ebp
jae 0x7caf
movq 0x28(%r15), %rcx
movl (%rcx,%rbp,4), %r13d
cmpl %edi, %r13d
jge 0x7b9c
xorl %ebx, %ebx
jmp 0x7ca4
testq %r12, %r12
jne 0x7be2
movzbl 0xb(%r14), %esi
addq 0x30(%r14), %rsi
movq %r14, %rdi
callq 0xf2c0
movl (%rsp), %edi
movq 0x8(%r14), %r12
movq %r12, %rcx
shrq $0x30, %rcx
shlq $0x2, %rcx
addq 0x30(%r14), %rcx
shrl $0x18, %r12d
addq %rcx, %r12
movl 0x10(%r14), %ecx
incl %ecx
sarl %ecx
movslq %ecx, %rcx
addq %r12, %rcx
movq %rcx, 0x8(%rsp)
movb $0x1, %bl
cmpl %eax, %r13d
jge 0x7ca4
movl %eax, 0x4(%rsp)
movq %r14, %rdi
movl %r13d, %esi
callq 0x7a14
testl %eax, %eax
js 0x7c9b
movl %eax, %ebx
cmpl 0x10(%r14), %eax
jge 0x7cbe
movl (%r14), %ecx
movq 0x10(%rsp), %rax
cmpl %ecx, (%rax)
je 0x7c4b
movq 0x30(%r14), %rdx
movq 0x20(%rsp), %rax
movsd (%rax), %xmm0
movsd 0x8(%rax), %xmm1
movq 0x18(%rsp), %rdi
leaq 0x1a785(%rip), %rsi     # 0x223bf
movb $0x2, %al
callq 0x3350
movl (%r14), %eax
movq 0x10(%rsp), %rcx
movl %eax, (%rcx)
leaq 0x24bbe(%rip), %rax     # 0x2c810
movq (%rax), %rax
movl %ebx, %edx
movl %ebx, %ecx
shrl %ecx
movzbl (%r12,%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
xorl %ebx, %ebx
movq 0x18(%rsp), %rdi
leaq 0x1a743(%rip), %rsi     # 0x223d2
movl %r13d, %edx
xorl %eax, %eax
callq 0x3350
jmp 0x7c9d
xorl %ebx, %ebx
movl (%rsp), %edi
movl 0x4(%rsp), %eax
incq %rbp
testb %bl, %bl
je 0x7b7e
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1a698(%rip), %rdi     # 0x2235d
leaq 0x1a039(%rip), %rsi     # 0x21d05
leaq 0x1a6a4(%rip), %rcx     # 0x22377
movl $0x53a, %edx            # imm = 0x53A
callq 0x3230