// File: /workspace/github_cpp_makefile_star2_O1/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, %rbx
movl %esi, %ebp
movl %edi, %r14d
callq 0x8598
movsd %xmm0, 0x8(%rsp)
leaq 0x20c0f0b(%rip), %rdi   # 0x20cc600
movl $0x320, %edx            # imm = 0x320
xorl %esi, %esi
callq 0x41c0
movl $0x0, 0x20c0edd(%rip)   # 0x20cc5e8
movl %r14d, 0x20c0ede(%rip)  # 0x20cc5f0
movl $0xffffffff, 0x20c0ed0(%rip) # imm = 0xFFFFFFFF
movb %bpl, 0x20c0ed1(%rip)   # 0x20cc5f4
movq %rbx, 0x20c1206(%rip)   # 0x20cc930
testl %ebp, %ebp
je 0xb73f
movq 0x1c85b(%rip), %rax     # 0x27f90
movq (%rax), %rdi
xorl %esi, %esi
callq 0x4460
callq 0xb99b
leaq 0x18(%rsp), %rdi
callq 0x43c0
cmpl $-0x1, %eax
jne 0xb761
leaq 0x13ab7(%rip), %rdi     # 0x1f211
xorl %eax, %eax
callq 0xa2a0
leaq 0x18(%rsp), %rdi
movl $0x400000, %esi         # imm = 0x400000
callq 0x4440
cmpl $-0x1, %eax
jne 0xb783
leaq 0x13aae(%rip), %rdi     # 0x1f22a
xorl %eax, %eax
callq 0xa2a0
cmpl $0x0, 0x1dbda(%rip)     # 0x29364
jle 0xb7da
leaq 0x50(%rsp), %rbx
leaq 0x280(%rip), %r14       # 0xba18
leaq 0x18(%rsp), %r15
leaq 0x13aa7(%rip), %r12     # 0x1f24b
xorl %r13d, %r13d
movq %rbx, %rdi
movq %r15, %rsi
movq %r14, %rdx
movq %r13, %rcx
callq 0x45b0
cmpl $-0x1, %eax
jne 0xb7c7
movq %r12, %rdi
xorl %eax, %eax
callq 0xa2a0
incq %r13
movslq 0x1db93(%rip), %rax     # 0x29364
addq $0x8, %rbx
cmpq %rax, %r13
jl 0xb7a7
cmpl $0x0, 0x1db83(%rip)     # 0x29364
jle 0xb81d
leaq 0x10(%rsp), %rbx
leaq 0x13a72(%rip), %r14     # 0x1f261
xorl %r15d, %r15d
movq 0x50(%rsp,%r15,8), %rdi
movq %rbx, %rsi
callq 0x42a0
cmpl $-0x1, %eax
jne 0xb80e
movq %r14, %rdi
xorl %eax, %eax
callq 0xa2a0
incq %r15
movslq 0x1db4c(%rip), %rax     # 0x29364
cmpq %rax, %r15
jl 0xb7f2
movq 0x20c1104(%rip), %rdi   # 0x20cc928
callq 0x4999
xorl %eax, %eax
movq %rax, 0x20c10f6(%rip)   # 0x20cc928
movq %rax, 0x20c10f7(%rip)   # 0x20cc930
callq 0x8598
cmpb $0x1, 0x20c0daf(%rip)   # 0x20cc5f4
jne 0xb866
leaq 0x13a27(%rip), %rdi     # 0x1f275
leaq 0x12464(%rip), %rsi     # 0x1dcb9
xorl %eax, %eax
movsd %xmm0, (%rsp)
callq 0xaba8
movsd (%rsp), %xmm0
subsd 0x8(%rsp), %xmm0
leaq 0x13a09(%rip), %rdi     # 0x1f27c
movb $0x1, %al
callq 0x9fb2
addq $0x258, %rsp            # imm = 0x258
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq