#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 */
float RAND_MAX;
int log(float);
scalar_t__ rand();
float sqrt(int);
float randn(float sd) {
  float U1, U2, S, x;
  do {
    U1 = ((float)rand()) / RAND_MAX;
    U2 = ((float)rand()) / RAND_MAX;
    U1 = 2 * U1 - 1;
    U2 = 2 * U2 - 1;
    S = U1 * U1 + U2 * U2;
  } while (S >= 1 || S == 0.0f);
  x = sd * sqrt(-2 * log(S) / S) * U1;
  return x;
}


x86 assembly (clang, -O0):
<randn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movss  %xmm0,-0x4(%rbp)
mov    $0x0,%al
call   1050 <rand@plt>
cvtsi2ss %rax,%xmm0
mov    0x2e98(%rip),%rax
divss  (%rax),%xmm0
movss  %xmm0,-0x8(%rbp)
mov    $0x0,%al
call   1050 <rand@plt>
cvtsi2ss %rax,%xmm0
mov    0x2e7c(%rip),%rax
divss  (%rax),%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0x8(%rbp),%xmm0
addss  %xmm0,%xmm0
movss  0xe7a(%rip),%xmm1
addss  %xmm1,%xmm0
movss  %xmm0,-0x8(%rbp)
movss  -0xc(%rbp),%xmm0
addss  %xmm0,%xmm0
movss  0xe60(%rip),%xmm1
addss  %xmm1,%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0x8(%rbp),%xmm0
movss  -0x8(%rbp),%xmm2
movss  -0xc(%rbp),%xmm1
mulss  -0xc(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x10(%rbp),%xmm0
mov    $0x1,%al
movss  0xe2b(%rip),%xmm1
ucomiss %xmm1,%xmm0
mov    %al,-0x15(%rbp)
jae    11fb <randn+0xcb>
movss  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
sete   %al
setnp  %cl
and    %cl,%al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    113d <randn+0xd>
movss  -0x4(%rbp),%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x10(%rbp),%xmm0
call   1030 <log@plt>
imul   $0xfffffffe,%eax,%eax
cvtsi2ss %eax,%xmm0
divss  -0x10(%rbp),%xmm0
cvttss2si %xmm0,%edi
call   1040 <sqrt@plt>
movaps %xmm0,%xmm1
movss  -0x1c(%rbp),%xmm0
mulss  %xmm1,%xmm0
mulss  -0x8(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x14(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<randn>:
push   %rbx
sub    $0x10,%rsp
movss  %xmm0,0xc(%rsp)
mov    0x2ea6(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1050 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
divss  (%rbx),%xmm0
movss  %xmm0,0x4(%rsp)
xor    %eax,%eax
call   1050 <rand@plt>
xorps  %xmm2,%xmm2
cvtsi2ss %rax,%xmm2
divss  (%rbx),%xmm2
movss  0x4(%rsp),%xmm0
addss  %xmm0,%xmm0
movss  0xe72(%rip),%xmm1
addss  %xmm1,%xmm0
addss  %xmm2,%xmm2
addss  %xmm1,%xmm2
mulss  %xmm2,%xmm2
movss  %xmm0,0x4(%rsp)
mulss  %xmm0,%xmm0
addss  %xmm2,%xmm0
ucomiss 0xe51(%rip),%xmm0
jae    1150 <randn+0x20>
ucomiss 0xe4c(%rip),%xmm0
jne    11c0 <randn+0x90>
jnp    1150 <randn+0x20>
movss  %xmm0,0x8(%rsp)
call   1030 <log@plt>
add    %eax,%eax
neg    %eax
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
divss  0x8(%rsp),%xmm0
cvttss2si %xmm0,%edi
call   1040 <sqrt@plt>
mulss  0xc(%rsp),%xmm0
mulss  0x4(%rsp),%xmm0
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@RAND_MAX = global float 0.000000e+00
define float @randn(float %0) {
%2 = alloca float
%3 = alloca float
%4 = alloca float
%5 = alloca float
%6 = alloca float
store float %0, float* %2
br label %7
7: ; preds = %32, %1
%8 = call i64 (...) @rand()
%9 = sitofp i64 %8 to float
%10 = load float, float* @RAND_MAX
%11 = fdiv float %9, %10
store float %11, float* %3
%12 = call i64 (...) @rand()
%13 = sitofp i64 %12 to float
%14 = load float, float* @RAND_MAX
%15 = fdiv float %13, %14
store float %15, float* %4
%16 = load float, float* %3
%17 = call float @llvm.fmuladd.f32(float 2.000000e+00, float %16, float -1.000000e+00)
store float %17, float* %3
%18 = load float, float* %4
%19 = call float @llvm.fmuladd.f32(float 2.000000e+00, float %18, float -1.000000e+00)
store float %19, float* %4
%20 = load float, float* %3
%21 = load float, float* %3
%22 = load float, float* %4
%23 = load float, float* %4
%24 = fmul float %22, %23
%25 = call float @llvm.fmuladd.f32(float %20, float %21, float %24)
store float %25, float* %5
br label %26
26: ; preds = %7
%27 = load float, float* %5
%28 = fcmp oge float %27, 1.000000e+00
br i1 %28, label %32, label %29
29: ; preds = %26
%30 = load float, float* %5
%31 = fcmp oeq float %30, 0.000000e+00
br label %32
32: ; preds = %29, %26
%33 = phi i1 [ true, %26 ], [ %31, %29 ]
br i1 %33, label %7, label %34
34: ; preds = %32
%35 = load float, float* %2
%36 = load float, float* %5
%37 = call i32 @log(float %36)
%38 = mul nsw i32 -2, %37
%39 = sitofp i32 %38 to float
%40 = load float, float* %5
%41 = fdiv float %39, %40
%42 = fptosi float %41 to i32
%43 = call float @sqrt(i32 %42)
%44 = fmul float %35, %43
%45 = load float, float* %3
%46 = fmul float %44, %45
store float %46, float* %6
%47 = load float, float* %6
ret float %47
}

LLVM IR (-O2):
@RAND_MAX = global float 0.000000e+00
define float @randn(float %0) {
br label %2
2: ; preds = %2, %1
%3 = tail call i64 (...) @rand()
%4 = sitofp i64 %3 to float
%5 = load float, float* @RAND_MAX
%6 = fdiv float %4, %5
%7 = tail call i64 (...) @rand()
%8 = sitofp i64 %7 to float
%9 = load float, float* @RAND_MAX
%10 = fdiv float %8, %9
%11 = tail call float @llvm.fmuladd.f32(float %6, float 2.000000e+00, float -1.000000e+00)
%12 = tail call float @llvm.fmuladd.f32(float %10, float 2.000000e+00, float -1.000000e+00)
%13 = fmul float %12, %12
%14 = tail call float @llvm.fmuladd.f32(float %11, float %11, float %13)
%15 = fcmp oge float %14, 1.000000e+00
%16 = fcmp oeq float %14, 0.000000e+00
%17 = or i1 %15, %16
br i1 %17, label %2, label %18
18: ; preds = %2
%19 = tail call i32 @log(float %14)
%20 = mul nsw i32 %19, -2
%21 = sitofp i32 %20 to float
%22 = fdiv float %21, %14
%23 = fptosi float %22 to i32
%24 = tail call float @sqrt(i32 %23)
%25 = fmul float %24, %0
%26 = fmul float %11, %25
ret float %26
}