// File: /workspace/github_cpp_makefile_star2_O1/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:
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testb $0x3, 0x2(%rdi)
je 0x44bdb
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %esi, %ebp
cmpl $0x2, %esi
jl 0x44bcd
cmpq $0x0, 0x40(%rdi)
jne 0x44bcd
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, %r15
movl $0x4, %esi
movq %r15, %rdi
callq 0x4360
movq %rax, 0x20(%r14)
movl $0x8, %esi
movq %r15, %rdi
callq 0x4360
movq %rax, 0x18(%r14)
testl %r15d, %r15d
jle 0x44adf
movl %r12d, %ebx
xorl %r15d, %r15d
movl $0x10000, %edi          # imm = 0x10000
callq 0x4700
movq 0x18(%r14), %rcx
movq %rax, (%rcx,%r15,8)
incq %r15
cmpq %r15, %rbx
jne 0x44ac5
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, 0x28(%r14)
testl %ebp, %ebp
jle 0x44b44
movq %rax, %r12
movq 0x8(%rsp), %rax
movl (%rax), %ebx
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 0x44b1b
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 0x44bc2
movl $0x1, %ebp
movl $0x20, %ebx
movl $0x8, %r15d
leaq 0x4b(%rip), %r12        # 0x44bdc
leaq 0x10(%rsp), %r13
movq 0x30(%r14), %rdi
addq %r15, %rdi
movq 0x28(%r14), %rcx
addq %rbx, %rcx
movq %r13, %rsi
movq %r12, %rdx
callq 0x49b0
incq %rbp
movslq (%r14), %rax
addq $0x20, %rbx
addq $0x8, %r15
cmpq %rax, %rbp
jl 0x44b96
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