#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 log(double);
int rnd();
double sqrt(int);
double GaussRand() {
  static double t = 0.;
  double x, v1, v2, r;
  if (t == 0) {
    do {
      v1 = 2. * rnd() - 1.;
      v2 = 2. * rnd() - 1.;
      r = v1 * v1 + v2 * v2;
    } while (r >= 1.);
    r = sqrt(-2. * log(r) / r);
    t = v2 * r;
    return v1 * r;
  } else {
    x = t;
    t = 0.;
    return x;
  }
}


x86 assembly (clang, -O0):
<GaussRand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  0x2f00(%rip),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1223 <GaussRand+0xf3>
jp     1223 <GaussRand+0xf3>
jmp    1158 <GaussRand+0x28>
mov    $0x0,%al
call   1030 <rnd@plt>
cvtsi2sd %eax,%xmm0
addsd  %xmm0,%xmm0
movsd  0xe91(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    $0x0,%al
call   1030 <rnd@plt>
cvtsi2sd %eax,%xmm0
addsd  %xmm0,%xmm0
movsd  0xe71(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm2
movsd  -0x20(%rbp),%xmm1
mulsd  -0x20(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  0xe42(%rip),%xmm1
ucomisd %xmm1,%xmm0
jae    1158 <GaussRand+0x28>
movsd  -0x28(%rbp),%xmm0
call   1040 <log@plt>
cvtsi2sd %eax,%xmm1
movsd  0xe2a(%rip),%xmm0
mulsd  %xmm1,%xmm0
divsd  -0x28(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1050 <sqrt@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,0x2e31(%rip)
movsd  -0x18(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1245 <GaussRand+0x115>
movsd  0x2e15(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,0x2e05(%rip)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GaussRand>:
sub    $0x18,%rsp
movsd  0x2f04(%rip),%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jne    11f8 <GaussRand+0xc8>
jp     11f8 <GaussRand+0xc8>
xor    %eax,%eax
call   1030 <rnd@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
addsd  %xmm1,%xmm1
movsd  0xe96(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
xor    %eax,%eax
call   1030 <rnd@plt>
movsd  (%rsp),%xmm0
xorps  %xmm2,%xmm2
cvtsi2sd %eax,%xmm2
addsd  %xmm2,%xmm2
addsd  0xe6e(%rip),%xmm2
movapd %xmm2,%xmm3
mulsd  %xmm2,%xmm3
mulsd  %xmm0,%xmm0
addsd  %xmm3,%xmm0
ucomisd 0xe5e(%rip),%xmm0
jae    1150 <GaussRand+0x20>
movsd  %xmm2,0x10(%rsp)
movsd  %xmm0,0x8(%rsp)
call   1040 <log@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0xe44(%rip),%xmm0
divsd  0x8(%rsp),%xmm0
cvttsd2si %xmm0,%edi
call   1050 <sqrt@plt>
movsd  (%rsp),%xmm1
movsd  0x10(%rsp),%xmm2
mulsd  %xmm0,%xmm2
movsd  %xmm2,0x2e4e(%rip)
mulsd  %xmm0,%xmm1
jmp    1203 <GaussRand+0xd3>
movq   $0x0,0x2e3d(%rip)
movapd %xmm1,%xmm0
add    $0x18,%rsp
ret

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

LLVM IR (-O2):
@GaussRand.t = internal unnamed_addr global double 0.000000e+00
define double @GaussRand() {
%1 = load double, double* @GaussRand.t
%2 = fcmp oeq double %1, 0.000000e+00
br i1 %2, label %3, label %22
3: ; preds = %0, %3
%4 = tail call i32 (...) @rnd()
%5 = sitofp i32 %4 to double
%6 = tail call double @llvm.fmuladd.f64(double %5, double 2.000000e+00, double -1.000000e+00)
%7 = tail call i32 (...) @rnd()
%8 = sitofp i32 %7 to double
%9 = tail call double @llvm.fmuladd.f64(double %8, double 2.000000e+00, double -1.000000e+00)
%10 = fmul double %9, %9
%11 = tail call double @llvm.fmuladd.f64(double %6, double %6, double %10)
%12 = fcmp ult double %11, 1.000000e+00
br i1 %12, label %13, label %3
13: ; preds = %3
%14 = tail call i32 @log(double %11)
%15 = sitofp i32 %14 to double
%16 = fmul double %15, -2.000000e+00
%17 = fdiv double %16, %11
%18 = fptosi double %17 to i32
%19 = tail call double @sqrt(i32 %18)
%20 = fmul double %9, %19
store double %20, double* @GaussRand.t
%21 = fmul double %6, %19
br label %23
22: ; preds = %0
store double 0.000000e+00, double* @GaussRand.t
br label %23
23: ; preds = %22, %13
%24 = phi double [ %21, %13 ], [ %1, %22 ]
ret double %24
}