// File: /workspace/github_c_makefile_star2_O3/xiongxu[P]bam2bedGraph2/samtools-0.1.19/phase.c
// Function: dump_aln
static void dump_aln(phaseg_t *g, int min_pos, const nseq_t *hash)
{
	int i, is_flip, drop_ambi;
	drop_ambi = g->flag & FLAG_DROP_AMBI;
	is_flip = (drand48() < 0.5);
	for (i = 0; i < g->n; ++i) {
		int end, which;
		uint64_t key;
		khint_t k;
		bam1_t *b = g->b[i];
		key = X31_hash_string(bam1_qname(b));
		end = bam_calend(&b->core, bam1_cigar(b));
		if (end > min_pos) break;
		k = kh_get(64, hash, key);
		if (k == kh_end(hash)) which = 3;
		else {
			frag_t *f = &kh_val(hash, k);
			if (f->ambig) which = drop_ambi? 2 : 3;
			else if (f->phased && f->flip) which = 2;
			else if (f->phased == 0) which = 3;
			else { // phased and not flipped
				char c = 'Y';
				which = f->phase;
				bam_aux_append(b, "ZP", 'A', 1, (uint8_t*)&c);
			}
			if (which < 2 && is_flip) which = 1 - which; // increase the randomness
		}
		if (which == 3) which = (drand48() < 0.5);
		bam_write1(g->out[which], b);
		bam_destroy1(b);
		g->b[i] = 0;
	}
	memmove(g->b, g->b + i, (g->n - i) * sizeof(void*));
	g->n -= i;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %r14
movl %esi, 0xc(%rsp)
movq %rdi, %rbx
movl (%rdi), %eax
movl %eax, 0x8(%rsp)
callq 0x3820
movl 0x40(%rbx), %eax
testl %eax, %eax
jle 0x1b001
movsd 0x241e2(%rip), %xmm1    # 0x3f018
xorl %eax, %eax
ucomisd %xmm0, %xmm1
seta %al
movq %rax, 0x10(%rsp)
xorl %r12d, %r12d
xorl %r15d, %r15d
movq 0x48(%rbx), %rax
movq (%rax,%r15,8), %r13
movq 0x30(%r13), %rsi
movsbq (%rsi), %rbp
testq %rbp, %rbp
je 0x1ae86
movb 0x1(%rsi), %al
testb %al, %al
je 0x1ae88
leaq 0x2(%rsi), %rcx
movq %rbp, %rdx
shlq $0x5, %rdx
subq %rbp, %rdx
movsbq %al, %rbp
addq %rdx, %rbp
movb (%rcx), %al
incq %rcx
testb %al, %al
jne 0x1ae6a
jmp 0x1ae88
xorl %ebp, %ebp
movzbl 0xb(%r13), %eax
addq %rax, %rsi
movq %r13, %rdi
callq 0x2343c
cmpl 0xc(%rsp), %eax
jg 0x1b006
movl (%r14), %edi
testl %edi, %edi
je 0x1af20
movq %rbp, %rcx
shrq $0x21, %rcx
movl %ebp, %eax
shll $0xb, %eax
xorl %eax, %ecx
xorl %ebp, %ecx
movl %ecx, %eax
xorl %edx, %edx
divl %edi
movl %edx, %esi
leal -0x1(%rdi), %r8d
movl %ecx, %eax
xorl %edx, %edx
divl %r8d
incl %edx
movq 0x10(%r14), %r8
movl %esi, %eax
movl %eax, %ecx
shrl $0x4, %ecx
movl (%r8,%rcx,4), %r9d
leal (%rax,%rax), %ecx
andl $0x1e, %ecx
movl %r9d, %r10d
shrl %cl, %r10d
testb $0x2, %r10b
jne 0x1af14
testb $0x1, %r10b
jne 0x1af02
movq 0x18(%r14), %r10
movl %eax, %r11d
cmpq %rbp, (%r10,%r11,8)
je 0x1af14
addl %edx, %eax
cmpl %edi, %eax
movl %edi, %ecx
cmovbl %r12d, %ecx
subl %ecx, %eax
cmpl %esi, %eax
jne 0x1aed4
jmp 0x1af26
shrl %cl, %r9d
testb $0x3, %r9b
cmovnel %edi, %eax
jmp 0x1af22
xorl %eax, %eax
cmpl %edi, %eax
jne 0x1af80
callq 0x3820
xorl %eax, %eax
movsd 0x240e3(%rip), %xmm1    # 0x3f018
ucomisd %xmm0, %xmm1
seta %al
movq 0x28(%rbx,%rax,8), %rdi
movq %r13, %rsi
callq 0x24370
testq %r13, %r13
je 0x1af5f
movq 0x30(%r13), %rdi
callq 0x3350
movq %r13, %rdi
callq 0x3350
movq 0x48(%rbx), %rax
movq $0x0, (%rax,%r15,8)
incq %r15
movslq 0x40(%rbx), %rax
cmpq %rax, %r15
jl 0x1ae4a
jmp 0x1b009
movq 0x20(%r14), %rcx
movl %eax, %eax
imulq $0x114, %rax, %rax      # imm = 0x114
movq 0x10c(%rcx,%rax), %rbp
btl $0x14, %ebp
jb 0x1afec
movl %ebp, %ecx
notl %ecx
movl $0x2, %eax
testl $0xa0000, %ecx          # imm = 0xA0000
je 0x1af3c
btl $0x13, %ebp
jae 0x1af26
movb $0x59, 0x7(%rsp)
shrl $0x12, %ebp
andl $0x1, %ebp
xorq 0x10(%rsp), %rbp
movq %r13, %rdi
leaq 0x27197(%rip), %rsi     # 0x42167
movl $0x41, %edx
movl $0x1, %ecx
leaq 0x7(%rsp), %r8
callq 0x222b8
movq %rbp, %rax
jmp 0x1af3c
movl $0x2, %eax
testb $0x8, 0x8(%rsp)
je 0x1af26
jmp 0x1af3c
xorl %r15d, %r15d
jmp 0x1b009
movl 0x40(%rbx), %eax
movq 0x48(%rbx), %rdi
movl %r15d, %ecx
leaq (%rdi,%rcx,8), %rsi
subl %r15d, %eax
movslq %eax, %rdx
shlq $0x3, %rdx
callq 0x34e0
subl %r15d, 0x40(%rbx)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq