#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 */
double acos(double);
double atan2(double, double);
double sqrt(double);
void rec2sph(double *v, double *lon, double *lat) {
  double r, theta;
  r = sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
  theta = acos(v[2] / r);
  *lon = atan2(v[1], v[0]);
  *lat = 1.5707963267948966 - theta;
}


x86 assembly (clang, -O0):
<rec2sph>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm1
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm2
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x8(%rbp),%rax
mulsd  0x8(%rax),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm0
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1050 <sqrt@plt>
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm0
divsd  -0x20(%rbp),%xmm0
call   1040 <acos@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm1
call   1030 <atan2@plt>
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  0xe30(%rip),%xmm0
subsd  -0x28(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rec2sph>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
movsd  (%rdi),%xmm1
movsd  0x8(%rdi),%xmm0
mulsd  %xmm0,%xmm0
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  0x10(%rdi),%xmm0
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     1174 <rec2sph+0x44>
sqrtsd %xmm0,%xmm0
jmp    1179 <rec2sph+0x49>
call   1050 <sqrt@plt>
movsd  0x10(%rbx),%xmm1
divsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
call   1040 <acos@plt>
movsd  %xmm0,0x8(%rsp)
movsd  (%rbx),%xmm1
movsd  0x8(%rbx),%xmm0
call   1030 <atan2@plt>
movsd  %xmm0,(%r15)
movsd  0xe54(%rip),%xmm0
subsd  0x8(%rsp),%xmm0
movsd  %xmm0,(%r14)
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @rec2sph(double* nocapture %0, double* nocapture writeonly %1, double* nocapture writeonly %2) {
%4 = load double, double* %0
%5 = getelementptr inbounds double, double* %0, i64 1
%6 = load double, double* %5
%7 = fmul double %6, %6
%8 = tail call double @llvm.fmuladd.f64(double %4, double %4, double %7)
%9 = getelementptr inbounds double, double* %0, i64 2
%10 = load double, double* %9
%11 = tail call double @llvm.fmuladd.f64(double %10, double %10, double %8)
%12 = tail call double @sqrt(double %11)
%13 = load double, double* %9
%14 = fdiv double %13, %12
%15 = tail call double @acos(double %14)
%16 = load double, double* %5
%17 = load double, double* %0
%18 = tail call double @atan2(double %16, double %17)
store double %18, double* %1
%19 = fsub double 0x3FF921FB54442D18, %15
store double %19, double* %2
ret void
}