#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 M_PI;
double cos(int);
int log(double);
double ran0(long *);
double sqrt(int);
double gauss0(long *idum) {
  double r1, r2, res1;
  r1 = ran0(idum);
  if (r1 == 0)
    r1 = 1e-9;
  r2 = ran0(idum);
  res1 = sqrt(-2. * log(r1)) * cos(2. * M_PI * r2);
  return (res1);
}


x86 assembly (clang, -O0):
<gauss0>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <ran0@plt>
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    117f <gauss0+0x3f>
jp     117f <gauss0+0x3f>
movsd  0xe86(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <ran0@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1050 <log@plt>
cvtsi2sd %eax,%xmm1
movsd  0xe6d(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1060 <sqrt@plt>
movsd  %xmm0,-0x28(%rbp)
mov    0x2e2c(%rip),%rax
cvtsi2sdl (%rax),%xmm1
movsd  0xe40(%rip),%xmm0
mulsd  %xmm1,%xmm0
mulsd  -0x18(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1040 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gauss0>:
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%rbx
call   1030 <ran0@plt>
xorpd  %xmm2,%xmm2
cmpeqsd %xmm0,%xmm2
movsd  0xea2(%rip),%xmm1
andpd  %xmm2,%xmm1
andnpd %xmm0,%xmm2
orpd   %xmm1,%xmm2
movapd %xmm2,(%rsp)
mov    %rbx,%rdi
call   1030 <ran0@plt>
movsd  %xmm0,0x18(%rsp)
movaps (%rsp),%xmm0
call   1050 <log@plt>
lea    (%rax,%rax,1),%edi
neg    %edi
call   1060 <sqrt@plt>
movsd  %xmm0,(%rsp)
mov    0x2e4c(%rip),%rax
xorps  %xmm0,%xmm0
cvtsi2sdl (%rax),%xmm0
addsd  %xmm0,%xmm0
mulsd  0x18(%rsp),%xmm0
cvttsd2si %xmm0,%edi
call   1040 <cos@plt>
mulsd  (%rsp),%xmm0
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@M_PI = global i32 0
define double @gauss0(i64* %0) {
%2 = alloca i64*
%3 = alloca double
%4 = alloca double
%5 = alloca double
store i64* %0, i64** %2
%6 = load i64*, i64** %2
%7 = call double @ran0(i64* %6)
store double %7, double* %3
%8 = load double, double* %3
%9 = fcmp oeq double %8, 0.000000e+00
br i1 %9, label %10, label %11
10: ; preds = %1
store double 1.000000e-09, double* %3
br label %11
11: ; preds = %10, %1
%12 = load i64*, i64** %2
%13 = call double @ran0(i64* %12)
store double %13, double* %4
%14 = load double, double* %3
%15 = call i32 @log(double %14)
%16 = sitofp i32 %15 to double
%17 = fmul double -2.000000e+00, %16
%18 = fptosi double %17 to i32
%19 = call double @sqrt(i32 %18)
%20 = load i32, i32* @M_PI
%21 = sitofp i32 %20 to double
%22 = fmul double 2.000000e+00, %21
%23 = load double, double* %4
%24 = fmul double %22, %23
%25 = fptosi double %24 to i32
%26 = call double @cos(i32 %25)
%27 = fmul double %19, %26
store double %27, double* %5
%28 = load double, double* %5
ret double %28
}

LLVM IR (-O2):
@M_PI = global i32 0
define double @gauss0(i64* %0) {
%2 = tail call double @ran0(i64* %0)
%3 = fcmp oeq double %2, 0.000000e+00
%4 = select i1 %3, double 1.000000e-09, double %2
%5 = tail call double @ran0(i64* %0)
%6 = tail call i32 @log(double %4)
%7 = mul i32 %6, -2
%8 = tail call double @sqrt(i32 %7)
%9 = load i32, i32* @M_PI
%10 = sitofp i32 %9 to double
%11 = fmul double %10, 2.000000e+00
%12 = fmul double %5, %11
%13 = fptosi double %12 to i32
%14 = tail call double @cos(i32 %13)
%15 = fmul double %8, %14
ret double %15
}