// File: /workspace/github_c_makefile_star2_O1/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, 0x8(%rsp)
movq %rdi, %rbx
movl (%rdi), %ebp
callq 0x3820
movsd %xmm0, 0x10(%rsp)
cmpl $0x0, 0x40(%rbx)
jle 0x1a793
andl $0x8, %ebp
cmpl $0x1, %ebp
movl $0x0, %eax
adcl $0x2, %eax
movl %eax, 0xc(%rsp)
xorl %r12d, %r12d
movq 0x48(%rbx), %rax
movq (%rax,%r12,8), %r13
movq 0x30(%r13), %rsi
movsbq (%rsi), %rbp
testq %rbp, %rbp
je 0x1a5f1
movb 0x1(%rsi), %al
testb %al, %al
je 0x1a5f3
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 0x1a5d5
jmp 0x1a5f3
xorl %ebp, %ebp
movzbl 0xb(%r13), %eax
addq %rax, %rsi
movq %r13, %rdi
callq 0x22d1c
cmpl 0x8(%rsp), %eax
jg 0x1a796
movl %eax, %r15d
movl (%r14), %edi
testl %edi, %edi
je 0x1a696
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 0x1a68a
testb $0x1, %r10b
jne 0x1a670
movq 0x18(%r14), %r10
movl %eax, %r11d
cmpq %rbp, (%r10,%r11,8)
je 0x1a68a
addl %edx, %eax
cmpl %edi, %eax
movl %edi, %ecx
movl $0x0, %r9d
cmovbl %r9d, %ecx
subl %ecx, %eax
cmpl %esi, %eax
jne 0x1a642
movl %edi, %eax
jmp 0x1a698
shrl %cl, %r9d
testb $0x3, %r9b
cmovnel %edi, %eax
jmp 0x1a698
xorl %eax, %eax
movl $0x3, %ecx
cmpl %edi, %eax
je 0x1a72e
movq 0x20(%r14), %rcx
movl %eax, %eax
imulq $0x114, %rax, %rax      # imm = 0x114
movq 0x10c(%rcx,%rax), %rbp
btl $0x14, %ebp
movl 0xc(%rsp), %eax
jb 0x1a710
btl $0x13, %ebp
setae %dl
movl %ebp, %ecx
notl %ecx
xorl %eax, %eax
testl $0xa0000, %ecx          # imm = 0xA0000
sete %cl
orb %cl, %dl
je 0x1a6e5
movb %cl, %al
xorl $0x3, %eax
jmp 0x1a710
movb $0x59, 0x7(%rsp)
shrl $0x12, %ebp
andl $0x1, %ebp
movq %r13, %rdi
leaq 0x26a1d(%rip), %rsi     # 0x41117
movl $0x41, %edx
movl $0x1, %ecx
leaq 0x7(%rsp), %r8
callq 0x21bc8
movl %ebp, %eax
movl $0x1, %ecx
subl %eax, %ecx
movsd 0x23911(%rip), %xmm0    # 0x3e030
ucomisd 0x10(%rsp), %xmm0
cmovbel %eax, %ecx
cmpl $0x2, %eax
cmovael %eax, %ecx
cmpl $0x3, %ecx
jne 0x1a749
callq 0x3820
xorl %ecx, %ecx
movsd 0x238ee(%rip), %xmm1    # 0x3e030
ucomisd %xmm0, %xmm1
seta %cl
movl %ecx, %eax
movq 0x28(%rbx,%rax,8), %rdi
movq %r13, %rsi
callq 0x23ccf
testq %r13, %r13
je 0x1a76e
movq 0x30(%r13), %rdi
callq 0x3350
movq %r13, %rdi
callq 0x3350
movq 0x48(%rbx), %rax
movq $0x0, (%rax,%r12,8)
cmpl 0x8(%rsp), %r15d
jg 0x1a796
incq %r12
movslq 0x40(%rbx), %rax
cmpq %rax, %r12
jl 0x1a5b5
jmp 0x1a796
xorl %r12d, %r12d
movq 0x48(%rbx), %rdi
movl %r12d, %eax
leaq (%rdi,%rax,8), %rsi
movslq 0x40(%rbx), %rdx
movslq %r12d, %r14
subq %r14, %rdx
shlq $0x3, %rdx
callq 0x34e0
subl %r14d, 0x40(%rbx)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq