#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 cos(int);
int drand();
int log(int);
double sqrt(int);
double rand_normal(double mean, double var) {
  double x;
  x = sqrt(var) * sqrt(-2 * log(drand())) *
          cos(2 * (3.141592653589793) * drand()) +
      mean;
  return x;
}


x86 assembly (clang, -O0):
<rand_normal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
cvttsd2si -0x10(%rbp),%edi
call   1060 <sqrt@plt>
movsd  %xmm0,-0x28(%rbp)
mov    $0x0,%al
call   1030 <drand@plt>
mov    %eax,%edi
call   1050 <log@plt>
imul   $0xfffffffe,%eax,%edi
call   1060 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    $0x0,%al
call   1030 <drand@plt>
cvtsi2sd %eax,%xmm1
movsd  0xe62(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1040 <cos@plt>
movaps %xmm0,%xmm2
movsd  -0x20(%rbp),%xmm0
movsd  -0x8(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rand_normal>:
sub    $0x18,%rsp
movsd  %xmm0,0x10(%rsp)
cvttsd2si %xmm1,%edi
call   1060 <sqrt@plt>
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1030 <drand@plt>
mov    %eax,%edi
call   1050 <log@plt>
lea    (%rax,%rax,1),%edi
neg    %edi
call   1060 <sqrt@plt>
mulsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1030 <drand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0xe6d(%rip),%xmm0
cvttsd2si %xmm0,%edi
call   1040 <cos@plt>
mulsd  0x8(%rsp),%xmm0
addsd  0x10(%rsp),%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
define double @rand_normal(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double
store double %0, double* %3
store double %1, double* %4
%6 = load double, double* %4
%7 = fptosi double %6 to i32
%8 = call double @sqrt(i32 %7)
%9 = call i32 (...) @drand()
%10 = call i32 @log(i32 %9)
%11 = mul nsw i32 -2, %10
%12 = call double @sqrt(i32 %11)
%13 = fmul double %8, %12
%14 = call i32 (...) @drand()
%15 = sitofp i32 %14 to double
%16 = fmul double 0x401921FB54442D18, %15
%17 = fptosi double %16 to i32
%18 = call double @cos(i32 %17)
%19 = load double, double* %3
%20 = call double @llvm.fmuladd.f64(double %13, double %18, double %19)
store double %20, double* %5
%21 = load double, double* %5
ret double %21
}

LLVM IR (-O2):
define double @rand_normal(double %0, double %1) {
%3 = fptosi double %1 to i32
%4 = tail call double @sqrt(i32 %3)
%5 = tail call i32 (...) @drand()
%6 = tail call i32 @log(i32 %5)
%7 = mul nsw i32 %6, -2
%8 = tail call double @sqrt(i32 %7)
%9 = fmul double %4, %8
%10 = tail call i32 (...) @drand()
%11 = sitofp i32 %10 to double
%12 = fmul double %11, 0x401921FB54442D18
%13 = fptosi double %12 to i32
%14 = tail call double @cos(i32 %13)
%15 = tail call double @llvm.fmuladd.f64(double %9, double %14, double %0)
ret double %15
}