int amsp_coord_rect2spheric(double out[3], double const r[3]) {
  out[0] = atan2(
      r[1], (sqrt(((r[0]) * (r[0])) + ((r[1]) * (r[1])) + ((r[2]) * (r[2])))));
  out[1] = atan2(r[0], r[2]);
  out[2] = (sqrt(((r[0]) * (r[0])) + ((r[1]) * (r[1])) + ((r[2]) * (r[2]))));
  return 0;
}


x86 assembly (clang, -O0):
<amsp_coord_rect2spheric>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm1
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm2
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x10(%rbp),%rax
mulsd  0x8(%rax),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm0
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1040 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x18(%rbp),%xmm0
call   1030 <atan2@plt>
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm1
call   1030 <atan2@plt>
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x8(%rax)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm1
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm2
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x10(%rbp),%rax
mulsd  0x8(%rax),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm0
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1040 <sqrt@plt>
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x10(%rax)
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<amsp_coord_rect2spheric>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
movsd  (%rsi),%xmm1
movsd  0x8(%rsi),%xmm2
movapd %xmm2,%xmm0
mulsd  %xmm2,%xmm0
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  0x10(%rsi),%xmm0
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     1163 <amsp_coord_rect2spheric+0x43>
xorps  %xmm1,%xmm1
sqrtsd %xmm0,%xmm1
jmp    1176 <amsp_coord_rect2spheric+0x56>
movsd  %xmm2,(%rsp)
call   1040 <sqrt@plt>
movsd  (%rsp),%xmm2
movapd %xmm0,%xmm1
movapd %xmm2,%xmm0
call   1030 <atan2@plt>
movsd  %xmm0,(%r14)
movsd  (%rbx),%xmm0
movsd  0x10(%rbx),%xmm1
call   1030 <atan2@plt>
movsd  %xmm0,0x8(%r14)
movsd  (%rbx),%xmm1
movsd  0x8(%rbx),%xmm0
mulsd  %xmm0,%xmm0
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  0x10(%rbx),%xmm0
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
ucomisd 0xe3e(%rip),%xmm0
jb     11ca <amsp_coord_rect2spheric+0xaa>
sqrtsd %xmm0,%xmm0
jmp    11cf <amsp_coord_rect2spheric+0xaf>
call   1040 <sqrt@plt>
movsd  %xmm0,0x10(%r14)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @amsp_coord_rect2spheric(double* %0, double* %1) {
%3 = alloca double*
%4 = alloca double*
store double* %0, double** %3
store double* %1, double** %4
%5 = load double*, double** %4
%6 = getelementptr inbounds double, double* %5, i64 1
%7 = load double, double* %6
%8 = load double*, double** %4
%9 = getelementptr inbounds double, double* %8, i64 0
%10 = load double, double* %9
%11 = load double*, double** %4
%12 = getelementptr inbounds double, double* %11, i64 0
%13 = load double, double* %12
%14 = load double*, double** %4
%15 = getelementptr inbounds double, double* %14, i64 1
%16 = load double, double* %15
%17 = load double*, double** %4
%18 = getelementptr inbounds double, double* %17, i64 1
%19 = load double, double* %18
%20 = fmul double %16, %19
%21 = call double @llvm.fmuladd.f64(double %10, double %13, double %20)
%22 = load double*, double** %4
%23 = getelementptr inbounds double, double* %22, i64 2
%24 = load double, double* %23
%25 = load double*, double** %4
%26 = getelementptr inbounds double, double* %25, i64 2
%27 = load double, double* %26
%28 = call double @llvm.fmuladd.f64(double %24, double %27, double %21)
%29 = call double @sqrt(double %28)
%30 = call double @atan2(double %7, double %29)
%31 = load double*, double** %3
%32 = getelementptr inbounds double, double* %31, i64 0
store double %30, double* %32
%33 = load double*, double** %4
%34 = getelementptr inbounds double, double* %33, i64 0
%35 = load double, double* %34
%36 = load double*, double** %4
%37 = getelementptr inbounds double, double* %36, i64 2
%38 = load double, double* %37
%39 = call double @atan2(double %35, double %38)
%40 = load double*, double** %3
%41 = getelementptr inbounds double, double* %40, i64 1
store double %39, double* %41
%42 = load double*, double** %4
%43 = getelementptr inbounds double, double* %42, i64 0
%44 = load double, double* %43
%45 = load double*, double** %4
%46 = getelementptr inbounds double, double* %45, i64 0
%47 = load double, double* %46
%48 = load double*, double** %4
%49 = getelementptr inbounds double, double* %48, i64 1
%50 = load double, double* %49
%51 = load double*, double** %4
%52 = getelementptr inbounds double, double* %51, i64 1
%53 = load double, double* %52
%54 = fmul double %50, %53
%55 = call double @llvm.fmuladd.f64(double %44, double %47, double %54)
%56 = load double*, double** %4
%57 = getelementptr inbounds double, double* %56, i64 2
%58 = load double, double* %57
%59 = load double*, double** %4
%60 = getelementptr inbounds double, double* %59, i64 2
%61 = load double, double* %60
%62 = call double @llvm.fmuladd.f64(double %58, double %61, double %55)
%63 = call double @sqrt(double %62)
%64 = load double*, double** %3
%65 = getelementptr inbounds double, double* %64, i64 2
store double %63, double* %65
ret i32 0
}

LLVM IR (-O2):
define i32 @amsp_coord_rect2spheric(double* nocapture writeonly %0, double* nocapture %1) {
%3 = getelementptr inbounds double, double* %1, i64 1
%4 = load double, double* %3
%5 = load double, double* %1
%6 = fmul double %4, %4
%7 = tail call double @llvm.fmuladd.f64(double %5, double %5, double %6)
%8 = getelementptr inbounds double, double* %1, i64 2
%9 = load double, double* %8
%10 = tail call double @llvm.fmuladd.f64(double %9, double %9, double %7)
%11 = tail call double @sqrt(double %10)
%12 = tail call double @atan2(double %4, double %11)
store double %12, double* %0
%13 = load double, double* %1
%14 = load double, double* %8
%15 = tail call double @atan2(double %13, double %14)
%16 = getelementptr inbounds double, double* %0, i64 1
store double %15, double* %16
%17 = load double, double* %1
%18 = load double, double* %3
%19 = fmul double %18, %18
%20 = tail call double @llvm.fmuladd.f64(double %17, double %17, double %19)
%21 = load double, double* %8
%22 = tail call double @llvm.fmuladd.f64(double %21, double %21, double %20)
%23 = tail call double @sqrt(double %22)
%24 = getelementptr inbounds double, double* %0, i64 2
store double %23, double* %24
ret i32 0
}