// File: /workspace/github_c_makefile_star2_O2/wuxb45[P]SLB/lib1.c
// Function: thread_fork_join_private
double
thread_fork_join_private(const u64 nr, void *(*func) (void *), void * const * const argv)
{
  if (nr == 0) return 0.0;
  const u64 ncpu = sysconf(_SC_NPROCESSORS_CONF);
  int cores[ncpu];
  size_t xsize = 0;
  cpu_set_t * const set = __cpu_set_alloc(&xsize);

  const bool force_use = (sched_getaffinity(0, xsize, set) != 0) ? true : false;
  u64 j = 0;
  for (u64 i = 0; i < ncpu; i++) {
    if (force_use || CPU_ISSET_S((int)i, xsize, set)) {
      cores[j++] = i;
    }
  }
  const u64 ncores = j;

  const u64 nr_threads = nr ? nr : ncores;
  pthread_t tids[nr_threads];
  pthread_attr_t attr;
  pthread_attr_init(&attr);
  pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
  char thname[32];
  const double t0 = time_sec();
  for (u64 i = 0; i < nr_threads; i++) {
    CPU_ZERO_S(xsize, set);
    CPU_SET_S(cores[i % ncores], xsize, set);
    pthread_attr_setaffinity_np(&attr, xsize, set);
    const int r = pthread_create(&(tids[i]), &attr, func, argv[i]);
    if (r != 0) {
      tids[i] = 0;
    } else {
      sprintf(thname, "fork_join_%"PRIu64, i);
      pthread_setname_np(tids[i], thname);
    }
  }
  for (u64 i = 0; i < nr_threads; i++) {
    if (tids[i]) pthread_join(tids[i], NULL);
  }
  const double dt = time_diff_sec(t0);
  pthread_attr_destroy(&attr);
  free(set);
  return dt;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rdx, -0x68(%rbp)
movq %rsi, -0x60(%rbp)
movq %rdi, -0x30(%rbp)
testq %rdi, %rdi
je 0x7a60
pushq $0x53
popq %rdi
callq 0x64a0
movq %rax, %r12
movq %rsp, -0x58(%rbp)
movq %rsp, %rcx
leaq 0xf(,%rax,4), %rax
andq $-0x10, %rax
subq %rax, %rcx
movq %rcx, -0x40(%rbp)
movq %rcx, %rsp
leaq -0x70(%rbp), %rbx
andq $0x0, (%rbx)
movq %rbx, %rdi
callq 0x7676
movq (%rbx), %r13
xorl %ebx, %ebx
xorl %edi, %edi
movq %r13, %rsi
movq %rax, -0x38(%rbp)
movq %rax, %rdx
callq 0x6580
movabsq $0x100000000, %rcx      # imm = 0x100000000
xorl %edx, %edx
xorl %r15d, %r15d
cmpq %rdx, %r12
je 0x791a
testl %eax, %eax
je 0x78ed
movq -0x40(%rbp), %rsi
movl %edx, (%rsi,%r15,4)
incq %r15
jmp 0x7912
movq %rbx, %rsi
sarq $0x20, %rsi
movq %rsi, %rdi
shrq $0x3, %rdi
cmpq %r13, %rdi
jae 0x7912
shrq $0x6, %rsi
movq -0x38(%rbp), %rdi
movq (%rdi,%rsi,8), %rsi
btq %rdx, %rsi
jb 0x78e0
incq %rdx
addq %rcx, %rbx
jmp 0x78d7
movq %rsp, %rcx
movq -0x30(%rbp), %rax
leaq 0xf(,%rax,8), %rax
andq $-0x10, %rax
subq %rax, %rcx
movq %rcx, -0x48(%rbp)
movq %rcx, %rsp
leaq -0xa8(%rbp), %rbx
movq %rbx, %rdi
callq 0x62b0
movq %rbx, %rdi
xorl %esi, %esi
callq 0x6380
callq 0x6ca5
vmovsd %xmm0, -0x50(%rbp)
xorl %r12d, %r12d
movq -0x38(%rbp), %rbx
cmpq -0x30(%rbp), %r12
je 0x7a10
movq %rbx, %rdi
xorl %esi, %esi
movq %r13, %rdx
callq 0x6210
movq %r12, %rax
xorl %edx, %edx
divq %r15
movq -0x40(%rbp), %rax
movslq (%rax,%rdx,4), %rax
movq %rax, %rcx
shrq $0x3, %rcx
cmpq %r13, %rcx
jae 0x79a4
pushq $0x1
popq %rcx
shlxq %rax, %rcx, %rcx
shrq $0x6, %rax
orq %rcx, (%rbx,%rax,8)
leaq -0xa8(%rbp), %r14
movq %r14, %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0x6080
movq -0x48(%rbp), %rax
leaq (%rax,%r12,8), %rbx
movq -0x68(%rbp), %rax
movq (%rax,%r12,8), %rcx
movq %rbx, %rdi
movq %r14, %rsi
movq -0x60(%rbp), %rdx
callq 0x6430
testl %eax, %eax
je 0x79e2
andq $0x0, (%rbx)
jmp 0x7a08
leaq -0xd0(%rbp), %r14
movq %r14, %rdi
leaq 0xa85d(%rip), %rsi      # 0x12250
movq %r12, %rdx
xorl %eax, %eax
callq 0x6520
movq (%rbx), %rdi
movq %r14, %rsi
callq 0x61d0
incq %r12
jmp 0x795d
xorl %ebx, %ebx
cmpq %rbx, -0x30(%rbp)
je 0x7a31
movq -0x48(%rbp), %rax
movq (%rax,%rbx,8), %rdi
testq %rdi, %rdi
je 0x7a2c
xorl %esi, %esi
callq 0x65a0
incq %rbx
jmp 0x7a12
callq 0x6ca5
vsubsd -0x50(%rbp), %xmm0, %xmm0
vmovsd %xmm0, -0x30(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x64c0
movq -0x38(%rbp), %rdi
callq 0x6060
vmovsd -0x30(%rbp), %xmm0
movq -0x58(%rbp), %rsp
jmp 0x7a64
vxorps %xmm0, %xmm0, %xmm0
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq