#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 RAND_MAX;
double log(double);
scalar_t__ rand();
double sqrt(double);
void random_gaussian(double *y1, double *y2) {
  double x1, x2, w;
  do {
    x1 = (double)rand() / RAND_MAX;
    x2 = (double)rand() / RAND_MAX;
    x1 = 2.0 * x1 - 1.0;
    x2 = 2.0 * x2 - 1.0;
    w = x1 * x1 + x2 * x2;
  } while (w >= 1.0 || w == 0.0);
  w = sqrt((-2.0 * log(w)) / w);
  *y1 = x1 * w;
  *y2 = x2 * w;
}


x86 assembly (clang, -O0):
<random_gaussian>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1050 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2e95(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    $0x0,%al
call   1050 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2e79(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
addsd  %xmm0,%xmm0
movsd  0xe77(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x20(%rbp),%xmm0
addsd  %xmm0,%xmm0
movsd  0xe5d(%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
mov    $0x1,%al
movsd  0xe2c(%rip),%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x29(%rbp)
jae    1200 <random_gaussian+0xd0>
movsd  -0x28(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
sete   %al
setnp  %cl
and    %cl,%al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    1140 <random_gaussian+0x10>
movsd  -0x28(%rbp),%xmm0
call   1030 <log@plt>
movaps %xmm0,%xmm1
movsd  0xdf0(%rip),%xmm0
mulsd  %xmm1,%xmm0
divsd  -0x28(%rbp),%xmm0
call   1040 <sqrt@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x20(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random_gaussian>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
mov    0x2ea2(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  (%rbx),%xmm0
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1050 <rand@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
divsd  (%rbx),%xmm1
movsd  0x8(%rsp),%xmm3
addsd  %xmm3,%xmm3
movsd  0xe72(%rip),%xmm0
addsd  %xmm0,%xmm3
addsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
movapd %xmm1,%xmm2
mulsd  %xmm1,%xmm2
movsd  %xmm3,0x8(%rsp)
movapd %xmm3,%xmm0
mulsd  %xmm3,%xmm0
addsd  %xmm2,%xmm0
ucomisd 0xe4c(%rip),%xmm0
jae    1150 <random_gaussian+0x20>
ucomisd 0xe52(%rip),%xmm0
jne    11ca <random_gaussian+0x9a>
jnp    1150 <random_gaussian+0x20>
movsd  %xmm1,0x18(%rsp)
movsd  %xmm0,0x10(%rsp)
call   1030 <log@plt>
mulsd  0xe2d(%rip),%xmm0
divsd  0x10(%rsp),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11f9 <random_gaussian+0xc9>
sqrtsd %xmm0,%xmm0
jmp    11fe <random_gaussian+0xce>
call   1040 <sqrt@plt>
movsd  0x8(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,(%r15)
movsd  0x18(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,(%r14)
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@RAND_MAX = global double 0.000000e+00
define void @random_gaussian(double* nocapture writeonly %0, double* nocapture writeonly %1) {
br label %3
3: ; preds = %3, %2
%4 = tail call i64 (...) @rand()
%5 = sitofp i64 %4 to double
%6 = load double, double* @RAND_MAX
%7 = fdiv double %5, %6
%8 = tail call i64 (...) @rand()
%9 = sitofp i64 %8 to double
%10 = load double, double* @RAND_MAX
%11 = fdiv double %9, %10
%12 = tail call double @llvm.fmuladd.f64(double %7, double 2.000000e+00, double -1.000000e+00)
%13 = tail call double @llvm.fmuladd.f64(double %11, double 2.000000e+00, double -1.000000e+00)
%14 = fmul double %13, %13
%15 = tail call double @llvm.fmuladd.f64(double %12, double %12, double %14)
%16 = fcmp oge double %15, 1.000000e+00
%17 = fcmp oeq double %15, 0.000000e+00
%18 = or i1 %16, %17
br i1 %18, label %3, label %19
19: ; preds = %3
%20 = tail call double @log(double %15)
%21 = fmul double %20, -2.000000e+00
%22 = fdiv double %21, %15
%23 = tail call double @sqrt(double %22)
%24 = fmul double %12, %23
store double %24, double* %0
%25 = fmul double %13, %23
store double %25, double* %1
ret void
}