// File: /workspace/github_cpp_makefile_star2_O3/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
movl (%rdi), %ebx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testl $0x30000, %ebx          # imm = 0x30000
je 0x43b87
movl %esi, %ebp
cmpl $0x2, %esi
jl 0x43b87
cmpq $0x0, 0x40(%rdi)
jne 0x43b87
movl %edx, %r12d
movq %rdi, 0x8(%rsp)
movl $0x1, %edi
movl $0x90, %esi
callq 0x4360
movq %rax, %r14
movl %ebp, (%rax)
imull %ebp, %r12d
movl %r12d, 0x4(%rax)
movslq %r12d, %r13
movl $0x4, %esi
movq %r13, %rdi
callq 0x4360
movq %rax, 0x20(%r14)
movl $0x8, %esi
movq %r13, %rdi
callq 0x4360
movq %rax, 0x18(%r14)
testl %r13d, %r13d
jle 0x43aa4
movq %rax, %r15
movl %r12d, %r12d
xorl %r13d, %r13d
movl $0x10000, %edi          # imm = 0x10000
callq 0x4700
movq %rax, (%r15,%r13,8)
incq %r13
cmpq %r13, %r12
jne 0x43a8e
movl %ebp, %r15d
movl $0x8, %esi
movq %r15, %rdi
callq 0x4360
movq %rax, 0x30(%r14)
movl $0x20, %esi
movq %r15, %rdi
callq 0x4360
movq %rax, %r12
movq %rax, 0x28(%r14)
shll $0x3, %ebx
sarl $0x17, %ebx
xorl %r13d, %r13d
movl %r13d, 0x10(%r12)
movq %r14, (%r12)
movl %ebx, 0x1c(%r12)
movl $0x10000, %edi          # imm = 0x10000
callq 0x4700
movq %rax, 0x8(%r12)
incq %r13
addq $0x20, %r12
cmpq %r13, %r15
jne 0x43ad5
leaq 0x10(%rsp), %r12
movq %r12, %rdi
callq 0x4640
movq %r12, %rdi
xorl %esi, %esi
callq 0x46f0
leaq 0x38(%r14), %rdi
xorl %esi, %esi
callq 0x47c0
movq %r14, %rdi
addq $0x60, %rdi
xorl %esi, %esi
callq 0x4620
cmpl $0x2, (%r14)
jl 0x43b7c
movl $0x1, %ebx
movl $0x20, %ebp
movl $0x8, %r15d
leaq 0x4b(%rip), %r12        # 0x43b96
leaq 0x10(%rsp), %r13
movq 0x30(%r14), %rdi
addq %r15, %rdi
movq 0x28(%r14), %rcx
addq %rbp, %rcx
movq %r13, %rsi
movq %r12, %rdx
callq 0x49b0
incq %rbx
movslq (%r14), %rax
addq $0x20, %rbp
addq $0x8, %r15
cmpq %rax, %rbx
jl 0x43b50
movq 0x8(%rsp), %rax
movq %r14, 0x40(%rax)
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq