// File: /workspace/github_c_makefile_star2_O0/aremmell[P]libsir/src/sirthreadpool.c
// Function: sir_threadpool_create
bool _sir_threadpool_create(sir_threadpool** pool, size_t num_threads) {
    if (!pool || !num_threads || num_threads > SIR_THREADPOOL_MAX_THREADS)
        return _sir_seterror(_SIR_E_INVALID);

    *pool = calloc(1, sizeof(sir_threadpool));
    if (!*pool)
        return _sir_handleerr(errno);

    (*pool)->threads = calloc(num_threads, sizeof(sir_thread));
    if (!(*pool)->threads) {
        int err = errno;
        _sir_safefree(pool);
        return _sir_handleerr(err);
    }

    (*pool)->num_threads = num_threads;

    if (!_sir_queue_create(&(*pool)->jobs) || !_sir_condcreate(&(*pool)->cond) ||
        !_sir_mutexcreate(&(*pool)->mutex)) {
        bool destroy = _sir_threadpool_destroy(pool);
        SIR_ASSERT_UNUSED(destroy, destroy);
        return false;
    }

#if !defined(__WIN__)
    pthread_attr_t attr = {0};
    int op = pthread_attr_init(&attr);
    if (0 != op) {
        bool destroy = _sir_threadpool_destroy(pool);
        SIR_ASSERT_UNUSED(destroy, destroy);
        return _sir_handleerr(op);
    }
#endif

    int thrd_err     = 0;
    bool thrd_create = true;
    for (size_t n = 0; n < num_threads; n++) {
#if !defined(__WIN__)
        op = pthread_create(&(*pool)->threads[n], &attr, &thread_pool_proc, *pool);
        if (0 != op) {
            (*pool)->threads[n] = 0;
            thrd_err    = op;
            thrd_create = false;
            break;
        }
#else /* __WIN__ */
        (*pool)->threads[n] = (HANDLE)_beginthreadex(NULL, 0, &thread_pool_proc,
            *pool, 0, NULL);
        if (!(*pool)->threads[n]) {
            thrd_err    = errno;
            thrd_create = false;
            break;
        }
#endif
    }

#if !defined(__WIN__)
    op = pthread_attr_destroy(&attr);
    SIR_ASSERT_UNUSED(0 == op, op);
#endif

    if (!thrd_create) {
        bool destroy = _sir_threadpool_destroy(pool);
        SIR_ASSERT_UNUSED(destroy, destroy);
        return _sir_handleerr(thrd_err);
    }

    return !!*pool;
}

