#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 lcg(long *);
double log(double);
double sqrt(double);
double gauss(double sigma, double mean, long int *seed) {
  double rgauss;
  double v1, v2;
  double r = 2.0;
  while (r >= 1.0) {
    v1 = 2.0 * (double)(lcg(seed) - 1.0);
    v2 = 2.0 * (double)(lcg(seed) - 1.0);
    r = v1 * v1 + v2 * v2;
  }
  rgauss = v1 * sqrt(-2.0 * log(r) / r);
  rgauss = mean + rgauss * sigma;
  return rgauss;
}


x86 assembly (clang, -O0):
<gauss>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
movsd  0xeb2(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  0xea8(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     11e2 <gauss+0xb2>
mov    -0x18(%rbp),%rdi
call   1030 <lcg@plt>
movaps %xmm0,%xmm1
movsd  0xe8a(%rip),%xmm0
subsd  %xmm0,%xmm1
movsd  0xe76(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <lcg@plt>
movaps %xmm0,%xmm1
movsd  0xe61(%rip),%xmm0
subsd  %xmm0,%xmm1
movsd  0xe4d(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm2
movsd  -0x30(%rbp),%xmm1
mulsd  -0x30(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    1153 <gauss+0x23>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x38(%rbp),%xmm0
call   1040 <log@plt>
movaps %xmm0,%xmm1
movsd  0xe0f(%rip),%xmm0
mulsd  %xmm1,%xmm0
divsd  -0x38(%rbp),%xmm0
call   1050 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
movsd  -0x8(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gauss>:
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%rbx
movsd  %xmm1,0x18(%rsp)
movsd  %xmm0,0x10(%rsp)
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
call   1030 <lcg@plt>
movapd %xmm0,%xmm1
movsd  0xe9c(%rip),%xmm0
addsd  %xmm0,%xmm1
addsd  %xmm1,%xmm1
movsd  %xmm1,(%rsp)
mov    %rbx,%rdi
call   1030 <lcg@plt>
movsd  (%rsp),%xmm2
addsd  0xe7a(%rip),%xmm0
addsd  %xmm0,%xmm0
mulsd  %xmm0,%xmm0
mulsd  %xmm2,%xmm2
addsd  %xmm0,%xmm2
ucomisd 0xe6a(%rip),%xmm2
jae    1150 <gauss+0x20>
movapd %xmm2,%xmm0
movsd  %xmm2,0x8(%rsp)
call   1040 <log@plt>
mulsd  0xe59(%rip),%xmm0
divsd  0x8(%rsp),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11cd <gauss+0x9d>
sqrtsd %xmm0,%xmm0
jmp    11d2 <gauss+0xa2>
call   1050 <sqrt@plt>
movsd  (%rsp),%xmm1
mulsd  %xmm0,%xmm1
mulsd  0x10(%rsp),%xmm1
addsd  0x18(%rsp),%xmm1
movapd %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
define double @gauss(double %0, double %1, i64* %2) {
br label %4
4: ; preds = %3, %4
%5 = tail call double @lcg(i64* %2)
%6 = fadd double %5, -1.000000e+00
%7 = fmul double %6, 2.000000e+00
%8 = tail call double @lcg(i64* %2)
%9 = fadd double %8, -1.000000e+00
%10 = fmul double %9, 2.000000e+00
%11 = fmul double %10, %10
%12 = tail call double @llvm.fmuladd.f64(double %7, double %7, double %11)
%13 = fcmp ult double %12, 1.000000e+00
br i1 %13, label %14, label %4
14: ; preds = %4
%15 = tail call double @log(double %12)
%16 = fmul double %15, -2.000000e+00
%17 = fdiv double %16, %12
%18 = tail call double @sqrt(double %17)
%19 = fmul double %7, %18
%20 = tail call double @llvm.fmuladd.f64(double %19, double %0, double %1)
ret double %20
}