#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 grn(double m, double s) {
  static int iset = 0;
  static double fac, v1, v2;
  double sum;
  if (iset == 0) {
    do {
      v1 = 2.0 * (double)rand() / RAND_MAX - 1.0;
      v2 = 2.0 * (double)rand() / RAND_MAX - 1.0;
      sum = v1 * v1 + v2 * v2;
    } while (sum >= 1.0 || sum == 0.0);
    fac = sqrt(-2.0 * log(sum) / sum);
    iset = 1;
    return m + v1 * fac * s;
  } else {
    iset = 0;
    return m + v2 * fac * s;
  }
}


x86 assembly (clang, -O0):
<grn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
cmpl   $0x0,0x2ef7(%rip)
jne    128e <grn+0x15e>
jmp    1154 <grn+0x24>
mov    $0x0,%al
call   1050 <rand@plt>
cvtsi2sd %rax,%xmm1
movsd  0xea0(%rip),%xmm0
mulsd  %xmm1,%xmm0
mov    0x2e75(%rip),%rax
divsd  (%rax),%xmm0
movsd  0xe81(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,0x2ec5(%rip)
mov    $0x0,%al
call   1050 <rand@plt>
cvtsi2sd %rax,%xmm1
movsd  0xe69(%rip),%xmm0
mulsd  %xmm1,%xmm0
mov    0x2e3e(%rip),%rax
divsd  (%rax),%xmm0
movsd  0xe4a(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,0x2e96(%rip)
movsd  0x2e86(%rip),%xmm0
movsd  0x2e7e(%rip),%xmm2
movsd  0x2e7e(%rip),%xmm1
mulsd  0x2e76(%rip),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
mov    $0x1,%al
movsd  0xe02(%rip),%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x21(%rbp)
jae    1222 <grn+0xf2>
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
sete   %al
setnp  %cl
and    %cl,%al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1154 <grn+0x24>
movsd  -0x20(%rbp),%xmm0
call   1030 <log@plt>
movaps %xmm0,%xmm1
movsd  0xdce(%rip),%xmm0
mulsd  %xmm1,%xmm0
divsd  -0x20(%rbp),%xmm0
call   1040 <sqrt@plt>
movsd  %xmm0,0x2df0(%rip)
movl   $0x1,0x2dde(%rip)
movsd  -0x10(%rbp),%xmm1
movsd  0x2de1(%rip),%xmm0
mulsd  0x2dd1(%rip),%xmm0
movsd  -0x18(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12bf <grn+0x18f>
movl   $0x0,0x2da8(%rip)
movsd  -0x10(%rbp),%xmm1
movsd  0x2db3(%rip),%xmm0
mulsd  0x2d9b(%rip),%xmm0
movsd  -0x18(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<grn>:
push   %rbx
sub    $0x20,%rsp
movapd %xmm0,%xmm2
cmpb   $0x0,0x2f00(%rip)
je     115d <grn+0x2d>
movb   $0x0,0x2ef7(%rip)
lea    0x2ef8(%rip),%rax
movsd  0x2f00(%rip),%xmm0
jmp    123c <grn+0x10c>
movsd  %xmm1,0x8(%rsp)
movsd  %xmm2,0x10(%rsp)
mov    0x2e78(%rip),%rbx
xor    %eax,%eax
call   1050 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  %xmm0,%xmm0
divsd  (%rbx),%xmm0
movsd  0xe71(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,0x2eb5(%rip)
xor    %eax,%eax
call   1050 <rand@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
addsd  %xmm1,%xmm1
divsd  (%rbx),%xmm1
addsd  0xe46(%rip),%xmm1
movsd  %xmm1,0x2e96(%rip)
movsd  0x2e86(%rip),%xmm0
mulsd  %xmm1,%xmm1
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
ucomisd 0xe2a(%rip),%xmm0
jae    1170 <grn+0x40>
ucomisd 0xe30(%rip),%xmm0
jne    11ec <grn+0xbc>
jnp    1170 <grn+0x40>
movsd  %xmm0,0x18(%rsp)
call   1030 <log@plt>
mulsd  0xe11(%rip),%xmm0
divsd  0x18(%rsp),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     1215 <grn+0xe5>
sqrtsd %xmm0,%xmm0
jmp    121a <grn+0xea>
call   1040 <sqrt@plt>
movsd  0x10(%rsp),%xmm2
movsd  0x8(%rsp),%xmm1
movsd  %xmm0,0x2e1a(%rip)
movb   $0x1,0x2e0b(%rip)
lea    0x2e14(%rip),%rax
mulsd  (%rax),%xmm0
mulsd  %xmm1,%xmm0
addsd  %xmm2,%xmm0
add    $0x20,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
@grn.iset = internal unnamed_addr global i1 false
@grn.fac = internal unnamed_addr global double 0.000000e+00
@grn.v1 = internal unnamed_addr global double 0.000000e+00
@grn.v2 = internal unnamed_addr global double 0.000000e+00
@RAND_MAX = global double 0.000000e+00
define double @grn(double %0, double %1) {
%3 = load i1, i1* @grn.iset
br i1 %3, label %28, label %4
4: ; preds = %2, %4
%5 = tail call i64 (...) @rand()
%6 = sitofp i64 %5 to double
%7 = fmul double %6, 2.000000e+00
%8 = load double, double* @RAND_MAX
%9 = fdiv double %7, %8
%10 = fadd double %9, -1.000000e+00
store double %10, double* @grn.v1
%11 = tail call i64 (...) @rand()
%12 = sitofp i64 %11 to double
%13 = fmul double %12, 2.000000e+00
%14 = load double, double* @RAND_MAX
%15 = fdiv double %13, %14
%16 = fadd double %15, -1.000000e+00
store double %16, double* @grn.v2
%17 = load double, double* @grn.v1
%18 = fmul double %16, %16
%19 = tail call double @llvm.fmuladd.f64(double %17, double %17, double %18)
%20 = fcmp oge double %19, 1.000000e+00
%21 = fcmp oeq double %19, 0.000000e+00
%22 = or i1 %20, %21
br i1 %22, label %4, label %23
23: ; preds = %4
%24 = tail call double @log(double %19)
%25 = fmul double %24, -2.000000e+00
%26 = fdiv double %25, %19
%27 = tail call double @sqrt(double %26)
store double %27, double* @grn.fac
store i1 true, i1* @grn.iset
br label %30
28: ; preds = %2
store i1 false, i1* @grn.iset
%29 = load double, double* @grn.v2
br label %30
30: ; preds = %28, %23
%31 = phi double* [ @grn.fac, %28 ], [ @grn.v1, %23 ]
%32 = phi double [ %29, %28 ], [ %27, %23 ]
%33 = load double, double* %31
%34 = fmul double %32, %33
%35 = tail call double @llvm.fmuladd.f64(double %34, double %1, double %0)
ret double %35
}