// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x754d
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
shrq $0x20, %rax
andq $0xffff, %rax           # imm = 0xFFFF
andl $0x4, %eax
cmpl $0x4, %eax
jne 0x7552
jmp 0x77a2
movq -0x28(%rbp), %rax
movq 0xa0(%rax), %rax
movq -0x18(%rbp), %rcx
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpl $0x0, 0x20(%rax)
jne 0x757b
jmp 0x77a2
movq -0x18(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x34(%rbp)
movq -0x30(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x30(%rbp), %rax
movl 0x20(%rax), %edx
subl $0x1, %edx
movl -0x34(%rbp), %ecx
xorl %esi, %esi
callq 0x7300
movl %eax, -0x3c(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
movl -0x3c(%rbp), %eax
movq -0x30(%rbp), %rcx
cmpl 0x20(%rcx), %eax
jae 0x77a2
movq -0x30(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x3c(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x3c(%rbp)
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0x75e9
jmp 0x75b4
cmpq $0x0, -0x48(%rbp)
jne 0x76a5
movq -0x18(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rsi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
shrq $0x18, %rax
andq $0xff, %rax
cltq
addq %rax, %rsi
callq 0x15e60
movl %eax, -0x38(%rbp)
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x8(%rcx), %rcx
shrq $0x30, %rcx
shll $0x2, %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq -0x18(%rbp), %rcx
movq 0x8(%rcx), %rcx
shrq $0x18, %rcx
andq $0xff, %rcx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x8(%rcx), %rcx
shrq $0x30, %rcx
shll $0x2, %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq -0x18(%rbp), %rcx
movq 0x8(%rcx), %rcx
shrq $0x18, %rcx
andq $0xff, %rcx
movslq %ecx, %rcx
addq %rcx, %rax
movq -0x18(%rbp), %rcx
movl 0x10(%rcx), %ecx
addl $0x1, %ecx
sarl %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movl -0x54(%rbp), %eax
cmpl -0x38(%rbp), %eax
jl 0x76b2
jmp 0x77a2
movq -0x18(%rbp), %rdi
movl -0x54(%rbp), %esi
callq 0x7390
movl %eax, -0x58(%rbp)
cmpl $0x0, -0x58(%rbp)
jl 0x779d
movl -0x58(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jge 0x76d9
jmp 0x76f8
leaq 0x28d3d(%rip), %rdi     # 0x3041d
leaq 0x286de(%rip), %rsi     # 0x2fdc5
movl $0x53a, %edx            # imm = 0x53A
leaq 0x28d44(%rip), %rcx     # 0x30437
callq 0x3220
movq -0x10(%rbp), %rax
movl (%rax), %eax
movq -0x18(%rbp), %rcx
cmpl (%rcx), %eax
je 0x7743
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rdx
movq -0x20(%rbp), %rax
movsd (%rax), %xmm0
movq -0x20(%rbp), %rax
movsd 0x8(%rax), %xmm1
movq -0x18(%rbp), %rax
movl (%rax), %ecx
leaq 0x28d4f(%rip), %rsi     # 0x3047f
movb $0x2, %al
callq 0x3350
movq -0x18(%rbp), %rax
movl (%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, (%rax)
movq -0x8(%rbp), %rdi
movl -0x54(%rbp), %edx
leaq 0x3279f(%rip), %rax     # 0x39ef0
movq (%rax), %rax
movq -0x48(%rbp), %rcx
movl -0x58(%rbp), %esi
sarl %esi
movslq %esi, %rsi
movzbl (%rcx,%rsi), %esi
movl -0x58(%rbp), %ecx
xorl $-0x1, %ecx
andl $0x1, %ecx
shll $0x2, %ecx
sarl %cl, %esi
movl %esi, %ecx
andl $0xf, %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %ecx
movq -0x50(%rbp), %rax
movslq -0x58(%rbp), %rsi
movzbl (%rax,%rsi), %r8d
addl $0x21, %r8d
leaq 0x28cfc(%rip), %rsi     # 0x30492
movb $0x0, %al
callq 0x3350
jmp 0x75b4
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)