// File: /workspace/github_c_makefile_star2_O3/xiongxu[P]bam2bedGraph2/samtools-0.1.19/bgzf.c
// Function: mt_flush
static int mt_flush(BGZF *fp)
{
	int i;
	mtaux_t *mt = (mtaux_t*)fp->mt;
	if (fp->block_offset) mt_queue(fp); // guaranteed that assertion does not fail
	// signal all the workers to compress
	pthread_mutex_lock(&mt->lock);
	for (i = 0; i < mt->n_threads; ++i) mt->w[i].toproc = 1;
	mt->proc_cnt = 0;
	pthread_cond_broadcast(&mt->cv);
	pthread_mutex_unlock(&mt->lock);
	// worker 0 is doing things here
	worker_aux(&mt->w[0]);
	// wait for all the threads to complete
	while (mt->proc_cnt < mt->n_threads);
	// dump data to disk
	for (i = 0; i < mt->n_threads; ++i) fp->errcode |= mt->w[i].errcode;
	for (i = 0; i < mt->curr; ++i)
		if (fwrite(mt->blk[i], 1, mt->len[i], fp->fp) != mt->len[i])
			fp->errcode |= BGZF_ERR_IO;
	mt->curr = 0;
	return 0;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq %rdi, %rbx
movq 0x38(%rdi), %r15
cmpl $0x0, 0xc(%rdi)
je 0x1839f
movq %rbx, %rdi
callq 0x18ec4
leaq 0x38(%r15), %r14
movq %r14, %rdi
callq 0x35e0
movslq (%r15), %rcx
testq %rcx, %rcx
jle 0x184c2
movq 0x28(%r15), %rax
leal 0x3(%rcx), %edx
decq %rcx
movq %rcx, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
shrl $0x2, %edx
shlq $0x5, %rdx
leaq (%rdx,%rdx,4), %rcx
movdqa 0x1dc2(%rip), %xmm1     # 0x1a1a0
movdqa 0x1dca(%rip), %xmm2     # 0x1a1b0
xorl %edx, %edx
movdqa 0x1dd0(%rip), %xmm3     # 0x1a1c0
pxor %xmm3, %xmm0
pcmpeqd %xmm4, %xmm4
movdqa 0x1dd0(%rip), %xmm5     # 0x1a1d0
movdqa %xmm2, %xmm6
pxor %xmm3, %xmm6
movdqa %xmm6, %xmm7
pcmpgtd %xmm0, %xmm7
pcmpeqd %xmm0, %xmm6
pshufd $0xf5, %xmm6, %xmm8     # xmm8 = xmm6[1,1,3,3]
pand %xmm7, %xmm8
pshufd $0xf5, %xmm7, %xmm6     # xmm6 = xmm7[1,1,3,3]
por %xmm8, %xmm6
movd %xmm6, %esi
notl %esi
testb $0x1, %sil
je 0x1843d
movl $0x1, 0x20(%rax,%rdx)
pxor %xmm4, %xmm6
pextrw $0x4, %xmm6, %esi
testb $0x1, %sil
je 0x18454
movl $0x1, 0x48(%rax,%rdx)
movdqa %xmm1, %xmm6
pxor %xmm3, %xmm6
movdqa %xmm6, %xmm7
pcmpgtd %xmm0, %xmm7
pcmpeqd %xmm0, %xmm6
pshufd $0xf5, %xmm6, %xmm8     # xmm8 = xmm6[1,1,3,3]
pand %xmm7, %xmm8
pshufd $0xf5, %xmm7, %xmm6     # xmm6 = xmm7[1,1,3,3]
por %xmm8, %xmm6
pxor %xmm4, %xmm6
pextrw $0x0, %xmm6, %esi
testb $0x1, %sil
je 0x18494
movl $0x1, 0x70(%rax,%rdx)
pextrw $0x4, %xmm6, %esi
testb $0x1, %sil
je 0x184aa
movl $0x1, 0x98(%rax,%rdx)
paddq %xmm5, %xmm2
paddq %xmm5, %xmm1
addq $0xa0, %rdx
cmpq %rdx, %rcx
jne 0x18400
movl $0x0, 0x10(%r15)
leaq 0x60(%r15), %rdi
callq 0x30f0
movq %r14, %rdi
callq 0x33d0
movq 0x28(%r15), %rdi
callq 0x18ce3
movl (%r15), %eax
movl 0x10(%r15), %ecx
cmpl %eax, %ecx
jl 0x184e7
testl %eax, %eax
jle 0x18517
movl (%rbx), %eax
movl $0x1c, %ecx
xorl %edx, %edx
movq 0x28(%r15), %rsi
movzwl (%rsi,%rcx), %esi
orl %esi, %eax
movl %eax, (%rbx)
incq %rdx
movslq (%r15), %rsi
addq $0x28, %rcx
cmpq %rsi, %rdx
jl 0x184fc
cmpl $0x0, 0x8(%r15)
jle 0x1855b
xorl %r14d, %r14d
movq 0x18(%r15), %rax
movq 0x20(%r15), %rcx
movq (%rax,%r14,8), %rdi
movslq (%rcx,%r14,4), %rdx
movq 0x30(%rbx), %rcx
movl $0x1, %esi
callq 0x3540
movq 0x20(%r15), %rcx
movslq (%rcx,%r14,4), %rcx
cmpq %rcx, %rax
je 0x1854f
orb $0x4, (%rbx)
incq %r14
movslq 0x8(%r15), %rax
cmpq %rax, %r14
jl 0x18521
movl $0x0, 0x8(%r15)
popq %rbx
popq %r14
popq %r15
retq