// File: /workspace/github_c_makefile_star2_O0/aremmell[P]libsir/src/sirthreadpool.c
// Function: sir_threadpool_destroy
bool _sir_threadpool_destroy(sir_threadpool** pool) {
    if (!pool || !*pool)
        return _sir_seterror(_SIR_E_INVALID);

    bool locked = _sir_mutexlock(&(*pool)->mutex);
    SIR_ASSERT(locked);

    if (locked) {
        _sir_selflog("broadcasting signal to condition var...");
        (*pool)->cancel = true;

        bool bcast = _sir_condbroadcast(&(*pool)->cond);
        SIR_ASSERT_UNUSED(bcast, bcast);

        bool unlock = _sir_mutexunlock(&(*pool)->mutex);
        SIR_ASSERT_UNUSED(unlock, unlock);
    }

    bool destroy = true;
    for (size_t n = 0; n < (*pool)->num_threads; n++) {
        SIR_ASSERT(0 != (*pool)->threads[n]);
        if (0 == (*pool)->threads[n])
            continue;
        _sir_selflog("joining thread %zu of %zu...", n + 1, (*pool)->num_threads);
#if !defined(__WIN__)
        int join = pthread_join((*pool)->threads[n], NULL);
        SIR_ASSERT(0 == join);
        _sir_eqland(destroy, 0 == join);
#else /* __WIN__ */
        DWORD join = WaitForSingleObject((*pool)->threads[n], INFINITE);
        SIR_ASSERT(WAIT_OBJECT_0 == join);
        _sir_eqland(destroy, WAIT_OBJECT_0 == join);
#endif
    }

    _sir_eqland(destroy, _sir_queue_destroy(&(*pool)->jobs));
    SIR_ASSERT(destroy);

    _sir_eqland(destroy, _sir_conddestroy(&(*pool)->cond));
    SIR_ASSERT(destroy);

    _sir_eqland(destroy, _sir_mutexdestroy(&(*pool)->mutex));
    SIR_ASSERT(destroy);

    _sir_safefree(&(*pool)->threads);
    _sir_safefree(pool);

    return destroy;
}

// Assembly:
subq $0x28, %rsp
movq %rdi, 0x18(%rsp)
cmpq $0x0, 0x18(%rsp)
je 0x1bfec
movq 0x18(%rsp), %rax
cmpq $0x0, (%rax)
jne 0x1c014
movl $0x800c0000, %edi       # imm = 0x800C0000
leaq 0x6e21(%rip), %rsi      # 0x22e19
leaq 0x6df1(%rip), %rdx      # 0x22df0
movl $0x8a, %ecx
callq 0x104c0
andb $0x1, %al
movb %al, 0x27(%rsp)
jmp 0x1c1e4
movq 0x18(%rsp), %rax
movq (%rax), %rdi
addq $0x48, %rdi
callq 0x196b0
andb $0x1, %al
movb %al, 0x17(%rsp)
testb $0x1, 0x17(%rsp)
je 0x1c07a
leaq 0x6df8(%rip), %rdi      # 0x22e31
movb $0x0, %al
callq 0x1c420
movq 0x18(%rsp), %rax
movq (%rax), %rax
movb $0x1, 0x70(%rax)
movq 0x18(%rsp), %rax
movq (%rax), %rdi
addq $0x18, %rdi
callq 0x1c540
andb $0x1, %al
movb %al, 0x16(%rsp)
movq 0x18(%rsp), %rax
movq (%rax), %rdi
addq $0x48, %rdi
callq 0x197f0
andb $0x1, %al
movb %al, 0x15(%rsp)
movb $0x1, 0x14(%rsp)
movq $0x0, 0x8(%rsp)
movq 0x8(%rsp), %rax
movq 0x18(%rsp), %rcx
movq (%rcx), %rcx
cmpq 0x8(%rcx), %rax
jae 0x1c130
movq 0x18(%rsp), %rax
movq (%rax), %rax
movq (%rax), %rcx
movq 0x8(%rsp), %rdx
xorl %eax, %eax
cmpq (%rcx,%rdx,8), %rax
jne 0x1c0b9
jmp 0x1c11d
movq 0x8(%rsp), %rsi
addq $0x1, %rsi
movq 0x18(%rsp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rdx
leaq 0x6d84(%rip), %rdi      # 0x22e59
movb $0x0, %al
callq 0x1c420
movq 0x18(%rsp), %rax
movq (%rax), %rax
movq (%rax), %rax
movq 0x8(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x4540
movl %eax, 0x4(%rsp)
xorl %eax, %eax
xorl %ecx, %ecx
cmpl 0x4(%rsp), %ecx
movb %al, 0x3(%rsp)
jne 0x1c113
movb 0x14(%rsp), %al
movb %al, 0x3(%rsp)
movb 0x3(%rsp), %al
andb $0x1, %al
movb %al, 0x14(%rsp)
movq 0x8(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x8(%rsp)
jmp 0x1c088
movq 0x18(%rsp), %rax
movq (%rax), %rdi
addq $0x10, %rdi
callq 0x1cb00
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, 0x2(%rsp)
jne 0x1c150
jmp 0x1c158
movb 0x14(%rsp), %al
movb %al, 0x2(%rsp)
movb 0x2(%rsp), %al
andb $0x1, %al
movb %al, 0x14(%rsp)
movq 0x18(%rsp), %rax
movq (%rax), %rdi
addq $0x18, %rdi
callq 0x1c5e0
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, 0x1(%rsp)
jne 0x1c182
jmp 0x1c18a
movb 0x14(%rsp), %al
movb %al, 0x1(%rsp)
movb 0x1(%rsp), %al
andb $0x1, %al
movb %al, 0x14(%rsp)
movq 0x18(%rsp), %rax
movq (%rax), %rdi
addq $0x48, %rdi
callq 0x19890
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, (%rsp)
jne 0x1c1b3
jmp 0x1c1ba
movb 0x14(%rsp), %al
movb %al, (%rsp)
movb (%rsp), %al
andb $0x1, %al
movb %al, 0x14(%rsp)
movq 0x18(%rsp), %rax
movq (%rax), %rdi
callq 0x14490
movq 0x18(%rsp), %rdi
callq 0x14490
movb 0x14(%rsp), %al
andb $0x1, %al
movb %al, 0x27(%rsp)
movb 0x27(%rsp), %al
andb $0x1, %al
addq $0x28, %rsp
retq
nop