#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 */
int omp_get_thread_num();
int rand_r(unsigned int *);
void populate_array_parall_better(int *v, int n) {
  unsigned seed;
#pragma omp parallel private(seed)
  {
    seed = 25234 + 17 * omp_get_thread_num();
#pragma omp for
    for (int i = 0; i < n; ++i) {
      v[i] = rand_r(&seed) % n;
    }
  }
}


x86 assembly (clang, -O0):
<populate_array_parall_better>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
imul   $0x11,%eax,%eax
add    $0x6292,%eax
mov    %eax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    117a <populate_array_parall_better+0x5a>
lea    -0x10(%rbp),%rdi
call   1040 <rand_r@plt>
cltd
idivl  -0xc(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1148 <populate_array_parall_better+0x28>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<populate_array_parall_better>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %esi,%r12d
mov    %rdi,%r14
xor    %eax,%eax
call   1030 <omp_get_thread_num@plt>
mov    %eax,%ecx
shl    $0x4,%ecx
add    %ecx,%eax
add    $0x6292,%eax
mov    %eax,0xc(%rsp)
test   %r12d,%r12d
jle    1179 <populate_array_parall_better+0x59>
mov    %r12d,%ebx
xor    %ebp,%ebp
lea    0xc(%rsp),%r15
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1040 <rand_r@plt>
cltd
idiv   %r12d
mov    %edx,(%r14,%rbp,4)
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1160 <populate_array_parall_better+0x40>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @populate_array_parall_better(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%7 = call i32 (...) @omp_get_thread_num()
%8 = mul nsw i32 17, %7
%9 = add nsw i32 25234, %8
store i32 %9, i32* %5
store i32 0, i32* %6
br label %10
10: ; preds = %22, %2
%11 = load i32, i32* %6
%12 = load i32, i32* %4
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %25
14: ; preds = %10
%15 = call i32 @rand_r(i32* %5)
%16 = load i32, i32* %4
%17 = srem i32 %15, %16
%18 = load i32*, i32** %3
%19 = load i32, i32* %6
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i32, i32* %18, i64 %20
store i32 %17, i32* %21
br label %22
22: ; preds = %14
%23 = load i32, i32* %6
%24 = add nsw i32 %23, 1
store i32 %24, i32* %6
br label %10
25: ; preds = %10
ret void
}

LLVM IR (-O2):
define void @populate_array_parall_better(i32* nocapture writeonly %0, i32 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i32 (...) @omp_get_thread_num()
%6 = mul nsw i32 %5, 17
%7 = add nsw i32 %6, 25234
store i32 %7, i32* %3
%8 = icmp sgt i32 %1, 0
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = zext i32 %1 to i64
br label %12
11: ; preds = %12, %2
ret void
12: ; preds = %9, %12
%13 = phi i64 [ 0, %9 ], [ %17, %12 ]
%14 = call i32 @rand_r(i32* %3)
%15 = srem i32 %14, %1
%16 = getelementptr inbounds i32, i32* %0, i64 %13
store i32 %15, i32* %16
%17 = add nuw nsw i64 %13, 1
%18 = icmp eq i64 %17, %10
br i1 %18, label %11, label %12
}