#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
void *malloc(size_t);
int /*<<< orphan*/ memset(void *, int /*<<< orphan*/, size_t);
int omp_get_max_threads();
int omp_get_thread_num();
void **ompx_calloc(size_t bytes) {
  int np = omp_get_max_threads();
  void **ptrs = malloc(np * sizeof(void *));
#pragma omp parallel shared(ptrs)
  {
    int me = omp_get_thread_num();
    ptrs[me] = malloc(bytes);
    memset(ptrs[me], 0, bytes);
  }
  return ptrs;
}


x86 assembly (clang, -O0):
<ompx_calloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1060 <omp_get_max_threads@plt>
mov    %eax,-0xc(%rbp)
movslq -0xc(%rbp),%rdi
shl    $0x3,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <malloc@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x8(%rbp),%rdx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ompx_calloc>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
xor    %eax,%eax
call   1060 <omp_get_max_threads@plt>
movslq %eax,%rdi
shl    $0x3,%rdi
call   1050 <malloc@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1030 <omp_get_thread_num@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1050 <malloc@plt>
movslq %ebp,%rcx
mov    %rax,(%rbx,%rcx,8)
mov    %rax,%rdi
xor    %esi,%esi
mov    %r14,%rdx
call   1040 <memset@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i8** @ompx_calloc(i64 %0) {
%2 = alloca i64
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
store i64 %0, i64* %2
%6 = call i32 (...) @omp_get_max_threads()
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = sext i32 %7 to i64
%9 = mul i64 %8, 8
%10 = call i8* @malloc(i64 %9)
%11 = bitcast i8* %10 to i8**
store i8** %11, i8*** %4
%12 = call i32 (...) @omp_get_thread_num()
store i32 %12, i32* %5
%13 = load i64, i64* %2
%14 = call i8* @malloc(i64 %13)
%15 = load i8**, i8*** %4
%16 = load i32, i32* %5
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8*, i8** %15, i64 %17
store i8* %14, i8** %18
%19 = load i8**, i8*** %4
%20 = load i32, i32* %5
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8*, i8** %19, i64 %21
%23 = load i8*, i8** %22
%24 = load i64, i64* %2
%25 = call i32 @memset(i8* %23, i32 0, i64 %24)
%26 = load i8**, i8*** %4
ret i8** %26
}

LLVM IR (-O2):
define noalias i8** @ompx_calloc(i64 %0) {
%2 = tail call i32 (...) @omp_get_max_threads()
%3 = sext i32 %2 to i64
%4 = shl nsw i64 %3, 3
%5 = tail call i8* @malloc(i64 %4)
%6 = bitcast i8* %5 to i8**
%7 = tail call i32 (...) @omp_get_thread_num()
%8 = tail call i8* @malloc(i64 %0)
%9 = sext i32 %7 to i64
%10 = getelementptr inbounds i8*, i8** %6, i64 %9
store i8* %8, i8** %10
%11 = tail call i32 @memset(i8* %8, i32 0, i64 %0)
ret i8** %6
}