#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 log(double);
double myrandom(int);
double sqrt(double);
double random_normal(int sn, double m, double s) {
  double v1, v2, w, z1;
  static double z2 = 0.0;
  if (z2 != 0.0) {
    z1 = z2;
    z2 = 0.0;
  } else {
    do {
      v1 = 2.0 * myrandom(sn) - 1.0;
      v2 = 2.0 * myrandom(sn) - 1.0;
      w = v1 * v1 + v2 * v2;
    } while (w >= 1.0);
    w = sqrt((-2.0 * log(w)) / w);
    z1 = v1 * w;
    z2 = v2 * w;
  }
  return (m + z1 * s);
}


x86 assembly (clang, -O0):
<random_normal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  0x2ef3(%rip),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1165 <random_normal+0x35>
jp     1165 <random_normal+0x35>
jmp    1182 <random_normal+0x52>
movsd  0x2ed3(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,0x2ec3(%rip)
jmp    1242 <random_normal+0x112>
jmp    1187 <random_normal+0x57>
mov    -0x4(%rbp),%edi
call   1030 <myrandom@plt>
addsd  %xmm0,%xmm0
movsd  0xe65(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <myrandom@plt>
addsd  %xmm0,%xmm0
movsd  0xe48(%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  0xe19(%rip),%xmm1
ucomisd %xmm1,%xmm0
jae    1187 <random_normal+0x57>
movsd  -0x30(%rbp),%xmm0
call   1040 <log@plt>
movaps %xmm0,%xmm1
movsd  0xe02(%rip),%xmm0
mulsd  %xmm1,%xmm0
divsd  -0x30(%rbp),%xmm0
call   1050 <sqrt@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x28(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,0x2dfe(%rip)
movsd  -0x10(%rbp),%xmm1
movsd  -0x38(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random_normal>:
push   %rbx
sub    $0x30,%rsp
movapd %xmm0,%xmm2
movsd  0x2eff(%rip),%xmm0
xorpd  %xmm3,%xmm3
ucomisd %xmm3,%xmm0
jne    114d <random_normal+0x1d>
jnp    115a <random_normal+0x2a>
xorpd  %xmm3,%xmm3
unpcklpd %xmm0,%xmm3
jmp    1209 <random_normal+0xd9>
mov    %edi,%ebx
movsd  %xmm1,(%rsp)
movsd  %xmm2,0x8(%rsp)
nopw   0x0(%rax,%rax,1)
mov    %ebx,%edi
call   1030 <myrandom@plt>
movapd %xmm0,0x10(%rsp)
mov    %ebx,%edi
call   1030 <myrandom@plt>
unpcklpd 0x10(%rsp),%xmm0
addpd  %xmm0,%xmm0
addpd  0xe6a(%rip),%xmm0
movapd %xmm0,%xmm1
mulsd  %xmm0,%xmm1
movapd %xmm0,%xmm2
unpckhpd %xmm0,%xmm2
mulsd  %xmm2,%xmm2
addsd  %xmm1,%xmm2
ucomisd 0xe5a(%rip),%xmm2
jae    1170 <random_normal+0x40>
movapd %xmm0,0x10(%rsp)
movapd %xmm2,%xmm0
movapd %xmm2,0x20(%rsp)
call   1040 <log@plt>
mulsd  0xe43(%rip),%xmm0
divsd  0x20(%rsp),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11eb <random_normal+0xbb>
sqrtsd %xmm0,%xmm0
jmp    11f0 <random_normal+0xc0>
call   1050 <sqrt@plt>
movsd  0x8(%rsp),%xmm2
movsd  (%rsp),%xmm1
unpcklpd %xmm0,%xmm0
movapd 0x10(%rsp),%xmm3
mulpd  %xmm0,%xmm3
movlpd %xmm3,0x2e2f(%rip)
unpckhpd %xmm3,%xmm3
mulsd  %xmm1,%xmm3
addsd  %xmm2,%xmm3
movapd %xmm3,%xmm0
add    $0x30,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
@random_normal.z2 = internal unnamed_addr global double 0.000000e+00
define double @random_normal(i32 %0, double %1, double %2) {
%4 = load double, double* @random_normal.z2
%5 = fcmp une double %4, 0.000000e+00
%6 = insertelement <2 x double> <double 0.000000e+00, double poison>, double %4, i64 1
br i1 %5, label %26, label %7
7: ; preds = %3, %7
%8 = tail call double @myrandom(i32 %0)
%9 = tail call double @myrandom(i32 %0)
%10 = insertelement <2 x double> poison, double %9, i64 0
%11 = insertelement <2 x double> %10, double %8, i64 1
%12 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %11, <2 x double> <double 2.000000e+00, double 2.000000e+00>, <2 x double> <double -1.000000e+00, double -1.000000e+00>)
%13 = fmul <2 x double> %12, %12
%14 = extractelement <2 x double> %13, i64 0
%15 = extractelement <2 x double> %12, i64 1
%16 = tail call double @llvm.fmuladd.f64(double %15, double %15, double %14)
%17 = fcmp ult double %16, 1.000000e+00
br i1 %17, label %18, label %7
18: ; preds = %7
%19 = tail call double @log(double %16)
%20 = fmul double %19, -2.000000e+00
%21 = fdiv double %20, %16
%22 = tail call double @sqrt(double %21)
%23 = insertelement <2 x double> poison, double %22, i64 0
%24 = shufflevector <2 x double> %23, <2 x double> poison, <2 x i32> zeroinitializer
%25 = fmul <2 x double> %12, %24
br label %26
26: ; preds = %3, %18
%27 = phi <2 x double> [ %25, %18 ], [ %6, %3 ]
%28 = extractelement <2 x double> %27, i64 0
store double %28, double* @random_normal.z2
%29 = extractelement <2 x double> %27, i64 1
%30 = tail call double @llvm.fmuladd.f64(double %29, double %2, double %1)
ret double %30
}