#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 drand48();
double log(double);
double sqrt(double);
double gaussdev() {
  double g1, g2, j, x1, x2, r_s;
  do {
    x1 = 2.0 * drand48() - 1.0;
    x2 = 2.0 * drand48() - 1.0;
    r_s = x1 * x1 + x2 * x2;
  } while (r_s >= 1.0 || r_s == 0.0);
  j = sqrt(-2.0 * log(r_s) / r_s);
  g1 = x1 * j;
  g2 = x2 * j;
  return g1;
}


x86 assembly (clang, -O0):
<gaussdev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    $0x0,%al
call   1050 <drand48@plt>
addsd  %xmm0,%xmm0
movsd  0xeb5(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    $0x0,%al
call   1050 <drand48@plt>
addsd  %xmm0,%xmm0
movsd  0xe99(%rip),%xmm1
addsd  %xmm1,%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,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
mov    $0x1,%al
movsd  0xe68(%rip),%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x31(%rbp)
jae    11c4 <gaussdev+0x94>
movsd  -0x30(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
sete   %al
setnp  %cl
and    %cl,%al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    1138 <gaussdev+0x8>
movsd  -0x30(%rbp),%xmm0
call   1030 <log@plt>
movaps %xmm0,%xmm1
movsd  0xe2c(%rip),%xmm0
mulsd  %xmm1,%xmm0
divsd  -0x30(%rbp),%xmm0
call   1040 <sqrt@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x20(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x28(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gaussdev>:
sub    $0x18,%rsp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   1050 <drand48@plt>
movapd %xmm0,%xmm1
addsd  %xmm0,%xmm1
movsd  0xea9(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
xor    %eax,%eax
call   1050 <drand48@plt>
addsd  %xmm0,%xmm0
addsd  0xe8c(%rip),%xmm0
mulsd  %xmm0,%xmm0
movsd  0x8(%rsp),%xmm1
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
ucomisd 0xe7a(%rip),%xmm1
jae    1140 <gaussdev+0x10>
ucomisd 0xe80(%rip),%xmm1
jne    119c <gaussdev+0x6c>
jnp    1140 <gaussdev+0x10>
movapd %xmm1,%xmm0
movsd  %xmm1,0x10(%rsp)
call   1030 <log@plt>
mulsd  0xe5d(%rip),%xmm0
divsd  0x10(%rsp),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11c9 <gaussdev+0x99>
sqrtsd %xmm0,%xmm0
jmp    11ce <gaussdev+0x9e>
call   1040 <sqrt@plt>
movsd  0x8(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x18,%rsp
ret

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

LLVM IR (-O2):
define double @gaussdev() {
br label %1
1: ; preds = %1, %0
%2 = tail call double (...) @drand48()
%3 = tail call double @llvm.fmuladd.f64(double %2, double 2.000000e+00, double -1.000000e+00)
%4 = tail call double (...) @drand48()
%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 oge double %7, 1.000000e+00
%9 = fcmp oeq double %7, 0.000000e+00
%10 = or i1 %8, %9
br i1 %10, label %1, label %11
11: ; preds = %1
%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
ret double %16
}