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


x86 assembly (clang, -O0):
<gaussienne>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    $0x0,%al
call   1030 <random_number@plt>
movsd  %xmm0,-0x10(%rbp)
mov    $0x0,%al
call   1030 <random_number@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1195 <gaussienne+0x45>
jp     1195 <gaussienne+0x45>
movsd  0xe70(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    $0x0,%al
call   1030 <random_number@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  0xe5f(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    1221 <gaussienne+0xd1>
movsd  -0x18(%rbp),%xmm0
call   1060 <log@plt>
cvtsi2sd %eax,%xmm1
movsd  0xe4e(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1070 <sqrt@plt>
movsd  %xmm0,-0x38(%rbp)
mov    0x2e05(%rip),%rax
cvtsi2sdl (%rax),%xmm1
movsd  0xe21(%rip),%xmm0
mulsd  %xmm1,%xmm0
mulsd  -0x20(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1050 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1289 <gaussienne+0x139>
movsd  -0x18(%rbp),%xmm0
call   1060 <log@plt>
cvtsi2sd %eax,%xmm1
movsd  0xde1(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1070 <sqrt@plt>
movsd  %xmm0,-0x40(%rbp)
mov    0x2d98(%rip),%rax
cvtsi2sdl (%rax),%xmm1
movsd  0xdb4(%rip),%xmm0
mulsd  %xmm1,%xmm0
mulsd  -0x20(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1040 <sin@plt>
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gaussienne>:
sub    $0x28,%rsp
xor    %eax,%eax
call   1030 <random_number@plt>
movsd  %xmm0,(%rsp)
xor    %eax,%eax
call   1030 <random_number@plt>
xorpd  %xmm2,%xmm2
cmpeqsd %xmm0,%xmm2
movsd  0xe88(%rip),%xmm1
andpd  %xmm2,%xmm1
andnpd %xmm0,%xmm2
orpd   %xmm1,%xmm2
movapd %xmm2,0x10(%rsp)
xor    %eax,%eax
call   1030 <random_number@plt>
movsd  %xmm0,0x8(%rsp)
movaps 0x10(%rsp),%xmm0
call   1060 <log@plt>
lea    (%rax,%rax,1),%edi
neg    %edi
call   1070 <sqrt@plt>
movsd  0xe55(%rip),%xmm1
ucomisd (%rsp),%xmm1
movsd  %xmm0,(%rsp)
mov    0x2e24(%rip),%rax
xorps  %xmm0,%xmm0
cvtsi2sdl (%rax),%xmm0
addsd  %xmm0,%xmm0
mulsd  0x8(%rsp),%xmm0
cvttsd2si %xmm0,%edi
jbe    11e2 <gaussienne+0x92>
call   1050 <cos@plt>
jmp    11e7 <gaussienne+0x97>
call   1040 <sin@plt>
movsd  (%rsp),%xmm1
mulsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x28,%rsp
ret

LLVM IR (-O0):
@M_PI = global i32 0
define double @gaussienne() {
%1 = alloca double
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = call double (...) @random_number()
store double %7, double* %2
%8 = call double (...) @random_number()
store double %8, double* %3
%9 = load double, double* %3
%10 = fcmp oeq double %9, 0.000000e+00
br i1 %10, label %11, label %12
11: ; preds = %0
store double 1.000000e-09, double* %3
br label %12
12: ; preds = %11, %0
%13 = call double (...) @random_number()
store double %13, double* %4
%14 = load double, double* %2
%15 = fcmp olt double %14, 5.000000e-01
br i1 %15, label %16, label %32
16: ; preds = %12
%17 = load double, double* %3
%18 = call i32 @log(double %17)
%19 = sitofp i32 %18 to double
%20 = fmul double -2.000000e+00, %19
%21 = fptosi double %20 to i32
%22 = call double @sqrt(i32 %21)
%23 = load i32, i32* @M_PI
%24 = sitofp i32 %23 to double
%25 = fmul double 2.000000e+00, %24
%26 = load double, double* %4
%27 = fmul double %25, %26
%28 = fptosi double %27 to i32
%29 = call double @cos(i32 %28)
%30 = fmul double %22, %29
store double %30, double* %5
%31 = load double, double* %5
store double %31, double* %1
br label %48
32: ; preds = %12
%33 = load double, double* %3
%34 = call i32 @log(double %33)
%35 = sitofp i32 %34 to double
%36 = fmul double -2.000000e+00, %35
%37 = fptosi double %36 to i32
%38 = call double @sqrt(i32 %37)
%39 = load i32, i32* @M_PI
%40 = sitofp i32 %39 to double
%41 = fmul double 2.000000e+00, %40
%42 = load double, double* %4
%43 = fmul double %41, %42
%44 = fptosi double %43 to i32
%45 = call double @sin(i32 %44)
%46 = fmul double %38, %45
store double %46, double* %6
%47 = load double, double* %6
store double %47, double* %1
br label %48
48: ; preds = %32, %16
%49 = load double, double* %1
ret double %49
}

LLVM IR (-O2):
@M_PI = global i32 0
define double @gaussienne() {
%1 = tail call double (...) @random_number()
%2 = tail call double (...) @random_number()
%3 = fcmp oeq double %2, 0.000000e+00
%4 = select i1 %3, double 1.000000e-09, double %2
%5 = tail call double (...) @random_number()
%6 = fcmp olt double %1, 5.000000e-01
%7 = tail call i32 @log(double %4)
%8 = mul i32 %7, -2
%9 = tail call double @sqrt(i32 %8)
%10 = load i32, i32* @M_PI
%11 = sitofp i32 %10 to double
%12 = fmul double %11, 2.000000e+00
%13 = fmul double %5, %12
%14 = fptosi double %13 to i32
br i1 %6, label %15, label %17
15: ; preds = %0
%16 = tail call double @cos(i32 %14)
br label %19
17: ; preds = %0
%18 = tail call double @sin(i32 %14)
br label %19
19: ; preds = %17, %15
%20 = phi double [ %18, %17 ], [ %16, %15 ]
%21 = fmul double %9, %20
ret double %21
}