#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 cart_to_spher(double spher[3], double cart[3]) {
  spher[2] = sqrt(cart[0] * cart[0] + cart[1] * cart[1] + cart[2] * cart[2]);
  if (spher[2] != 0.0) {
    spher[0] = acos(cart[2] / spher[2]);
    spher[1] = atan2(cart[1], cart[0]);
  } else {
    spher[0] = 0.0;
    spher[1] = 0.0;
  }
}


x86 assembly (clang, -O0):
<cart_to_spher>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%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   1050 <sqrt@plt>
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x10(%rax)
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11b3 <cart_to_spher+0x83>
jp     11b3 <cart_to_spher+0x83>
jmp    11f6 <cart_to_spher+0xc6>
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm0
mov    -0x8(%rbp),%rax
divsd  0x10(%rax),%xmm0
call   1040 <acos@plt>
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm1
call   1030 <atan2@plt>
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x8(%rax)
jmp    120d <cart_to_spher+0xdd>
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,0x8(%rax)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cart_to_spher>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
movsd  (%rsi),%xmm1
movsd  0x8(%rsi),%xmm0
mulsd  %xmm0,%xmm0
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  0x10(%rsi),%xmm0
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     116c <cart_to_spher+0x3c>
sqrtsd %xmm0,%xmm0
jmp    1175 <cart_to_spher+0x45>
call   1050 <sqrt@plt>
xorpd  %xmm1,%xmm1
movsd  %xmm0,0x10(%r14)
ucomisd %xmm1,%xmm0
jne    1183 <cart_to_spher+0x53>
jnp    11aa <cart_to_spher+0x7a>
movsd  0x10(%rbx),%xmm1
divsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
call   1040 <acos@plt>
movsd  %xmm0,(%r14)
movsd  (%rbx),%xmm1
movsd  0x8(%rbx),%xmm0
call   1030 <atan2@plt>
jmp    11b5 <cart_to_spher+0x85>
movq   $0x0,(%r14)
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @cart_to_spher(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 0
%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 1
%13 = load double, double* %12
%14 = load double*, double** %4
%15 = getelementptr inbounds double, double* %14, i64 1
%16 = load double, double* %15
%17 = fmul double %13, %16
%18 = call double @llvm.fmuladd.f64(double %7, double %10, double %17)
%19 = load double*, double** %4
%20 = getelementptr inbounds double, double* %19, i64 2
%21 = load double, double* %20
%22 = load double*, double** %4
%23 = getelementptr inbounds double, double* %22, i64 2
%24 = load double, double* %23
%25 = call double @llvm.fmuladd.f64(double %21, double %24, double %18)
%26 = call double @sqrt(double %25)
%27 = load double*, double** %3
%28 = getelementptr inbounds double, double* %27, i64 2
store double %26, double* %28
%29 = load double*, double** %3
%30 = getelementptr inbounds double, double* %29, i64 2
%31 = load double, double* %30
%32 = fcmp une double %31, 0.000000e+00
br i1 %32, label %33, label %53
33: ; preds = %2
%34 = load double*, double** %4
%35 = getelementptr inbounds double, double* %34, i64 2
%36 = load double, double* %35
%37 = load double*, double** %3
%38 = getelementptr inbounds double, double* %37, i64 2
%39 = load double, double* %38
%40 = fdiv double %36, %39
%41 = call double @acos(double %40)
%42 = load double*, double** %3
%43 = getelementptr inbounds double, double* %42, i64 0
store double %41, double* %43
%44 = load double*, double** %4
%45 = getelementptr inbounds double, double* %44, i64 1
%46 = load double, double* %45
%47 = load double*, double** %4
%48 = getelementptr inbounds double, double* %47, i64 0
%49 = load double, double* %48
%50 = call double @atan2(double %46, double %49)
%51 = load double*, double** %3
%52 = getelementptr inbounds double, double* %51, i64 1
store double %50, double* %52
br label %58
53: ; preds = %2
%54 = load double*, double** %3
%55 = getelementptr inbounds double, double* %54, i64 0
store double 0.000000e+00, double* %55
%56 = load double*, double** %3
%57 = getelementptr inbounds double, double* %56, i64 1
store double 0.000000e+00, double* %57
br label %58
58: ; preds = %53, %33
ret void
}

LLVM IR (-O2):
define void @cart_to_spher(double* nocapture writeonly %0, double* nocapture %1) {
%3 = load double, double* %1
%4 = getelementptr inbounds double, double* %1, i64 1
%5 = load double, double* %4
%6 = fmul double %5, %5
%7 = tail call double @llvm.fmuladd.f64(double %3, double %3, 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 = getelementptr inbounds double, double* %0, i64 2
store double %11, double* %12
%13 = fcmp une double %11, 0.000000e+00
br i1 %13, label %14, label %21
14: ; preds = %2
%15 = load double, double* %8
%16 = fdiv double %15, %11
%17 = tail call double @acos(double %16)
store double %17, double* %0
%18 = load double, double* %4
%19 = load double, double* %1
%20 = tail call double @atan2(double %18, double %19)
br label %22
21: ; preds = %2
store double 0.000000e+00, double* %0
br label %22
22: ; preds = %21, %14
%23 = phi double [ %20, %14 ], [ 0.000000e+00, %21 ]
%24 = getelementptr inbounds double, double* %0, i64 1
store double %23, double* %24
ret void
}