// File: /workspace/github_cpp_makefile_star2_O2/karel-brinda[P]ococo/ext/htslib/bgzf.c
// Function: bgzf_mt
int bgzf_mt(BGZF *fp, int n_threads, int n_sub_blks)
{
    int i;
    mtaux_t *mt;
    pthread_attr_t attr;
    if (!fp->is_write || fp->mt || n_threads <= 1) return -1;
    mt = (mtaux_t*)calloc(1, sizeof(mtaux_t));
    mt->n_threads = n_threads;
    mt->n_blks = n_threads * n_sub_blks;
    mt->len = (int*)calloc(mt->n_blks, sizeof(int));
    mt->blk = (void**)calloc(mt->n_blks, sizeof(void*));
    for (i = 0; i < mt->n_blks; ++i)
        mt->blk[i] = malloc(BGZF_MAX_BLOCK_SIZE);
    mt->tid = (pthread_t*)calloc(mt->n_threads, sizeof(pthread_t)); // tid[0] is not used, as the worker 0 is launched by the master
    mt->w = (worker_t*)calloc(mt->n_threads, sizeof(worker_t));
    for (i = 0; i < mt->n_threads; ++i) {
        mt->w[i].i = i;
        mt->w[i].mt = mt;
        mt->w[i].compress_level = fp->compress_level;
        mt->w[i].buf = malloc(BGZF_MAX_BLOCK_SIZE);
    }
    pthread_attr_init(&attr);
    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
    pthread_mutex_init(&mt->lock, 0);
    pthread_cond_init(&mt->cv, 0);
    for (i = 1; i < mt->n_threads; ++i) // worker 0 is effectively launched by the master thread
        pthread_create(&mt->tid[i], &attr, mt_worker, &mt->w[i]);
    fp->mt = mt;
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
pushq $-0x1
popq %rax
movq %rdi, 0x8(%rsp)
testb $0x3, 0x2(%rdi)
je 0x372e5
movl %esi, %ebp
cmpl $0x2, %esi
jl 0x372e5
movq 0x8(%rsp), %rcx
cmpq $0x0, 0x40(%rcx)
jne 0x372e5
movl %edx, %ebx
pushq $0x1
popq %rdi
movl $0x90, %esi
callq 0x4370
movq %rax, %r15
movl %ebp, (%rax)
imull %ebp, %ebx
movl %ebx, 0x4(%rax)
movslq %ebx, %r12
pushq $0x4
popq %rsi
movq %r12, %rdi
callq 0x4370
movq %rax, 0x20(%r15)
pushq $0x8
popq %rsi
movq %r12, %rdi
callq 0x4370
movq %rax, %rbx
movq %rax, 0x18(%r15)
xorl %r13d, %r13d
testl %r12d, %r12d
cmovlel %r13d, %r12d
cmpq %r13, %r12
je 0x3720f
movl $0x10000, %edi          # imm = 0x10000
callq 0x46f0
movq %rax, (%rbx,%r13,8)
incq %r13
jmp 0x371f7
movl %ebp, %ebx
pushq $0x8
popq %r12
movq %rbx, %rdi
movq %r12, %rsi
callq 0x4370
movq %rax, 0x30(%r15)
pushq $0x20
popq %r13
movq %rbx, %r14
movq %rbx, %rdi
movq %r13, %rsi
callq 0x4370
movq %rax, %rbx
movq %rax, 0x28(%r15)
xorl %ebp, %ebp
cmpq %rbp, %r14
je 0x37271
movl %ebp, 0x10(%rbx)
movq %r15, (%rbx)
movq 0x8(%rsp), %rax
movl (%rax), %eax
shll $0x3, %eax
sarl $0x17, %eax
movl %eax, 0x1c(%rbx)
movl $0x10000, %edi          # imm = 0x10000
callq 0x46f0
movq %rax, 0x8(%rbx)
incq %rbp
addq $0x20, %rbx
jmp 0x3723f
leaq 0x10(%rsp), %rbp
movq %rbp, %rdi
callq 0x4630
movq %rbp, %rdi
xorl %esi, %esi
callq 0x46e0
leaq 0x38(%r15), %rdi
xorl %esi, %esi
callq 0x47c0
movq %r15, %rdi
addq $0x60, %rdi
xorl %esi, %esi
callq 0x4610
leaq 0x4c(%rip), %rbx        # 0x372f4
pushq $0x1
popq %r14
movslq (%r15), %rax
cmpq %rax, %r14
jge 0x372da
movq 0x30(%r15), %rdi
addq %r12, %rdi
movq 0x28(%r15), %rcx
addq %r13, %rcx
movq %rbp, %rsi
movq %rbx, %rdx
callq 0x4990
incq %r14
addq $0x20, %r13
addq $0x8, %r12
jmp 0x372ac
movq 0x8(%rsp), %rax
movq %r15, 0x40(%rax)
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq