#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 rand_uni();
double sqrt(int);
double rand_gaus(double mean, double sigma) {
  double u, v, s;
  do {
    u = rand_uni();
    v = rand_uni();
    s = u * u + v * v;
  } while (s >= 1);
  return u * sqrt(-2 * log(s) / s) * sigma + mean;
}


x86 assembly (clang, -O0):
<rand_gaus>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    $0x0,%al
call   1030 <rand_uni@plt>
movsd  %xmm0,-0x18(%rbp)
mov    $0x0,%al
call   1030 <rand_uni@plt>
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
movsd  0xe78(%rip),%xmm1
ucomisd %xmm1,%xmm0
jae    1142 <rand_gaus+0x12>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1040 <log@plt>
imul   $0xfffffffe,%eax,%eax
cvtsi2sd %eax,%xmm0
divsd  -0x28(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1050 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  -0x10(%rbp),%xmm2
movsd  -0x8(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rand_gaus>:
sub    $0x28,%rsp
movsd  %xmm1,0x18(%rsp)
movsd  %xmm0,0x20(%rsp)
xor    %eax,%eax
call   1030 <rand_uni@plt>
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1030 <rand_uni@plt>
mulsd  %xmm0,%xmm0
movsd  0x8(%rsp),%xmm1
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
ucomisd 0xe92(%rip),%xmm1
jae    1140 <rand_gaus+0x10>
movapd %xmm1,%xmm0
movsd  %xmm1,0x10(%rsp)
call   1040 <log@plt>
add    %eax,%eax
neg    %eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  0x10(%rsp),%xmm0
cvttsd2si %xmm0,%edi
call   1050 <sqrt@plt>
mulsd  0x8(%rsp),%xmm0
mulsd  0x18(%rsp),%xmm0
addsd  0x20(%rsp),%xmm0
add    $0x28,%rsp
ret

LLVM IR (-O0):
define double @rand_gaus(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 = %17, %2
%9 = call double (...) @rand_uni()
store double %9, double* %5
%10 = call double (...) @rand_uni()
store double %10, double* %6
%11 = load double, double* %5
%12 = load double, double* %5
%13 = load double, double* %6
%14 = load double, double* %6
%15 = fmul double %13, %14
%16 = call double @llvm.fmuladd.f64(double %11, double %12, double %15)
store double %16, double* %7
br label %17
17: ; preds = %8
%18 = load double, double* %7
%19 = fcmp oge double %18, 1.000000e+00
br i1 %19, label %8, label %20
20: ; preds = %17
%21 = load double, double* %5
%22 = load double, double* %7
%23 = call i32 @log(double %22)
%24 = mul nsw i32 -2, %23
%25 = sitofp i32 %24 to double
%26 = load double, double* %7
%27 = fdiv double %25, %26
%28 = fptosi double %27 to i32
%29 = call double @sqrt(i32 %28)
%30 = fmul double %21, %29
%31 = load double, double* %4
%32 = load double, double* %3
%33 = call double @llvm.fmuladd.f64(double %30, double %31, double %32)
ret double %33
}

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