#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 */
scalar_t__ atan2(float const, float const);
float const sqrt(float);
void VecCarthesianToSpherical3fv(float v[3], const float a[3]) {
  float r2 = a[0] * a[0] + a[1] * a[1];
  v[1] = (float)atan2(a[0], a[1]);
  v[2] = (float)atan2(sqrt(r2), a[2]);
  v[0] = (float)sqrt(r2 + a[2] * a[2]);
}


x86 assembly (clang, -O0):
<VecCarthesianToSpherical3fv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movss  (%rax),%xmm0
mov    -0x10(%rbp),%rax
movss  (%rax),%xmm2
mov    -0x10(%rbp),%rax
movss  0x4(%rax),%xmm1
mov    -0x10(%rbp),%rax
mulss  0x4(%rax),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movss  (%rax),%xmm0
mov    -0x10(%rbp),%rax
movss  0x4(%rax),%xmm1
call   1030 <atan2@plt>
cvtsi2ss %rax,%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x4(%rax)
movss  -0x14(%rbp),%xmm0
call   1040 <sqrt@plt>
mov    -0x10(%rbp),%rax
movss  0x8(%rax),%xmm1
call   1030 <atan2@plt>
cvtsi2ss %rax,%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x8(%rax)
movss  -0x14(%rbp),%xmm1
mov    -0x10(%rbp),%rax
movss  0x8(%rax),%xmm0
mov    -0x10(%rbp),%rax
movss  0x8(%rax),%xmm2
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
call   1040 <sqrt@plt>
mov    -0x8(%rbp),%rax
movss  %xmm0,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<VecCarthesianToSpherical3fv>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
movss  (%rsi),%xmm0
movss  0x4(%rsi),%xmm1
movaps %xmm1,%xmm2
mulss  %xmm1,%xmm2
movaps %xmm0,%xmm3
mulss  %xmm0,%xmm3
addss  %xmm2,%xmm3
movss  %xmm3,0x4(%rsp)
call   1030 <atan2@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
movss  %xmm0,0x4(%r14)
xorps  %xmm0,%xmm0
movss  0x4(%rsp),%xmm1
ucomiss %xmm0,%xmm1
jb     1178 <VecCarthesianToSpherical3fv+0x58>
movss  0x4(%rsp),%xmm0
sqrtss %xmm0,%xmm0
jmp    1183 <VecCarthesianToSpherical3fv+0x63>
movss  0x4(%rsp),%xmm0
call   1040 <sqrt@plt>
movss  0x8(%rbx),%xmm1
call   1030 <atan2@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
movss  %xmm0,0x8(%r14)
movss  0x8(%rbx),%xmm0
mulss  %xmm0,%xmm0
addss  0x4(%rsp),%xmm0
ucomiss 0xe4f(%rip),%xmm0
jb     11b9 <VecCarthesianToSpherical3fv+0x99>
sqrtss %xmm0,%xmm0
jmp    11be <VecCarthesianToSpherical3fv+0x9e>
call   1040 <sqrt@plt>
movss  %xmm0,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @VecCarthesianToSpherical3fv(float* %0, float* %1) {
%3 = alloca float*
%4 = alloca float*
%5 = alloca float
store float* %0, float** %3
store float* %1, float** %4
%6 = load float*, float** %4
%7 = getelementptr inbounds float, float* %6, i64 0
%8 = load float, float* %7
%9 = load float*, float** %4
%10 = getelementptr inbounds float, float* %9, i64 0
%11 = load float, float* %10
%12 = load float*, float** %4
%13 = getelementptr inbounds float, float* %12, i64 1
%14 = load float, float* %13
%15 = load float*, float** %4
%16 = getelementptr inbounds float, float* %15, i64 1
%17 = load float, float* %16
%18 = fmul float %14, %17
%19 = call float @llvm.fmuladd.f32(float %8, float %11, float %18)
store float %19, float* %5
%20 = load float*, float** %4
%21 = getelementptr inbounds float, float* %20, i64 0
%22 = load float, float* %21
%23 = load float*, float** %4
%24 = getelementptr inbounds float, float* %23, i64 1
%25 = load float, float* %24
%26 = call i64 @atan2(float %22, float %25)
%27 = sitofp i64 %26 to float
%28 = load float*, float** %3
%29 = getelementptr inbounds float, float* %28, i64 1
store float %27, float* %29
%30 = load float, float* %5
%31 = call float @sqrt(float %30)
%32 = load float*, float** %4
%33 = getelementptr inbounds float, float* %32, i64 2
%34 = load float, float* %33
%35 = call i64 @atan2(float %31, float %34)
%36 = sitofp i64 %35 to float
%37 = load float*, float** %3
%38 = getelementptr inbounds float, float* %37, i64 2
store float %36, float* %38
%39 = load float, float* %5
%40 = load float*, float** %4
%41 = getelementptr inbounds float, float* %40, i64 2
%42 = load float, float* %41
%43 = load float*, float** %4
%44 = getelementptr inbounds float, float* %43, i64 2
%45 = load float, float* %44
%46 = call float @llvm.fmuladd.f32(float %42, float %45, float %39)
%47 = call float @sqrt(float %46)
%48 = load float*, float** %3
%49 = getelementptr inbounds float, float* %48, i64 0
store float %47, float* %49
ret void
}

LLVM IR (-O2):
define void @VecCarthesianToSpherical3fv(float* nocapture writeonly %0, float* nocapture %1) {
%3 = load float, float* %1
%4 = getelementptr inbounds float, float* %1, i64 1
%5 = load float, float* %4
%6 = fmul float %5, %5
%7 = tail call float @llvm.fmuladd.f32(float %3, float %3, float %6)
%8 = tail call i64 @atan2(float %3, float %5)
%9 = sitofp i64 %8 to float
%10 = getelementptr inbounds float, float* %0, i64 1
store float %9, float* %10
%11 = tail call float @sqrt(float %7)
%12 = getelementptr inbounds float, float* %1, i64 2
%13 = load float, float* %12
%14 = tail call i64 @atan2(float %11, float %13)
%15 = sitofp i64 %14 to float
%16 = getelementptr inbounds float, float* %0, i64 2
store float %15, float* %16
%17 = load float, float* %12
%18 = tail call float @llvm.fmuladd.f32(float %17, float %17, float %7)
%19 = tail call float @sqrt(float %18)
store float %19, float* %0
ret void
}