#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_norm();
int sqrt(int);
void rand_marsaglia(double *x, double *y) {
  double u, v, r_squared;
start_all_over:
  u = rand_norm();
  v = rand_norm();
  r_squared = u * u + v * v;
  if (r_squared > 1)
    goto start_all_over;
  *x = 2 * u * sqrt(1 - r_squared);
  *y = 2 * v * sqrt(1 - r_squared);
}


x86 assembly (clang, -O0):
<rand_marsaglia>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1030 <rand_norm@plt>
movsd  %xmm0,-0x18(%rbp)
mov    $0x0,%al
call   1030 <rand_norm@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm2
movsd  -0x20(%rbp),%xmm1
mulsd  -0x20(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  0xe8a(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1185 <rand_marsaglia+0x65>
jmp    1130 <rand_marsaglia+0x10>
movsd  0xe7b(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  0xe61(%rip),%xmm0
subsd  -0x28(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1040 <sqrt@plt>
movsd  -0x38(%rbp),%xmm0
cvtsi2sd %eax,%xmm1
mulsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  0xe3e(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xe24(%rip),%xmm0
subsd  -0x28(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1040 <sqrt@plt>
movsd  -0x30(%rbp),%xmm0
cvtsi2sd %eax,%xmm1
mulsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rand_marsaglia>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
xchg   %ax,%ax
xor    %eax,%eax
call   1030 <rand_norm@plt>
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1030 <rand_norm@plt>
movapd %xmm0,%xmm1
mulsd  %xmm0,%xmm1
movsd  0x8(%rsp),%xmm2
movapd %xmm2,%xmm3
mulsd  %xmm2,%xmm2
addsd  %xmm1,%xmm2
ucomisd 0xe9a(%rip),%xmm2
ja     1130 <rand_marsaglia+0x10>
addsd  %xmm3,%xmm3
movsd  %xmm3,0x8(%rsp)
movsd  0xe86(%rip),%xmm1
subsd  %xmm2,%xmm1
cvttsd2si %xmm1,%ebp
mov    %ebp,%edi
movsd  %xmm0,(%rsp)
call   1040 <sqrt@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0x8(%rsp),%xmm0
movsd  %xmm0,(%rbx)
movsd  (%rsp),%xmm0
addsd  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
mov    %ebp,%edi
call   1040 <sqrt@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  (%rsp),%xmm0
movsd  %xmm0,(%r14)
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @rand_marsaglia(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 = %19, %2
%9 = call double (...) @rand_norm()
store double %9, double* %5
%10 = call double (...) @rand_norm()
store double %10, double* %6
%11 = load double, double* %5
%12 = load double, double* %5
%13 = load double, double* %6
%14 = load double, double* %6
%15 = fmul double %13, %14
%16 = call double @llvm.fmuladd.f64(double %11, double %12, double %15)
store double %16, double* %7
%17 = load double, double* %7
%18 = fcmp ogt double %17, 1.000000e+00
br i1 %18, label %19, label %20
19: ; preds = %8
br label %8
20: ; preds = %8
%21 = load double, double* %5
%22 = fmul double 2.000000e+00, %21
%23 = load double, double* %7
%24 = fsub double 1.000000e+00, %23
%25 = fptosi double %24 to i32
%26 = call i32 @sqrt(i32 %25)
%27 = sitofp i32 %26 to double
%28 = fmul double %22, %27
%29 = load double*, double** %3
store double %28, double* %29
%30 = load double, double* %6
%31 = fmul double 2.000000e+00, %30
%32 = load double, double* %7
%33 = fsub double 1.000000e+00, %32
%34 = fptosi double %33 to i32
%35 = call i32 @sqrt(i32 %34)
%36 = sitofp i32 %35 to double
%37 = fmul double %31, %36
%38 = load double*, double** %4
store double %37, double* %38
ret void
}

LLVM IR (-O2):
define void @rand_marsaglia(double* nocapture writeonly %0, double* nocapture writeonly %1) {
br label %3
3: ; preds = %3, %2
%4 = tail call double (...) @rand_norm()
%5 = tail call double (...) @rand_norm()
%6 = fmul double %5, %5
%7 = tail call double @llvm.fmuladd.f64(double %4, double %4, double %6)
%8 = fcmp ogt double %7, 1.000000e+00
br i1 %8, label %3, label %9
9: ; preds = %3
%10 = fmul double %4, 2.000000e+00
%11 = fsub double 1.000000e+00, %7
%12 = fptosi double %11 to i32
%13 = tail call i32 @sqrt(i32 %12)
%14 = sitofp i32 %13 to double
%15 = fmul double %10, %14
store double %15, double* %0
%16 = fmul double %5, 2.000000e+00
%17 = tail call i32 @sqrt(i32 %12)
%18 = sitofp i32 %17 to double
%19 = fmul double %16, %18
store double %19, double* %1
ret void
}