#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 RAND_MAX;
int log(float);
float pow(float, int);
int /*<<< orphan*/ printf(char *, float, ...);
scalar_t__ rand();
float sqrt(int);
float normrand(float mu, float sigma) {
  float U1, U2, W, mult;
  static float X1, X2;
  static int call = 0;
  if (call == 1) {
    call = !call;
    printf("Using previously created normrnds %4.4f for this call.\n", X2);
    return (mu + sigma * (float)X2);
  }
  do {
    U1 = -1 + ((float)rand() / RAND_MAX) * 2;
    U2 = -1 + ((float)rand() / RAND_MAX) * 2;
    W = pow(U1, 2) + pow(U2, 2);
  } while (W >= 1 || W == 0);
  mult = sqrt((-2 * log(W)) / W);
  X1 = U1 * mult;
  X2 = U2 * mult;
  printf("Generated two normrnds: %4.4f and %4.4f\n", X1, X2);
  call = !call;
  return (mu + sigma * (float)X1);
}


x86 assembly (clang, -O0):
<normrand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movss  %xmm0,-0x8(%rbp)
movss  %xmm1,-0xc(%rbp)
cmpl   $0x1,0x2eeb(%rip)
jne    11c0 <normrand+0x70>
cmpl   $0x0,0x2ede(%rip)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,0x2ece(%rip)
movss  0x2ec2(%rip),%xmm0
lea    0xe73(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movss  -0x8(%rbp),%xmm1
movss  -0xc(%rbp),%xmm0
movss  0x2ea2(%rip),%xmm2
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1330 <normrand+0x1e0>
jmp    11c5 <normrand+0x75>
mov    $0x0,%al
call   1070 <rand@plt>
cvtsi2ss %rax,%xmm0
mov    0x2e10(%rip),%rax
divss  (%rax),%xmm0
addss  %xmm0,%xmm0
movss  0xe18(%rip),%xmm1
addss  %xmm1,%xmm0
movss  %xmm0,-0x10(%rbp)
mov    $0x0,%al
call   1070 <rand@plt>
cvtsi2ss %rax,%xmm0
mov    0x2de4(%rip),%rax
divss  (%rax),%xmm0
addss  %xmm0,%xmm0
movss  0xdec(%rip),%xmm1
addss  %xmm1,%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x10(%rbp),%xmm0
mov    $0x2,%edi
call   1050 <pow@plt>
movss  %xmm0,-0x20(%rbp)
movss  -0x14(%rbp),%xmm0
mov    $0x2,%edi
call   1050 <pow@plt>
movaps %xmm0,%xmm1
movss  -0x20(%rbp),%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x18(%rbp),%xmm0
mov    $0x1,%al
movss  0xda4(%rip),%xmm1
ucomiss %xmm1,%xmm0
mov    %al,-0x21(%rbp)
jae    1282 <normrand+0x132>
movss  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
sete   %al
setnp  %cl
and    %cl,%al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    11c5 <normrand+0x75>
movss  -0x18(%rbp),%xmm0
call   1040 <log@plt>
imul   $0xfffffffe,%eax,%eax
cvtsi2ss %eax,%xmm0
divss  -0x18(%rbp),%xmm0
cvttss2si %xmm0,%edi
call   1060 <sqrt@plt>
movss  %xmm0,-0x1c(%rbp)
movss  -0x10(%rbp),%xmm0
mulss  -0x1c(%rbp),%xmm0
movss  %xmm0,0x2d86(%rip)
movss  -0x14(%rbp),%xmm0
mulss  -0x1c(%rbp),%xmm0
movss  %xmm0,0x2d78(%rip)
movss  0x2d6c(%rip),%xmm0
movss  0x2d68(%rip),%xmm1
cvtss2sd %xmm1,%xmm1
lea    0xd4d(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
cmpl   $0x0,0x2d53(%rip)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,0x2d43(%rip)
movss  -0x8(%rbp),%xmm1
movss  -0xc(%rbp),%xmm0
movss  0x2d29(%rip),%xmm2
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<normrand>:
push   %rbx
sub    $0x20,%rsp
movss  %xmm1,0x1c(%rsp)
movss  %xmm0,0x18(%rsp)
cmpl   $0x1,0x2eec(%rip)
jne    1196 <normrand+0x46>
movl   $0x0,0x2ee0(%rip)
lea    0x2ed5(%rip),%rbx
movss  0x2ecd(%rip),%xmm0
lea    0xe82(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    12ad <normrand+0x15d>
mov    0x2e4b(%rip),%rbx
nopl   (%rax)
xor    %eax,%eax
call   1070 <rand@plt>
xorps  %xmm1,%xmm1
cvtsi2ss %rax,%xmm1
divss  (%rbx),%xmm1
addss  %xmm1,%xmm1
movss  0xe41(%rip),%xmm0
addss  %xmm0,%xmm1
movss  %xmm1,0x14(%rsp)
xor    %eax,%eax
call   1070 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
divss  (%rbx),%xmm0
addss  %xmm0,%xmm0
addss  0xe18(%rip),%xmm0
movss  %xmm0,0x10(%rsp)
movss  0x14(%rsp),%xmm0
mov    $0x2,%edi
call   1050 <pow@plt>
movss  %xmm0,0xc(%rsp)
movss  0x10(%rsp),%xmm0
mov    $0x2,%edi
call   1050 <pow@plt>
addss  0xc(%rsp),%xmm0
ucomiss 0xde3(%rip),%xmm0
jae    11a0 <normrand+0x50>
ucomiss 0xdda(%rip),%xmm0
jne    1236 <normrand+0xe6>
jnp    11a0 <normrand+0x50>
movss  %xmm0,0xc(%rsp)
call   1040 <log@plt>
add    %eax,%eax
neg    %eax
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
divss  0xc(%rsp),%xmm0
cvttss2si %xmm0,%edi
call   1060 <sqrt@plt>
movss  0x14(%rsp),%xmm2
mulss  %xmm0,%xmm2
movss  %xmm2,0x2ddf(%rip)
lea    0x2dd8(%rip),%rbx
movss  0x10(%rsp),%xmm1
mulss  %xmm0,%xmm1
movss  %xmm1,0x2dca(%rip)
cvtss2sd %xmm1,%xmm1
lea    0xdb3(%rip),%rdi
movaps %xmm2,%xmm0
mov    $0x2,%al
call   1030 <printf@plt>
xor    %eax,%eax
cmpl   $0x0,0x2db0(%rip)
sete   %al
mov    %eax,0x2da7(%rip)
movss  0x1c(%rsp),%xmm0
mulss  (%rbx),%xmm0
addss  0x18(%rsp),%xmm0
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@normrand.X1 = internal global float 0.000000e+00
@normrand.X2 = internal global float 0.000000e+00
@normrand.call = internal global i32 0
@.str = [56 x i8] c"Using previously created normrnds %4.4f for this call.\0A\00"
@RAND_MAX = global float 0.000000e+00
@.str.1 = [41 x i8] c"Generated two normrnds: %4.4f and %4.4f\0A\00"
define float @normrand(float %0, float %1) {
%3 = alloca float
%4 = alloca float
%5 = alloca float
%6 = alloca float
%7 = alloca float
%8 = alloca float
%9 = alloca float
store float %0, float* %4
store float %1, float* %5
%10 = load i32, i32* @normrand.call
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %23
12: ; preds = %2
%13 = load i32, i32* @normrand.call
%14 = icmp ne i32 %13, 0
%15 = xor i1 %14, true
%16 = zext i1 %15 to i32
store i32 %16, i32* @normrand.call
%17 = load float, float* @normrand.X2
%18 = call i32 (i8*, float, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), float %17)
%19 = load float, float* %4
%20 = load float, float* %5
%21 = load float, float* @normrand.X2
%22 = call float @llvm.fmuladd.f32(float %20, float %21, float %19)
store float %22, float* %3
br label %75
23: ; preds = %2
br label %24
24: ; preds = %46, %23
%25 = call i64 (...) @rand()
%26 = sitofp i64 %25 to float
%27 = load float, float* @RAND_MAX
%28 = fdiv float %26, %27
%29 = call float @llvm.fmuladd.f32(float %28, float 2.000000e+00, float -1.000000e+00)
store float %29, float* %6
%30 = call i64 (...) @rand()
%31 = sitofp i64 %30 to float
%32 = load float, float* @RAND_MAX
%33 = fdiv float %31, %32
%34 = call float @llvm.fmuladd.f32(float %33, float 2.000000e+00, float -1.000000e+00)
store float %34, float* %7
%35 = load float, float* %6
%36 = call float @pow(float %35, i32 2)
%37 = load float, float* %7
%38 = call float @pow(float %37, i32 2)
%39 = fadd float %36, %38
store float %39, float* %8
br label %40
40: ; preds = %24
%41 = load float, float* %8
%42 = fcmp oge float %41, 1.000000e+00
br i1 %42, label %46, label %43
43: ; preds = %40
%44 = load float, float* %8
%45 = fcmp oeq float %44, 0.000000e+00
br label %46
46: ; preds = %43, %40
%47 = phi i1 [ true, %40 ], [ %45, %43 ]
br i1 %47, label %24, label %48
48: ; preds = %46
%49 = load float, float* %8
%50 = call i32 @log(float %49)
%51 = mul nsw i32 -2, %50
%52 = sitofp i32 %51 to float
%53 = load float, float* %8
%54 = fdiv float %52, %53
%55 = fptosi float %54 to i32
%56 = call float @sqrt(i32 %55)
store float %56, float* %9
%57 = load float, float* %6
%58 = load float, float* %9
%59 = fmul float %57, %58
store float %59, float* @normrand.X1
%60 = load float, float* %7
%61 = load float, float* %9
%62 = fmul float %60, %61
store float %62, float* @normrand.X2
%63 = load float, float* @normrand.X1
%64 = load float, float* @normrand.X2
%65 = fpext float %64 to double
%66 = call i32 (i8*, float, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), float %63, double %65)
%67 = load i32, i32* @normrand.call
%68 = icmp ne i32 %67, 0
%69 = xor i1 %68, true
%70 = zext i1 %69 to i32
store i32 %70, i32* @normrand.call
%71 = load float, float* %4
%72 = load float, float* %5
%73 = load float, float* @normrand.X1
%74 = call float @llvm.fmuladd.f32(float %72, float %73, float %71)
store float %74, float* %3
br label %75
75: ; preds = %48, %12
%76 = load float, float* %3
ret float %76
}

LLVM IR (-O2):
@normrand.X1 = internal unnamed_addr global float 0.000000e+00
@normrand.X2 = internal unnamed_addr global float 0.000000e+00
@normrand.call = internal unnamed_addr global i32 0
@.str = [56 x i8] c"Using previously created normrnds %4.4f for this call.\0A\00"
@RAND_MAX = global float 0.000000e+00
@.str.1 = [41 x i8] c"Generated two normrnds: %4.4f and %4.4f\0A\00"
define float @normrand(float %0, float %1) {
%3 = load i32, i32* @normrand.call
%4 = icmp eq i32 %3, 1
br i1 %4, label %5, label %8
5: ; preds = %2
store i32 0, i32* @normrand.call
%6 = load float, float* @normrand.X2
%7 = tail call i32 (i8*, float, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), float %6)
br label %39
8: ; preds = %2, %8
%9 = tail call i64 (...) @rand()
%10 = sitofp i64 %9 to float
%11 = load float, float* @RAND_MAX
%12 = fdiv float %10, %11
%13 = tail call float @llvm.fmuladd.f32(float %12, float 2.000000e+00, float -1.000000e+00)
%14 = tail call i64 (...) @rand()
%15 = sitofp i64 %14 to float
%16 = load float, float* @RAND_MAX
%17 = fdiv float %15, %16
%18 = tail call float @llvm.fmuladd.f32(float %17, float 2.000000e+00, float -1.000000e+00)
%19 = tail call float @pow(float %13, i32 2)
%20 = tail call float @pow(float %18, i32 2)
%21 = fadd float %19, %20
%22 = fcmp oge float %21, 1.000000e+00
%23 = fcmp oeq float %21, 0.000000e+00
%24 = or i1 %22, %23
br i1 %24, label %8, label %25
25: ; preds = %8
%26 = tail call i32 @log(float %21)
%27 = mul nsw i32 %26, -2
%28 = sitofp i32 %27 to float
%29 = fdiv float %28, %21
%30 = fptosi float %29 to i32
%31 = tail call float @sqrt(i32 %30)
%32 = fmul float %13, %31
store float %32, float* @normrand.X1
%33 = fmul float %18, %31
store float %33, float* @normrand.X2
%34 = fpext float %33 to double
%35 = tail call i32 (i8*, float, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), float %32, double %34)
%36 = load i32, i32* @normrand.call
%37 = icmp eq i32 %36, 0
%38 = zext i1 %37 to i32
store i32 %38, i32* @normrand.call
br label %39
39: ; preds = %25, %5
%40 = phi float* [ @normrand.X1, %25 ], [ @normrand.X2, %5 ]
%41 = load float, float* %40
%42 = tail call float @llvm.fmuladd.f32(float %1, float %41, float %0)
ret float %42
}