#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 */
scalar_t__ RAND_MAX;
double cos(double);
double fabs(double);
scalar_t__ floor(double);
double log(double);
int rand_r(unsigned int *);
double sin(double);
double sqrt(double);
int randomGaussian_r(int mean, int stddev, unsigned int *state) {
  double mu = 0.5 + (double)mean;
  double sigma = fabs((double)stddev);
  double f1 = sqrt(-2.0 * log((double)rand_r(state) / (double)RAND_MAX));
  double f2 = 2.0 * 3.14159265359 * (double)rand_r(state) / (double)RAND_MAX;
  if (rand_r(state) & (1 << 5))
    return (int)floor(mu + sigma * cos(f2) * f1);
  else
    return (int)floor(mu + sigma * sin(f2) * f1);
}


x86 assembly (clang, -O0):
<randomGaussian_r>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
cvtsi2sdl -0x8(%rbp),%xmm1
movsd  0xe91(%rip),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
cvtsi2sdl -0xc(%rbp),%xmm0
movaps 0xe8c(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <rand_r@plt>
cvtsi2sd %eax,%xmm0
mov    0x2e37(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
call   1060 <log@plt>
movaps %xmm0,%xmm1
movsd  0xe3e(%rip),%xmm0
mulsd  %xmm1,%xmm0
call   1070 <sqrt@plt>
movsd  %xmm0,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <rand_r@plt>
cvtsi2sd %eax,%xmm1
movsd  0xe13(%rip),%xmm0
mulsd  %xmm1,%xmm0
mov    0x2df0(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <rand_r@plt>
and    $0x20,%eax
cmp    $0x0,%eax
je     1264 <randomGaussian_r+0x104>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x38(%rbp),%xmm0
call   1050 <cos@plt>
movsd  -0x48(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x40(%rbp),%xmm0
mulsd  %xmm2,%xmm0
movsd  -0x30(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1080 <floor@plt>
mov    %eax,-0x4(%rbp)
jmp    12a8 <randomGaussian_r+0x148>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x38(%rbp),%xmm0
call   1040 <sin@plt>
movsd  -0x58(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x50(%rbp),%xmm0
mulsd  %xmm2,%xmm0
movsd  -0x30(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1080 <floor@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<randomGaussian_r>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%rbx
mov    %esi,%r15d
mov    %edi,%r14d
mov    %rdx,%rdi
call   1030 <rand_r@plt>
cvtsi2sd %eax,%xmm0
mov    0x2e62(%rip),%rbp
cvtsi2sdq 0x0(%rbp),%xmm1
divsd  %xmm1,%xmm0
call   1060 <log@plt>
mulsd  0xe63(%rip),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11ad <randomGaussian_r+0x4d>
sqrtsd %xmm0,%xmm0
jmp    11b2 <randomGaussian_r+0x52>
call   1070 <sqrt@plt>
movsd  %xmm0,0x10(%rsp)
mov    %rbx,%rdi
call   1030 <rand_r@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
mulsd  0xe39(%rip),%xmm1
xorps  %xmm0,%xmm0
cvtsi2sdq 0x0(%rbp),%xmm0
divsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
mov    %rbx,%rdi
call   1030 <rand_r@plt>
test   $0x20,%al
jne    11fb <randomGaussian_r+0x9b>
movsd  0x8(%rsp),%xmm0
call   1040 <sin@plt>
jmp    1206 <randomGaussian_r+0xa6>
movsd  0x8(%rsp),%xmm0
call   1050 <cos@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %r15d,%xmm1
andpd  0xe0a(%rip),%xmm1
cvtsi2sd %r14d,%xmm2
addsd  0xded(%rip),%xmm2
mulsd  %xmm0,%xmm1
mulsd  0x10(%rsp),%xmm1
addsd  %xmm2,%xmm1
movapd %xmm1,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <floor@plt>

LLVM IR (-O0):
@RAND_MAX = global i64 0
define i32 @randomGaussian_r(i32 %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32* %2, i32** %7
%12 = load i32, i32* %5
%13 = sitofp i32 %12 to double
%14 = fadd double 5.000000e-01, %13
store double %14, double* %8
%15 = load i32, i32* %6
%16 = sitofp i32 %15 to double
%17 = call double @llvm.fabs.f64(double %16)
store double %17, double* %9
%18 = load i32*, i32** %7
%19 = call i32 @rand_r(i32* %18)
%20 = sitofp i32 %19 to double
%21 = load i64, i64* @RAND_MAX
%22 = sitofp i64 %21 to double
%23 = fdiv double %20, %22
%24 = call double @log(double %23)
%25 = fmul double -2.000000e+00, %24
%26 = call double @sqrt(double %25)
store double %26, double* %10
%27 = load i32*, i32** %7
%28 = call i32 @rand_r(i32* %27)
%29 = sitofp i32 %28 to double
%30 = fmul double 0x401921FB54442EEA, %29
%31 = load i64, i64* @RAND_MAX
%32 = sitofp i64 %31 to double
%33 = fdiv double %30, %32
store double %33, double* %11
%34 = load i32*, i32** %7
%35 = call i32 @rand_r(i32* %34)
%36 = and i32 %35, 32
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %48
38: ; preds = %3
%39 = load double, double* %8
%40 = load double, double* %9
%41 = load double, double* %11
%42 = call double @cos(double %41)
%43 = fmul double %40, %42
%44 = load double, double* %10
%45 = call double @llvm.fmuladd.f64(double %43, double %44, double %39)
%46 = call i64 @floor(double %45)
%47 = trunc i64 %46 to i32
store i32 %47, i32* %4
br label %58
48: ; preds = %3
%49 = load double, double* %8
%50 = load double, double* %9
%51 = load double, double* %11
%52 = call double @sin(double %51)
%53 = fmul double %50, %52
%54 = load double, double* %10
%55 = call double @llvm.fmuladd.f64(double %53, double %54, double %49)
%56 = call i64 @floor(double %55)
%57 = trunc i64 %56 to i32
store i32 %57, i32* %4
br label %58
58: ; preds = %48, %38
%59 = load i32, i32* %4
ret i32 %59
}

LLVM IR (-O2):
@RAND_MAX = global i64 0
define i32 @randomGaussian_r(i32 %0, i32 %1, i32* %2) {
%4 = tail call i32 @rand_r(i32* %2)
%5 = sitofp i32 %4 to double
%6 = load i64, i64* @RAND_MAX
%7 = sitofp i64 %6 to double
%8 = fdiv double %5, %7
%9 = tail call double @log(double %8)
%10 = fmul double %9, -2.000000e+00
%11 = tail call double @sqrt(double %10)
%12 = tail call i32 @rand_r(i32* %2)
%13 = sitofp i32 %12 to double
%14 = fmul double %13, 0x401921FB54442EEA
%15 = load i64, i64* @RAND_MAX
%16 = sitofp i64 %15 to double
%17 = fdiv double %14, %16
%18 = tail call i32 @rand_r(i32* %2)
%19 = and i32 %18, 32
%20 = icmp eq i32 %19, 0
br i1 %20, label %23, label %21
21: ; preds = %3
%22 = tail call double @cos(double %17)
br label %25
23: ; preds = %3
%24 = tail call double @sin(double %17)
br label %25
25: ; preds = %23, %21
%26 = phi double [ %24, %23 ], [ %22, %21 ]
%27 = sitofp i32 %1 to double
%28 = tail call double @llvm.fabs.f64(double %27)
%29 = sitofp i32 %0 to double
%30 = fadd double %29, 5.000000e-01
%31 = fmul double %28, %26
%32 = tail call double @llvm.fmuladd.f64(double %31, double %11, double %30)
%33 = tail call i64 @floor(double %32)
%34 = trunc i64 %33 to i32
ret i32 %34
}