#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 get_rand_double(double, double);
double log(double);
double sqrt(double);
double GaussDev() {
  static int iset = 0;
  static float gset;
  double fac, r, v1, v2;
  if (iset == 0) {
    do {
      v1 = get_rand_double(-1.0, 1.0);
      v2 = get_rand_double(-1.0, 1.0);
      r = v1 * v1 + v2 * v2;
    } while (r >= 1.0);
    fac = sqrt(-2.0 * log(r) / r);
    gset = v1 * fac;
    iset = 1;
    return v2 * fac;
  } else {
    iset = 0;
    return gset;
  }
}


x86 assembly (clang, -O0):
<GaussDev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
cmpl   $0x0,0x2efd(%rip)
jne    1212 <GaussDev+0xe2>
jmp    114a <GaussDev+0x1a>
movsd  0xeae(%rip),%xmm0
movsd  0xeae(%rip),%xmm1
call   1050 <get_rand_double@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  0xe94(%rip),%xmm0
movsd  0xe94(%rip),%xmm1
call   1050 <get_rand_double@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm2
movsd  -0x28(%rbp),%xmm1
mulsd  -0x28(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xe5c(%rip),%xmm1
ucomisd %xmm1,%xmm0
jae    114a <GaussDev+0x1a>
movsd  -0x18(%rbp),%xmm0
call   1030 <log@plt>
movaps %xmm0,%xmm1
movsd  0xe45(%rip),%xmm0
mulsd  %xmm1,%xmm0
divsd  -0x18(%rbp),%xmm0
call   1040 <sqrt@plt>
movsd  %xmm0,-0x10(%rbp)
movsd  -0x20(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,0x2e4c(%rip)
movl   $0x1,0x2e3e(%rip)
movsd  -0x28(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    122d <GaussDev+0xfd>
movl   $0x0,0x2e20(%rip)
movss  0x2e1c(%rip),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GaussDev>:
sub    $0x18,%rsp
cmpb   $0x0,0x2f01(%rip)
je     1160 <GaussDev+0x30>
movb   $0x0,0x2ef8(%rip)
movss  0x2ef4(%rip),%xmm0
cvtss2sd %xmm0,%xmm1
jmp    120c <GaussDev+0xdc>
cs nopw 0x0(%rax,%rax,1)
nop
movsd  0xe98(%rip),%xmm0
movsd  0xe98(%rip),%xmm1
call   1050 <get_rand_double@plt>
movsd  %xmm0,(%rsp)
movsd  0xe7e(%rip),%xmm0
movsd  0xe7e(%rip),%xmm1
call   1050 <get_rand_double@plt>
movsd  (%rsp),%xmm3
movapd %xmm0,%xmm1
mulsd  %xmm0,%xmm1
mulsd  %xmm3,%xmm3
addsd  %xmm1,%xmm3
ucomisd 0xe5c(%rip),%xmm3
jae    1160 <GaussDev+0x30>
movsd  %xmm0,0x10(%rsp)
movapd %xmm3,%xmm0
movsd  %xmm3,0x8(%rsp)
call   1030 <log@plt>
mulsd  0xe45(%rip),%xmm0
divsd  0x8(%rsp),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11e1 <GaussDev+0xb1>
sqrtsd %xmm0,%xmm0
jmp    11e6 <GaussDev+0xb6>
call   1040 <sqrt@plt>
movsd  (%rsp),%xmm1
mulsd  %xmm0,%xmm1
cvtsd2ss %xmm1,%xmm1
movss  %xmm1,0x2e45(%rip)
movb   $0x1,0x2e3a(%rip)
movsd  0x10(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movaps %xmm1,%xmm0
add    $0x18,%rsp
ret

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

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