#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 acos(int);
double cos(int);
int log(double);
double randu(int *, int);
double sqrt(double);
double randn(int *seed, int index) {
  double u = randu(seed, index);
  double v = randu(seed, index);
  double cosine = cos(2 * acos(-1) * v);
  double rt = -2 * log(u);
  return sqrt(rt) * cosine;
}


x86 assembly (clang, -O0):
<randn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1050 <randu@plt>
movsd  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1050 <randu@plt>
movsd  %xmm0,-0x20(%rbp)
mov    $0xffffffff,%edi
call   1030 <acos@plt>
shl    $0x1,%eax
cvtsi2sd %eax,%xmm0
mulsd  -0x20(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1040 <cos@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1060 <log@plt>
imul   $0xfffffffe,%eax,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1070 <sqrt@plt>
mulsd  -0x28(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<randn>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %esi,%ebp
mov    %rdi,%rbx
call   1050 <randu@plt>
movsd  %xmm0,0x10(%rsp)
mov    %rbx,%rdi
mov    %ebp,%esi
call   1050 <randu@plt>
movsd  %xmm0,0x8(%rsp)
mov    $0xffffffff,%edi
call   1030 <acos@plt>
add    %eax,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0x8(%rsp),%xmm0
cvttsd2si %xmm0,%edi
call   1040 <cos@plt>
movsd  %xmm0,0x8(%rsp)
movsd  0x10(%rsp),%xmm0
call   1060 <log@plt>
add    %eax,%eax
neg    %eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11c4 <randn+0x74>
sqrtsd %xmm0,%xmm0
jmp    11c9 <randn+0x79>
call   1070 <sqrt@plt>
movsd  0x8(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define double @randn(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
store i32* %0, i32** %3
store i32 %1, i32* %4
%9 = load i32*, i32** %3
%10 = load i32, i32* %4
%11 = call double @randu(i32* %9, i32 %10)
store double %11, double* %5
%12 = load i32*, i32** %3
%13 = load i32, i32* %4
%14 = call double @randu(i32* %12, i32 %13)
store double %14, double* %6
%15 = call i32 @acos(i32 -1)
%16 = mul nsw i32 2, %15
%17 = sitofp i32 %16 to double
%18 = load double, double* %6
%19 = fmul double %17, %18
%20 = fptosi double %19 to i32
%21 = call double @cos(i32 %20)
store double %21, double* %7
%22 = load double, double* %5
%23 = call i32 @log(double %22)
%24 = mul nsw i32 -2, %23
%25 = sitofp i32 %24 to double
store double %25, double* %8
%26 = load double, double* %8
%27 = call double @sqrt(double %26)
%28 = load double, double* %7
%29 = fmul double %27, %28
ret double %29
}

LLVM IR (-O2):
define double @randn(i32* %0, i32 %1) {
%3 = tail call double @randu(i32* %0, i32 %1)
%4 = tail call double @randu(i32* %0, i32 %1)
%5 = tail call i32 @acos(i32 -1)
%6 = shl nsw i32 %5, 1
%7 = sitofp i32 %6 to double
%8 = fmul double %4, %7
%9 = fptosi double %8 to i32
%10 = tail call double @cos(i32 %9)
%11 = tail call i32 @log(double %3)
%12 = mul nsw i32 %11, -2
%13 = sitofp i32 %12 to double
%14 = tail call double @sqrt(double %13)
%15 = fmul double %10, %14
ret double %15
}