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


x86 assembly (clang, -O0):
<gauss>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1030 <random_number@plt>
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1179 <gauss+0x39>
jp     1179 <gauss+0x39>
movsd  0xe8c(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
mov    $0x0,%al
call   1030 <random_number@plt>
movsd  %xmm0,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1050 <log@plt>
cvtsi2sd %eax,%xmm1
movsd  0xe75(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1060 <sqrt@plt>
movsd  %xmm0,-0x20(%rbp)
mov    0x2e34(%rip),%rax
cvtsi2sdl (%rax),%xmm1
movsd  0xe48(%rip),%xmm0
mulsd  %xmm1,%xmm0
mulsd  -0x10(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1040 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gauss>:
sub    $0x18,%rsp
xor    %eax,%eax
call   1030 <random_number@plt>
xorpd  %xmm2,%xmm2
cmpeqsd %xmm0,%xmm2
movsd  0xea4(%rip),%xmm1
andpd  %xmm2,%xmm1
andnpd %xmm0,%xmm2
orpd   %xmm1,%xmm2
movapd %xmm2,(%rsp)
xor    %eax,%eax
call   1030 <random_number@plt>
movsd  %xmm0,0x10(%rsp)
movaps (%rsp),%xmm0
call   1050 <log@plt>
lea    (%rax,%rax,1),%edi
neg    %edi
call   1060 <sqrt@plt>
movsd  %xmm0,(%rsp)
mov    0x2e4f(%rip),%rax
xorps  %xmm0,%xmm0
cvtsi2sdl (%rax),%xmm0
addsd  %xmm0,%xmm0
mulsd  0x10(%rsp),%xmm0
cvttsd2si %xmm0,%edi
call   1040 <cos@plt>
mulsd  (%rsp),%xmm0
add    $0x18,%rsp
ret

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

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