#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(double);
double log(double);
double simplerng_getuniform();
double sin(double);
double sqrt(double);
double simplerng_getnorm() {
  double u1, u2, r, theta;
  static int saved = 0;
  static double y;
  if (saved == 0) {
    u1 = simplerng_getuniform();
    u2 = simplerng_getuniform();
    r = sqrt(-2.0 * log(u1));
    theta = 2.0 * 3.1415926535897932384626433832795 * u2;
    y = r * cos(theta);
    saved = 1;
    return r * sin(theta);
  } else {
    saved = 0;
    return y;
  }
}


x86 assembly (clang, -O0):
<simplerng_getnorm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
cmpl   $0x0,0x2ef1(%rip)
jne    120e <simplerng_getnorm+0xbe>
mov    $0x0,%al
call   1030 <simplerng_getuniform@plt>
movsd  %xmm0,-0x10(%rbp)
mov    $0x0,%al
call   1030 <simplerng_getuniform@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1060 <log@plt>
movaps %xmm0,%xmm1
movsd  0xe76(%rip),%xmm0
mulsd  %xmm1,%xmm0
call   1070 <sqrt@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  0xe58(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1050 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,0x2e7e(%rip)
movl   $0x1,0x2e6c(%rip)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1040 <sin@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1225 <simplerng_getnorm+0xd5>
movl   $0x0,0x2e38(%rip)
movsd  0x2e38(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<simplerng_getnorm>:
sub    $0x18,%rsp
cmpb   $0x0,0x2ef5(%rip)
je     1171 <simplerng_getnorm+0x21>
movb   $0x0,0x2eec(%rip)
movsd  0x2eec(%rip),%xmm0
add    $0x18,%rsp
ret
xor    %eax,%eax
call   1030 <simplerng_getuniform@plt>
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1030 <simplerng_getuniform@plt>
movsd  %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
call   1060 <log@plt>
mulsd  0xe62(%rip),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11ae <simplerng_getnorm+0x5e>
sqrtsd %xmm0,%xmm0
jmp    11b3 <simplerng_getnorm+0x63>
call   1070 <sqrt@plt>
movsd  %xmm0,0x8(%rsp)
movsd  0x10(%rsp),%xmm0
mulsd  0xe41(%rip),%xmm0
movsd  %xmm0,0x10(%rsp)
call   1050 <cos@plt>
mulsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x2e78(%rip)
movb   $0x1,0x2e69(%rip)
movsd  0x10(%rsp),%xmm0
call   1040 <sin@plt>
mulsd  0x8(%rsp),%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
@simplerng_getnorm.saved = internal global i32 0
@simplerng_getnorm.y = internal global double 0.000000e+00
define double @simplerng_getnorm() {
%1 = alloca double
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = load i32, i32* @simplerng_getnorm.saved
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %25
8: ; preds = %0
%9 = call double (...) @simplerng_getuniform()
store double %9, double* %2
%10 = call double (...) @simplerng_getuniform()
store double %10, double* %3
%11 = load double, double* %2
%12 = call double @log(double %11)
%13 = fmul double -2.000000e+00, %12
%14 = call double @sqrt(double %13)
store double %14, double* %4
%15 = load double, double* %3
%16 = fmul double 0x401921FB54442D18, %15
store double %16, double* %5
%17 = load double, double* %4
%18 = load double, double* %5
%19 = call double @cos(double %18)
%20 = fmul double %17, %19
store double %20, double* @simplerng_getnorm.y
store i32 1, i32* @simplerng_getnorm.saved
%21 = load double, double* %4
%22 = load double, double* %5
%23 = call double @sin(double %22)
%24 = fmul double %21, %23
store double %24, double* %1
br label %27
25: ; preds = %0
store i32 0, i32* @simplerng_getnorm.saved
%26 = load double, double* @simplerng_getnorm.y
store double %26, double* %1
br label %27
27: ; preds = %25, %8
%28 = load double, double* %1
ret double %28
}

LLVM IR (-O2):
@simplerng_getnorm.saved = internal unnamed_addr global i1 false
@simplerng_getnorm.y = internal unnamed_addr global double 0.000000e+00
define double @simplerng_getnorm() {
%1 = load i1, i1* @simplerng_getnorm.saved
br i1 %1, label %13, label %2
2: ; preds = %0
%3 = tail call double (...) @simplerng_getuniform()
%4 = tail call double (...) @simplerng_getuniform()
%5 = tail call double @log(double %3)
%6 = fmul double %5, -2.000000e+00
%7 = tail call double @sqrt(double %6)
%8 = fmul double %4, 0x401921FB54442D18
%9 = tail call double @cos(double %8)
%10 = fmul double %7, %9
store double %10, double* @simplerng_getnorm.y
store i1 true, i1* @simplerng_getnorm.saved
%11 = tail call double @sin(double %8)
%12 = fmul double %7, %11
br label %15
13: ; preds = %0
store i1 false, i1* @simplerng_getnorm.saved
%14 = load double, double* @simplerng_getnorm.y
br label %15
15: ; preds = %13, %2
%16 = phi double [ %12, %2 ], [ %14, %13 ]
ret double %16
}