#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;
double log(float);
float rand();
float sqrt(double);
float randf() {
  do {
    float x = rand() * 2.0f / RAND_MAX - 1.0f;
    float y = rand() * 2.0f / RAND_MAX - 1.0f;
    float r = x * x + y * y;
    if (r == 0.0f || r > 1.0f)
      continue;
    return x * sqrt(-2.0 * log(r) / r);
  } while (1);
}


x86 assembly (clang, -O0):
<randf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1050 <rand@plt>
movss  0xebd(%rip),%xmm1
mulss  %xmm1,%xmm0
mov    0x2e96(%rip),%rax
divss  (%rax),%xmm0
movss  0xea2(%rip),%xmm1
subss  %xmm1,%xmm0
movss  %xmm0,-0x8(%rbp)
mov    $0x0,%al
call   1050 <rand@plt>
movss  0xe8e(%rip),%xmm1
mulss  %xmm1,%xmm0
mov    0x2e67(%rip),%rax
divss  (%rax),%xmm0
movss  0xe73(%rip),%xmm1
subss  %xmm1,%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0x8(%rbp),%xmm0
movss  -0x8(%rbp),%xmm2
movss  -0xc(%rbp),%xmm1
mulss  -0xc(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    11d3 <randf+0xa3>
jp     11d3 <randf+0xa3>
jmp    11e9 <randf+0xb9>
movss  -0x10(%rbp),%xmm0
movss  0xe20(%rip),%xmm1
ucomiss %xmm1,%xmm0
jbe    11ee <randf+0xbe>
jmp    1239 <randf+0x109>
movss  -0x8(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x10(%rbp),%xmm0
call   1030 <log@plt>
movaps %xmm0,%xmm1
movsd  0xdfb(%rip),%xmm0
mulsd  %xmm1,%xmm0
movss  -0x10(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
divsd  %xmm1,%xmm0
call   1040 <sqrt@plt>
movaps %xmm0,%xmm1
movss  -0x14(%rbp),%xmm0
mulss  %xmm1,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1248 <randf+0x118>
mov    $0x1,%al
test   $0x1,%al
jne    1138 <randf+0x8>
jmp    1248 <randf+0x118>
movss  -0x4(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<randf>:
push   %rbx
sub    $0x10,%rsp
mov    0x2eac(%rip),%rbx
nopl   0x0(%rax)
xor    %eax,%eax
call   1050 <rand@plt>
movaps %xmm0,%xmm1
addss  %xmm0,%xmm1
divss  (%rbx),%xmm1
movss  0xea6(%rip),%xmm0
addss  %xmm0,%xmm1
movss  %xmm1,0x8(%rsp)
xor    %eax,%eax
call   1050 <rand@plt>
addss  %xmm0,%xmm0
divss  (%rbx),%xmm0
addss  0xe85(%rip),%xmm0
mulss  %xmm0,%xmm0
movss  0x8(%rsp),%xmm1
mulss  %xmm1,%xmm1
addss  %xmm0,%xmm1
ucomiss 0xe74(%rip),%xmm1
jne    1198 <randf+0x68>
jnp    1140 <randf+0x10>
ucomiss 0xe65(%rip),%xmm1
ja     1140 <randf+0x10>
movaps %xmm1,%xmm0
movss  %xmm1,0xc(%rsp)
call   1030 <log@plt>
mulsd  0xe59(%rip),%xmm0
movss  0xc(%rsp),%xmm1
cvtss2sd %xmm1,%xmm1
divsd  %xmm1,%xmm0
call   1040 <sqrt@plt>
mulss  0x8(%rsp),%xmm0
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@RAND_MAX = global float 0.000000e+00
define float @randf() {
%1 = alloca float
%2 = alloca float
%3 = alloca float
%4 = alloca float
br label %5
5: ; preds = %38, %0
%6 = call float (...) @rand()
%7 = fmul float %6, 2.000000e+00
%8 = load float, float* @RAND_MAX
%9 = fdiv float %7, %8
%10 = fsub float %9, 1.000000e+00
store float %10, float* %2
%11 = call float (...) @rand()
%12 = fmul float %11, 2.000000e+00
%13 = load float, float* @RAND_MAX
%14 = fdiv float %12, %13
%15 = fsub float %14, 1.000000e+00
store float %15, float* %3
%16 = load float, float* %2
%17 = load float, float* %2
%18 = load float, float* %3
%19 = load float, float* %3
%20 = fmul float %18, %19
%21 = call float @llvm.fmuladd.f32(float %16, float %17, float %20)
store float %21, float* %4
%22 = load float, float* %4
%23 = fcmp oeq float %22, 0.000000e+00
br i1 %23, label %27, label %24
24: ; preds = %5
%25 = load float, float* %4
%26 = fcmp ogt float %25, 1.000000e+00
br i1 %26, label %27, label %28
27: ; preds = %24, %5
br label %38
28: ; preds = %24
%29 = load float, float* %2
%30 = load float, float* %4
%31 = call double @log(float %30)
%32 = fmul double -2.000000e+00, %31
%33 = load float, float* %4
%34 = fpext float %33 to double
%35 = fdiv double %32, %34
%36 = call float @sqrt(double %35)
%37 = fmul float %29, %36
store float %37, float* %1
br label %39
38: ; preds = %27
br i1 true, label %5, label %39
39: ; preds = %28, %38
%40 = load float, float* %1
ret float %40
}

LLVM IR (-O2):
@RAND_MAX = global float 0.000000e+00
define float @randf() {
br label %1
1: ; preds = %1, %0
%2 = tail call float (...) @rand()
%3 = fmul float %2, 2.000000e+00
%4 = load float, float* @RAND_MAX
%5 = fdiv float %3, %4
%6 = fadd float %5, -1.000000e+00
%7 = tail call float (...) @rand()
%8 = fmul float %7, 2.000000e+00
%9 = load float, float* @RAND_MAX
%10 = fdiv float %8, %9
%11 = fadd float %10, -1.000000e+00
%12 = fmul float %11, %11
%13 = tail call float @llvm.fmuladd.f32(float %6, float %6, float %12)
%14 = fcmp oeq float %13, 0.000000e+00
%15 = fcmp ogt float %13, 1.000000e+00
%16 = or i1 %14, %15
br i1 %16, label %1, label %17
17: ; preds = %1
%18 = tail call double @log(float %13)
%19 = fmul double %18, -2.000000e+00
%20 = fpext float %13 to double
%21 = fdiv double %19, %20
%22 = tail call float @sqrt(double %21)
%23 = fmul float %6, %22
ret float %23
}