#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 cos(float);
float glmRandomNumberf(float, double);
float sin(float);
float sqrt(float);
void glmGenerateRandomVector3f(float v[3]) {
  float a, r;
  v[2] = glmRandomNumberf(-1.0f, 1.0f);
  a = glmRandomNumberf(0.0f, 6.283185307179586476925286766559);
  r = sqrt(1.0f - v[2] * v[2]);
  v[0] = r * cos(a);
  v[1] = r * sin(a);
}


x86 assembly (clang, -O0):
<glmGenerateRandomVector3f>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movss  0xeb0(%rip),%xmm0
movsd  0xeb4(%rip),%xmm1
call   1060 <glmRandomNumberf@plt>
mov    -0x8(%rbp),%rax
movss  %xmm0,0x8(%rax)
xorps  %xmm0,%xmm0
movsd  0xe93(%rip),%xmm1
call   1060 <glmRandomNumberf@plt>
movss  %xmm0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movss  0x8(%rax),%xmm0
mov    -0x8(%rbp),%rax
movss  0x8(%rax),%xmm1
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
mulss  %xmm1,%xmm0
movss  0xe56(%rip),%xmm1
addss  %xmm1,%xmm0
call   1050 <sqrt@plt>
movss  %xmm0,-0x10(%rbp)
movss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0xc(%rbp),%xmm0
call   1040 <cos@plt>
movaps %xmm0,%xmm1
movss  -0x18(%rbp),%xmm0
mulss  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,(%rax)
movss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0xc(%rbp),%xmm0
call   1030 <sin@plt>
movaps %xmm0,%xmm1
movss  -0x14(%rbp),%xmm0
mulss  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x4(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<glmGenerateRandomVector3f>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
movss  0xeb0(%rip),%xmm0
movsd  0xeb8(%rip),%xmm1
call   1060 <glmRandomNumberf@plt>
movss  %xmm0,0x8(%rbx)
movsd  0xeae(%rip),%xmm1
xorps  %xmm0,%xmm0
call   1060 <glmRandomNumberf@plt>
movss  %xmm0,0xc(%rsp)
movss  0x8(%rbx),%xmm1
mulss  %xmm1,%xmm1
movss  0xe7b(%rip),%xmm0
subss  %xmm1,%xmm0
ucomiss 0xe74(%rip),%xmm0
jb     119c <glmGenerateRandomVector3f+0x5c>
sqrtss %xmm0,%xmm0
jmp    11a1 <glmGenerateRandomVector3f+0x61>
call   1050 <sqrt@plt>
movss  %xmm0,0x8(%rsp)
movss  0xc(%rsp),%xmm0
call   1040 <cos@plt>
mulss  0x8(%rsp),%xmm0
movss  %xmm0,(%rbx)
movss  0xc(%rsp),%xmm0
call   1030 <sin@plt>
mulss  0x8(%rsp),%xmm0
movss  %xmm0,0x4(%rbx)
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define void @glmGenerateRandomVector3f(float* %0) {
%2 = alloca float*
%3 = alloca float
%4 = alloca float
store float* %0, float** %2
%5 = call float @glmRandomNumberf(float -1.000000e+00, double 1.000000e+00)
%6 = load float*, float** %2
%7 = getelementptr inbounds float, float* %6, i64 2
store float %5, float* %7
%8 = call float @glmRandomNumberf(float 0.000000e+00, double 0x401921FB54442D18)
store float %8, float* %3
%9 = load float*, float** %2
%10 = getelementptr inbounds float, float* %9, i64 2
%11 = load float, float* %10
%12 = load float*, float** %2
%13 = getelementptr inbounds float, float* %12, i64 2
%14 = load float, float* %13
%15 = fneg float %11
%16 = call float @llvm.fmuladd.f32(float %15, float %14, float 1.000000e+00)
%17 = call float @sqrt(float %16)
store float %17, float* %4
%18 = load float, float* %4
%19 = load float, float* %3
%20 = call float @cos(float %19)
%21 = fmul float %18, %20
%22 = load float*, float** %2
%23 = getelementptr inbounds float, float* %22, i64 0
store float %21, float* %23
%24 = load float, float* %4
%25 = load float, float* %3
%26 = call float @sin(float %25)
%27 = fmul float %24, %26
%28 = load float*, float** %2
%29 = getelementptr inbounds float, float* %28, i64 1
store float %27, float* %29
ret void
}

LLVM IR (-O2):
define void @glmGenerateRandomVector3f(float* nocapture %0) {
%2 = tail call float @glmRandomNumberf(float -1.000000e+00, double 1.000000e+00)
%3 = getelementptr inbounds float, float* %0, i64 2
store float %2, float* %3
%4 = tail call float @glmRandomNumberf(float 0.000000e+00, double 0x401921FB54442D18)
%5 = load float, float* %3
%6 = fneg float %5
%7 = tail call float @llvm.fmuladd.f32(float %6, float %5, float 1.000000e+00)
%8 = tail call float @sqrt(float %7)
%9 = tail call float @cos(float %4)
%10 = fmul float %8, %9
store float %10, float* %0
%11 = tail call float @sin(float %4)
%12 = fmul float %8, %11
%13 = getelementptr inbounds float, float* %0, i64 1
store float %12, float* %13
ret void
}