// File: /workspace/github_c_makefile_star2_O2/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 0x60d1
movq %rdx, %r14
testb $0x4, 0xc(%rdx)
jne 0x60d1
movq 0xa0(%r8), %rax
movslq (%r14), %rcx
movq (%rax,%rcx,8), %r12
movl 0x20(%r12), %ebx
testl %ebx, %ebx
je 0x60d1
movl 0x4(%r14), %r15d
movq 0x28(%r12), %rdi
leal -0x1(%rbx), %edx
xorl %esi, %esi
movl %r15d, %ecx
callq 0x5e4a
movl %eax, %r13d
xorl %ebp, %ebp
movq $0x0, 0x8(%rsp)
movl %r15d, (%rsp)
movl %ebx, %eax
cmpq %rax, %r13
jae 0x60d1
movq 0x28(%r12), %rax
movl (%rax,%r13,4), %ebx
cmpl %r15d, %ebx
jl 0x60c4
testq %rbp, %rbp
jne 0x600b
movzbl 0xb(%r14), %esi
addq 0x30(%r14), %rsi
movq %r14, %rdi
callq 0xd54c
movq 0x8(%r14), %rbp
movq %rbp, %rcx
shrq $0x30, %rcx
shlq $0x2, %rcx
addq 0x30(%r14), %rcx
movl %eax, 0x4(%rsp)
shrl $0x18, %ebp
addq %rcx, %rbp
movl 0x10(%r14), %eax
incl %eax
sarl %eax
cltq
addq %rbp, %rax
movq %rax, 0x8(%rsp)
cmpl 0x4(%rsp), %ebx
jge 0x60d1
movq %r14, %rdi
movl %ebx, %esi
callq 0x5e84
testl %eax, %eax
js 0x60c0
movl %eax, %r15d
cmpl 0x10(%r14), %eax
jge 0x60e0
movl (%r14), %ecx
movq 0x18(%rsp), %rax
cmpl %ecx, (%rax)
je 0x606f
movq 0x30(%r14), %rdx
movq 0x20(%rsp), %rax
movsd (%rax), %xmm0
movsd 0x8(%rax), %xmm1
movq 0x10(%rsp), %rdi
leaq 0x18391(%rip), %rsi     # 0x1e3ef
movb $0x2, %al
callq 0x3350
movl (%r14), %eax
movq 0x18(%rsp), %rcx
movl %eax, (%rcx)
leaq 0x2379a(%rip), %rax     # 0x29810
movq (%rax), %rax
movl %r15d, %edx
movl %r15d, %ecx
shrl %ecx
movzbl (%rbp,%rcx), %esi
shll $0x2, %r15d
notb %r15b
andb $0x4, %r15b
movl %r15d, %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 0x1834b(%rip), %rsi     # 0x1e402
movl %ebx, %edx
xorl %eax, %eax
callq 0x3350
movl (%rsp), %r15d
movl 0x20(%r12), %ebx
incq %r13
jmp 0x5fa9
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x182a6(%rip), %rdi     # 0x1e38d
leaq 0x17c47(%rip), %rsi     # 0x1dd35
leaq 0x182b2(%rip), %rcx     # 0x1e3a7
movl $0x53a, %edx            # imm = 0x53A
callq 0x3230