#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 sqrt(int);
void calculate_unit_vectors_spherical(double pos[3], double erad[3],
                                      double ephi[3], double etheta[3]) {
  double dist;
  double cosphi, sinphi, costheta, sintheta;
  dist = sqrt(pos[0] * pos[0] + pos[1] * pos[1]);
  cosphi = pos[0] / dist;
  sinphi = pos[1] / dist;
  if ((pos[0] == 0) && (pos[1] == 0)) {
    cosphi = 1;
    sinphi = 0;
  }
  dist = sqrt(pos[0] * pos[0] + pos[1] * pos[1] + pos[2] * pos[2]);
  costheta = pos[2] / dist;
  sintheta = sqrt(1 - costheta * costheta);
  if (dist == 0) {
    cosphi = 0;
    sinphi = 0;
    costheta = 0;
    sintheta = 0;
  }
  erad[0] = sintheta * cosphi;
  erad[1] = sintheta * sinphi;
  erad[2] = costheta;
  ephi[0] = -sinphi;
  ephi[1] = cosphi;
  ephi[2] = 0;
  etheta[0] = -costheta * cosphi;
  etheta[1] = -costheta * sinphi;
  etheta[2] = sintheta;
}


x86 assembly (clang, -O0):
<calculate_unit_vectors_spherical>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm2
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm1
mov    -0x8(%rbp),%rax
mulsd  0x8(%rax),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1030 <sqrt@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
divsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
divsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11d1 <calculate_unit_vectors_spherical+0xc1>
jp     11d1 <calculate_unit_vectors_spherical+0xc1>
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11d1 <calculate_unit_vectors_spherical+0xc1>
jp     11d1 <calculate_unit_vectors_spherical+0xc1>
movsd  0xe3c(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%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
cvttsd2si %xmm0,%edi
call   1030 <sqrt@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm0
divsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm1
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm1,%xmm0
movsd  0xd9d(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1030 <sqrt@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x28(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    12ad <calculate_unit_vectors_spherical+0x19d>
jp     12ad <calculate_unit_vectors_spherical+0x19d>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x48(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x8(%rax)
movsd  -0x40(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x10(%rax)
movsd  -0x38(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x30(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,0x8(%rax)
mov    -0x18(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,0x10(%rax)
movsd  -0x40(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  -0x30(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x40(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  -0x38(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,0x8(%rax)
movsd  -0x48(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,0x10(%rax)
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calculate_unit_vectors_spherical>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%rbx
movsd  (%rdi),%xmm0
movsd  0x8(%rdi),%xmm1
mulsd  %xmm1,%xmm1
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1030 <sqrt@plt>
movupd (%rbx),%xmm1
unpcklpd %xmm0,%xmm0
movapd %xmm1,%xmm3
xorpd  %xmm4,%xmm4
ucomisd %xmm4,%xmm1
setnp  %al
sete   %cl
and    %al,%cl
movapd %xmm1,%xmm2
unpckhpd %xmm1,%xmm2
ucomisd %xmm4,%xmm2
divpd  %xmm0,%xmm3
movapd %xmm3,0x20(%rsp)
setnp  %al
sete   %dl
and    %al,%dl
and    %cl,%dl
movzbl %dl,%eax
movd   %eax,%xmm0
pshufd $0x44,%xmm0,%xmm0
psllq  $0x3f,%xmm0
psrad  $0x1f,%xmm0
pshufd $0xf5,%xmm0,%xmm0
movdqa %xmm0,0x10(%rsp)
mulsd  %xmm2,%xmm2
mulsd  %xmm1,%xmm1
addsd  %xmm2,%xmm1
movsd  0x10(%rbx),%xmm0
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1030 <sqrt@plt>
movapd %xmm0,%xmm1
movsd  %xmm0,0x8(%rsp)
movsd  0x10(%rbx),%xmm0
divsd  %xmm1,%xmm0
movapd %xmm0,0x30(%rsp)
mulsd  %xmm0,%xmm0
movsd  0xe17(%rip),%xmm1
subsd  %xmm0,%xmm1
cvttsd2si %xmm1,%edi
call   1030 <sqrt@plt>
movsd  0x8(%rsp),%xmm1
ucomisd 0xe04(%rip),%xmm1
jne    1228 <calculate_unit_vectors_spherical+0x118>
movsd  0xdf2(%rip),%xmm3
movapd 0x30(%rsp),%xmm4
movapd 0x20(%rsp),%xmm1
movapd 0x10(%rsp),%xmm2
jp     1242 <calculate_unit_vectors_spherical+0x132>
xorpd  %xmm4,%xmm4
jmp    1242 <calculate_unit_vectors_spherical+0x132>
movsd  0xdd0(%rip),%xmm3
movapd 0x30(%rsp),%xmm4
movapd 0x20(%rsp),%xmm1
movapd 0x10(%rsp),%xmm2
andpd  %xmm2,%xmm3
andnpd %xmm1,%xmm2
jne    1252 <calculate_unit_vectors_spherical+0x142>
jp     1252 <calculate_unit_vectors_spherical+0x142>
xorpd  %xmm0,%xmm0
orpd   %xmm2,%xmm3
jne    125e <calculate_unit_vectors_spherical+0x14e>
jp     125e <calculate_unit_vectors_spherical+0x14e>
xorpd  %xmm3,%xmm3
movapd %xmm0,%xmm1
unpcklpd %xmm0,%xmm1
mulpd  %xmm3,%xmm1
movupd %xmm1,(%r12)
movsd  %xmm4,0x10(%r12)
movapd %xmm3,%xmm1
unpckhpd %xmm3,%xmm1
movapd 0xd89(%rip),%xmm2
xorpd  %xmm2,%xmm1
unpcklpd %xmm3,%xmm1
movupd %xmm1,(%r15)
movq   $0x0,0x10(%r15)
xorpd  %xmm2,%xmm4
pshufd $0x44,%xmm4,%xmm1
mulpd  %xmm3,%xmm1
movupd %xmm1,(%r14)
movsd  %xmm0,0x10(%r14)
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @calculate_unit_vectors_spherical(double* %0, double* %1, double* %2, double* %3) {
%5 = alloca double*
%6 = alloca double*
%7 = alloca double*
%8 = alloca double*
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
store double* %0, double** %5
store double* %1, double** %6
store double* %2, double** %7
store double* %3, double** %8
%14 = load double*, double** %5
%15 = getelementptr inbounds double, double* %14, i64 0
%16 = load double, double* %15
%17 = load double*, double** %5
%18 = getelementptr inbounds double, double* %17, i64 0
%19 = load double, double* %18
%20 = load double*, double** %5
%21 = getelementptr inbounds double, double* %20, i64 1
%22 = load double, double* %21
%23 = load double*, double** %5
%24 = getelementptr inbounds double, double* %23, i64 1
%25 = load double, double* %24
%26 = fmul double %22, %25
%27 = call double @llvm.fmuladd.f64(double %16, double %19, double %26)
%28 = fptosi double %27 to i32
%29 = call double @sqrt(i32 %28)
store double %29, double* %9
%30 = load double*, double** %5
%31 = getelementptr inbounds double, double* %30, i64 0
%32 = load double, double* %31
%33 = load double, double* %9
%34 = fdiv double %32, %33
store double %34, double* %10
%35 = load double*, double** %5
%36 = getelementptr inbounds double, double* %35, i64 1
%37 = load double, double* %36
%38 = load double, double* %9
%39 = fdiv double %37, %38
store double %39, double* %11
%40 = load double*, double** %5
%41 = getelementptr inbounds double, double* %40, i64 0
%42 = load double, double* %41
%43 = fcmp oeq double %42, 0.000000e+00
br i1 %43, label %44, label %50
44: ; preds = %4
%45 = load double*, double** %5
%46 = getelementptr inbounds double, double* %45, i64 1
%47 = load double, double* %46
%48 = fcmp oeq double %47, 0.000000e+00
br i1 %48, label %49, label %50
49: ; preds = %44
store double 1.000000e+00, double* %10
store double 0.000000e+00, double* %11
br label %50
50: ; preds = %49, %44, %4
%51 = load double*, double** %5
%52 = getelementptr inbounds double, double* %51, i64 0
%53 = load double, double* %52
%54 = load double*, double** %5
%55 = getelementptr inbounds double, double* %54, i64 0
%56 = load double, double* %55
%57 = load double*, double** %5
%58 = getelementptr inbounds double, double* %57, i64 1
%59 = load double, double* %58
%60 = load double*, double** %5
%61 = getelementptr inbounds double, double* %60, i64 1
%62 = load double, double* %61
%63 = fmul double %59, %62
%64 = call double @llvm.fmuladd.f64(double %53, double %56, double %63)
%65 = load double*, double** %5
%66 = getelementptr inbounds double, double* %65, i64 2
%67 = load double, double* %66
%68 = load double*, double** %5
%69 = getelementptr inbounds double, double* %68, i64 2
%70 = load double, double* %69
%71 = call double @llvm.fmuladd.f64(double %67, double %70, double %64)
%72 = fptosi double %71 to i32
%73 = call double @sqrt(i32 %72)
store double %73, double* %9
%74 = load double*, double** %5
%75 = getelementptr inbounds double, double* %74, i64 2
%76 = load double, double* %75
%77 = load double, double* %9
%78 = fdiv double %76, %77
store double %78, double* %12
%79 = load double, double* %12
%80 = load double, double* %12
%81 = fneg double %79
%82 = call double @llvm.fmuladd.f64(double %81, double %80, double 1.000000e+00)
%83 = fptosi double %82 to i32
%84 = call double @sqrt(i32 %83)
store double %84, double* %13
%85 = load double, double* %9
%86 = fcmp oeq double %85, 0.000000e+00
br i1 %86, label %87, label %88
87: ; preds = %50
store double 0.000000e+00, double* %10
store double 0.000000e+00, double* %11
store double 0.000000e+00, double* %12
store double 0.000000e+00, double* %13
br label %88
88: ; preds = %87, %50
%89 = load double, double* %13
%90 = load double, double* %10
%91 = fmul double %89, %90
%92 = load double*, double** %6
%93 = getelementptr inbounds double, double* %92, i64 0
store double %91, double* %93
%94 = load double, double* %13
%95 = load double, double* %11
%96 = fmul double %94, %95
%97 = load double*, double** %6
%98 = getelementptr inbounds double, double* %97, i64 1
store double %96, double* %98
%99 = load double, double* %12
%100 = load double*, double** %6
%101 = getelementptr inbounds double, double* %100, i64 2
store double %99, double* %101
%102 = load double, double* %11
%103 = fneg double %102
%104 = load double*, double** %7
%105 = getelementptr inbounds double, double* %104, i64 0
store double %103, double* %105
%106 = load double, double* %10
%107 = load double*, double** %7
%108 = getelementptr inbounds double, double* %107, i64 1
store double %106, double* %108
%109 = load double*, double** %7
%110 = getelementptr inbounds double, double* %109, i64 2
store double 0.000000e+00, double* %110
%111 = load double, double* %12
%112 = fneg double %111
%113 = load double, double* %10
%114 = fmul double %112, %113
%115 = load double*, double** %8
%116 = getelementptr inbounds double, double* %115, i64 0
store double %114, double* %116
%117 = load double, double* %12
%118 = fneg double %117
%119 = load double, double* %11
%120 = fmul double %118, %119
%121 = load double*, double** %8
%122 = getelementptr inbounds double, double* %121, i64 1
store double %120, double* %122
%123 = load double, double* %13
%124 = load double*, double** %8
%125 = getelementptr inbounds double, double* %124, i64 2
store double %123, double* %125
ret void
}

LLVM IR (-O2):
define void @calculate_unit_vectors_spherical(double* nocapture %0, double* nocapture writeonly %1, double* nocapture writeonly %2, double* nocapture writeonly %3) {
%5 = load double, double* %0
%6 = getelementptr inbounds double, double* %0, i64 1
%7 = load double, double* %6
%8 = fmul double %7, %7
%9 = tail call double @llvm.fmuladd.f64(double %5, double %5, double %8)
%10 = fptosi double %9 to i32
%11 = tail call double @sqrt(i32 %10)
%12 = bitcast double* %0 to <2 x double>*
%13 = load <2 x double>, <2 x double>* %12
%14 = insertelement <2 x double> poison, double %11, i64 0
%15 = shufflevector <2 x double> %14, <2 x double> poison, <2 x i32> zeroinitializer
%16 = fdiv <2 x double> %13, %15
%17 = extractelement <2 x double> %13, i64 0
%18 = fcmp oeq double %17, 0.000000e+00
%19 = extractelement <2 x double> %13, i64 1
%20 = fcmp oeq double %19, 0.000000e+00
%21 = select i1 %18, i1 %20, i1 false
%22 = insertelement <2 x i1> poison, i1 %21, i64 0
%23 = shufflevector <2 x i1> %22, <2 x i1> poison, <2 x i32> zeroinitializer
%24 = select <2 x i1> %23, <2 x double> <double 1.000000e+00, double 0.000000e+00>, <2 x double> %16
%25 = fmul double %19, %19
%26 = tail call double @llvm.fmuladd.f64(double %17, double %17, double %25)
%27 = getelementptr inbounds double, double* %0, i64 2
%28 = load double, double* %27
%29 = tail call double @llvm.fmuladd.f64(double %28, double %28, double %26)
%30 = fptosi double %29 to i32
%31 = tail call double @sqrt(i32 %30)
%32 = load double, double* %27
%33 = fdiv double %32, %31
%34 = fneg double %33
%35 = tail call double @llvm.fmuladd.f64(double %34, double %33, double 1.000000e+00)
%36 = fptosi double %35 to i32
%37 = tail call double @sqrt(i32 %36)
%38 = fcmp oeq double %31, 0.000000e+00
%39 = select i1 %38, double 0.000000e+00, double %33
%40 = select i1 %38, double 0.000000e+00, double %37
%41 = select i1 %38, <2 x double> zeroinitializer, <2 x double> %24
%42 = insertelement <2 x double> poison, double %40, i64 0
%43 = shufflevector <2 x double> %42, <2 x double> poison, <2 x i32> zeroinitializer
%44 = fmul <2 x double> %41, %43
%45 = bitcast double* %1 to <2 x double>*
store <2 x double> %44, <2 x double>* %45
%46 = getelementptr inbounds double, double* %1, i64 2
store double %39, double* %46
%47 = extractelement <2 x double> %41, i64 1
%48 = fneg double %47
store double %48, double* %2
%49 = getelementptr inbounds double, double* %2, i64 1
%50 = extractelement <2 x double> %41, i64 0
store double %50, double* %49
%51 = getelementptr inbounds double, double* %2, i64 2
store double 0.000000e+00, double* %51
%52 = fneg double %39
%53 = insertelement <2 x double> poison, double %52, i64 0
%54 = shufflevector <2 x double> %53, <2 x double> poison, <2 x i32> zeroinitializer
%55 = fmul <2 x double> %41, %54
%56 = bitcast double* %3 to <2 x double>*
store <2 x double> %55, <2 x double>* %56
%57 = getelementptr inbounds double, double* %3, i64 2
store double %40, double* %57
ret void
}