#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 */
int M_PI;
double acos(int);
double cos(double);
double getRandom();
double sin(double);
void generateSurfacePointOnUnitSphere(int N, double *points) {
  double u, v, theta, phi, sinPhi;
  int j = 0, i = 0;
  for (i = 0; i < N; ++i, j += 3) {
    u = getRandom();
    v = getRandom();
    theta = 2 * M_PI * u;
    phi = acos(2 * v - 1);
    sinPhi = sin(phi);
    points[j] = cos(theta) * sinPhi;
    points[j + 1] = sin(theta) * sinPhi;
    points[j + 2] = 2 * v - 1;
  }
}


x86 assembly (clang, -O0):
<generateSurfacePointOnUnitSphere>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x40(%rbp)
movl   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    124f <generateSurfacePointOnUnitSphere+0x10f>
mov    $0x0,%al
call   1060 <getRandom@plt>
movsd  %xmm0,-0x18(%rbp)
mov    $0x0,%al
call   1060 <getRandom@plt>
movsd  %xmm0,-0x20(%rbp)
mov    0x2e59(%rip),%rax
mov    (%rax),%eax
shl    $0x1,%eax
cvtsi2sd %eax,%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
addsd  %xmm0,%xmm0
movsd  0xe4d(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1030 <acos@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1040 <sin@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1050 <cos@plt>
mulsd  -0x38(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x28(%rbp),%xmm0
call   1040 <sin@plt>
mulsd  -0x38(%rbp),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x3c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x20(%rbp),%xmm0
addsd  %xmm0,%xmm0
movsd  0xdde(%rip),%xmm1
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
mov    -0x3c(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x3c(%rbp)
jmp    1164 <generateSurfacePointOnUnitSphere+0x24>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generateSurfacePointOnUnitSphere>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
test   %edi,%edi
jle    11f5 <generateSurfacePointOnUnitSphere+0xb5>
mov    %rsi,%rbx
mov    %edi,%ebp
add    $0x10,%rbx
mov    0x2e88(%rip),%r14
xor    %eax,%eax
call   1060 <getRandom@plt>
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1060 <getRandom@plt>
mov    (%r14),%eax
add    %eax,%eax
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
mulsd  0x8(%rsp),%xmm1
movsd  %xmm1,0x8(%rsp)
addsd  %xmm0,%xmm0
addsd  0xe68(%rip),%xmm0
movsd  %xmm0,0x18(%rsp)
cvttsd2si %xmm0,%edi
call   1030 <acos@plt>
call   1040 <sin@plt>
movsd  %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
call   1050 <cos@plt>
mulsd  0x10(%rsp),%xmm0
movsd  %xmm0,-0x10(%rbx)
movsd  0x8(%rsp),%xmm0
call   1040 <sin@plt>
mulsd  0x10(%rsp),%xmm0
movsd  %xmm0,-0x8(%rbx)
movsd  0x18(%rsp),%xmm0
movsd  %xmm0,(%rbx)
add    $0x18,%rbx
add    $0xffffffff,%ebp
jne    1160 <generateSurfacePointOnUnitSphere+0x20>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@M_PI = global i32 0
define void @generateSurfacePointOnUnitSphere(i32 %0, double* %1) {
%3 = alloca i32
%4 = alloca double*
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %3
store double* %1, double** %4
store i32 0, i32* %10
store i32 0, i32* %11
store i32 0, i32* %11
br label %12
12: ; preds = %54, %2
%13 = load i32, i32* %11
%14 = load i32, i32* %3
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %59
16: ; preds = %12
%17 = call double (...) @getRandom()
store double %17, double* %5
%18 = call double (...) @getRandom()
store double %18, double* %6
%19 = load i32, i32* @M_PI
%20 = mul nsw i32 2, %19
%21 = sitofp i32 %20 to double
%22 = load double, double* %5
%23 = fmul double %21, %22
store double %23, double* %7
%24 = load double, double* %6
%25 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %24, double -1.000000e+00)
%26 = fptosi double %25 to i32
%27 = call double @acos(i32 %26)
store double %27, double* %8
%28 = load double, double* %8
%29 = call double @sin(double %28)
store double %29, double* %9
%30 = load double, double* %7
%31 = call double @cos(double %30)
%32 = load double, double* %9
%33 = fmul double %31, %32
%34 = load double*, double** %4
%35 = load i32, i32* %10
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds double, double* %34, i64 %36
store double %33, double* %37
%38 = load double, double* %7
%39 = call double @sin(double %38)
%40 = load double, double* %9
%41 = fmul double %39, %40
%42 = load double*, double** %4
%43 = load i32, i32* %10
%44 = add nsw i32 %43, 1
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds double, double* %42, i64 %45
store double %41, double* %46
%47 = load double, double* %6
%48 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %47, double -1.000000e+00)
%49 = load double*, double** %4
%50 = load i32, i32* %10
%51 = add nsw i32 %50, 2
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds double, double* %49, i64 %52
store double %48, double* %53
br label %54
54: ; preds = %16
%55 = load i32, i32* %11
%56 = add nsw i32 %55, 1
store i32 %56, i32* %11
%57 = load i32, i32* %10
%58 = add nsw i32 %57, 3
store i32 %58, i32* %10
br label %12
59: ; preds = %12
ret void
}

LLVM IR (-O2):
@M_PI = global i32 0
define void @generateSurfacePointOnUnitSphere(i32 %0, double* nocapture writeonly %1) {
%3 = icmp sgt i32 %0, 0
br i1 %3, label %4, label %29
4: ; preds = %2, %4
%5 = phi i64 [ %27, %4 ], [ 0, %2 ]
%6 = phi i32 [ %26, %4 ], [ 0, %2 ]
%7 = tail call double (...) @getRandom()
%8 = tail call double (...) @getRandom()
%9 = load i32, i32* @M_PI
%10 = shl nsw i32 %9, 1
%11 = sitofp i32 %10 to double
%12 = fmul double %7, %11
%13 = tail call double @llvm.fmuladd.f64(double %8, double 2.000000e+00, double -1.000000e+00)
%14 = fptosi double %13 to i32
%15 = tail call double @acos(i32 %14)
%16 = tail call double @sin(double %15)
%17 = tail call double @cos(double %12)
%18 = fmul double %16, %17
%19 = getelementptr inbounds double, double* %1, i64 %5
store double %18, double* %19
%20 = tail call double @sin(double %12)
%21 = fmul double %16, %20
%22 = add nuw nsw i64 %5, 1
%23 = getelementptr inbounds double, double* %1, i64 %22
store double %21, double* %23
%24 = add nuw nsw i64 %5, 2
%25 = getelementptr inbounds double, double* %1, i64 %24
store double %13, double* %25
%26 = add nuw nsw i32 %6, 1
%27 = add nuw nsw i64 %5, 3
%28 = icmp eq i32 %26, %0
br i1 %28, label %29, label %4
29: ; preds = %4, %2
ret void
}