#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 lms_log(float);
scalar_t__ lms_rand();
float lms_sqrt(float);
float gaussian() {
  static int ready = 0;
  static float gstore;
  static float rconst1 = (float)(2.0 / 32768);
  static float rconst2 = (float)(32768 / 2.0);
  float v1, v2, r, fac;
  float gaus;
  if (ready == 0) {
    v1 = (float)lms_rand() - rconst2;
    v2 = (float)lms_rand() - rconst2;
    v1 *= rconst1;
    v2 *= rconst1;
    r = v1 * v1 + v2 * v2;
    while (r > 1.0f) {
      v1 = (float)lms_rand() - rconst2;
      v2 = (float)lms_rand() - rconst2;
      v1 *= rconst1;
      v2 *= rconst1;
      r = v1 * v1 + v2 * v2;
    }
    fac = lms_sqrt(-2.0f * lms_log(r) / r);
    gstore = v1 * fac;
    gaus = v2 * fac;
    ready = 1;
  } else {
    ready = 0;
    gaus = gstore;
  }
  return (gaus);
}


x86 assembly (clang, -O0):
<gaussian>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
cmpl   $0x0,0x2f05(%rip)
jne    12a6 <gaussian+0x176>
mov    $0x0,%al
call   1050 <lms_rand@plt>
cvtsi2ss %rax,%xmm0
subss  0x2ee3(%rip),%xmm0
movss  %xmm0,-0x4(%rbp)
mov    $0x0,%al
call   1050 <lms_rand@plt>
cvtsi2ss %rax,%xmm0
subss  0x2eca(%rip),%xmm0
movss  %xmm0,-0x8(%rbp)
movss  0x2eb9(%rip),%xmm0
mulss  -0x4(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
movss  0x2ea7(%rip),%xmm0
mulss  -0x8(%rbp),%xmm0
movss  %xmm0,-0x8(%rbp)
movss  -0x4(%rbp),%xmm0
movss  -0x4(%rbp),%xmm2
movss  -0x8(%rbp),%xmm1
mulss  -0x8(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
movss  0xe37(%rip),%xmm1
ucomiss %xmm1,%xmm0
jbe    124e <gaussian+0x11e>
mov    $0x0,%al
call   1050 <lms_rand@plt>
cvtsi2ss %rax,%xmm0
subss  0x2e56(%rip),%xmm0
movss  %xmm0,-0x4(%rbp)
mov    $0x0,%al
call   1050 <lms_rand@plt>
cvtsi2ss %rax,%xmm0
subss  0x2e3d(%rip),%xmm0
movss  %xmm0,-0x8(%rbp)
movss  0x2e2c(%rip),%xmm0
mulss  -0x4(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
movss  0x2e1a(%rip),%xmm0
mulss  -0x8(%rbp),%xmm0
movss  %xmm0,-0x8(%rbp)
movss  -0x4(%rbp),%xmm0
movss  -0x4(%rbp),%xmm2
movss  -0x8(%rbp),%xmm1
mulss  -0x8(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0xc(%rbp)
jmp    11bc <gaussian+0x8c>
movss  -0xc(%rbp),%xmm0
call   1040 <lms_log@plt>
movaps %xmm0,%xmm1
movss  0xda1(%rip),%xmm0
mulss  %xmm1,%xmm0
divss  -0xc(%rbp),%xmm0
call   1030 <lms_sqrt@plt>
movss  %xmm0,-0x10(%rbp)
movss  -0x4(%rbp),%xmm0
mulss  -0x10(%rbp),%xmm0
movss  %xmm0,0x2dc0(%rip)
movss  -0x8(%rbp),%xmm0
mulss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
movl   $0x1,0x2da3(%rip)
jmp    12bd <gaussian+0x18d>
movl   $0x0,0x2d94(%rip)
movss  0x2d90(%rip),%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x14(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gaussian>:
sub    $0x18,%rsp
cmpb   $0x0,0x2f01(%rip)
je     1151 <gaussian+0x21>
movb   $0x0,0x2ef8(%rip)
movss  0x2ef4(%rip),%xmm1
jmp    1265 <gaussian+0x135>
xor    %eax,%eax
call   1050 <lms_rand@plt>
cvtsi2ss %rax,%xmm0
addss  0xe9b(%rip),%xmm0
movss  %xmm0,0xc(%rsp)
xor    %eax,%eax
call   1050 <lms_rand@plt>
cvtsi2ss %rax,%xmm1
addss  0xe81(%rip),%xmm1
movss  0xe7d(%rip),%xmm0
movss  0xc(%rsp),%xmm3
mulss  %xmm0,%xmm3
mulss  %xmm0,%xmm1
movaps %xmm1,%xmm2
mulss  %xmm1,%xmm2
movss  %xmm3,0xc(%rsp)
movaps %xmm3,%xmm0
mulss  %xmm3,%xmm0
nopl   0x0(%rax)
addss  %xmm2,%xmm0
ucomiss 0xe4d(%rip),%xmm0
jbe    121e <gaussian+0xee>
xor    %eax,%eax
call   1050 <lms_rand@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
addss  0xe2c(%rip),%xmm0
movss  %xmm0,0xc(%rsp)
xor    %eax,%eax
call   1050 <lms_rand@plt>
movss  0xe1b(%rip),%xmm2
movss  0xe0f(%rip),%xmm0
xorps  %xmm1,%xmm1
cvtsi2ss %rax,%xmm1
addss  %xmm0,%xmm1
movss  0xc(%rsp),%xmm0
mulss  %xmm2,%xmm0
mulss  %xmm2,%xmm1
movaps %xmm1,%xmm2
mulss  %xmm1,%xmm2
movss  %xmm0,0xc(%rsp)
mulss  %xmm0,%xmm0
jmp    11b0 <gaussian+0x80>
movss  %xmm0,0x10(%rsp)
movss  %xmm1,0x14(%rsp)
call   1040 <lms_log@plt>
mulss  0xdd5(%rip),%xmm0
divss  0x10(%rsp),%xmm0
call   1030 <lms_sqrt@plt>
movss  0xc(%rsp),%xmm1
mulss  %xmm0,%xmm1
movss  %xmm1,0x2dec(%rip)
movss  0x14(%rsp),%xmm1
mulss  %xmm0,%xmm1
movb   $0x1,0x2dd7(%rip)
movaps %xmm1,%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
@gaussian.ready = internal global i32 0
@gaussian.gstore = internal global float 0.000000e+00
@gaussian.rconst1 = internal global float 0x3F10000000000000
@gaussian.rconst2 = internal global float 1.638400e+04
define float @gaussian() {
%1 = alloca float
%2 = alloca float
%3 = alloca float
%4 = alloca float
%5 = alloca float
%6 = load i32, i32* @gaussian.ready
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %66
8: ; preds = %0
%9 = call i64 (...) @lms_rand()
%10 = sitofp i64 %9 to float
%11 = load float, float* @gaussian.rconst2
%12 = fsub float %10, %11
store float %12, float* %1
%13 = call i64 (...) @lms_rand()
%14 = sitofp i64 %13 to float
%15 = load float, float* @gaussian.rconst2
%16 = fsub float %14, %15
store float %16, float* %2
%17 = load float, float* @gaussian.rconst1
%18 = load float, float* %1
%19 = fmul float %18, %17
store float %19, float* %1
%20 = load float, float* @gaussian.rconst1
%21 = load float, float* %2
%22 = fmul float %21, %20
store float %22, float* %2
%23 = load float, float* %1
%24 = load float, float* %1
%25 = load float, float* %2
%26 = load float, float* %2
%27 = fmul float %25, %26
%28 = call float @llvm.fmuladd.f32(float %23, float %24, float %27)
store float %28, float* %3
br label %29
29: ; preds = %32, %8
%30 = load float, float* %3
%31 = fcmp ogt float %30, 1.000000e+00
br i1 %31, label %32, label %53
32: ; preds = %29
%33 = call i64 (...) @lms_rand()
%34 = sitofp i64 %33 to float
%35 = load float, float* @gaussian.rconst2
%36 = fsub float %34, %35
store float %36, float* %1
%37 = call i64 (...) @lms_rand()
%38 = sitofp i64 %37 to float
%39 = load float, float* @gaussian.rconst2
%40 = fsub float %38, %39
store float %40, float* %2
%41 = load float, float* @gaussian.rconst1
%42 = load float, float* %1
%43 = fmul float %42, %41
store float %43, float* %1
%44 = load float, float* @gaussian.rconst1
%45 = load float, float* %2
%46 = fmul float %45, %44
store float %46, float* %2
%47 = load float, float* %1
%48 = load float, float* %1
%49 = load float, float* %2
%50 = load float, float* %2
%51 = fmul float %49, %50
%52 = call float @llvm.fmuladd.f32(float %47, float %48, float %51)
store float %52, float* %3
br label %29
53: ; preds = %29
%54 = load float, float* %3
%55 = call float @lms_log(float %54)
%56 = fmul float -2.000000e+00, %55
%57 = load float, float* %3
%58 = fdiv float %56, %57
%59 = call float @lms_sqrt(float %58)
store float %59, float* %4
%60 = load float, float* %1
%61 = load float, float* %4
%62 = fmul float %60, %61
store float %62, float* @gaussian.gstore
%63 = load float, float* %2
%64 = load float, float* %4
%65 = fmul float %63, %64
store float %65, float* %5
store i32 1, i32* @gaussian.ready
br label %68
66: ; preds = %0
store i32 0, i32* @gaussian.ready
%67 = load float, float* @gaussian.gstore
store float %67, float* %5
br label %68
68: ; preds = %66, %53
%69 = load float, float* %5
ret float %69
}

LLVM IR (-O2):
@gaussian.ready = internal unnamed_addr global i1 false
@gaussian.gstore = internal unnamed_addr global float 0.000000e+00
define float @gaussian() {
%1 = load i1, i1* @gaussian.ready
br i1 %1, label %36, label %2
2: ; preds = %0
%3 = tail call i64 (...) @lms_rand()
%4 = sitofp i64 %3 to float
%5 = fadd float %4, -1.638400e+04
%6 = tail call i64 (...) @lms_rand()
%7 = sitofp i64 %6 to float
%8 = fadd float %7, -1.638400e+04
%9 = fmul float %5, 0x3F10000000000000
%10 = fmul float %8, 0x3F10000000000000
%11 = fmul float %10, %10
%12 = tail call float @llvm.fmuladd.f32(float %9, float %9, float %11)
%13 = fcmp ogt float %12, 1.000000e+00
br i1 %13, label %14, label %26
14: ; preds = %2, %14
%15 = tail call i64 (...) @lms_rand()
%16 = sitofp i64 %15 to float
%17 = fadd float %16, -1.638400e+04
%18 = tail call i64 (...) @lms_rand()
%19 = sitofp i64 %18 to float
%20 = fadd float %19, -1.638400e+04
%21 = fmul float %17, 0x3F10000000000000
%22 = fmul float %20, 0x3F10000000000000
%23 = fmul float %22, %22
%24 = tail call float @llvm.fmuladd.f32(float %21, float %21, float %23)
%25 = fcmp ogt float %24, 1.000000e+00
br i1 %25, label %14, label %26
26: ; preds = %14, %2
%27 = phi float [ %10, %2 ], [ %22, %14 ]
%28 = phi float [ %12, %2 ], [ %24, %14 ]
%29 = phi float [ %9, %2 ], [ %21, %14 ]
%30 = tail call float @lms_log(float %28)
%31 = fmul float %30, -2.000000e+00
%32 = fdiv float %31, %28
%33 = tail call float @lms_sqrt(float %32)
%34 = fmul float %29, %33
store float %34, float* @gaussian.gstore
%35 = fmul float %27, %33
store i1 true, i1* @gaussian.ready
br label %38
36: ; preds = %0
store i1 false, i1* @gaussian.ready
%37 = load float, float* @gaussian.gstore
br label %38
38: ; preds = %36, %26
%39 = phi float [ %35, %26 ], [ %37, %36 ]
ret float %39
}