#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 RAND_MAX;
double log(double);
scalar_t__ rand();
double sqrt(double);
double rnorm1(void) {
  double v1, v2, s;
  do {
    v1 = 2.0 * ((double)rand() / RAND_MAX) - 1;
    v2 = 2.0 * ((double)rand() / RAND_MAX) - 1;
    s = v1 * v1 + v2 * v2;
  } while (s >= 1.0);
  if (s == 0.0)
    return 0.0;
  else
    return (v1 * sqrt(-2.0 * log(s) / s));
}


x86 assembly (clang, -O0):
<rnorm1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    $0x0,%al
call   1050 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2e9d(%rip),%rax
divsd  (%rax),%xmm0
addsd  %xmm0,%xmm0
movsd  0xea5(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    $0x0,%al
call   1050 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2e71(%rip),%rax
divsd  (%rax),%xmm0
addsd  %xmm0,%xmm0
movsd  0xe79(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm2
movsd  -0x18(%rbp),%xmm1
mulsd  -0x18(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  0xe4a(%rip),%xmm1
ucomisd %xmm1,%xmm0
jae    1138 <rnorm1+0x8>
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11ed <rnorm1+0xbd>
jp     11ed <rnorm1+0xbd>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    122b <rnorm1+0xfb>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1030 <log@plt>
movaps %xmm0,%xmm1
movsd  0xe04(%rip),%xmm0
mulsd  %xmm1,%xmm0
divsd  -0x20(%rbp),%xmm0
call   1040 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rnorm1>:
push   %rbx
sub    $0x10,%rsp
mov    0x2eac(%rip),%rbx
nopl   0x0(%rax)
xor    %eax,%eax
call   1050 <rand@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
divsd  (%rbx),%xmm1
addsd  %xmm1,%xmm1
movsd  0xea1(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
xor    %eax,%eax
call   1050 <rand@plt>
movsd  (%rsp),%xmm2
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  (%rbx),%xmm0
addsd  %xmm0,%xmm0
addsd  0xe74(%rip),%xmm0
mulsd  %xmm0,%xmm0
mulsd  %xmm2,%xmm2
addsd  %xmm0,%xmm2
ucomisd 0xe68(%rip),%xmm2
jae    1140 <rnorm1+0x10>
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm2
jne    11ae <rnorm1+0x7e>
jnp    11ed <rnorm1+0xbd>
movapd %xmm2,%xmm0
movsd  %xmm2,0x8(%rsp)
call   1030 <log@plt>
mulsd  0xe4b(%rip),%xmm0
divsd  0x8(%rsp),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11db <rnorm1+0xab>
sqrtsd %xmm0,%xmm0
jmp    11e0 <rnorm1+0xb0>
call   1040 <sqrt@plt>
movsd  (%rsp),%xmm1
mulsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x10,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
@RAND_MAX = global double 0.000000e+00
define double @rnorm1() {
br label %1
1: ; preds = %1, %0
%2 = tail call i64 (...) @rand()
%3 = sitofp i64 %2 to double
%4 = load double, double* @RAND_MAX
%5 = fdiv double %3, %4
%6 = tail call double @llvm.fmuladd.f64(double %5, double 2.000000e+00, double -1.000000e+00)
%7 = tail call i64 (...) @rand()
%8 = sitofp i64 %7 to double
%9 = load double, double* @RAND_MAX
%10 = fdiv double %8, %9
%11 = tail call double @llvm.fmuladd.f64(double %10, double 2.000000e+00, double -1.000000e+00)
%12 = fmul double %11, %11
%13 = tail call double @llvm.fmuladd.f64(double %6, double %6, double %12)
%14 = fcmp ult double %13, 1.000000e+00
br i1 %14, label %15, label %1
15: ; preds = %1
%16 = fcmp oeq double %13, 0.000000e+00
br i1 %16, label %23, label %17
17: ; preds = %15
%18 = tail call double @log(double %13)
%19 = fmul double %18, -2.000000e+00
%20 = fdiv double %19, %13
%21 = tail call double @sqrt(double %20)
%22 = fmul double %6, %21
br label %23
23: ; preds = %15, %17
%24 = phi double [ %22, %17 ], [ 0.000000e+00, %15 ]
ret double %24
}