#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 */
int M_PI;
double acos(double);
double atan2(double, double);
double sqrt(double);
void vec2ang(double *vec, double *theta, double *phi) {
  double norm;
  double twopi = 2 * M_PI;
  norm = sqrt(vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2]);
  *theta = acos(vec[2] / norm);
  *phi = 0.0;
  if (vec[0] != 0.0 || vec[1] != 0.0) {
    *phi = atan2(vec[1], vec[0]);
    if (*phi < 0.0)
      *phi += twopi;
  }
}


x86 assembly (clang, -O0):
<vec2ang>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    0x2e9d(%rip),%rax
mov    (%rax),%eax
shl    $0x1,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x28(%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
call   1050 <sqrt@plt>
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm0
divsd  -0x20(%rbp),%xmm0
call   1040 <acos@plt>
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x18(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1209 <vec2ang+0xd9>
jp     1209 <vec2ang+0xd9>
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1209 <vec2ang+0xd9>
jp     1209 <vec2ang+0xd9>
jmp    124e <vec2ang+0x11e>
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm1
call   1030 <atan2@plt>
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x18(%rbp),%rax
xorps  %xmm0,%xmm0
ucomisd (%rax),%xmm0
jbe    1249 <vec2ang+0x119>
movsd  -0x28(%rbp),%xmm0
mov    -0x18(%rbp),%rax
addsd  (%rax),%xmm0
movsd  %xmm0,(%rax)
jmp    124e <vec2ang+0x11e>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vec2ang>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    0x2ea1(%rip),%rax
mov    (%rax),%ebp
movsd  (%rdi),%xmm1
movsd  0x8(%rdi),%xmm0
mulsd  %xmm0,%xmm0
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  0x10(%rdi),%xmm0
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     117b <vec2ang+0x4b>
sqrtsd %xmm0,%xmm0
jmp    1180 <vec2ang+0x50>
call   1050 <sqrt@plt>
movsd  0x10(%rbx),%xmm1
divsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
call   1040 <acos@plt>
movsd  %xmm0,(%r15)
movq   $0x0,(%r14)
movsd  (%rbx),%xmm1
movsd  0x8(%rbx),%xmm0
ucomisd 0xe51(%rip),%xmm1
jne    11bf <vec2ang+0x8f>
jp     11bf <vec2ang+0x8f>
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm0
jne    11bf <vec2ang+0x8f>
jnp    11e5 <vec2ang+0xb5>
call   1030 <atan2@plt>
movsd  %xmm0,(%r14)
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jbe    11e5 <vec2ang+0xb5>
add    %ebp,%ebp
xorps  %xmm1,%xmm1
cvtsi2sd %ebp,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@M_PI = global i32 0
define void @vec2ang(double* %0, double* %1, double* %2) {
%4 = alloca double*
%5 = alloca double*
%6 = alloca double*
%7 = alloca double
%8 = alloca double
store double* %0, double** %4
store double* %1, double** %5
store double* %2, double** %6
%9 = load i32, i32* @M_PI
%10 = mul nsw i32 2, %9
%11 = sitofp i32 %10 to double
store double %11, double* %8
%12 = load double*, double** %4
%13 = getelementptr inbounds double, double* %12, i64 0
%14 = load double, double* %13
%15 = load double*, double** %4
%16 = getelementptr inbounds double, double* %15, i64 0
%17 = load double, double* %16
%18 = load double*, double** %4
%19 = getelementptr inbounds double, double* %18, i64 1
%20 = load double, double* %19
%21 = load double*, double** %4
%22 = getelementptr inbounds double, double* %21, i64 1
%23 = load double, double* %22
%24 = fmul double %20, %23
%25 = call double @llvm.fmuladd.f64(double %14, double %17, double %24)
%26 = load double*, double** %4
%27 = getelementptr inbounds double, double* %26, i64 2
%28 = load double, double* %27
%29 = load double*, double** %4
%30 = getelementptr inbounds double, double* %29, i64 2
%31 = load double, double* %30
%32 = call double @llvm.fmuladd.f64(double %28, double %31, double %25)
%33 = call double @sqrt(double %32)
store double %33, double* %7
%34 = load double*, double** %4
%35 = getelementptr inbounds double, double* %34, i64 2
%36 = load double, double* %35
%37 = load double, double* %7
%38 = fdiv double %36, %37
%39 = call double @acos(double %38)
%40 = load double*, double** %5
store double %39, double* %40
%41 = load double*, double** %6
store double 0.000000e+00, double* %41
%42 = load double*, double** %4
%43 = getelementptr inbounds double, double* %42, i64 0
%44 = load double, double* %43
%45 = fcmp une double %44, 0.000000e+00
br i1 %45, label %51, label %46
46: ; preds = %3
%47 = load double*, double** %4
%48 = getelementptr inbounds double, double* %47, i64 1
%49 = load double, double* %48
%50 = fcmp une double %49, 0.000000e+00
br i1 %50, label %51, label %69
51: ; preds = %46, %3
%52 = load double*, double** %4
%53 = getelementptr inbounds double, double* %52, i64 1
%54 = load double, double* %53
%55 = load double*, double** %4
%56 = getelementptr inbounds double, double* %55, i64 0
%57 = load double, double* %56
%58 = call double @atan2(double %54, double %57)
%59 = load double*, double** %6
store double %58, double* %59
%60 = load double*, double** %6
%61 = load double, double* %60
%62 = fcmp olt double %61, 0.000000e+00
br i1 %62, label %63, label %68
63: ; preds = %51
%64 = load double, double* %8
%65 = load double*, double** %6
%66 = load double, double* %65
%67 = fadd double %66, %64
store double %67, double* %65
br label %68
68: ; preds = %63, %51
br label %69
69: ; preds = %68, %46
ret void
}

LLVM IR (-O2):
@M_PI = global i32 0
define void @vec2ang(double* nocapture %0, double* nocapture writeonly %1, double* nocapture writeonly %2) {
%4 = load i32, i32* @M_PI
%5 = shl nsw i32 %4, 1
%6 = sitofp i32 %5 to double
%7 = load double, double* %0
%8 = getelementptr inbounds double, double* %0, i64 1
%9 = load double, double* %8
%10 = fmul double %9, %9
%11 = tail call double @llvm.fmuladd.f64(double %7, double %7, double %10)
%12 = getelementptr inbounds double, double* %0, i64 2
%13 = load double, double* %12
%14 = tail call double @llvm.fmuladd.f64(double %13, double %13, double %11)
%15 = tail call double @sqrt(double %14)
%16 = load double, double* %12
%17 = fdiv double %16, %15
%18 = tail call double @acos(double %17)
store double %18, double* %1
store double 0.000000e+00, double* %2
%19 = load double, double* %0
%20 = fcmp une double %19, 0.000000e+00
%21 = load double, double* %8
%22 = fcmp une double %21, 0.000000e+00
%23 = select i1 %20, i1 true, i1 %22
br i1 %23, label %24, label %29
24: ; preds = %3
%25 = tail call double @atan2(double %21, double %19)
store double %25, double* %2
%26 = fcmp olt double %25, 0.000000e+00
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = fadd double %25, %6
store double %28, double* %2
br label %29
29: ; preds = %3, %24, %27
ret void
}