#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 atan2(double, double);
double sqrt(double);
void xyz2sph(double x, double y, double z, double *pr, double *ptheta,
             double *pphi) {
  double r, theta, phi;
  r = sqrt(x * x + y * y + z * z);
  theta = atan2(z, r);
  phi = atan2(y, x);
  *pr = r;
  *ptheta = theta;
  *pphi = phi;
}


x86 assembly (clang, -O0):
<xyz2sph>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
mov    %rdi,-0x20(%rbp)
mov    %rsi,-0x28(%rbp)
mov    %rdx,-0x30(%rbp)
movsd  -0x8(%rbp),%xmm1
movsd  -0x8(%rbp),%xmm2
movsd  -0x10(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x18(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1040 <sqrt@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
call   1030 <atan2@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x8(%rbp),%xmm1
call   1030 <atan2@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x38(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x40(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x48(%rbp),%xmm0
mov    -0x30(%rbp),%rax
movsd  %xmm0,(%rax)
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xyz2sph>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
movapd %xmm2,%xmm3
movsd  %xmm1,0x10(%rsp)
movapd %xmm1,%xmm2
mulsd  %xmm1,%xmm2
movsd  %xmm0,0x18(%rsp)
movapd %xmm0,%xmm1
mulsd  %xmm0,%xmm1
addsd  %xmm2,%xmm1
movapd %xmm3,%xmm0
mulsd  %xmm3,%xmm0
addsd  %xmm1,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     1175 <xyz2sph+0x55>
xorps  %xmm1,%xmm1
sqrtsd %xmm0,%xmm1
jmp    1188 <xyz2sph+0x68>
movsd  %xmm3,(%rsp)
call   1040 <sqrt@plt>
movsd  (%rsp),%xmm3
movapd %xmm0,%xmm1
movapd %xmm3,%xmm0
movsd  %xmm1,(%rsp)
call   1030 <atan2@plt>
movsd  %xmm0,0x8(%rsp)
movsd  0x10(%rsp),%xmm0
movsd  0x18(%rsp),%xmm1
call   1030 <atan2@plt>
movsd  (%rsp),%xmm1
movsd  %xmm1,(%rbx)
movsd  0x8(%rsp),%xmm1
movsd  %xmm1,(%r15)
movsd  %xmm0,(%r14)
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @xyz2sph(double %0, double %1, double %2, double* %3, double* %4, double* %5) {
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double*
%11 = alloca double*
%12 = alloca double*
%13 = alloca double
%14 = alloca double
%15 = alloca double
store double %0, double* %7
store double %1, double* %8
store double %2, double* %9
store double* %3, double** %10
store double* %4, double** %11
store double* %5, double** %12
%16 = load double, double* %7
%17 = load double, double* %7
%18 = load double, double* %8
%19 = load double, double* %8
%20 = fmul double %18, %19
%21 = call double @llvm.fmuladd.f64(double %16, double %17, double %20)
%22 = load double, double* %9
%23 = load double, double* %9
%24 = call double @llvm.fmuladd.f64(double %22, double %23, double %21)
%25 = call double @sqrt(double %24)
store double %25, double* %13
%26 = load double, double* %9
%27 = load double, double* %13
%28 = call double @atan2(double %26, double %27)
store double %28, double* %14
%29 = load double, double* %8
%30 = load double, double* %7
%31 = call double @atan2(double %29, double %30)
store double %31, double* %15
%32 = load double, double* %13
%33 = load double*, double** %10
store double %32, double* %33
%34 = load double, double* %14
%35 = load double*, double** %11
store double %34, double* %35
%36 = load double, double* %15
%37 = load double*, double** %12
store double %36, double* %37
ret void
}

LLVM IR (-O2):
define void @xyz2sph(double %0, double %1, double %2, double* nocapture writeonly %3, double* nocapture writeonly %4, double* nocapture writeonly %5) {
%7 = fmul double %1, %1
%8 = tail call double @llvm.fmuladd.f64(double %0, double %0, double %7)
%9 = tail call double @llvm.fmuladd.f64(double %2, double %2, double %8)
%10 = tail call double @sqrt(double %9)
%11 = tail call double @atan2(double %2, double %10)
%12 = tail call double @atan2(double %1, double %0)
store double %10, double* %3
store double %11, double* %4
store double %12, double* %5
ret void
}