#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);
int rand_float();
double sqrt(int);
double norm_sample(double mu, double sigma) {
  while (true) {
    double r1 = rand_float() * 2 - 1;
    double r2 = rand_float() * 2 - 1;
    double s = r1 * r1 + r2 * r2;
    if (s < 1) {
      double unscaled = r1 * sqrt((-2 * log(s)) / s);
      return mu + sigma * unscaled;
    }
  }
}


x86 assembly (clang, -O0):
<norm_sample>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    $0x0,%al
call   1030 <rand_float@plt>
shl    $0x1,%eax
sub    $0x1,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    $0x0,%al
call   1030 <rand_float@plt>
shl    $0x1,%eax
sub    $0x1,%eax
cvtsi2sd %eax,%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  0xe69(%rip),%xmm0
ucomisd -0x28(%rbp),%xmm0
jbe    11fc <norm_sample+0xcc>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x38(%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  -0x38(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x8(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
add    $0x40,%rsp
pop    %rbp
ret
jmp    1142 <norm_sample+0x12>

x86 assembly (clang, -O2):
<norm_sample>:
sub    $0x28,%rsp
movsd  %xmm1,0x18(%rsp)
movsd  %xmm0,0x20(%rsp)
xor    %eax,%eax
call   1030 <rand_float@plt>
add    %eax,%eax
add    $0xffffffff,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1030 <rand_float@plt>
add    %eax,%eax
add    $0xffffffff,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  %xmm0,%xmm0
movsd  0x8(%rsp),%xmm1
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  0xe7a(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1140 <norm_sample+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 @norm_sample(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
store double %0, double* %3
store double %1, double* %4
br label %9
9: ; preds = %2, %41
%10 = call i32 (...) @rand_float()
%11 = mul nsw i32 %10, 2
%12 = sub nsw i32 %11, 1
%13 = sitofp i32 %12 to double
store double %13, double* %5
%14 = call i32 (...) @rand_float()
%15 = mul nsw i32 %14, 2
%16 = sub nsw i32 %15, 1
%17 = sitofp i32 %16 to double
store double %17, double* %6
%18 = load double, double* %5
%19 = load double, double* %5
%20 = load double, double* %6
%21 = load double, double* %6
%22 = fmul double %20, %21
%23 = call double @llvm.fmuladd.f64(double %18, double %19, double %22)
store double %23, double* %7
%24 = load double, double* %7
%25 = fcmp olt double %24, 1.000000e+00
br i1 %25, label %26, label %41
26: ; preds = %9
%27 = load double, double* %5
%28 = load double, double* %7
%29 = call i32 @log(double %28)
%30 = mul nsw i32 -2, %29
%31 = sitofp i32 %30 to double
%32 = load double, double* %7
%33 = fdiv double %31, %32
%34 = fptosi double %33 to i32
%35 = call double @sqrt(i32 %34)
%36 = fmul double %27, %35
store double %36, double* %8
%37 = load double, double* %3
%38 = load double, double* %4
%39 = load double, double* %8
%40 = call double @llvm.fmuladd.f64(double %38, double %39, double %37)
ret double %40
41: ; preds = %9
br label %9
}

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