#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 sin(float);
double sqrt(double);
void generate_sphere_points(float *sphere_points, int n_points) {
  int i;
  float y, r, phi;
  float inc = 3.14159265358979323846 * (3.0 - sqrt(5));
  float offset = 2.0 / n_points;
  for (i = 0; i < n_points; i++) {
    y = i * offset - 1.0 + (offset / 2.0);
    r = sqrt(1.0 - y * y);
    phi = i * inc;
    sphere_points[3 * i] = cos(phi) * r;
    sphere_points[3 * i + 1] = y;
    sphere_points[3 * i + 2] = sin(phi) * r;
  }
}


x86 assembly (clang, -O0):
<generate_sphere_points>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movsd  0xed1(%rip),%xmm0
call   1050 <sqrt@plt>
movsd  0xebc(%rip),%xmm1
subsd  %xmm0,%xmm1
movsd  0xea8(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x20(%rbp)
cvtsi2sdl -0xc(%rbp),%xmm1
movsd  0xe86(%rip),%xmm0
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x24(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1274 <generate_sphere_points+0x144>
cvtsi2ssl -0x10(%rbp),%xmm0
mulss  -0x24(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe70(%rip),%xmm1
subsd  %xmm1,%xmm0
movss  -0x24(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
movsd  0xe3b(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x14(%rbp),%xmm0
mulss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xe34(%rip),%xmm0
subsd  %xmm1,%xmm0
call   1050 <sqrt@plt>
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x18(%rbp)
cvtsi2ssl -0x10(%rbp),%xmm0
mulss  -0x20(%rbp),%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x1c(%rbp),%xmm0
call   1040 <cos@plt>
mulss  -0x18(%rbp),%xmm0
mov    -0x8(%rbp),%rax
imul   $0x3,-0x10(%rbp),%ecx
movslq %ecx,%rcx
movss  %xmm0,(%rax,%rcx,4)
movss  -0x14(%rbp),%xmm0
mov    -0x8(%rbp),%rax
imul   $0x3,-0x10(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movss  %xmm0,(%rax,%rcx,4)
movss  -0x1c(%rbp),%xmm0
call   1030 <sin@plt>
mulss  -0x18(%rbp),%xmm0
mov    -0x8(%rbp),%rax
imul   $0x3,-0x10(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    118e <generate_sphere_points+0x5e>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_sphere_points>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
test   %esi,%esi
jle    124d <generate_sphere_points+0x11d>
mov    %rdi,%r15
cvtsi2sd %esi,%xmm0
movsd  0xeb0(%rip),%xmm1
divsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtsd2ss %xmm1,%xmm0
movss  %xmm0,0x10(%rsp)
cvtss2sd %xmm0,%xmm0
mulsd  0xe9b(%rip),%xmm0
movsd  %xmm0,0x18(%rsp)
mov    %esi,%r14d
add    $0x8,%r15
xor    %ebx,%ebx
jmp    11ec <generate_sphere_points+0xbc>
xchg   %ax,%ax
movss  %xmm2,0x8(%rsp)
call   1050 <sqrt@plt>
movss  0x8(%rsp),%xmm2
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,0xc(%rsp)
mulss  0xe85(%rip),%xmm2
movss  %xmm2,0x8(%rsp)
movaps %xmm2,%xmm0
call   1040 <cos@plt>
mulss  0xc(%rsp),%xmm0
movss  %xmm0,-0x8(%r15)
movss  0x14(%rsp),%xmm0
movss  %xmm0,-0x4(%r15)
movss  0x8(%rsp),%xmm0
call   1030 <sin@plt>
mulss  0xc(%rsp),%xmm0
movss  %xmm0,(%r15)
add    $0x1,%rbx
add    $0xc,%r15
cmp    %rbx,%r14
je     124d <generate_sphere_points+0x11d>
xorps  %xmm2,%xmm2
cvtsi2ss %ebx,%xmm2
movss  0x10(%rsp),%xmm0
mulss  %xmm2,%xmm0
cvtss2sd %xmm0,%xmm0
addsd  0xe07(%rip),%xmm0
addsd  0x18(%rsp),%xmm0
xorps  %xmm3,%xmm3
cvtsd2ss %xmm0,%xmm3
movaps %xmm3,%xmm0
mulss  %xmm3,%xmm0
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
movsd  0xdec(%rip),%xmm0
subsd  %xmm1,%xmm0
ucomisd 0xde8(%rip),%xmm0
movss  %xmm3,0x14(%rsp)
jb     1180 <generate_sphere_points+0x50>
sqrtsd %xmm0,%xmm0
jmp    1191 <generate_sphere_points+0x61>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @generate_sphere_points(float* %0, i32 %1) {
%3 = alloca float*
%4 = alloca i32
%5 = alloca i32
%6 = alloca float
%7 = alloca float
%8 = alloca float
%9 = alloca float
%10 = alloca float
store float* %0, float** %3
store i32 %1, i32* %4
%11 = call double @sqrt(double 5.000000e+00)
%12 = fsub double 3.000000e+00, %11
%13 = fmul double 0x400921FB54442D18, %12
%14 = fptrunc double %13 to float
store float %14, float* %9
%15 = load i32, i32* %4
%16 = sitofp i32 %15 to double
%17 = fdiv double 2.000000e+00, %16
%18 = fptrunc double %17 to float
store float %18, float* %10
store i32 0, i32* %5
br label %19
19: ; preds = %72, %2
%20 = load i32, i32* %5
%21 = load i32, i32* %4
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %75
23: ; preds = %19
%24 = load i32, i32* %5
%25 = sitofp i32 %24 to float
%26 = load float, float* %10
%27 = fmul float %25, %26
%28 = fpext float %27 to double
%29 = fsub double %28, 1.000000e+00
%30 = load float, float* %10
%31 = fpext float %30 to double
%32 = fdiv double %31, 2.000000e+00
%33 = fadd double %29, %32
%34 = fptrunc double %33 to float
store float %34, float* %6
%35 = load float, float* %6
%36 = load float, float* %6
%37 = fmul float %35, %36
%38 = fpext float %37 to double
%39 = fsub double 1.000000e+00, %38
%40 = call double @sqrt(double %39)
%41 = fptrunc double %40 to float
store float %41, float* %7
%42 = load i32, i32* %5
%43 = sitofp i32 %42 to float
%44 = load float, float* %9
%45 = fmul float %43, %44
store float %45, float* %8
%46 = load float, float* %8
%47 = call float @cos(float %46)
%48 = load float, float* %7
%49 = fmul float %47, %48
%50 = load float*, float** %3
%51 = load i32, i32* %5
%52 = mul nsw i32 3, %51
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds float, float* %50, i64 %53
store float %49, float* %54
%55 = load float, float* %6
%56 = load float*, float** %3
%57 = load i32, i32* %5
%58 = mul nsw i32 3, %57
%59 = add nsw i32 %58, 1
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds float, float* %56, i64 %60
store float %55, float* %61
%62 = load float, float* %8
%63 = call float @sin(float %62)
%64 = load float, float* %7
%65 = fmul float %63, %64
%66 = load float*, float** %3
%67 = load i32, i32* %5
%68 = mul nsw i32 3, %67
%69 = add nsw i32 %68, 2
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds float, float* %66, i64 %70
store float %65, float* %71
br label %72
72: ; preds = %23
%73 = load i32, i32* %5
%74 = add nsw i32 %73, 1
store i32 %74, i32* %5
br label %19
75: ; preds = %19
ret void
}

LLVM IR (-O2):
define void @generate_sphere_points(float* nocapture writeonly %0, i32 %1) {
%3 = sitofp i32 %1 to double
%4 = fdiv double 2.000000e+00, %3
%5 = fptrunc double %4 to float
%6 = icmp sgt i32 %1, 0
br i1 %6, label %7, label %38
7: ; preds = %2
%8 = fpext float %5 to double
%9 = fmul double %8, 5.000000e-01
%10 = zext i32 %1 to i64
br label %11
11: ; preds = %7, %11
%12 = phi i64 [ 0, %7 ], [ %36, %11 ]
%13 = trunc i64 %12 to i32
%14 = sitofp i32 %13 to float
%15 = fmul float %5, %14
%16 = fpext float %15 to double
%17 = fadd double %16, -1.000000e+00
%18 = fadd double %9, %17
%19 = fptrunc double %18 to float
%20 = fmul float %19, %19
%21 = fpext float %20 to double
%22 = fsub double 1.000000e+00, %21
%23 = tail call double @sqrt(double %22)
%24 = fptrunc double %23 to float
%25 = fmul float %14, 0x4003331FE0000000
%26 = tail call float @cos(float %25)
%27 = fmul float %26, %24
%28 = mul nuw nsw i64 %12, 3
%29 = getelementptr inbounds float, float* %0, i64 %28
store float %27, float* %29
%30 = add nuw nsw i64 %28, 1
%31 = getelementptr inbounds float, float* %0, i64 %30
store float %19, float* %31
%32 = tail call float @sin(float %25)
%33 = fmul float %32, %24
%34 = add nuw nsw i64 %28, 2
%35 = getelementptr inbounds float, float* %0, i64 %34
store float %33, float* %35
%36 = add nuw nsw i64 %12, 1
%37 = icmp eq i64 %36, %10
br i1 %37, label %38, label %11
38: ; preds = %11, %2
ret void
}