#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 */
float MP_Rand(long *);
int cos(double);
double log(double);
int sin(double);
int sqrt(double);
float MP_RandGauss(long *rand_seed) {
  float r1, r2;
  static float w1, w2;
  static int iset = 0;
  if (iset == 0) {
    r1 = MP_Rand(rand_seed);
    r2 = MP_Rand(rand_seed);
    w1 = (float)(sqrt(-2.0 * log((double)r1)) *
                 cos(2.0 * 3.14159265358979323846 * (double)r2));
    w2 = (float)(sqrt(-2.0 * log((double)r1)) *
                 sin(2.0 * 3.14159265358979323846 * (double)r2));
    iset = 1;
    return w1;
  } else {
    iset = 0;
    return w2;
  }
}


x86 assembly (clang, -O0):
<MP_RandGauss>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpl   $0x0,0x2ef1(%rip)
jne    1247 <MP_RandGauss+0xf7>
mov    -0x10(%rbp),%rdi
call   1030 <MP_Rand@plt>
movss  %xmm0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <MP_Rand@plt>
movss  %xmm0,-0x18(%rbp)
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
call   1060 <log@plt>
movaps %xmm0,%xmm1
movsd  0xe6a(%rip),%xmm0
mulsd  %xmm1,%xmm0
call   1070 <sqrt@plt>
mov    %eax,-0x20(%rbp)
movss  -0x18(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xe45(%rip),%xmm0
mulsd  %xmm1,%xmm0
call   1050 <cos@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
imul   %ecx,%eax
cvtsi2ss %eax,%xmm0
movss  %xmm0,0x2e74(%rip)
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
call   1060 <log@plt>
movaps %xmm0,%xmm1
movsd  0xe17(%rip),%xmm0
mulsd  %xmm1,%xmm0
call   1070 <sqrt@plt>
mov    %eax,-0x1c(%rbp)
movss  -0x18(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xdf2(%rip),%xmm0
mulsd  %xmm1,%xmm0
call   1040 <sin@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
imul   %ecx,%eax
cvtsi2ss %eax,%xmm0
movss  %xmm0,0x2e25(%rip)
movl   $0x1,0x2e1f(%rip)
movss  0x2e0f(%rip),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    125e <MP_RandGauss+0x10e>
movl   $0x0,0x2e03(%rip)
movss  0x2df7(%rip),%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MP_RandGauss>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2ef5(%rip),%bpl
test   %bpl,%bpl
je     1170 <MP_RandGauss+0x20>
lea    0x2ee5(%rip),%rbx
jmp    121b <MP_RandGauss+0xcb>
mov    %rdi,%rbx
call   1030 <MP_Rand@plt>
movss  %xmm0,0x8(%rsp)
mov    %rbx,%rdi
call   1030 <MP_Rand@plt>
movss  %xmm0,(%rsp)
movss  0x8(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
call   1060 <log@plt>
mulsd  0xe58(%rip),%xmm0
call   1070 <sqrt@plt>
mov    %eax,%ebx
movss  (%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
mulsd  0xe48(%rip),%xmm0
movsd  %xmm0,(%rsp)
call   1050 <cos@plt>
imul   %ebx,%eax
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
movss  %xmm0,0x2e70(%rip)
lea    0x2e69(%rip),%rbx
movsd  0x8(%rsp),%xmm0
call   1060 <log@plt>
mulsd  0xe0a(%rip),%xmm0
call   1070 <sqrt@plt>
mov    %eax,%r14d
movsd  (%rsp),%xmm0
call   1040 <sin@plt>
imul   %r14d,%eax
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
movss  %xmm0,0x2e35(%rip)
xor    $0x1,%bpl
mov    %bpl,0x2e2e(%rip)
movss  (%rbx),%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@MP_RandGauss.w1 = internal global float 0.000000e+00
@MP_RandGauss.w2 = internal global float 0.000000e+00
@MP_RandGauss.iset = internal global i32 0
define float @MP_RandGauss(i64* %0) {
%2 = alloca float
%3 = alloca i64*
%4 = alloca float
%5 = alloca float
store i64* %0, i64** %3
%6 = load i32, i32* @MP_RandGauss.iset
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %36
8: ; preds = %1
%9 = load i64*, i64** %3
%10 = call float @MP_Rand(i64* %9)
store float %10, float* %4
%11 = load i64*, i64** %3
%12 = call float @MP_Rand(i64* %11)
store float %12, float* %5
%13 = load float, float* %4
%14 = fpext float %13 to double
%15 = call double @log(double %14)
%16 = fmul double -2.000000e+00, %15
%17 = call i32 @sqrt(double %16)
%18 = load float, float* %5
%19 = fpext float %18 to double
%20 = fmul double 0x401921FB54442D18, %19
%21 = call i32 @cos(double %20)
%22 = mul nsw i32 %17, %21
%23 = sitofp i32 %22 to float
store float %23, float* @MP_RandGauss.w1
%24 = load float, float* %4
%25 = fpext float %24 to double
%26 = call double @log(double %25)
%27 = fmul double -2.000000e+00, %26
%28 = call i32 @sqrt(double %27)
%29 = load float, float* %5
%30 = fpext float %29 to double
%31 = fmul double 0x401921FB54442D18, %30
%32 = call i32 @sin(double %31)
%33 = mul nsw i32 %28, %32
%34 = sitofp i32 %33 to float
store float %34, float* @MP_RandGauss.w2
store i32 1, i32* @MP_RandGauss.iset
%35 = load float, float* @MP_RandGauss.w1
store float %35, float* %2
br label %38
36: ; preds = %1
store i32 0, i32* @MP_RandGauss.iset
%37 = load float, float* @MP_RandGauss.w2
store float %37, float* %2
br label %38
38: ; preds = %36, %8
%39 = load float, float* %2
ret float %39
}

LLVM IR (-O2):
@MP_RandGauss.w1 = internal unnamed_addr global float 0.000000e+00
@MP_RandGauss.w2 = internal unnamed_addr global float 0.000000e+00
@MP_RandGauss.iset = internal unnamed_addr global i1 false
define float @MP_RandGauss(i64* %0) {
%2 = load i1, i1* @MP_RandGauss.iset
br i1 %2, label %21, label %3
3: ; preds = %1
%4 = tail call float @MP_Rand(i64* %0)
%5 = tail call float @MP_Rand(i64* %0)
%6 = fpext float %4 to double
%7 = tail call double @log(double %6)
%8 = fmul double %7, -2.000000e+00
%9 = tail call i32 @sqrt(double %8)
%10 = fpext float %5 to double
%11 = fmul double %10, 0x401921FB54442D18
%12 = tail call i32 @cos(double %11)
%13 = mul nsw i32 %12, %9
%14 = sitofp i32 %13 to float
store float %14, float* @MP_RandGauss.w1
%15 = tail call double @log(double %6)
%16 = fmul double %15, -2.000000e+00
%17 = tail call i32 @sqrt(double %16)
%18 = tail call i32 @sin(double %11)
%19 = mul nsw i32 %18, %17
%20 = sitofp i32 %19 to float
store float %20, float* @MP_RandGauss.w2
br label %21
21: ; preds = %1, %3
%22 = phi float* [ @MP_RandGauss.w1, %3 ], [ @MP_RandGauss.w2, %1 ]
%23 = xor i1 %2, true
store i1 %23, i1* @MP_RandGauss.iset
%24 = load float, float* %22
ret float %24
}