// File: karel-brinda[P]ococo/ext/htslib/bgzf.c
// Function: worker_aux
static int worker_aux(worker_t *w)
{
    int i, stop = 0;
    // wait for condition: to process or all done
    pthread_mutex_lock(&w->mt->lock);
    while (!w->toproc && !w->mt->done)
        pthread_cond_wait(&w->mt->cv, &w->mt->lock);
    if (w->mt->done) stop = 1;
    w->toproc = 0;
    pthread_mutex_unlock(&w->mt->lock);
    if (stop) return 1; // to quit the thread
    w->errcode = 0;
    for (i = w->i; i < w->mt->curr; i += w->mt->n_threads) {
        size_t clen = BGZF_MAX_BLOCK_SIZE;
        int ret = bgzf_compress(w->buf, &clen, w->mt->blk[i], w->mt->len[i], w->compress_level);
        if (ret != 0) {
            if (hts_verbose >= 2) fprintf(stderr, "[E::%s] bgzf_compress error %d\n", __func__, ret);
            w->errcode |= BGZF_ERR_ZLIB; // Report error
            // We're not going to do any more, so set remaining lengths to 0
            for (; i < w->mt->curr; i += w->mt->n_threads) w->mt->len[i] = 0;
            break; // Give up
        } else {
            memcpy(w->mt->blk[i], w->buf, clen);
            w->mt->len[i] = clen;
        }
    }
    __sync_fetch_and_add(&w->mt->proc_cnt, 1);
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movl $0x0, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
addq $0x38, %rdi
callq 0x4880
movq -0x10(%rbp), %rcx
xorl %eax, %eax
cmpl $0x0, 0x18(%rcx)
movb %al, -0x25(%rbp)
jne 0x67b05
movq -0x10(%rbp), %rax
movq (%rax), %rax
cmpl $0x0, 0xc(%rax)
setne %al
xorb $-0x1, %al
movb %al, -0x25(%rbp)
movb -0x25(%rbp), %al
testb $0x1, %al
jne 0x67b0e
jmp 0x67b2b
movq -0x10(%rbp), %rax
movq (%rax), %rdi
addq $0x60, %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
addq $0x38, %rsi
callq 0x48d0
jmp 0x67ae3
movq -0x10(%rbp), %rax
movq (%rax), %rax
cmpl $0x0, 0xc(%rax)
je 0x67b3f
movl $0x1, -0x18(%rbp)
movq -0x10(%rbp), %rax
movl $0x0, 0x18(%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
addq $0x38, %rdi
callq 0x4420
cmpl $0x0, -0x18(%rbp)
je 0x67b6c
movl $0x1, -0x4(%rbp)
jmp 0x67cbb
movq -0x10(%rbp), %rax
movl $0x0, 0x14(%rax)
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %eax
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
cmpl 0x8(%rcx), %eax
jge 0x67ca9
movq $0x10000, -0x20(%rbp)   # imm = 0x10000
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x18(%rax), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x20(%rax), %rax
movslq -0x14(%rbp), %rcx
movslq (%rax,%rcx,4), %rcx
movq -0x10(%rbp), %rax
movl 0x1c(%rax), %r8d
leaq -0x20(%rbp), %rsi
callq 0x63640
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
je 0x67c57
leaq 0x229f5(%rip), %rax     # 0x8a5e0
cmpl $0x2, (%rax)
jl 0x67c12
movq 0x223d9(%rip), %rax     # 0x89fd0
movq (%rax), %rdi
movl -0x24(%rbp), %ecx
leaq 0x1675a(%rip), %rsi     # 0x7e35e
leaq 0x16773(%rip), %rdx     # 0x7e37e
movb $0x0, %al
callq 0x4830
movq -0x10(%rbp), %rax
movl 0x14(%rax), %ecx
orl $0x1, %ecx
movl %ecx, 0x14(%rax)
movl -0x14(%rbp), %eax
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
cmpl 0x8(%rcx), %eax
jge 0x67c55
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x20(%rax), %rax
movslq -0x14(%rbp), %rcx
movl $0x0, (%rax,%rcx,4)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl (%rax), %eax
addl -0x14(%rbp), %eax
movl %eax, -0x14(%rbp)
jmp 0x67c1f
jmp 0x67ca9
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x18(%rax), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x20(%rbp), %rdx
callq 0x4460
movq -0x20(%rbp), %rax
movl %eax, %edx
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x20(%rax), %rax
movslq -0x14(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x67c95
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl (%rax), %eax
addl -0x14(%rbp), %eax
movl %eax, -0x14(%rbp)
jmp 0x67b81
movq -0x10(%rbp), %rax
movq (%rax), %rax
lock
incl 0x10(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)