// Assembly:
subq $0x78, %rsp
movq %rdi, 0x68(%rsp)
movq %rsi, 0x60(%rsp)
cmpq $0x0, 0x68(%rsp)
je 0x1bd19
cmpq $0x0, 0x60(%rsp)
je 0x1bd19
cmpq $0x182, 0x60(%rsp)      # imm = 0x182
jbe 0x1bd41
movl $0x800c0000, %edi       # imm = 0x800C0000
leaq 0x70b4(%rip), %rsi      # 0x22dd9
leaq 0x70c4(%rip), %rdx      # 0x22df0
movl $0x2f, %ecx
callq 0x104c0
andb $0x1, %al
movb %al, 0x77(%rsp)
jmp 0x1bfbc
movl $0x1, %edi
movl $0x78, %esi
callq 0x42d0
movq %rax, %rcx
movq 0x68(%rsp), %rax
movq %rcx, (%rax)
movq 0x68(%rsp), %rax
cmpq $0x0, (%rax)
jne 0x1bd90
callq 0x4070
movl (%rax), %edi
leaq 0x7065(%rip), %rsi      # 0x22dd9
leaq 0x7075(%rip), %rdx      # 0x22df0
movl $0x33, %ecx
callq 0x10780
andb $0x1, %al
movb %al, 0x77(%rsp)
jmp 0x1bfbc
movq 0x60(%rsp), %rdi
movl $0x8, %esi
callq 0x42d0
movq %rax, %rcx
movq 0x68(%rsp), %rax
movq (%rax), %rax
movq %rcx, (%rax)
movq 0x68(%rsp), %rax
movq (%rax), %rax
cmpq $0x0, (%rax)
jne 0x1bdf7
callq 0x4070
movl (%rax), %eax
movl %eax, 0x5c(%rsp)
movq 0x68(%rsp), %rdi
callq 0x14490
movl 0x5c(%rsp), %edi
leaq 0x6ffe(%rip), %rsi      # 0x22dd9
leaq 0x700e(%rip), %rdx      # 0x22df0
movl $0x39, %ecx
callq 0x10780
andb $0x1, %al
movb %al, 0x77(%rsp)
jmp 0x1bfbc
movq 0x60(%rsp), %rcx
movq 0x68(%rsp), %rax
movq (%rax), %rax
movq %rcx, 0x8(%rax)
movq 0x68(%rsp), %rax
movq (%rax), %rdi
addq $0x10, %rdi
callq 0x1ca20
testb $0x1, %al
jne 0x1be1f
jmp 0x1be4b
movq 0x68(%rsp), %rax
movq (%rax), %rdi
addq $0x18, %rdi
callq 0x1c430
testb $0x1, %al
jne 0x1be36
jmp 0x1be4b
movq 0x68(%rsp), %rax
movq (%rax), %rdi
addq $0x48, %rdi
callq 0x19590
testb $0x1, %al
jne 0x1be65
movq 0x68(%rsp), %rdi
callq 0x1bfd0
andb $0x1, %al
movb %al, 0x5b(%rsp)
movb $0x0, 0x77(%rsp)
jmp 0x1bfbc
leaq 0x20(%rsp), %rdi
xorl %esi, %esi
movl $0x38, %edx
callq 0x4210
leaq 0x20(%rsp), %rdi
callq 0x42b0
movl %eax, 0x1c(%rsp)
xorl %eax, %eax
cmpl 0x1c(%rsp), %eax
je 0x1bec3
movq 0x68(%rsp), %rdi
callq 0x1bfd0
andb $0x1, %al
movb %al, 0x1b(%rsp)
movl 0x1c(%rsp), %edi
leaq 0x6f32(%rip), %rsi      # 0x22dd9
leaq 0x6f42(%rip), %rdx      # 0x22df0
movl $0x4b, %ecx
callq 0x10780
andb $0x1, %al
movb %al, 0x77(%rsp)
jmp 0x1bfbc
movl $0x0, 0x14(%rsp)
movb $0x1, 0x13(%rsp)
movq $0x0, 0x8(%rsp)
movq 0x8(%rsp), %rax
cmpq 0x60(%rsp), %rax
jae 0x1bf5d
movq 0x68(%rsp), %rax
movq (%rax), %rax
movq (%rax), %rdi
movq 0x8(%rsp), %rax
shlq $0x3, %rax
addq %rax, %rdi
movq 0x68(%rsp), %rax
movq (%rax), %rcx
leaq 0x20(%rsp), %rsi
leaq 0x2e0(%rip), %rdx       # 0x1c1f0
callq 0x4430
movl %eax, 0x1c(%rsp)
xorl %eax, %eax
cmpl 0x1c(%rsp), %eax
je 0x1bf48
movq 0x68(%rsp), %rax
movq (%rax), %rax
movq (%rax), %rax
movq 0x8(%rsp), %rcx
movq $0x0, (%rax,%rcx,8)
movl 0x1c(%rsp), %eax
movl %eax, 0x14(%rsp)
movb $0x0, 0x13(%rsp)
jmp 0x1bf5d
jmp 0x1bf4a
movq 0x8(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x8(%rsp)
jmp 0x1bed9
leaq 0x20(%rsp), %rdi
callq 0x44e0
movl %eax, 0x1c(%rsp)
testb $0x1, 0x13(%rsp)
jne 0x1bfa6
movq 0x68(%rsp), %rdi
callq 0x1bfd0
andb $0x1, %al
movb %al, 0x7(%rsp)
movl 0x14(%rsp), %edi
leaq 0x6e4c(%rip), %rsi      # 0x22dd9
leaq 0x6e5c(%rip), %rdx      # 0x22df0
movl $0x6d, %ecx
callq 0x10780
andb $0x1, %al
movb %al, 0x77(%rsp)
jmp 0x1bfbc
movq 0x68(%rsp), %rax
cmpq $0x0, (%rax)
setne %al
xorb $-0x1, %al
xorb $-0x1, %al
andb $0x1, %al
movb %al, 0x77(%rsp)
movb 0x77(%rsp), %al
andb $0x1, %al
addq $0x78, %rsp
retq
nopw (%rax,%rax)