#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 M_PI;
double acos(double const);
double atan(double const);
double const fabs(double const);
double sqrt(double const);
void sphericalCoordinates(double *cartesian, double *spherical) {
  double r, theta, phi;
  const double accuracy = 1.0E-14;
  const double x = cartesian[0];
  const double y = cartesian[1];
  const double z = cartesian[2];
  r = sqrt(x * x + y * y + z * z);
  if (r < accuracy)
    theta = 0.0;
  else
    theta = acos(z / r);
  if (fabs(x) < accuracy) {
    if (fabs(y) < accuracy)
      phi = 0.0;
    else if (y < 0.0)
      phi = 1.5 * M_PI;
    else
      phi = 0.5 * M_PI;
  } else {
    if (x > 0.0)
      phi = atan(y / x);
    else
      phi = atan(y / x) + M_PI;
  }
  spherical[0] = r;
  spherical[1] = theta;
  spherical[2] = phi;
}


x86 assembly (clang, -O0):
<sphericalCoordinates>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  0xea8(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x38(%rbp),%xmm1
movsd  -0x38(%rbp),%xmm2
movsd  -0x40(%rbp),%xmm0
mulsd  -0x40(%rbp),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x48(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1060 <sqrt@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  0xe3a(%rip),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    11de <sphericalCoordinates+0x9e>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    11f2 <sphericalCoordinates+0xb2>
movsd  -0x48(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
call   1030 <acos@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x38(%rbp),%xmm0
call   1040 <fabs@plt>
movaps %xmm0,%xmm1
movsd  0xdf9(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    128a <sphericalCoordinates+0x14a>
movsd  -0x40(%rbp),%xmm0
call   1040 <fabs@plt>
movaps %xmm0,%xmm1
movsd  0xdda(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    123d <sphericalCoordinates+0xfd>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    1285 <sphericalCoordinates+0x145>
xorps  %xmm0,%xmm0
ucomisd -0x40(%rbp),%xmm0
jbe    1268 <sphericalCoordinates+0x128>
movsd  0xdbd(%rip),%xmm0
mov    0x2d8e(%rip),%rax
mulsd  (%rax),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    1280 <sphericalCoordinates+0x140>
movsd  0xd98(%rip),%xmm0
mov    0x2d71(%rip),%rax
mulsd  (%rax),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    1285 <sphericalCoordinates+0x145>
jmp    12d9 <sphericalCoordinates+0x199>
movsd  -0x38(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    12b5 <sphericalCoordinates+0x175>
movsd  -0x40(%rbp),%xmm0
divsd  -0x38(%rbp),%xmm0
call   1050 <atan@plt>
movsd  %xmm0,-0x28(%rbp)
jmp    12d4 <sphericalCoordinates+0x194>
movsd  -0x40(%rbp),%xmm0
divsd  -0x38(%rbp),%xmm0
call   1050 <atan@plt>
mov    0x2d1d(%rip),%rax
addsd  (%rax),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    12d9 <sphericalCoordinates+0x199>
movsd  -0x18(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x20(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x8(%rax)
movsd  -0x28(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x10(%rax)
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sphericalCoordinates>:
push   %rbx
sub    $0x30,%rsp
mov    %rsi,%rbx
movsd  (%rdi),%xmm5
movsd  0x8(%rdi),%xmm4
movsd  0x10(%rdi),%xmm6
movapd %xmm4,%xmm0
mulsd  %xmm4,%xmm0
movapd %xmm5,%xmm1
mulsd  %xmm5,%xmm1
addsd  %xmm0,%xmm1
movapd %xmm6,%xmm0
mulsd  %xmm6,%xmm0
addsd  %xmm1,%xmm0
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm0
movapd %xmm4,0x20(%rsp)
movapd %xmm5,0x10(%rsp)
jb     1182 <sphericalCoordinates+0x52>
sqrtsd %xmm0,%xmm3
jmp    11a5 <sphericalCoordinates+0x75>
movsd  %xmm6,(%rsp)
call   1050 <sqrt@plt>
movsd  (%rsp),%xmm6
movapd 0x10(%rsp),%xmm5
movapd 0x20(%rsp),%xmm4
xorpd  %xmm2,%xmm2
movapd %xmm0,%xmm3
movsd  0xe53(%rip),%xmm7
ucomisd %xmm3,%xmm7
movsd  %xmm3,(%rsp)
ja     11e2 <sphericalCoordinates+0xb2>
divsd  %xmm3,%xmm6
movapd %xmm6,%xmm0
call   1030 <acos@plt>
movsd  0xe33(%rip),%xmm7
movapd 0x10(%rsp),%xmm5
movapd 0x20(%rsp),%xmm4
movsd  (%rsp),%xmm3
movapd %xmm0,%xmm2
movapd 0xe36(%rip),%xmm0
andpd  %xmm5,%xmm0
ucomisd %xmm0,%xmm7
jbe    1229 <sphericalCoordinates+0xf9>
movapd 0xe24(%rip),%xmm1
andpd  %xmm4,%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm1,%xmm7
ja     126c <sphericalCoordinates+0x13c>
xorpd  %xmm0,%xmm0
ucomisd %xmm4,%xmm0
mov    0x2dcf(%rip),%rax
movsd  (%rax),%xmm0
jbe    1264 <sphericalCoordinates+0x134>
mulsd  0xde9(%rip),%xmm0
jmp    126c <sphericalCoordinates+0x13c>
movsd  %xmm2,0x8(%rsp)
divsd  %xmm5,%xmm4
movapd %xmm4,%xmm0
call   1040 <atan@plt>
xorpd  %xmm1,%xmm1
movapd 0x10(%rsp),%xmm2
ucomisd %xmm1,%xmm2
ja     1257 <sphericalCoordinates+0x127>
mov    0x2d95(%rip),%rax
addsd  (%rax),%xmm0
movsd  0x8(%rsp),%xmm2
movsd  (%rsp),%xmm3
jmp    126c <sphericalCoordinates+0x13c>
mulsd  0xd9c(%rip),%xmm0
movsd  %xmm3,(%rbx)
movsd  %xmm2,0x8(%rbx)
movsd  %xmm0,0x10(%rbx)
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@M_PI = global double 0.000000e+00
define void @sphericalCoordinates(double* %0, double* %1) {
%3 = alloca double*
%4 = alloca double*
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
store double* %0, double** %3
store double* %1, double** %4
store double 0x3D06849B86A12B9B, double* %8
%12 = load double*, double** %3
%13 = getelementptr inbounds double, double* %12, i64 0
%14 = load double, double* %13
store double %14, double* %9
%15 = load double*, double** %3
%16 = getelementptr inbounds double, double* %15, i64 1
%17 = load double, double* %16
store double %17, double* %10
%18 = load double*, double** %3
%19 = getelementptr inbounds double, double* %18, i64 2
%20 = load double, double* %19
store double %20, double* %11
%21 = load double, double* %9
%22 = load double, double* %9
%23 = load double, double* %10
%24 = load double, double* %10
%25 = fmul double %23, %24
%26 = call double @llvm.fmuladd.f64(double %21, double %22, double %25)
%27 = load double, double* %11
%28 = load double, double* %11
%29 = call double @llvm.fmuladd.f64(double %27, double %28, double %26)
%30 = call double @sqrt(double %29)
store double %30, double* %5
%31 = load double, double* %5
%32 = fcmp olt double %31, 0x3D06849B86A12B9B
br i1 %32, label %33, label %34
33: ; preds = %2
store double 0.000000e+00, double* %6
br label %39
34: ; preds = %2
%35 = load double, double* %11
%36 = load double, double* %5
%37 = fdiv double %35, %36
%38 = call double @acos(double %37)
store double %38, double* %6
br label %39
39: ; preds = %34, %33
%40 = load double, double* %9
%41 = call double @fabs(double %40)
%42 = fcmp olt double %41, 0x3D06849B86A12B9B
br i1 %42, label %43, label %59
43: ; preds = %39
%44 = load double, double* %10
%45 = call double @fabs(double %44)
%46 = fcmp olt double %45, 0x3D06849B86A12B9B
br i1 %46, label %47, label %48
47: ; preds = %43
store double 0.000000e+00, double* %7
br label %58
48: ; preds = %43
%49 = load double, double* %10
%50 = fcmp olt double %49, 0.000000e+00
br i1 %50, label %51, label %54
51: ; preds = %48
%52 = load double, double* @M_PI
%53 = fmul double 1.500000e+00, %52
store double %53, double* %7
br label %57
54: ; preds = %48
%55 = load double, double* @M_PI
%56 = fmul double 5.000000e-01, %55
store double %56, double* %7
br label %57
57: ; preds = %54, %51
br label %58
58: ; preds = %57, %47
br label %75
59: ; preds = %39
%60 = load double, double* %9
%61 = fcmp ogt double %60, 0.000000e+00
br i1 %61, label %62, label %67
62: ; preds = %59
%63 = load double, double* %10
%64 = load double, double* %9
%65 = fdiv double %63, %64
%66 = call double @atan(double %65)
store double %66, double* %7
br label %74
67: ; preds = %59
%68 = load double, double* %10
%69 = load double, double* %9
%70 = fdiv double %68, %69
%71 = call double @atan(double %70)
%72 = load double, double* @M_PI
%73 = fadd double %71, %72
store double %73, double* %7
br label %74
74: ; preds = %67, %62
br label %75
75: ; preds = %74, %58
%76 = load double, double* %5
%77 = load double*, double** %4
%78 = getelementptr inbounds double, double* %77, i64 0
store double %76, double* %78
%79 = load double, double* %6
%80 = load double*, double** %4
%81 = getelementptr inbounds double, double* %80, i64 1
store double %79, double* %81
%82 = load double, double* %7
%83 = load double*, double** %4
%84 = getelementptr inbounds double, double* %83, i64 2
store double %82, double* %84
ret void
}

LLVM IR (-O2):
@M_PI = global double 0.000000e+00
define void @sphericalCoordinates(double* nocapture %0, double* nocapture writeonly %1) {
%3 = load double, double* %0
%4 = getelementptr inbounds double, double* %0, i64 1
%5 = load double, double* %4
%6 = getelementptr inbounds double, double* %0, i64 2
%7 = load double, double* %6
%8 = fmul double %5, %5
%9 = tail call double @llvm.fmuladd.f64(double %3, double %3, double %8)
%10 = tail call double @llvm.fmuladd.f64(double %7, double %7, double %9)
%11 = tail call double @sqrt(double %10)
%12 = fcmp olt double %11, 0x3D06849B86A12B9B
br i1 %12, label %16, label %13
13: ; preds = %2
%14 = fdiv double %7, %11
%15 = tail call double @acos(double %14)
br label %16
16: ; preds = %2, %13
%17 = phi double [ %15, %13 ], [ 0.000000e+00, %2 ]
%18 = tail call double @llvm.fabs.f64(double %3)
%19 = fcmp olt double %18, 0x3D06849B86A12B9B
br i1 %19, label %20, label %30
20: ; preds = %16
%21 = tail call double @llvm.fabs.f64(double %5)
%22 = fcmp olt double %21, 0x3D06849B86A12B9B
br i1 %22, label %37, label %23
23: ; preds = %20
%24 = fcmp olt double %5, 0.000000e+00
%25 = load double, double* @M_PI
br i1 %24, label %26, label %28
26: ; preds = %23
%27 = fmul double %25, 1.500000e+00
br label %37
28: ; preds = %23
%29 = fmul double %25, 5.000000e-01
br label %37
30: ; preds = %16
%31 = fcmp ogt double %3, 0.000000e+00
%32 = fdiv double %5, %3
%33 = tail call double @atan(double %32)
br i1 %31, label %37, label %34
34: ; preds = %30
%35 = load double, double* @M_PI
%36 = fadd double %33, %35
br label %37
37: ; preds = %30, %20, %34, %28, %26
%38 = phi double [ %27, %26 ], [ %29, %28 ], [ %36, %34 ], [ 0.000000e+00, %20 ], [ %33, %30 ]
store double %11, double* %1
%39 = getelementptr inbounds double, double* %1, i64 1
store double %17, double* %39
%40 = getelementptr inbounds double, double* %1, i64 2
store double %38, double* %40
ret void
}