#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 */
double fabs(float);
float snis_random_float();
float sqrt(float);
void random_dpoint_on_sphere(float radius, double *x, double *y, double *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 = fabs(1.0f - 2.0f * s);
  *x *= radius;
  *y *= radius;
  *z *= radius;
}


x86 assembly (clang, -O0):
<random_dpoint_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   1040 <snis_random_float@plt>
movss  %xmm0,-0x24(%rbp)
mov    $0x0,%al
call   1040 <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  0xe71(%rip),%xmm1
ucomiss %xmm1,%xmm0
ja     1149 <random_dpoint_on_sphere+0x19>
movss  0xe64(%rip),%xmm0
mulss  -0x24(%rbp),%xmm0
movss  %xmm0,-0x34(%rbp)
movss  0xe4e(%rip),%xmm0
subss  -0x2c(%rbp),%xmm0
call   1050 <sqrt@plt>
movaps %xmm0,%xmm1
movss  -0x34(%rbp),%xmm0
mulss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
movss  0xe28(%rip),%xmm0
mulss  -0x28(%rbp),%xmm0
movss  %xmm0,-0x30(%rbp)
movss  0xe12(%rip),%xmm0
subss  -0x2c(%rbp),%xmm0
call   1050 <sqrt@plt>
movaps %xmm0,%xmm1
movss  -0x30(%rbp),%xmm0
mulss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
movss  -0x2c(%rbp),%xmm1
addss  %xmm1,%xmm1
movss  0xddf(%rip),%xmm0
subss  %xmm1,%xmm0
call   1030 <fabs@plt>
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
movss  -0x4(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
mov    -0x10(%rbp),%rax
mulsd  (%rax),%xmm0
movsd  %xmm0,(%rax)
movss  -0x4(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
mov    -0x18(%rbp),%rax
mulsd  (%rax),%xmm0
movsd  %xmm0,(%rax)
movss  -0x4(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
mov    -0x20(%rbp),%rax
mulsd  (%rax),%xmm0
movsd  %xmm0,(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random_dpoint_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   1040 <snis_random_float@plt>
movss  %xmm0,0xc(%rsp)
xor    %eax,%eax
call   1040 <snis_random_float@plt>
movss  0xc(%rsp),%xmm3
movaps %xmm0,%xmm2
mulss  %xmm0,%xmm0
movaps %xmm3,%xmm1
mulss  %xmm3,%xmm1
addss  %xmm0,%xmm1
movss  0xe7c(%rip),%xmm0
ucomiss %xmm0,%xmm1
ja     1150 <random_dpoint_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    11ea <random_dpoint_on_sphere+0xba>
movaps %xmm5,%xmm0
movss  %xmm2,0x8(%rsp)
movss  %xmm3,0xc(%rsp)
movss  %xmm4,0x18(%rsp)
movss  %xmm5,0x14(%rsp)
call   1050 <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
xorps  %xmm0,%xmm0
cvtss2sd %xmm3,%xmm0
movsd  %xmm0,(%rbx)
addss  %xmm2,%xmm2
ucomiss %xmm6,%xmm5
jae    121f <random_dpoint_on_sphere+0xef>
movaps %xmm5,%xmm0
movss  %xmm2,0x8(%rsp)
call   1050 <sqrt@plt>
movss  0x8(%rsp),%xmm2
movss  0x10(%rsp),%xmm1
movaps %xmm0,%xmm4
mulss  %xmm4,%xmm2
xorps  %xmm0,%xmm0
cvtss2sd %xmm2,%xmm0
movsd  %xmm0,(%r15)
addss  %xmm1,%xmm1
movss  0xdc5(%rip),%xmm0
subss  %xmm1,%xmm0
call   1030 <fabs@plt>
movsd  %xmm0,(%r14)
movss  0x1c(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  (%rbx),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,(%rbx)
movsd  (%r15),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,(%r15)
mulsd  (%r14),%xmm0
movsd  %xmm0,(%r14)
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @random_dpoint_on_sphere(float %0, double* %1, double* %2, double* %3) {
%5 = alloca float
%6 = alloca double*
%7 = alloca double*
%8 = alloca double*
%9 = alloca float
%10 = alloca float
%11 = alloca float
store float %0, float* %5
store double* %1, double** %6
store double* %2, double** %7
store double* %3, double** %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 = fpext float %30 to double
%32 = load double*, double** %6
store double %31, double* %32
%33 = load float, float* %10
%34 = fmul float 2.000000e+00, %33
%35 = load float, float* %11
%36 = fsub float 1.000000e+00, %35
%37 = call float @sqrt(float %36)
%38 = fmul float %34, %37
%39 = fpext float %38 to double
%40 = load double*, double** %7
store double %39, double* %40
%41 = load float, float* %11
%42 = call float @llvm.fmuladd.f32(float -2.000000e+00, float %41, float 1.000000e+00)
%43 = call double @fabs(float %42)
%44 = load double*, double** %8
store double %43, double* %44
%45 = load float, float* %5
%46 = fpext float %45 to double
%47 = load double*, double** %6
%48 = load double, double* %47
%49 = fmul double %48, %46
store double %49, double* %47
%50 = load float, float* %5
%51 = fpext float %50 to double
%52 = load double*, double** %7
%53 = load double, double* %52
%54 = fmul double %53, %51
store double %54, double* %52
%55 = load float, float* %5
%56 = fpext float %55 to double
%57 = load double*, double** %8
%58 = load double, double* %57
%59 = fmul double %58, %56
store double %59, double* %57
ret void
}

LLVM IR (-O2):
define void @random_dpoint_on_sphere(float %0, double* nocapture %1, double* nocapture %2, double* 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
%16 = fpext float %15 to double
store double %16, double* %1
%17 = fmul float %7, 2.000000e+00
%18 = tail call float @sqrt(float %13)
%19 = fmul float %17, %18
%20 = fpext float %19 to double
store double %20, double* %2
%21 = tail call float @llvm.fmuladd.f32(float %9, float -2.000000e+00, float 1.000000e+00)
%22 = tail call double @fabs(float %21)
store double %22, double* %3
%23 = fpext float %0 to double
%24 = load double, double* %1
%25 = fmul double %24, %23
store double %25, double* %1
%26 = load double, double* %2
%27 = fmul double %26, %23
store double %27, double* %2
%28 = load double, double* %3
%29 = fmul double %28, %23
store double %29, double* %3
ret void
}