#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 */
struct mtwist_state {
  int dummy;
};

/* Variables and functions */
float fabs(float);
float mtwist_float(struct mtwist_state *);
float sqrt(float);
void consistent_random_point_on_sphere(struct mtwist_state *mt, float radius,
                                       float *x, float *y, float *z) {
  float x1, x2, s;
  do {
    x1 = mtwist_float(mt);
    x2 = mtwist_float(mt);
    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):
<consistent_random_point_on_sphere>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movss  %xmm0,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <mtwist_float@plt>
movss  %xmm0,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <mtwist_float@plt>
movss  %xmm0,-0x30(%rbp)
movss  -0x2c(%rbp),%xmm0
movss  -0x2c(%rbp),%xmm2
movss  -0x30(%rbp),%xmm1
mulss  -0x30(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x34(%rbp)
movss  -0x34(%rbp),%xmm0
movss  0xe69(%rip),%xmm1
ucomiss %xmm1,%xmm0
ja     114d <consistent_random_point_on_sphere+0x1d>
movss  0xe5c(%rip),%xmm0
mulss  -0x2c(%rbp),%xmm0
movss  %xmm0,-0x3c(%rbp)
movss  0xe46(%rip),%xmm0
subss  -0x34(%rbp),%xmm0
call   1050 <sqrt@plt>
movaps %xmm0,%xmm1
movss  -0x3c(%rbp),%xmm0
mulss  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movss  %xmm0,(%rax)
movss  0xe24(%rip),%xmm0
mulss  -0x30(%rbp),%xmm0
movss  %xmm0,-0x38(%rbp)
movss  0xe0e(%rip),%xmm0
subss  -0x34(%rbp),%xmm0
call   1050 <sqrt@plt>
movaps %xmm0,%xmm1
movss  -0x38(%rbp),%xmm0
mulss  %xmm1,%xmm0
mov    -0x20(%rbp),%rax
movss  %xmm0,(%rax)
movss  -0x34(%rbp),%xmm1
addss  %xmm1,%xmm1
movss  0xddf(%rip),%xmm0
subss  %xmm1,%xmm0
call   1040 <fabs@plt>
mov    -0x28(%rbp),%rax
movss  %xmm0,(%rax)
movss  -0xc(%rbp),%xmm0
mov    -0x18(%rbp),%rax
mulss  (%rax),%xmm0
movss  %xmm0,(%rax)
movss  -0xc(%rbp),%xmm0
mov    -0x20(%rbp),%rax
mulss  (%rax),%xmm0
movss  %xmm0,(%rax)
movss  -0xc(%rbp),%xmm0
mov    -0x28(%rbp),%rax
mulss  (%rax),%xmm0
movss  %xmm0,(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<consistent_random_point_on_sphere>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
movss  %xmm0,0x14(%rsp)
mov    %rdi,%rbx
nopl   (%rax)
mov    %rbx,%rdi
call   1030 <mtwist_float@plt>
movss  %xmm0,0x4(%rsp)
mov    %rbx,%rdi
call   1030 <mtwist_float@plt>
movss  0x4(%rsp),%xmm3
movaps %xmm0,%xmm2
mulss  %xmm0,%xmm0
movaps %xmm3,%xmm1
mulss  %xmm3,%xmm1
addss  %xmm0,%xmm1
movss  0xe8a(%rip),%xmm0
ucomiss %xmm0,%xmm1
ja     1140 <consistent_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,0x8(%rsp)
jae    11da <consistent_random_point_on_sphere+0xba>
movaps %xmm5,%xmm0
movss  %xmm2,(%rsp)
movss  %xmm3,0x4(%rsp)
movss  %xmm4,0x10(%rsp)
movss  %xmm5,0xc(%rsp)
call   1040 <sqrt@plt>
xorps  %xmm6,%xmm6
movss  0xc(%rsp),%xmm5
movss  0x10(%rsp),%xmm4
movss  0x4(%rsp),%xmm3
movss  (%rsp),%xmm2
movss  0x8(%rsp),%xmm1
mulss  %xmm0,%xmm3
movss  %xmm3,(%r12)
addss  %xmm2,%xmm2
ucomiss %xmm6,%xmm5
jae    1208 <consistent_random_point_on_sphere+0xe8>
movaps %xmm5,%xmm0
movss  %xmm2,(%rsp)
call   1040 <sqrt@plt>
movss  (%rsp),%xmm2
movss  0x8(%rsp),%xmm1
movaps %xmm0,%xmm4
mulss  %xmm4,%xmm2
movss  %xmm2,(%r15)
addss  %xmm1,%xmm1
movss  0xde3(%rip),%xmm0
subss  %xmm1,%xmm0
andps  0xde8(%rip),%xmm0
movss  %xmm0,(%r14)
movss  (%r12),%xmm0
movss  0x14(%rsp),%xmm1
mulss  %xmm1,%xmm0
movss  %xmm0,(%r12)
movss  (%r15),%xmm0
mulss  %xmm1,%xmm0
movss  %xmm0,(%r15)
mulss  (%r14),%xmm1
movss  %xmm1,(%r14)
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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