#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 snis_random_float();
float sqrt(float);
void random_point_on_sphere(float radius, float *x, float *y, float *z) {
  float x1, x2, s;
  do {
    x1 = snis_random_float();
    x2 = snis_random_float();
    s = x1 * x1 + x2 * x2;
  } while (s > 1.0f);
  *x = 2.0f * x1 * sqrt(1.0f - s);
  *y = 2.0f * x2 * sqrt(1.0f - s);
  *z = 1.0f - 2.0f * s;
  *x *= radius;
  *y *= radius;
  *z *= radius;
}


x86 assembly (clang, -O0):
<random_point_on_sphere>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movss  %xmm0,-0x4(%rbp)
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    $0x0,%al
call   1030 <snis_random_float@plt>
movss  %xmm0,-0x24(%rbp)
mov    $0x0,%al
call   1030 <snis_random_float@plt>
movss  %xmm0,-0x28(%rbp)
movss  -0x24(%rbp),%xmm0
movss  -0x24(%rbp),%xmm2
movss  -0x28(%rbp),%xmm1
mulss  -0x28(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x2c(%rbp)
movss  -0x2c(%rbp),%xmm0
movss  0xe81(%rip),%xmm1
ucomiss %xmm1,%xmm0
ja     1139 <random_point_on_sphere+0x19>
movss  0xe74(%rip),%xmm0
mulss  -0x24(%rbp),%xmm0
movss  %xmm0,-0x34(%rbp)
movss  0xe5e(%rip),%xmm0
subss  -0x2c(%rbp),%xmm0
call   1040 <sqrt@plt>
movaps %xmm0,%xmm1
movss  -0x34(%rbp),%xmm0
mulss  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movss  %xmm0,(%rax)
movss  0xe3c(%rip),%xmm0
mulss  -0x28(%rbp),%xmm0
movss  %xmm0,-0x30(%rbp)
movss  0xe26(%rip),%xmm0
subss  -0x2c(%rbp),%xmm0
call   1040 <sqrt@plt>
movaps %xmm0,%xmm1
movss  -0x30(%rbp),%xmm0
mulss  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movss  %xmm0,(%rax)
movss  -0x2c(%rbp),%xmm1
addss  %xmm1,%xmm1
movss  0xdf7(%rip),%xmm0
subss  %xmm1,%xmm0
mov    -0x20(%rbp),%rax
movss  %xmm0,(%rax)
movss  -0x4(%rbp),%xmm0
mov    -0x10(%rbp),%rax
mulss  (%rax),%xmm0
movss  %xmm0,(%rax)
movss  -0x4(%rbp),%xmm0
mov    -0x18(%rbp),%rax
mulss  (%rax),%xmm0
movss  %xmm0,(%rax)
movss  -0x4(%rbp),%xmm0
mov    -0x20(%rbp),%rax
mulss  (%rax),%xmm0
movss  %xmm0,(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random_point_on_sphere>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
movss  %xmm0,0x1c(%rsp)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <snis_random_float@plt>
movss  %xmm0,0xc(%rsp)
xor    %eax,%eax
call   1030 <snis_random_float@plt>
movss  0xc(%rsp),%xmm3
movaps %xmm0,%xmm2
mulss  %xmm0,%xmm0
movaps %xmm3,%xmm1
mulss  %xmm3,%xmm1
addss  %xmm0,%xmm1
movss  0xe8c(%rip),%xmm0
ucomiss %xmm0,%xmm1
ja     1140 <random_point_on_sphere+0x20>
addss  %xmm3,%xmm3
movaps %xmm0,%xmm5
subss  %xmm1,%xmm5
sqrtss %xmm5,%xmm4
xorps  %xmm6,%xmm6
ucomiss %xmm6,%xmm5
movaps %xmm4,%xmm0
movss  %xmm1,0x10(%rsp)
jae    11da <random_point_on_sphere+0xba>
movaps %xmm5,%xmm0
movss  %xmm2,0x8(%rsp)
movss  %xmm3,0xc(%rsp)
movss  %xmm4,0x18(%rsp)
movss  %xmm5,0x14(%rsp)
call   1040 <sqrt@plt>
xorps  %xmm6,%xmm6
movss  0x14(%rsp),%xmm5
movss  0x18(%rsp),%xmm4
movss  0xc(%rsp),%xmm3
movss  0x8(%rsp),%xmm2
movss  0x10(%rsp),%xmm1
mulss  %xmm0,%xmm3
movss  %xmm3,(%rbx)
addss  %xmm2,%xmm2
ucomiss %xmm6,%xmm5
jae    1208 <random_point_on_sphere+0xe8>
movaps %xmm5,%xmm0
movss  %xmm2,0x8(%rsp)
call   1040 <sqrt@plt>
movss  0x8(%rsp),%xmm2
movss  0x10(%rsp),%xmm1
movaps %xmm0,%xmm4
mulss  %xmm4,%xmm2
movss  %xmm2,(%r15)
addss  %xmm1,%xmm1
movss  0xde3(%rip),%xmm0
subss  %xmm1,%xmm0
movss  %xmm0,(%r14)
movss  (%rbx),%xmm0
movss  0x1c(%rsp),%xmm1
mulss  %xmm1,%xmm0
movss  %xmm0,(%rbx)
movss  (%r15),%xmm0
mulss  %xmm1,%xmm0
movss  %xmm0,(%r15)
mulss  (%r14),%xmm1
movss  %xmm1,(%r14)
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @random_point_on_sphere(float %0, float* %1, float* %2, float* %3) {
%5 = alloca float
%6 = alloca float*
%7 = alloca float*
%8 = alloca float*
%9 = alloca float
%10 = alloca float
%11 = alloca float
store float %0, float* %5
store float* %1, float** %6
store float* %2, float** %7
store float* %3, float** %8
br label %12
12: ; preds = %21, %4
%13 = call float (...) @snis_random_float()
store float %13, float* %9
%14 = call float (...) @snis_random_float()
store float %14, float* %10
%15 = load float, float* %9
%16 = load float, float* %9
%17 = load float, float* %10
%18 = load float, float* %10
%19 = fmul float %17, %18
%20 = call float @llvm.fmuladd.f32(float %15, float %16, float %19)
store float %20, float* %11
br label %21
21: ; preds = %12
%22 = load float, float* %11
%23 = fcmp ogt float %22, 1.000000e+00
br i1 %23, label %12, label %24
24: ; preds = %21
%25 = load float, float* %9
%26 = fmul float 2.000000e+00, %25
%27 = load float, float* %11
%28 = fsub float 1.000000e+00, %27
%29 = call float @sqrt(float %28)
%30 = fmul float %26, %29
%31 = load float*, float** %6
store float %30, float* %31
%32 = load float, float* %10
%33 = fmul float 2.000000e+00, %32
%34 = load float, float* %11
%35 = fsub float 1.000000e+00, %34
%36 = call float @sqrt(float %35)
%37 = fmul float %33, %36
%38 = load float*, float** %7
store float %37, float* %38
%39 = load float, float* %11
%40 = call float @llvm.fmuladd.f32(float -2.000000e+00, float %39, float 1.000000e+00)
%41 = load float*, float** %8
store float %40, float* %41
%42 = load float, float* %5
%43 = load float*, float** %6
%44 = load float, float* %43
%45 = fmul float %44, %42
store float %45, float* %43
%46 = load float, float* %5
%47 = load float*, float** %7
%48 = load float, float* %47
%49 = fmul float %48, %46
store float %49, float* %47
%50 = load float, float* %5
%51 = load float*, float** %8
%52 = load float, float* %51
%53 = fmul float %52, %50
store float %53, float* %51
ret void
}

LLVM IR (-O2):
define void @random_point_on_sphere(float %0, float* nocapture %1, float* nocapture %2, float* nocapture %3) {
br label %5
5: ; preds = %5, %4
%6 = tail call float (...) @snis_random_float()
%7 = tail call float (...) @snis_random_float()
%8 = fmul float %7, %7
%9 = tail call float @llvm.fmuladd.f32(float %6, float %6, float %8)
%10 = fcmp ogt float %9, 1.000000e+00
br i1 %10, label %5, label %11
11: ; preds = %5
%12 = fmul float %6, 2.000000e+00
%13 = fsub float 1.000000e+00, %9
%14 = tail call float @sqrt(float %13)
%15 = fmul float %12, %14
store float %15, float* %1
%16 = fmul float %7, 2.000000e+00
%17 = tail call float @sqrt(float %13)
%18 = fmul float %16, %17
store float %18, float* %2
%19 = tail call float @llvm.fmuladd.f32(float %9, float -2.000000e+00, float 1.000000e+00)
store float %19, float* %3
%20 = load float, float* %1
%21 = fmul float %20, %0
store float %21, float* %1
%22 = load float, float* %2
%23 = fmul float %22, %0
store float %23, float* %2
%24 = load float, float* %3
%25 = fmul float %24, %0
store float %25, float* %3
ret void
}