#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 rand_double();
double sqrt(double);
double _normal_01_peiji() {
  double v1, v2, s;
  double x1, x2;
  do {
    v1 = rand_double() * 2.0 - 1.0;
    v2 = rand_double() * 2.0 - 1.0;
    s = v1 * v1 + v2 * v2;
  } while (s >= 1.0);
  if (s == 0)
    x1 = x2 = 0.0;
  else {
    x1 = v1 * sqrt(-2.0 * log(s) / s);
    x2 = v2 * sqrt(-2.0 * log(s) / s);
  }
  return x1;
}


x86 assembly (clang, -O0):
<_normal_01_peiji>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    $0x0,%al
call   1030 <rand_double@plt>
addsd  %xmm0,%xmm0
movsd  0xeb5(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
mov    $0x0,%al
call   1030 <rand_double@plt>
addsd  %xmm0,%xmm0
movsd  0xe99(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  -0x8(%rbp),%xmm2
movsd  -0x10(%rbp),%xmm1
mulsd  -0x10(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xe6a(%rip),%xmm1
ucomisd %xmm1,%xmm0
jae    1138 <_normal_01_peiji+0x8>
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11d5 <_normal_01_peiji+0xa5>
jp     11d5 <_normal_01_peiji+0xa5>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    1251 <_normal_01_peiji+0x121>
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1040 <log@plt>
movaps %xmm0,%xmm1
movsd  0xe1c(%rip),%xmm0
mulsd  %xmm1,%xmm0
divsd  -0x18(%rbp),%xmm0
call   1050 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1040 <log@plt>
movaps %xmm0,%xmm1
movsd  0xdde(%rip),%xmm0
mulsd  %xmm1,%xmm0
divsd  -0x18(%rbp),%xmm0
call   1050 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_normal_01_peiji>:
sub    $0x18,%rsp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   1030 <rand_double@plt>
movapd %xmm0,%xmm1
addsd  %xmm0,%xmm1
movsd  0xea9(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
xor    %eax,%eax
call   1030 <rand_double@plt>
movsd  0x8(%rsp),%xmm2
addsd  %xmm0,%xmm0
addsd  0xe86(%rip),%xmm0
mulsd  %xmm0,%xmm0
mulsd  %xmm2,%xmm2
addsd  %xmm0,%xmm2
ucomisd 0xe7a(%rip),%xmm2
jae    1140 <_normal_01_peiji+0x10>
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm2
jne    11a1 <_normal_01_peiji+0x71>
jp     11a1 <_normal_01_peiji+0x71>
add    $0x18,%rsp
ret
movapd %xmm2,%xmm0
movsd  %xmm2,0x10(%rsp)
call   1040 <log@plt>
movsd  0x10(%rsp),%xmm2
mulsd  0xe52(%rip),%xmm0
divsd  %xmm2,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11d2 <_normal_01_peiji+0xa2>
sqrtsd %xmm0,%xmm0
jmp    11dd <_normal_01_peiji+0xad>
call   1050 <sqrt@plt>
movsd  0x10(%rsp),%xmm2
movsd  0x8(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movapd %xmm2,%xmm0
call   1040 <log@plt>
mulsd  0xe12(%rip),%xmm0
divsd  0x10(%rsp),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
ja     1219 <_normal_01_peiji+0xe9>
movsd  0x8(%rsp),%xmm0
add    $0x18,%rsp
ret
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jae    120e <_normal_01_peiji+0xde>
call   1050 <sqrt@plt>
jmp    120e <_normal_01_peiji+0xde>

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

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