#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 */
scalar_t__ RAND_MAX;
double log(double);
double rand();
double sqrt(double);
double gauss() {
  static int zaliha = 0;
  static double na_zalihi = 0.0;
  double v1, v2, rsq, fac;
  if (zaliha) {
    zaliha = 0;
    return na_zalihi;
  } else {
    do {
      v1 = 2.0 * rand() / (double)RAND_MAX - 1.0;
      v2 = 2.0 * rand() / (double)RAND_MAX - 1.0;
      rsq = v1 * v1 + v2 * v2;
    } while (rsq >= 1.0);
    fac = sqrt(-2.0 * log(rsq) / rsq);
    na_zalihi = v1 * fac;
    zaliha = 1;
    return v2 * fac;
  }
}


x86 assembly (clang, -O0):
<gauss>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
cmpl   $0x0,0x2f01(%rip)
je     1161 <gauss+0x31>
movl   $0x0,0x2ef1(%rip)
movsd  0x2ef1(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    125f <gauss+0x12f>
jmp    1166 <gauss+0x36>
mov    $0x0,%al
call   1050 <rand@plt>
movaps %xmm0,%xmm1
movsd  0xe90(%rip),%xmm0
mulsd  %xmm1,%xmm0
mov    0x2e65(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  0xe6c(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    $0x0,%al
call   1050 <rand@plt>
movaps %xmm0,%xmm1
movsd  0xe59(%rip),%xmm0
mulsd  %xmm1,%xmm0
mov    0x2e2e(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  0xe35(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm2
movsd  -0x18(%rbp),%xmm1
mulsd  -0x18(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  0xdfe(%rip),%xmm1
ucomisd %xmm1,%xmm0
jae    1166 <gauss+0x36>
movsd  -0x20(%rbp),%xmm0
call   1030 <log@plt>
movaps %xmm0,%xmm1
movsd  0xdef(%rip),%xmm0
mulsd  %xmm1,%xmm0
divsd  -0x20(%rbp),%xmm0
call   1040 <sqrt@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,0x2e02(%rip)
movl   $0x1,0x2df0(%rip)
movsd  -0x18(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gauss>:
push   %rbx
sub    $0x20,%rsp
cmpb   $0x0,0x2f04(%rip)
je     1152 <gauss+0x22>
movb   $0x0,0x2efb(%rip)
movsd  0x2efb(%rip),%xmm1
jmp    1227 <gauss+0xf7>
mov    0x2e8f(%rip),%rbx
nopl   0x0(%rax)
xor    %eax,%eax
call   1050 <rand@plt>
movapd %xmm0,%xmm1
addsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sdq (%rbx),%xmm0
divsd  %xmm0,%xmm1
movsd  0xe7d(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
xor    %eax,%eax
call   1050 <rand@plt>
movsd  0x8(%rsp),%xmm3
xorps  %xmm2,%xmm2
cvtsi2sdq (%rbx),%xmm2
addsd  %xmm0,%xmm0
divsd  %xmm2,%xmm0
addsd  0xe4e(%rip),%xmm0
movapd %xmm0,%xmm2
mulsd  %xmm0,%xmm2
mulsd  %xmm3,%xmm3
addsd  %xmm2,%xmm3
ucomisd 0xe3e(%rip),%xmm3
jae    1160 <gauss+0x30>
movsd  %xmm0,0x18(%rsp)
movapd %xmm3,%xmm0
movsd  %xmm3,0x10(%rsp)
call   1030 <log@plt>
mulsd  0xe27(%rip),%xmm0
divsd  0x10(%rsp),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11ff <gauss+0xcf>
sqrtsd %xmm0,%xmm0
jmp    1204 <gauss+0xd4>
call   1040 <sqrt@plt>
movsd  0x8(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x2e32(%rip)
movb   $0x1,0x2e23(%rip)
movsd  0x18(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
@gauss.zaliha = internal unnamed_addr global i1 false
@gauss.na_zalihi = internal unnamed_addr global double 0.000000e+00
@RAND_MAX = global i64 0
define double @gauss() {
%1 = load i1, i1* @gauss.zaliha
br i1 %1, label %2, label %4
2: ; preds = %0
store i1 false, i1* @gauss.zaliha
%3 = load double, double* @gauss.na_zalihi
br label %27
4: ; preds = %0, %4
%5 = tail call double (...) @rand()
%6 = fmul double %5, 2.000000e+00
%7 = load i64, i64* @RAND_MAX
%8 = sitofp i64 %7 to double
%9 = fdiv double %6, %8
%10 = fadd double %9, -1.000000e+00
%11 = tail call double (...) @rand()
%12 = fmul double %11, 2.000000e+00
%13 = load i64, i64* @RAND_MAX
%14 = sitofp i64 %13 to double
%15 = fdiv double %12, %14
%16 = fadd double %15, -1.000000e+00
%17 = fmul double %16, %16
%18 = tail call double @llvm.fmuladd.f64(double %10, double %10, double %17)
%19 = fcmp ult double %18, 1.000000e+00
br i1 %19, label %20, label %4
20: ; preds = %4
%21 = tail call double @log(double %18)
%22 = fmul double %21, -2.000000e+00
%23 = fdiv double %22, %18
%24 = tail call double @sqrt(double %23)
%25 = fmul double %10, %24
store double %25, double* @gauss.na_zalihi
store i1 true, i1* @gauss.zaliha
%26 = fmul double %16, %24
br label %27
27: ; preds = %20, %2
%28 = phi double [ %3, %2 ], [ %26, %20 ]
ret double %28
}