#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;
int log(double);
double rand();
double sqrt(int);
double pollar_rejection() {
  static unsigned short cont = 3;
  static double v1, v2, d, f;
  if (cont > 2) {
    do {
      v1 = (2 * (rand() / (1.0 * RAND_MAX)) - 1);
      v2 = (2 * (rand() / (1.0 * RAND_MAX)) - 1);
      d = v1 * v1 + v2 * v2;
    } while (d <= 0 || d >= 1);
    cont = 0;
    f = sqrt(-2 * log(d) / d);
  }
  return (++cont == 1 ? f * v1 : f * v2);
}


x86 assembly (clang, -O0):
<pollar_rejection>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movzwl 0x2ef9(%rip),%eax
cmp    $0x2,%eax
jle    125d <pollar_rejection+0x12d>
jmp    114d <pollar_rejection+0x1d>
mov    $0x0,%al
call   1050 <rand@plt>
movsd  0xeac(%rip),%xmm1
mov    0x2e85(%rip),%rax
mulsd  (%rax),%xmm1
divsd  %xmm1,%xmm0
addsd  %xmm0,%xmm0
movsd  0xe89(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,0x2ec5(%rip)
mov    $0x0,%al
call   1050 <rand@plt>
movsd  0xe76(%rip),%xmm1
mov    0x2e4f(%rip),%rax
mulsd  (%rax),%xmm1
divsd  %xmm1,%xmm0
addsd  %xmm0,%xmm0
movsd  0xe53(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,0x2e97(%rip)
movsd  0x2e87(%rip),%xmm0
movsd  0x2e7f(%rip),%xmm2
movsd  0x2e7f(%rip),%xmm1
mulsd  0x2e77(%rip),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,0x2e6f(%rip)
mov    $0x1,%al
xorps  %xmm0,%xmm0
ucomisd 0x2e62(%rip),%xmm0
mov    %al,-0x1(%rbp)
jae    1219 <pollar_rejection+0xe9>
movsd  0x2e51(%rip),%xmm0
movsd  0xdf9(%rip),%xmm1
ucomisd %xmm1,%xmm0
setae  %al
mov    %al,-0x1(%rbp)
mov    -0x1(%rbp),%al
test   $0x1,%al
jne    114d <pollar_rejection+0x1d>
movw   $0x0,0x2e0b(%rip)
movsd  0x2e23(%rip),%xmm0
call   1030 <log@plt>
imul   $0xfffffffe,%eax,%eax
cvtsi2sd %eax,%xmm0
divsd  0x2e0c(%rip),%xmm0
cvttsd2si %xmm0,%edi
call   1040 <sqrt@plt>
movsd  %xmm0,0x2e03(%rip)
mov    0x2dd4(%rip),%ax
add    $0x1,%ax
mov    %ax,0x2dc9(%rip)
movzwl %ax,%eax
cmp    $0x1,%eax
jne    1295 <pollar_rejection+0x165>
movsd  0x2ddd(%rip),%xmm0
mulsd  0x2dbd(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    12aa <pollar_rejection+0x17a>
movsd  0x2dc3(%rip),%xmm0
mulsd  0x2dab(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pollar_rejection>:
push   %rbx
movzwl 0x2f00(%rip),%eax
cmp    $0x3,%ax
jb     11ff <pollar_rejection+0xcf>
mov    0x2e9f(%rip),%rbx
nopl   0x0(%rax)
xor    %eax,%eax
call   1050 <rand@plt>
divsd  (%rbx),%xmm0
addsd  %xmm0,%xmm0
movsd  0xe99(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,0x2ed5(%rip)
xor    %eax,%eax
call   1050 <rand@plt>
movapd %xmm0,%xmm1
divsd  (%rbx),%xmm1
addsd  %xmm1,%xmm1
addsd  0xe72(%rip),%xmm1
movsd  %xmm1,0x2eba(%rip)
movsd  0x2eaa(%rip),%xmm0
mulsd  %xmm1,%xmm1
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,0x2ea6(%rip)
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jae    1150 <pollar_rejection+0x20>
ucomisd 0xe44(%rip),%xmm0
jae    1150 <pollar_rejection+0x20>
movw   $0x0,0x2e69(%rip)
call   1030 <log@plt>
add    %eax,%eax
neg    %eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  0x2e71(%rip),%xmm0
cvttsd2si %xmm0,%edi
call   1040 <sqrt@plt>
movsd  %xmm0,0x2e68(%rip)
movzwl 0x2e39(%rip),%eax
lea    0x1(%rax),%ecx
mov    %cx,0x2e2f(%rip)
test   %ax,%ax
movsd  0x2e4c(%rip),%xmm0
lea    0x2e2d(%rip),%rax
lea    0x2e2e(%rip),%rcx
cmove  %rax,%rcx
mulsd  (%rcx),%xmm0
pop    %rbx
ret

LLVM IR (-O0):
@pollar_rejection.cont = internal global i16 3
@pollar_rejection.v1 = internal global double 0.000000e+00
@pollar_rejection.v2 = internal global double 0.000000e+00
@pollar_rejection.d = internal global double 0.000000e+00
@pollar_rejection.f = internal global double 0.000000e+00
@RAND_MAX = global double 0.000000e+00
define double @pollar_rejection() {
%1 = load i16, i16* @pollar_rejection.cont
%2 = zext i16 %1 to i32
%3 = icmp sgt i32 %2, 2
br i1 %3, label %4, label %39
4: ; preds = %0
br label %5
5: ; preds = %28, %4
%6 = call double (...) @rand()
%7 = load double, double* @RAND_MAX
%8 = fmul double 1.000000e+00, %7
%9 = fdiv double %6, %8
%10 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %9, double -1.000000e+00)
store double %10, double* @pollar_rejection.v1
%11 = call double (...) @rand()
%12 = load double, double* @RAND_MAX
%13 = fmul double 1.000000e+00, %12
%14 = fdiv double %11, %13
%15 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %14, double -1.000000e+00)
store double %15, double* @pollar_rejection.v2
%16 = load double, double* @pollar_rejection.v1
%17 = load double, double* @pollar_rejection.v1
%18 = load double, double* @pollar_rejection.v2
%19 = load double, double* @pollar_rejection.v2
%20 = fmul double %18, %19
%21 = call double @llvm.fmuladd.f64(double %16, double %17, double %20)
store double %21, double* @pollar_rejection.d
br label %22
22: ; preds = %5
%23 = load double, double* @pollar_rejection.d
%24 = fcmp ole double %23, 0.000000e+00
br i1 %24, label %28, label %25
25: ; preds = %22
%26 = load double, double* @pollar_rejection.d
%27 = fcmp oge double %26, 1.000000e+00
br label %28
28: ; preds = %25, %22
%29 = phi i1 [ true, %22 ], [ %27, %25 ]
br i1 %29, label %5, label %30
30: ; preds = %28
store i16 0, i16* @pollar_rejection.cont
%31 = load double, double* @pollar_rejection.d
%32 = call i32 @log(double %31)
%33 = mul nsw i32 -2, %32
%34 = sitofp i32 %33 to double
%35 = load double, double* @pollar_rejection.d
%36 = fdiv double %34, %35
%37 = fptosi double %36 to i32
%38 = call double @sqrt(i32 %37)
store double %38, double* @pollar_rejection.f
br label %39
39: ; preds = %30, %0
%40 = load i16, i16* @pollar_rejection.cont
%41 = add i16 %40, 1
store i16 %41, i16* @pollar_rejection.cont
%42 = zext i16 %41 to i32
%43 = icmp eq i32 %42, 1
br i1 %43, label %44, label %48
44: ; preds = %39
%45 = load double, double* @pollar_rejection.f
%46 = load double, double* @pollar_rejection.v1
%47 = fmul double %45, %46
br label %52
48: ; preds = %39
%49 = load double, double* @pollar_rejection.f
%50 = load double, double* @pollar_rejection.v2
%51 = fmul double %49, %50
br label %52
52: ; preds = %48, %44
%53 = phi double [ %47, %44 ], [ %51, %48 ]
ret double %53
}

LLVM IR (-O2):
@pollar_rejection.cont = internal unnamed_addr global i16 3
@pollar_rejection.v1 = internal unnamed_addr global double 0.000000e+00
@pollar_rejection.v2 = internal unnamed_addr global double 0.000000e+00
@pollar_rejection.d = internal unnamed_addr global double 0.000000e+00
@pollar_rejection.f = internal unnamed_addr global double 0.000000e+00
@RAND_MAX = global double 0.000000e+00
define double @pollar_rejection() {
%1 = load i16, i16* @pollar_rejection.cont
%2 = icmp ugt i16 %1, 2
br i1 %2, label %3, label %27
3: ; preds = %0, %3
%4 = tail call double (...) @rand()
%5 = load double, double* @RAND_MAX
%6 = fdiv double %4, %5
%7 = tail call double @llvm.fmuladd.f64(double %6, double 2.000000e+00, double -1.000000e+00)
store double %7, double* @pollar_rejection.v1
%8 = tail call double (...) @rand()
%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)
store double %11, double* @pollar_rejection.v2
%12 = load double, double* @pollar_rejection.v1
%13 = fmul double %11, %11
%14 = tail call double @llvm.fmuladd.f64(double %12, double %12, double %13)
store double %14, double* @pollar_rejection.d
%15 = fcmp ole double %14, 0.000000e+00
%16 = fcmp oge double %14, 1.000000e+00
%17 = or i1 %15, %16
br i1 %17, label %3, label %18
18: ; preds = %3
store i16 0, i16* @pollar_rejection.cont
%19 = tail call i32 @log(double %14)
%20 = mul nsw i32 %19, -2
%21 = sitofp i32 %20 to double
%22 = load double, double* @pollar_rejection.d
%23 = fdiv double %21, %22
%24 = fptosi double %23 to i32
%25 = tail call double @sqrt(i32 %24)
store double %25, double* @pollar_rejection.f
%26 = load i16, i16* @pollar_rejection.cont
br label %27
27: ; preds = %18, %0
%28 = phi i16 [ %26, %18 ], [ %1, %0 ]
%29 = add i16 %28, 1
store i16 %29, i16* @pollar_rejection.cont
%30 = icmp eq i16 %28, 0
%31 = load double, double* @pollar_rejection.f
%32 = load double, double* @pollar_rejection.v1
%33 = load double, double* @pollar_rejection.v2
%34 = select i1 %30, double %32, double %33
%35 = fmul double %31, %34
ret double %35
}