#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 */
int airDrandMT();
int log(double);
double sqrt(int);
void airNormalRand(double *z1, double *z2) {
  double w, x1, x2;
  do {
    x1 = 2 * airDrandMT() - 1;
    x2 = 2 * airDrandMT() - 1;
    w = x1 * x1 + x2 * x2;
  } while (w >= 1);
  w = sqrt((-2 * log(w)) / w);
  if (z1) {
    *z1 = x1 * w;
  }
  if (z2) {
    *z2 = x2 * w;
  }
  return;
}


x86 assembly (clang, -O0):
<airNormalRand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1030 <airDrandMT@plt>
shl    $0x1,%eax
sub    $0x1,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    $0x0,%al
call   1030 <airDrandMT@plt>
shl    $0x1,%eax
sub    $0x1,%eax
cvtsi2sd %eax,%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,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xe66(%rip),%xmm1
ucomisd %xmm1,%xmm0
jae    1140 <airNormalRand+0x10>
movsd  -0x18(%rbp),%xmm0
call   1040 <log@plt>
imul   $0xfffffffe,%eax,%eax
cvtsi2sd %eax,%xmm0
divsd  -0x18(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1050 <sqrt@plt>
movsd  %xmm0,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11e8 <airNormalRand+0xb8>
movsd  -0x20(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
cmpq   $0x0,-0x10(%rbp)
je     1205 <airNormalRand+0xd5>
movsd  -0x28(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<airNormalRand>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
nopl   (%rax)
xor    %eax,%eax
call   1030 <airDrandMT@plt>
add    %eax,%eax
add    $0xffffffff,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,(%rsp)
xor    %eax,%eax
call   1030 <airDrandMT@plt>
movsd  (%rsp),%xmm0
add    %eax,%eax
add    $0xffffffff,%eax
xorps  %xmm2,%xmm2
cvtsi2sd %eax,%xmm2
movapd %xmm2,%xmm3
mulsd  %xmm2,%xmm3
mulsd  %xmm0,%xmm0
addsd  %xmm3,%xmm0
ucomisd 0xe78(%rip),%xmm0
jae    1140 <airNormalRand+0x10>
movsd  %xmm2,0x10(%rsp)
movsd  %xmm0,0x8(%rsp)
call   1040 <log@plt>
add    %eax,%eax
neg    %eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  0x8(%rsp),%xmm0
cvttsd2si %xmm0,%edi
call   1050 <sqrt@plt>
test   %rbx,%rbx
je     11c7 <airNormalRand+0x97>
movsd  (%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,(%rbx)
test   %r14,%r14
movsd  0x10(%rsp),%xmm1
je     11db <airNormalRand+0xab>
mulsd  %xmm1,%xmm0
movsd  %xmm0,(%r14)
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @airNormalRand(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
br label %8
8: ; preds = %23, %2
%9 = call i32 (...) @airDrandMT()
%10 = mul nsw i32 2, %9
%11 = sub nsw i32 %10, 1
%12 = sitofp i32 %11 to double
store double %12, double* %6
%13 = call i32 (...) @airDrandMT()
%14 = mul nsw i32 2, %13
%15 = sub nsw i32 %14, 1
%16 = sitofp i32 %15 to double
store double %16, double* %7
%17 = load double, double* %6
%18 = load double, double* %6
%19 = load double, double* %7
%20 = load double, double* %7
%21 = fmul double %19, %20
%22 = call double @llvm.fmuladd.f64(double %17, double %18, double %21)
store double %22, double* %5
br label %23
23: ; preds = %8
%24 = load double, double* %5
%25 = fcmp oge double %24, 1.000000e+00
br i1 %25, label %8, label %26
26: ; preds = %23
%27 = load double, double* %5
%28 = call i32 @log(double %27)
%29 = mul nsw i32 -2, %28
%30 = sitofp i32 %29 to double
%31 = load double, double* %5
%32 = fdiv double %30, %31
%33 = fptosi double %32 to i32
%34 = call double @sqrt(i32 %33)
store double %34, double* %5
%35 = load double*, double** %3
%36 = icmp ne double* %35, null
br i1 %36, label %37, label %42
37: ; preds = %26
%38 = load double, double* %6
%39 = load double, double* %5
%40 = fmul double %38, %39
%41 = load double*, double** %3
store double %40, double* %41
br label %42
42: ; preds = %37, %26
%43 = load double*, double** %4
%44 = icmp ne double* %43, null
br i1 %44, label %45, label %50
45: ; preds = %42
%46 = load double, double* %7
%47 = load double, double* %5
%48 = fmul double %46, %47
%49 = load double*, double** %4
store double %48, double* %49
br label %50
50: ; preds = %45, %42
ret void
}

LLVM IR (-O2):
define void @airNormalRand(double* writeonly %0, double* writeonly %1) {
br label %3
3: ; preds = %3, %2
%4 = tail call i32 (...) @airDrandMT()
%5 = shl nsw i32 %4, 1
%6 = add nsw i32 %5, -1
%7 = sitofp i32 %6 to double
%8 = tail call i32 (...) @airDrandMT()
%9 = shl nsw i32 %8, 1
%10 = add nsw i32 %9, -1
%11 = sitofp i32 %10 to double
%12 = fmul double %11, %11
%13 = tail call double @llvm.fmuladd.f64(double %7, double %7, double %12)
%14 = fcmp ult double %13, 1.000000e+00
br i1 %14, label %15, label %3
15: ; preds = %3
%16 = tail call i32 @log(double %13)
%17 = mul nsw i32 %16, -2
%18 = sitofp i32 %17 to double
%19 = fdiv double %18, %13
%20 = fptosi double %19 to i32
%21 = tail call double @sqrt(i32 %20)
%22 = icmp eq double* %0, null
br i1 %22, label %25, label %23
23: ; preds = %15
%24 = fmul double %21, %7
store double %24, double* %0
br label %25
25: ; preds = %23, %15
%26 = icmp eq double* %1, null
br i1 %26, label %29, label %27
27: ; preds = %25
%28 = fmul double %21, %11
store double %28, double* %1
br label %29
29: ; preds = %27, %25
ret void
}