#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 */
scalar_t__ RAND_MAX;
double log(double);
scalar_t__ rand();
double sqrt(double);
double normaldist(double x0, double sigma) {
  double u, v, s;
  u = 2.0 * (((double)rand()) / (double)RAND_MAX) - 1.0;
  v = 2.0 * (((double)rand()) / (double)RAND_MAX) - 1.0;
  s = u * u + v * v;
  while (s >= u || s >= v) {
    u = 2.0 * (((double)rand()) / (double)RAND_MAX) - 1.0;
    v = 2.0 * (((double)rand()) / (double)RAND_MAX) - 1.0;
    s = u * u + v * v;
  }
  return x0 + sigma * u * sqrt(-2.0 * log(s) / s);
}


x86 assembly (clang, -O0):
<normaldist>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    $0x0,%al
call   1050 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2e93(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
addsd  %xmm0,%xmm0
movsd  0xe96(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    $0x0,%al
call   1050 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2e62(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
addsd  %xmm0,%xmm0
movsd  0xe65(%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
ucomisd -0x18(%rbp),%xmm0
mov    %al,-0x29(%rbp)
jae    11ea <normaldist+0xba>
movsd  -0x28(%rbp),%xmm0
ucomisd -0x20(%rbp),%xmm0
setae  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    11fa <normaldist+0xca>
jmp    1282 <normaldist+0x152>
mov    $0x0,%al
call   1050 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2ddb(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
addsd  %xmm0,%xmm0
movsd  0xdde(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    $0x0,%al
call   1050 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2daa(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
addsd  %xmm0,%xmm0
movsd  0xdad(%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)
jmp    11c5 <normaldist+0x95>
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x10(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1030 <log@plt>
movaps %xmm0,%xmm1
movsd  0xd58(%rip),%xmm0
mulsd  %xmm1,%xmm0
divsd  -0x28(%rbp),%xmm0
call   1040 <sqrt@plt>
movsd  -0x40(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x38(%rbp),%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<normaldist>:
push   %rbx
sub    $0x20,%rsp
movsd  %xmm1,0x10(%rsp)
movsd  %xmm0,0x18(%rsp)
xor    %eax,%eax
call   1050 <rand@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
mov    0x2e91(%rip),%rbx
xorps  %xmm0,%xmm0
cvtsi2sdq (%rbx),%xmm0
divsd  %xmm0,%xmm1
addsd  %xmm1,%xmm1
addsd  0xe91(%rip),%xmm1
jmp    11ab <normaldist+0x7b>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <rand@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sdq (%rbx),%xmm0
divsd  %xmm0,%xmm1
addsd  %xmm1,%xmm1
movsd  0xe59(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
xor    %eax,%eax
call   1050 <rand@plt>
xorps  %xmm2,%xmm2
cvtsi2sd %rax,%xmm2
xorps  %xmm1,%xmm1
cvtsi2sdq (%rbx),%xmm1
divsd  %xmm1,%xmm2
addsd  %xmm2,%xmm2
addsd  0xe29(%rip),%xmm2
movapd %xmm2,%xmm1
mulsd  %xmm2,%xmm1
movsd  (%rsp),%xmm3
movapd %xmm3,%xmm0
mulsd  %xmm3,%xmm0
addsd  %xmm1,%xmm0
ucomisd %xmm3,%xmm0
jae    1180 <normaldist+0x50>
movapd %xmm3,%xmm1
ucomisd %xmm2,%xmm0
jae    1180 <normaldist+0x50>
movsd  %xmm0,0x8(%rsp)
mulsd  0x10(%rsp),%xmm1
movsd  %xmm1,(%rsp)
call   1030 <log@plt>
mulsd  0xdea(%rip),%xmm0
divsd  0x8(%rsp),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     1234 <normaldist+0x104>
sqrtsd %xmm0,%xmm0
jmp    1239 <normaldist+0x109>
call   1040 <sqrt@plt>
movsd  (%rsp),%xmm1
mulsd  %xmm0,%xmm1
addsd  0x18(%rsp),%xmm1
movapd %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@RAND_MAX = global i64 0
define double @normaldist(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
%8 = call i64 (...) @rand()
%9 = sitofp i64 %8 to double
%10 = load i64, i64* @RAND_MAX
%11 = sitofp i64 %10 to double
%12 = fdiv double %9, %11
%13 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %12, double -1.000000e+00)
store double %13, double* %5
%14 = call i64 (...) @rand()
%15 = sitofp i64 %14 to double
%16 = load i64, i64* @RAND_MAX
%17 = sitofp i64 %16 to double
%18 = fdiv double %15, %17
%19 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %18, double -1.000000e+00)
store double %19, double* %6
%20 = load double, double* %5
%21 = load double, double* %5
%22 = load double, double* %6
%23 = load double, double* %6
%24 = fmul double %22, %23
%25 = call double @llvm.fmuladd.f64(double %20, double %21, double %24)
store double %25, double* %7
br label %26
26: ; preds = %36, %2
%27 = load double, double* %7
%28 = load double, double* %5
%29 = fcmp oge double %27, %28
br i1 %29, label %34, label %30
30: ; preds = %26
%31 = load double, double* %7
%32 = load double, double* %6
%33 = fcmp oge double %31, %32
br label %34
34: ; preds = %30, %26
%35 = phi i1 [ true, %26 ], [ %33, %30 ]
br i1 %35, label %36, label %55
36: ; preds = %34
%37 = call i64 (...) @rand()
%38 = sitofp i64 %37 to double
%39 = load i64, i64* @RAND_MAX
%40 = sitofp i64 %39 to double
%41 = fdiv double %38, %40
%42 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %41, double -1.000000e+00)
store double %42, double* %5
%43 = call i64 (...) @rand()
%44 = sitofp i64 %43 to double
%45 = load i64, i64* @RAND_MAX
%46 = sitofp i64 %45 to double
%47 = fdiv double %44, %46
%48 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %47, double -1.000000e+00)
store double %48, double* %6
%49 = load double, double* %5
%50 = load double, double* %5
%51 = load double, double* %6
%52 = load double, double* %6
%53 = fmul double %51, %52
%54 = call double @llvm.fmuladd.f64(double %49, double %50, double %53)
store double %54, double* %7
br label %26
55: ; preds = %34
%56 = load double, double* %3
%57 = load double, double* %4
%58 = load double, double* %5
%59 = fmul double %57, %58
%60 = load double, double* %7
%61 = call double @log(double %60)
%62 = fmul double -2.000000e+00, %61
%63 = load double, double* %7
%64 = fdiv double %62, %63
%65 = call double @sqrt(double %64)
%66 = call double @llvm.fmuladd.f64(double %59, double %65, double %56)
ret double %66
}

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