#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);
double randrange(int, int);
double sqrt(int);
double gaussian_rand() {
  double v1, v2, s;
  do {
    v1 = randrange(-1., 1.);
    v2 = randrange(-1., 1.);
    s = v1 * v1 + v2 * v2;
  } while (s >= 1.);
  return sqrt(-2. * log(s) / s) * v1;
}


x86 assembly (clang, -O0):
<gaussian_rand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0xffffffff,%edi
mov    $0x1,%esi
call   1040 <randrange@plt>
movsd  %xmm0,-0x8(%rbp)
mov    $0xffffffff,%edi
mov    $0x1,%esi
call   1040 <randrange@plt>
movsd  %xmm0,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  -0x8(%rbp),%xmm2
movsd  -0x10(%rbp),%xmm1
mulsd  -0x10(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xe72(%rip),%xmm1
ucomisd %xmm1,%xmm0
jae    1138 <gaussian_rand+0x8>
movsd  -0x18(%rbp),%xmm0
call   1030 <log@plt>
cvtsi2sd %eax,%xmm1
movsd  0xe5a(%rip),%xmm0
mulsd  %xmm1,%xmm0
divsd  -0x18(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1050 <sqrt@plt>
mulsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gaussian_rand>:
sub    $0x18,%rsp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    $0xffffffff,%edi
mov    $0x1,%esi
call   1040 <randrange@plt>
movsd  %xmm0,0x8(%rsp)
mov    $0xffffffff,%edi
mov    $0x1,%esi
call   1040 <randrange@plt>
mulsd  %xmm0,%xmm0
movsd  0x8(%rsp),%xmm1
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
ucomisd 0xe82(%rip),%xmm1
jae    1140 <gaussian_rand+0x10>
movapd %xmm1,%xmm0
movsd  %xmm1,0x10(%rsp)
call   1030 <log@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0xe6a(%rip),%xmm0
divsd  0x10(%rsp),%xmm0
cvttsd2si %xmm0,%edi
call   1050 <sqrt@plt>
mulsd  0x8(%rsp),%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
define double @gaussian_rand() {
%1 = alloca double
%2 = alloca double
%3 = alloca double
br label %4
4: ; preds = %13, %0
%5 = call double @randrange(i32 -1, i32 1)
store double %5, double* %1
%6 = call double @randrange(i32 -1, i32 1)
store double %6, double* %2
%7 = load double, double* %1
%8 = load double, double* %1
%9 = load double, double* %2
%10 = load double, double* %2
%11 = fmul double %9, %10
%12 = call double @llvm.fmuladd.f64(double %7, double %8, double %11)
store double %12, double* %3
br label %13
13: ; preds = %4
%14 = load double, double* %3
%15 = fcmp oge double %14, 1.000000e+00
br i1 %15, label %4, label %16
16: ; preds = %13
%17 = load double, double* %3
%18 = call i32 @log(double %17)
%19 = sitofp i32 %18 to double
%20 = fmul double -2.000000e+00, %19
%21 = load double, double* %3
%22 = fdiv double %20, %21
%23 = fptosi double %22 to i32
%24 = call double @sqrt(i32 %23)
%25 = load double, double* %1
%26 = fmul double %24, %25
ret double %26
}

LLVM IR (-O2):
define double @gaussian_rand() {
br label %1
1: ; preds = %1, %0
%2 = tail call double @randrange(i32 -1, i32 1)
%3 = tail call double @randrange(i32 -1, i32 1)
%4 = fmul double %3, %3
%5 = tail call double @llvm.fmuladd.f64(double %2, double %2, double %4)
%6 = fcmp ult double %5, 1.000000e+00
br i1 %6, label %7, label %1
7: ; preds = %1
%8 = tail call i32 @log(double %5)
%9 = sitofp i32 %8 to double
%10 = fmul double %9, -2.000000e+00
%11 = fdiv double %10, %5
%12 = fptosi double %11 to i32
%13 = tail call double @sqrt(i32 %12)
%14 = fmul double %2, %13
ret double %14
}