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


x86 assembly (clang, -O0):
<coord_spherical>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%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>
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x8(%rbp),%xmm0
movsd  -0x8(%rbp),%xmm2
movsd  -0x10(%rbp),%xmm1
mulsd  -0x10(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1040 <sqrt@plt>
movsd  -0x18(%rbp),%xmm1
call   1030 <atan2@plt>
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x10(%rbp),%xmm0
movsd  -0x8(%rbp),%xmm1
call   1030 <atan2@plt>
mov    -0x30(%rbp),%rax
movsd  %xmm0,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<coord_spherical>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
movapd %xmm0,%xmm3
movsd  %xmm1,0x10(%rsp)
mulsd  %xmm1,%xmm1
movsd  %xmm0,0x18(%rsp)
mulsd  %xmm0,%xmm3
addsd  %xmm1,%xmm3
movsd  %xmm2,0x8(%rsp)
movapd %xmm2,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm3,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     1170 <coord_spherical+0x50>
sqrtsd %xmm0,%xmm0
jmp    1183 <coord_spherical+0x63>
movsd  %xmm3,(%rsp)
call   1040 <sqrt@plt>
xorpd  %xmm1,%xmm1
movsd  (%rsp),%xmm3
movsd  %xmm0,(%rbx)
ucomisd %xmm1,%xmm3
jb     1196 <coord_spherical+0x76>
xorps  %xmm0,%xmm0
sqrtsd %xmm3,%xmm0
jmp    119f <coord_spherical+0x7f>
movapd %xmm3,%xmm0
call   1040 <sqrt@plt>
movsd  0x8(%rsp),%xmm1
call   1030 <atan2@plt>
movsd  %xmm0,(%r15)
movsd  0x10(%rsp),%xmm0
movsd  0x18(%rsp),%xmm1
call   1030 <atan2@plt>
movsd  %xmm0,(%r14)
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @coord_spherical(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*
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
%13 = load double, double* %7
%14 = load double, double* %7
%15 = load double, double* %8
%16 = load double, double* %8
%17 = fmul double %15, %16
%18 = call double @llvm.fmuladd.f64(double %13, double %14, double %17)
%19 = load double, double* %9
%20 = load double, double* %9
%21 = call double @llvm.fmuladd.f64(double %19, double %20, double %18)
%22 = call double @sqrt(double %21)
%23 = load double*, double** %10
store double %22, double* %23
%24 = load double, double* %7
%25 = load double, double* %7
%26 = load double, double* %8
%27 = load double, double* %8
%28 = fmul double %26, %27
%29 = call double @llvm.fmuladd.f64(double %24, double %25, double %28)
%30 = call double @sqrt(double %29)
%31 = load double, double* %9
%32 = call double @atan2(double %30, double %31)
%33 = load double*, double** %11
store double %32, double* %33
%34 = load double, double* %8
%35 = load double, double* %7
%36 = call double @atan2(double %34, double %35)
%37 = load double*, double** %12
store double %36, double* %37
ret void
}

LLVM IR (-O2):
define void @coord_spherical(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)
store double %10, double* %3
%11 = tail call double @sqrt(double %8)
%12 = tail call double @atan2(double %11, double %2)
store double %12, double* %4
%13 = tail call double @atan2(double %1, double %0)
store double %13, double* %5
ret void
}