#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 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 * 3.1415926535897932 * 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   1040 <randu@plt>
movsd  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <randu@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  0xe87(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1030 <cos@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1050 <log@plt>
imul   $0xfffffffe,%eax,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1060 <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   1040 <randu@plt>
movsd  %xmm0,0x8(%rsp)
mov    %rbx,%rdi
mov    %ebp,%esi
call   1040 <randu@plt>
mulsd  0xe98(%rip),%xmm0
cvttsd2si %xmm0,%edi
call   1030 <cos@plt>
movsd  %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
call   1050 <log@plt>
add    %eax,%eax
neg    %eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     119d <randn+0x5d>
sqrtsd %xmm0,%xmm0
jmp    11a2 <randn+0x62>
call   1060 <sqrt@plt>
movsd  0x10(%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 = load double, double* %6
%16 = fmul double 0x401921FB54442D18, %15
%17 = fptosi double %16 to i32
%18 = call double @cos(i32 %17)
store double %18, double* %7
%19 = load double, double* %5
%20 = call i32 @log(double %19)
%21 = mul nsw i32 -2, %20
%22 = sitofp i32 %21 to double
store double %22, double* %8
%23 = load double, double* %8
%24 = call double @sqrt(double %23)
%25 = load double, double* %7
%26 = fmul double %24, %25
ret double %26
}

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 = fmul double %4, 0x401921FB54442D18
%6 = fptosi double %5 to i32
%7 = tail call double @cos(i32 %6)
%8 = tail call i32 @log(double %3)
%9 = mul nsw i32 %8, -2
%10 = sitofp i32 %9 to double
%11 = tail call double @sqrt(double %10)
%12 = fmul double %7, %11
ret double %12
}