#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 drand48();
double log(double);
double sqrt(double);
double gauss() {
  double x1, x2, w, y1;
  static int flag = 0;
  static double y2;
  if (flag) {
    flag = 0;
    return y2;
  }
  do {
    x1 = 2.0 * drand48() - 1.0;
    x2 = 2.0 * drand48() - 1.0;
    w = x1 * x1 + x2 * x2;
  } while (w >= 1.0);
  w = sqrt((-2.0 * log(w)) / w);
  y1 = x1 * w;
  y2 = x2 * w;
  flag = 1;
  return y1;
}


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    1233 <gauss+0x103>
jmp    1166 <gauss+0x36>
mov    $0x0,%al
call   1050 <drand48@plt>
addsd  %xmm0,%xmm0
movsd  0xe87(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    $0x0,%al
call   1050 <drand48@plt>
addsd  %xmm0,%xmm0
movsd  0xe6b(%rip),%xmm1
addsd  %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  0xe3c(%rip),%xmm1
ucomisd %xmm1,%xmm0
jae    1166 <gauss+0x36>
movsd  -0x20(%rbp),%xmm0
call   1030 <log@plt>
movaps %xmm0,%xmm1
movsd  0xe25(%rip),%xmm0
mulsd  %xmm1,%xmm0
divsd  -0x20(%rbp),%xmm0
call   1040 <sqrt@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,0x2e29(%rip)
movl   $0x1,0x2e17(%rip)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gauss>:
sub    $0x18,%rsp
cmpb   $0x0,0x2f05(%rip)
je     1160 <gauss+0x30>
movb   $0x0,0x2efc(%rip)
movsd  0x2efc(%rip),%xmm1
jmp    120c <gauss+0xdc>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <drand48@plt>
movapd %xmm0,%xmm1
addsd  %xmm0,%xmm1
movsd  0xe89(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
xor    %eax,%eax
call   1050 <drand48@plt>
movsd  (%rsp),%xmm3
addsd  %xmm0,%xmm0
addsd  0xe68(%rip),%xmm0
movapd %xmm0,%xmm2
mulsd  %xmm0,%xmm2
mulsd  %xmm3,%xmm3
addsd  %xmm2,%xmm3
ucomisd 0xe58(%rip),%xmm3
jae    1160 <gauss+0x30>
movsd  %xmm0,0x10(%rsp)
movapd %xmm3,%xmm0
movsd  %xmm3,0x8(%rsp)
call   1030 <log@plt>
mulsd  0xe41(%rip),%xmm0
divsd  0x8(%rsp),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11e5 <gauss+0xb5>
sqrtsd %xmm0,%xmm0
jmp    11ea <gauss+0xba>
call   1040 <sqrt@plt>
movsd  (%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  0x10(%rsp),%xmm2
mulsd  %xmm0,%xmm2
movsd  %xmm2,0x2e43(%rip)
movb   $0x1,0x2e34(%rip)
movapd %xmm1,%xmm0
add    $0x18,%rsp
ret

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

LLVM IR (-O2):
@gauss.flag = internal unnamed_addr global i1 false
@gauss.y2 = internal unnamed_addr global double 0.000000e+00
define double @gauss() {
%1 = load i1, i1* @gauss.flag
br i1 %1, label %2, label %4
2: ; preds = %0
store i1 false, i1* @gauss.flag
%3 = load double, double* @gauss.y2
br label %19
4: ; preds = %0, %4
%5 = tail call double (...) @drand48()
%6 = tail call double @llvm.fmuladd.f64(double %5, double 2.000000e+00, double -1.000000e+00)
%7 = tail call double (...) @drand48()
%8 = tail call double @llvm.fmuladd.f64(double %7, double 2.000000e+00, double -1.000000e+00)
%9 = fmul double %8, %8
%10 = tail call double @llvm.fmuladd.f64(double %6, double %6, double %9)
%11 = fcmp ult double %10, 1.000000e+00
br i1 %11, label %12, label %4
12: ; preds = %4
%13 = tail call double @log(double %10)
%14 = fmul double %13, -2.000000e+00
%15 = fdiv double %14, %10
%16 = tail call double @sqrt(double %15)
%17 = fmul double %6, %16
%18 = fmul double %8, %16
store double %18, double* @gauss.y2
store i1 true, i1* @gauss.flag
br label %19
19: ; preds = %12, %2
%20 = phi double [ %3, %2 ], [ %17, %12 ]
ret double %20
}