#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 URan(long *);
double log(double);
double sqrt(double);
double Norm(double mu, double sd, long *z) {
  double v1, v2, r;
  do {
    v1 = 2.0 * URan(z) - 1.;
    v2 = 2.0 * URan(z) - 1.;
    r = v1 * v1 + v2 * v2;
  } while (r >= 1.0);
  return (mu + sd * (v1 * sqrt(-2.0 * log(r) / r)));
}


x86 assembly (clang, -O0):
<Norm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <URan@plt>
addsd  %xmm0,%xmm0
movsd  0xea5(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <URan@plt>
addsd  %xmm0,%xmm0
movsd  0xe87(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm2
movsd  -0x28(%rbp),%xmm1
mulsd  -0x28(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  0xe58(%rip),%xmm1
ucomisd %xmm1,%xmm0
jae    1146 <Norm+0x16>
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1030 <log@plt>
movaps %xmm0,%xmm1
movsd  0xe23(%rip),%xmm0
mulsd  %xmm1,%xmm0
divsd  -0x30(%rbp),%xmm0
call   1040 <sqrt@plt>
movsd  -0x48(%rbp),%xmm2
movsd  -0x40(%rbp),%xmm1
movaps %xmm0,%xmm3
movsd  -0x38(%rbp),%xmm0
mulsd  %xmm3,%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Norm>:
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   1050 <URan@plt>
movapd %xmm0,%xmm1
addsd  %xmm0,%xmm1
movsd  0xe98(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
mov    %rbx,%rdi
call   1050 <URan@plt>
movsd  (%rsp),%xmm2
addsd  %xmm0,%xmm0
addsd  0xe76(%rip),%xmm0
mulsd  %xmm0,%xmm0
mulsd  %xmm2,%xmm2
addsd  %xmm0,%xmm2
ucomisd 0xe6a(%rip),%xmm2
jae    1150 <Norm+0x20>
movapd %xmm2,%xmm0
movsd  %xmm2,0x8(%rsp)
call   1030 <log@plt>
mulsd  0xe59(%rip),%xmm0
divsd  0x8(%rsp),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11cd <Norm+0x9d>
sqrtsd %xmm0,%xmm0
jmp    11d2 <Norm+0xa2>
call   1040 <sqrt@plt>
movsd  (%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  0x18(%rsp),%xmm0
mulsd  %xmm1,%xmm0
addsd  0x10(%rsp),%xmm0
add    $0x20,%rsp
pop    %rbx
ret

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

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