#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 */
double erand48(unsigned short *);
double log(double);
int omp_get_thread_num();
double sqrt(double);
void randn(double *x, int n) {
  short unsigned int seed[3];
#pragma omp parallel private(seed)
  {
    *(int *)(seed) = 1202107158 + omp_get_thread_num() * 1999;
#pragma omp for schedule(static)
    for (int i = 0; i < n; i += 2) {
      double x1, x2, w;
      do {
        x1 = erand48(seed);
        x2 = erand48(seed);
        x1 = 2.0 * x1 - 1.0;
        x2 = 2.0 * x2 - 1.0;
        w = x1 * x1 + x2 * x2;
      } while (w >= 1.0);
      w = sqrt((-2.0 * log(w)) / w);
      x[i] = x1 * w;
      if (i + 1 < n) {
        x[i + 1] = x2 * w;
      }
    }
  }
}


x86 assembly (clang, -O0):
<randn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
imul   $0x7cf,%eax,%eax
add    $0x47a6b316,%eax
mov    %eax,-0x12(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1281 <randn+0x141>
jmp    117c <randn+0x3c>
lea    -0x12(%rbp),%rdi
call   1050 <erand48@plt>
movsd  %xmm0,-0x20(%rbp)
lea    -0x12(%rbp),%rdi
call   1050 <erand48@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
addsd  %xmm0,%xmm0
movsd  0xe57(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x28(%rbp),%xmm0
addsd  %xmm0,%xmm0
movsd  0xe3d(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm2
movsd  -0x28(%rbp),%xmm1
mulsd  -0x28(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  0xe0e(%rip),%xmm1
ucomisd %xmm1,%xmm0
jae    117c <randn+0x3c>
movsd  -0x30(%rbp),%xmm0
call   1040 <log@plt>
movaps %xmm0,%xmm1
movsd  0xdf7(%rip),%xmm0
mulsd  %xmm1,%xmm0
divsd  -0x30(%rbp),%xmm0
call   1060 <sqrt@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
cmp    -0xc(%rbp),%eax
jge    126e <randn+0x12e>
movsd  -0x28(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    1273 <randn+0x133>
mov    -0x18(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x18(%rbp)
jmp    116b <randn+0x2b>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<randn>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %esi,%r14d
mov    %rdi,%r12
xor    %eax,%eax
call   1030 <omp_get_thread_num@plt>
imul   $0x7cf,%eax,%eax
add    $0x47a6b316,%eax
mov    %eax,0x8(%rsp)
test   %r14d,%r14d
jle    1251 <randn+0x111>
mov    %r14d,%r15d
xor    %ebx,%ebx
lea    0x8(%rsp),%rbp
jmp    1190 <randn+0x50>
add    $0x2,%rbx
cmp    %r14d,%ebx
jge    1251 <randn+0x111>
nopw   0x0(%rax,%rax,1)
mov    %rbp,%rdi
call   1050 <erand48@plt>
movsd  %xmm0,(%rsp)
mov    %rbp,%rdi
call   1050 <erand48@plt>
movsd  (%rsp),%xmm2
addsd  %xmm2,%xmm2
movsd  0xe4a(%rip),%xmm1
addsd  %xmm1,%xmm2
addsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
movapd %xmm0,%xmm1
mulsd  %xmm0,%xmm1
movapd %xmm2,%xmm3
mulsd  %xmm2,%xmm3
addsd  %xmm1,%xmm3
ucomisd 0xe2a(%rip),%xmm3
jae    1190 <randn+0x50>
movsd  %xmm2,(%rsp)
movsd  %xmm0,0x10(%rsp)
movapd %xmm3,%xmm0
movsd  %xmm3,0x18(%rsp)
call   1040 <log@plt>
mulsd  0xe0e(%rip),%xmm0
divsd  0x18(%rsp),%xmm0
ucomisd 0xe08(%rip),%xmm0
jb     1218 <randn+0xd8>
sqrtsd %xmm0,%xmm0
jmp    121d <randn+0xdd>
call   1060 <sqrt@plt>
movsd  (%rsp),%xmm3
mulsd  %xmm0,%xmm3
movsd  %xmm3,(%r12,%rbx,8)
mov    %rbx,%rax
or     $0x1,%rax
cmp    %r15,%rax
jge    117d <randn+0x3d>
movsd  0x10(%rsp),%xmm3
mulsd  %xmm0,%xmm3
movsd  %xmm3,(%r12,%rax,8)
jmp    117d <randn+0x3d>
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @randn(double* %0, i32 %1) {
%3 = alloca double*
%4 = alloca i32
%5 = alloca [3 x i16]
%6 = alloca i32
%7 = alloca double
%8 = alloca double
%9 = alloca double
store double* %0, double** %3
store i32 %1, i32* %4
%10 = call i32 (...) @omp_get_thread_num()
%11 = mul nsw i32 %10, 1999
%12 = add nsw i32 1202107158, %11
%13 = getelementptr inbounds [3 x i16], [3 x i16]* %5, i64 0, i64 0
%14 = bitcast i16* %13 to i32*
store i32 %12, i32* %14
store i32 0, i32* %6
br label %15
15: ; preds = %66, %2
%16 = load i32, i32* %6
%17 = load i32, i32* %4
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %69
19: ; preds = %15
br label %20
20: ; preds = %35, %19
%21 = getelementptr inbounds [3 x i16], [3 x i16]* %5, i64 0, i64 0
%22 = call double @erand48(i16* %21)
store double %22, double* %7
%23 = getelementptr inbounds [3 x i16], [3 x i16]* %5, i64 0, i64 0
%24 = call double @erand48(i16* %23)
store double %24, double* %8
%25 = load double, double* %7
%26 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %25, double -1.000000e+00)
store double %26, double* %7
%27 = load double, double* %8
%28 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %27, double -1.000000e+00)
store double %28, double* %8
%29 = load double, double* %7
%30 = load double, double* %7
%31 = load double, double* %8
%32 = load double, double* %8
%33 = fmul double %31, %32
%34 = call double @llvm.fmuladd.f64(double %29, double %30, double %33)
store double %34, double* %9
br label %35
35: ; preds = %20
%36 = load double, double* %9
%37 = fcmp oge double %36, 1.000000e+00
br i1 %37, label %20, label %38
38: ; preds = %35
%39 = load double, double* %9
%40 = call double @log(double %39)
%41 = fmul double -2.000000e+00, %40
%42 = load double, double* %9
%43 = fdiv double %41, %42
%44 = call double @sqrt(double %43)
store double %44, double* %9
%45 = load double, double* %7
%46 = load double, double* %9
%47 = fmul double %45, %46
%48 = load double*, double** %3
%49 = load i32, i32* %6
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds double, double* %48, i64 %50
store double %47, double* %51
%52 = load i32, i32* %6
%53 = add nsw i32 %52, 1
%54 = load i32, i32* %4
%55 = icmp slt i32 %53, %54
br i1 %55, label %56, label %65
56: ; preds = %38
%57 = load double, double* %8
%58 = load double, double* %9
%59 = fmul double %57, %58
%60 = load double*, double** %3
%61 = load i32, i32* %6
%62 = add nsw i32 %61, 1
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds double, double* %60, i64 %63
store double %59, double* %64
br label %65
65: ; preds = %56, %38
br label %66
66: ; preds = %65
%67 = load i32, i32* %6
%68 = add nsw i32 %67, 2
store i32 %68, i32* %6
br label %15
69: ; preds = %15
ret void
}

LLVM IR (-O2):
define void @randn(double* nocapture writeonly %0, i32 %1) {
%3 = alloca [3 x i16]
%4 = bitcast [3 x i16]* %3 to i8*
%5 = tail call i32 (...) @omp_get_thread_num()
%6 = mul nsw i32 %5, 1999
%7 = add nsw i32 %6, 1202107158
%8 = getelementptr inbounds [3 x i16], [3 x i16]* %3, i64 0, i64 0
%9 = bitcast [3 x i16]* %3 to i32*
store i32 %7, i32* %9
%10 = icmp sgt i32 %1, 0
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = zext i32 %1 to i64
br label %13
13: ; preds = %11, %36
%14 = phi i64 [ 0, %11 ], [ %37, %36 ]
br label %16
15: ; preds = %36, %2
ret void
16: ; preds = %13, %16
%17 = call double @erand48(i16* %8)
%18 = call double @erand48(i16* %8)
%19 = call double @llvm.fmuladd.f64(double %17, double 2.000000e+00, double -1.000000e+00)
%20 = call double @llvm.fmuladd.f64(double %18, double 2.000000e+00, double -1.000000e+00)
%21 = fmul double %20, %20
%22 = call double @llvm.fmuladd.f64(double %19, double %19, double %21)
%23 = fcmp ult double %22, 1.000000e+00
br i1 %23, label %24, label %16
24: ; preds = %16
%25 = call double @log(double %22)
%26 = fmul double %25, -2.000000e+00
%27 = fdiv double %26, %22
%28 = call double @sqrt(double %27)
%29 = fmul double %19, %28
%30 = getelementptr inbounds double, double* %0, i64 %14
store double %29, double* %30
%31 = or i64 %14, 1
%32 = icmp slt i64 %31, %12
br i1 %32, label %33, label %36
33: ; preds = %24
%34 = fmul double %20, %28
%35 = getelementptr inbounds double, double* %0, i64 %31
store double %34, double* %35
br label %36
36: ; preds = %33, %24
%37 = add nuw i64 %14, 2
%38 = trunc i64 %37 to i32
%39 = icmp slt i32 %38, %1
br i1 %39, label %13, label %15
}