#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();
float 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)rand() - rconst2;
    v2 = (float)rand() - rconst2;
    v1 *= rconst1;
    v2 *= rconst1;
    r = v1 * v1 + v2 * v2;
    while (r > 1.0f) {
      v1 = (float)rand() - rconst2;
      v2 = (float)rand() - rconst2;
      v1 *= rconst1;
      v2 *= rconst1;
      r = v1 * v1 + v2 * v2;
    }
    fac = sqrt(-2.0f * 0.1);
    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,0x2f0d(%rip)
jne    1280 <gaussian+0x160>
mov    $0x0,%al
call   1040 <rand@plt>
cvtsi2ss %rax,%xmm0
subss  0x2eeb(%rip),%xmm0
movss  %xmm0,-0x4(%rbp)
mov    $0x0,%al
call   1040 <rand@plt>
cvtsi2ss %rax,%xmm0
subss  0x2ed2(%rip),%xmm0
movss  %xmm0,-0x8(%rbp)
movss  0x2ec1(%rip),%xmm0
mulss  -0x4(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
movss  0x2eaf(%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  0xe47(%rip),%xmm1
ucomiss %xmm1,%xmm0
jbe    123e <gaussian+0x11e>
mov    $0x0,%al
call   1040 <rand@plt>
cvtsi2ss %rax,%xmm0
subss  0x2e5e(%rip),%xmm0
movss  %xmm0,-0x4(%rbp)
mov    $0x0,%al
call   1040 <rand@plt>
cvtsi2ss %rax,%xmm0
subss  0x2e45(%rip),%xmm0
movss  %xmm0,-0x8(%rbp)
movss  0x2e34(%rip),%xmm0
mulss  -0x4(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
movss  0x2e22(%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    11ac <gaussian+0x8c>
movss  0xdbe(%rip),%xmm0
call   1030 <sqrt@plt>
movss  %xmm0,-0x10(%rbp)
movss  -0x4(%rbp),%xmm0
mulss  -0x10(%rbp),%xmm0
movss  %xmm0,0x2dde(%rip)
movss  -0x8(%rbp),%xmm0
mulss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
movl   $0x1,0x2dc1(%rip)
jmp    1297 <gaussian+0x177>
movl   $0x0,0x2db2(%rip)
movss  0x2dae(%rip),%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x14(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gaussian>:
push   %rax
cmpb   $0x0,0x2f0c(%rip)
je     113e <gaussian+0x1e>
movb   $0x0,0x2f03(%rip)
movss  0x2eff(%rip),%xmm2
jmp    1233 <gaussian+0x113>
xor    %eax,%eax
call   1040 <rand@plt>
cvtsi2ss %rax,%xmm0
addss  0xeae(%rip),%xmm0
movss  %xmm0,(%rsp)
xor    %eax,%eax
call   1040 <rand@plt>
cvtsi2ss %rax,%xmm2
addss  0xe95(%rip),%xmm2
movss  0xe91(%rip),%xmm0
movss  (%rsp),%xmm1
mulss  %xmm0,%xmm1
mulss  %xmm0,%xmm2
movaps %xmm2,%xmm0
mulss  %xmm2,%xmm0
movss  %xmm1,(%rsp)
mulss  %xmm1,%xmm1
addss  %xmm0,%xmm1
ucomiss 0xe6d(%rip),%xmm1
jbe    11fe <gaussian+0xde>
xor    %eax,%eax
call   1040 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
addss  0xe4c(%rip),%xmm0
movss  %xmm0,(%rsp)
xor    %eax,%eax
call   1040 <rand@plt>
movss  0xe3c(%rip),%xmm1
movss  0xe30(%rip),%xmm0
xorps  %xmm2,%xmm2
cvtsi2ss %rax,%xmm2
addss  %xmm0,%xmm2
movss  (%rsp),%xmm3
mulss  %xmm1,%xmm3
mulss  %xmm1,%xmm2
movaps %xmm2,%xmm0
mulss  %xmm2,%xmm0
movss  %xmm3,(%rsp)
movaps %xmm3,%xmm1
mulss  %xmm3,%xmm1
jmp    1190 <gaussian+0x70>
movss  %xmm2,0x4(%rsp)
movss  0xe00(%rip),%xmm0
call   1030 <sqrt@plt>
movss  0x4(%rsp),%xmm2
movss  (%rsp),%xmm1
mulss  %xmm0,%xmm1
movss  %xmm1,0x2e10(%rip)
mulss  %xmm0,%xmm2
movb   $0x1,0x2e01(%rip)
movaps %xmm2,%xmm0
pop    %rax
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 %61
8: ; preds = %0
%9 = call i64 (...) @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 (...) @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 (...) @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 (...) @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 = call float @sqrt(float 0xBFC99999A0000000)
store float %54, float* %4
%55 = load float, float* %1
%56 = load float, float* %4
%57 = fmul float %55, %56
store float %57, float* @gaussian.gstore
%58 = load float, float* %2
%59 = load float, float* %4
%60 = fmul float %58, %59
store float %60, float* %5
store i32 1, i32* @gaussian.ready
br label %63
61: ; preds = %0
store i32 0, i32* @gaussian.ready
%62 = load float, float* @gaussian.gstore
store float %62, float* %5
br label %63
63: ; preds = %61, %53
%64 = load float, float* %5
ret float %64
}

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 %32, label %2
2: ; preds = %0
%3 = tail call i64 (...) @rand()
%4 = sitofp i64 %3 to float
%5 = fadd float %4, -1.638400e+04
%6 = tail call i64 (...) @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 (...) @rand()
%16 = sitofp i64 %15 to float
%17 = fadd float %16, -1.638400e+04
%18 = tail call i64 (...) @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 [ %9, %2 ], [ %21, %14 ]
%29 = tail call float @sqrt(float 0xBFC99999A0000000)
%30 = fmul float %28, %29
store float %30, float* @gaussian.gstore
%31 = fmul float %27, %29
store i1 true, i1* @gaussian.ready
br label %34
32: ; preds = %0
store i1 false, i1* @gaussian.ready
%33 = load float, float* @gaussian.gstore
br label %34
34: ; preds = %32, %26
%35 = phi float [ %31, %26 ], [ %33, %32 ]
ret float %35
}