// File: /workspace/github_cpp_makefile_star2_O2/FreeSlave[P]vhlt/common/threads.cpp
// Function: RunThreadsOn(int, bool, void (*)(int))
void            RunThreadsOn(int workcnt, bool showpacifier, q_threadfunction func)
{
    intptr_t        i;
    pthread_t       work_threads[MAX_THREADS];
    pthread_addr_t  status;
    pthread_attr_t  attrib;
    double          start, end;

    threadstart = I_FloatTime();
    start = threadstart;
    for (i = 0; i < THREADTIMES_SIZE; i++)
    {
        threadtimes[i] = 0;
    }

    dispatch = 0;
    workcount = workcnt;
    oldf = -1;
    pacifier = showpacifier;
    threaded = true;
    q_entry = func;

    if (pacifier)
    {
        setbuf(stdout, NULL);
    }

    threads_InitCrit();

    if (pthread_attr_init(&attrib) == -1)
    {
        Error("pthread_attr_init failed");
    }
#ifdef _POSIX_THREAD_ATTR_STACKSIZE
    if (pthread_attr_setstacksize(&attrib, 0x400000) == -1)
    {
        Error("pthread_attr_setstacksize failed");
    }
#endif

    for (i = 0; i < g_numthreads; i++)
    {
        if (pthread_create(&work_threads[i], &attrib, ThreadEntryStub, (void*)i) == -1)
        {
            Error("pthread_create failed");
        }
    }

    for (i = 0; i < g_numthreads; i++)
    {
        if (pthread_join(work_threads[i], &status) == -1)
        {
            Error("pthread_join failed");
        }
    }

    threads_UninitCrit();

    q_entry = NULL;
    threaded = false;

    end = I_FloatTime();
    if (pacifier)
    {
#ifdef ZHLT_CONSOLE
		PrintConsole
#else
        printf
#endif
			("\r%60s\r", "");
    }

    Log(" (%.2f seconds)\n", end - start);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x258, %rsp            # imm = 0x258
movq %rdx, %r14
movl %esi, %ebx
movl %edi, %ebp
xorl %r15d, %r15d
callq 0x7554
movsd %xmm0, 0x8(%rsp)
leaq 0x20c0546(%rip), %rax   # 0x20ca600
cmpq $0x320, %r15            # imm = 0x320
je 0xa0ce
andq $0x0, (%r15,%rax)
addq $0x8, %r15
jmp 0xa0ba
andl $0x0, 0x20c0513(%rip)   # 0x20ca5e8
orl $-0x1, 0x20c0510(%rip)  # 0x20ca5ec
movl %ebp, 0x20c050e(%rip)   # 0x20ca5f0
movb %bl, 0x20c050c(%rip)    # 0x20ca5f4
movq %r14, 0x20c0841(%rip)   # 0x20ca930
testb %bl, %bl
je 0xa104
movq 0x1bea6(%rip), %rax     # 0x25fa0
movq (%rax), %rdi
xorl %esi, %esi
callq 0x4490
callq 0xa329
leaq 0x18(%rsp), %rdi
callq 0x43d0
cmpl $-0x1, %eax
jne 0xa126
leaq 0x12052(%rip), %rdi     # 0x1c171
xorl %eax, %eax
callq 0x8d7b
leaq 0x18(%rsp), %rdi
movl $0x400000, %esi         # imm = 0x400000
callq 0x4460
cmpl $-0x1, %eax
jne 0xa148
leaq 0x12049(%rip), %rdi     # 0x1c18a
xorl %eax, %eax
callq 0x8d7b
leaq 0x50(%rsp), %rbx
leaq 0x24d(%rip), %r14       # 0xa3a1
leaq 0x18(%rsp), %r15
leaq 0x1204b(%rip), %r12     # 0x1c1ab
xorl %r13d, %r13d
movslq 0x1d1fa(%rip), %rax     # 0x27364
cmpq %rax, %r13
jge 0xa198
movq %rbx, %rdi
movq %r15, %rsi
movq %r14, %rdx
movq %r13, %rcx
callq 0x45c0
cmpl $-0x1, %eax
jne 0xa18f
movq %r12, %rdi
xorl %eax, %eax
callq 0x8d7b
incq %r13
addq $0x8, %rbx
jmp 0xa163
leaq 0x10(%rsp), %rbx
leaq 0x1201d(%rip), %r14     # 0x1c1c1
xorl %r15d, %r15d
cltq
cmpq %rax, %r15
jge 0xa1d5
movq 0x50(%rsp,%r15,8), %rdi
movq %rbx, %rsi
callq 0x42b0
cmpl $-0x1, %eax
jne 0xa1ca
movq %r14, %rdi
xorl %eax, %eax
callq 0x8d7b
incq %r15
movl 0x1d191(%rip), %eax     # 0x27364
jmp 0xa1a7
callq 0xa38a
andq $0x0, 0x20c074e(%rip)   # 0x20ca930
callq 0x7554
cmpb $0x1, 0x20c0406(%rip)   # 0x20ca5f4
jne 0xa20f
leaq 0x11fde(%rip), %rdi     # 0x1c1d5
leaq 0x10a1b(%rip), %rsi     # 0x1ac19
xorl %eax, %eax
movsd %xmm0, (%rsp)
callq 0x9668
movsd (%rsp), %xmm0
subsd 0x8(%rsp), %xmm0
leaq 0x11fc0(%rip), %rdi     # 0x1c1dc
movb $0x1, %al
callq 0x89dc
addq $0x258, %rsp            # imm = 0x258
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq