#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;
int atan2(double, double);
scalar_t__ sqrtf(float const);
void vectoangles(const float vec[3], float angles[3]) {
  double forward;
  double yaw, pitch;
  if (vec[1] == 0 && vec[0] == 0) {
    yaw = 0;
    if (vec[2] > 0) {
      pitch = 90;
    } else {
      pitch = 270;
    }
  } else {
    if (vec[0]) {
      yaw = (atan2((double)vec[1], (double)vec[0]) * 180 / M_PI);
    } else if (vec[1] > 0) {
      yaw = 90;
    } else {
      yaw = 270;
    }
    if (yaw < 0) {
      yaw += 360;
    }
    forward = (double)sqrtf(vec[0] * vec[0] + vec[1] * vec[1]);
    pitch = (atan2((double)vec[2], forward) * 180 / M_PI);
    if (pitch < 0) {
      pitch += 360;
    }
  }
  angles[0] = (float)(-pitch);
  angles[1] = (float)(yaw);
  angles[2] = 0.0f;
}


x86 assembly (clang, -O0):
<vectoangles>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movss  0x4(%rax),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    11a6 <vectoangles+0x86>
jp     11a6 <vectoangles+0x86>
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    11a6 <vectoangles+0x86>
jp     11a6 <vectoangles+0x86>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movss  0x8(%rax),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jbe    1194 <vectoangles+0x74>
movsd  0xe7e(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    11a1 <vectoangles+0x81>
movsd  0xe64(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    12e8 <vectoangles+0x1c8>
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    11c5 <vectoangles+0xa5>
jp     11c5 <vectoangles+0xa5>
jmp    1201 <vectoangles+0xe1>
mov    -0x8(%rbp),%rax
movss  0x4(%rax),%xmm0
cvtss2sd %xmm0,%xmm0
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm1
cvtss2sd %xmm1,%xmm1
call   1030 <atan2@plt>
imul   $0xb4,%eax,%eax
mov    0x2df8(%rip),%rcx
cltd
idivl  (%rcx)
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    123a <vectoangles+0x11a>
mov    -0x8(%rbp),%rax
movss  0x4(%rax),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jbe    1228 <vectoangles+0x108>
movsd  0xdea(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    1235 <vectoangles+0x115>
movsd  0xdd0(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    123a <vectoangles+0x11a>
xorps  %xmm0,%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    125a <vectoangles+0x13a>
movsd  0xdc0(%rip),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm0
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm2
mov    -0x8(%rbp),%rax
movss  0x4(%rax),%xmm1
mov    -0x8(%rbp),%rax
mulss  0x4(%rax),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
call   1040 <sqrtf@plt>
cvtsi2sd %rax,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movss  0x8(%rax),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  -0x18(%rbp),%xmm1
call   1030 <atan2@plt>
imul   $0xb4,%eax,%eax
mov    0x2d31(%rip),%rcx
cltd
idivl  (%rcx)
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x28(%rbp),%xmm0
jbe    12e3 <vectoangles+0x1c3>
movsd  0xd37(%rip),%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    12e8 <vectoangles+0x1c8>
movsd  -0x28(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
cvtsd2ss %xmm0,%xmm0
mov    -0x10(%rbp),%rax
movss  %xmm0,(%rax)
movsd  -0x20(%rbp),%xmm0
cvtsd2ss %xmm0,%xmm0
mov    -0x10(%rbp),%rax
movss  %xmm0,0x4(%rax)
mov    -0x10(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,0x8(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vectoangles>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
movss  (%rdi),%xmm0
movss  0x4(%rdi),%xmm1
xorps  %xmm2,%xmm2
ucomiss %xmm2,%xmm1
jne    1168 <vectoangles+0x48>
jp     1168 <vectoangles+0x48>
ucomiss %xmm2,%xmm0
jne    1168 <vectoangles+0x48>
jp     1168 <vectoangles+0x48>
movss  0x8(%rbx),%xmm1
xorps  %xmm0,%xmm0
xor    %eax,%eax
ucomiss %xmm0,%xmm1
seta   %al
lea    0xea2(%rip),%rcx
movsd  (%rcx,%rax,8),%xmm1
jmp    123a <vectoangles+0x11a>
ucomiss %xmm2,%xmm0
jne    116f <vectoangles+0x4f>
jnp    11a7 <vectoangles+0x87>
xorps  %xmm2,%xmm2
cvtss2sd %xmm1,%xmm2
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
movaps %xmm2,%xmm0
call   1030 <atan2@plt>
imul   $0xb4,%eax,%eax
mov    0x2e56(%rip),%rcx
cltd
idivl  (%rcx)
xorps  %xmm2,%xmm2
cvtsi2sd %eax,%xmm2
movss  (%rbx),%xmm0
movss  0x4(%rbx),%xmm1
jmp    11be <vectoangles+0x9e>
xorps  %xmm2,%xmm2
xor    %eax,%eax
ucomiss %xmm2,%xmm1
seta   %al
lea    0xe47(%rip),%rcx
movsd  (%rcx,%rax,8),%xmm2
movapd %xmm2,%xmm3
addsd  0xe56(%rip),%xmm3
xorpd  %xmm4,%xmm4
movapd %xmm2,%xmm5
cmpltsd %xmm4,%xmm5
andpd  %xmm5,%xmm3
andnpd %xmm2,%xmm5
orpd   %xmm3,%xmm5
movapd %xmm5,(%rsp)
mulss  %xmm1,%xmm1
mulss  %xmm0,%xmm0
addss  %xmm1,%xmm0
call   1040 <sqrtf@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
movss  0x8(%rbx),%xmm0
cvtss2sd %xmm0,%xmm0
call   1030 <atan2@plt>
imul   $0xb4,%eax,%eax
mov    0x2dcc(%rip),%rcx
cltd
idivl  (%rcx)
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
test   %eax,%eax
jns    1232 <vectoangles+0x112>
addsd  0xdee(%rip),%xmm1
movaps (%rsp),%xmm0
cvtsd2ss %xmm0,%xmm0
cvtsd2ss %xmm1,%xmm1
xorps  0xdcb(%rip),%xmm1
movss  %xmm1,(%r14)
movss  %xmm0,0x4(%r14)
movl   $0x0,0x8(%r14)
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@M_PI = global i32 0
define void @vectoangles(float* %0, float* %1) {
%3 = alloca float*
%4 = alloca float*
%5 = alloca double
%6 = alloca double
%7 = alloca double
store float* %0, float** %3
store float* %1, float** %4
%8 = load float*, float** %3
%9 = getelementptr inbounds float, float* %8, i64 1
%10 = load float, float* %9
%11 = fcmp oeq float %10, 0.000000e+00
br i1 %11, label %12, label %25
12: ; preds = %2
%13 = load float*, float** %3
%14 = getelementptr inbounds float, float* %13, i64 0
%15 = load float, float* %14
%16 = fcmp oeq float %15, 0.000000e+00
br i1 %16, label %17, label %25
17: ; preds = %12
store double 0.000000e+00, double* %6
%18 = load float*, float** %3
%19 = getelementptr inbounds float, float* %18, i64 2
%20 = load float, float* %19
%21 = fcmp ogt float %20, 0.000000e+00
br i1 %21, label %22, label %23
22: ; preds = %17
store double 9.000000e+01, double* %7
br label %24
23: ; preds = %17
store double 2.700000e+02, double* %7
br label %24
24: ; preds = %23, %22
br label %91
25: ; preds = %12, %2
%26 = load float*, float** %3
%27 = getelementptr inbounds float, float* %26, i64 0
%28 = load float, float* %27
%29 = fcmp une float %28, 0.000000e+00
br i1 %29, label %30, label %44
30: ; preds = %25
%31 = load float*, float** %3
%32 = getelementptr inbounds float, float* %31, i64 1
%33 = load float, float* %32
%34 = fpext float %33 to double
%35 = load float*, float** %3
%36 = getelementptr inbounds float, float* %35, i64 0
%37 = load float, float* %36
%38 = fpext float %37 to double
%39 = call i32 @atan2(double %34, double %38)
%40 = mul nsw i32 %39, 180
%41 = load i32, i32* @M_PI
%42 = sdiv i32 %40, %41
%43 = sitofp i32 %42 to double
store double %43, double* %6
br label %52
44: ; preds = %25
%45 = load float*, float** %3
%46 = getelementptr inbounds float, float* %45, i64 1
%47 = load float, float* %46
%48 = fcmp ogt float %47, 0.000000e+00
br i1 %48, label %49, label %50
49: ; preds = %44
store double 9.000000e+01, double* %6
br label %51
50: ; preds = %44
store double 2.700000e+02, double* %6
br label %51
51: ; preds = %50, %49
br label %52
52: ; preds = %51, %30
%53 = load double, double* %6
%54 = fcmp olt double %53, 0.000000e+00
br i1 %54, label %55, label %58
55: ; preds = %52
%56 = load double, double* %6
%57 = fadd double %56, 3.600000e+02
store double %57, double* %6
br label %58
58: ; preds = %55, %52
%59 = load float*, float** %3
%60 = getelementptr inbounds float, float* %59, i64 0
%61 = load float, float* %60
%62 = load float*, float** %3
%63 = getelementptr inbounds float, float* %62, i64 0
%64 = load float, float* %63
%65 = load float*, float** %3
%66 = getelementptr inbounds float, float* %65, i64 1
%67 = load float, float* %66
%68 = load float*, float** %3
%69 = getelementptr inbounds float, float* %68, i64 1
%70 = load float, float* %69
%71 = fmul float %67, %70
%72 = call float @llvm.fmuladd.f32(float %61, float %64, float %71)
%73 = call i64 @sqrtf(float %72)
%74 = sitofp i64 %73 to double
store double %74, double* %5
%75 = load float*, float** %3
%76 = getelementptr inbounds float, float* %75, i64 2
%77 = load float, float* %76
%78 = fpext float %77 to double
%79 = load double, double* %5
%80 = call i32 @atan2(double %78, double %79)
%81 = mul nsw i32 %80, 180
%82 = load i32, i32* @M_PI
%83 = sdiv i32 %81, %82
%84 = sitofp i32 %83 to double
store double %84, double* %7
%85 = load double, double* %7
%86 = fcmp olt double %85, 0.000000e+00
br i1 %86, label %87, label %90
87: ; preds = %58
%88 = load double, double* %7
%89 = fadd double %88, 3.600000e+02
store double %89, double* %7
br label %90
90: ; preds = %87, %58
br label %91
91: ; preds = %90, %24
%92 = load double, double* %7
%93 = fneg double %92
%94 = fptrunc double %93 to float
%95 = load float*, float** %4
%96 = getelementptr inbounds float, float* %95, i64 0
store float %94, float* %96
%97 = load double, double* %6
%98 = fptrunc double %97 to float
%99 = load float*, float** %4
%100 = getelementptr inbounds float, float* %99, i64 1
store float %98, float* %100
%101 = load float*, float** %4
%102 = getelementptr inbounds float, float* %101, i64 2
store float 0.000000e+00, float* %102
ret void
}

LLVM IR (-O2):
@M_PI = global i32 0
define void @vectoangles(float* nocapture %0, float* nocapture writeonly %1) {
%3 = getelementptr inbounds float, float* %0, i64 1
%4 = load float, float* %3
%5 = fcmp oeq float %4, 0.000000e+00
%6 = load float, float* %0
%7 = fcmp oeq float %6, 0.000000e+00
%8 = select i1 %5, i1 %7, i1 false
br i1 %8, label %9, label %14
9: ; preds = %2
%10 = getelementptr inbounds float, float* %0, i64 2
%11 = load float, float* %10
%12 = fcmp ogt float %11, 0.000000e+00
%13 = select i1 %12, double 9.000000e+01, double 2.700000e+02
br label %52
14: ; preds = %2
%15 = fcmp une float %6, 0.000000e+00
br i1 %15, label %16, label %26
16: ; preds = %14
%17 = fpext float %4 to double
%18 = fpext float %6 to double
%19 = tail call i32 @atan2(double %17, double %18)
%20 = mul nsw i32 %19, 180
%21 = load i32, i32* @M_PI
%22 = sdiv i32 %20, %21
%23 = sitofp i32 %22 to double
%24 = load float, float* %0
%25 = load float, float* %3
br label %29
26: ; preds = %14
%27 = fcmp ogt float %4, 0.000000e+00
%28 = select i1 %27, double 9.000000e+01, double 2.700000e+02
br label %29
29: ; preds = %26, %16
%30 = phi float [ %25, %16 ], [ %4, %26 ]
%31 = phi float [ %24, %16 ], [ %6, %26 ]
%32 = phi double [ %23, %16 ], [ %28, %26 ]
%33 = fcmp olt double %32, 0.000000e+00
%34 = fadd double %32, 3.600000e+02
%35 = select i1 %33, double %34, double %32
%36 = fmul float %30, %30
%37 = tail call float @llvm.fmuladd.f32(float %31, float %31, float %36)
%38 = tail call i64 @sqrtf(float %37)
%39 = sitofp i64 %38 to double
%40 = getelementptr inbounds float, float* %0, i64 2
%41 = load float, float* %40
%42 = fpext float %41 to double
%43 = tail call i32 @atan2(double %42, double %39)
%44 = mul nsw i32 %43, 180
%45 = load i32, i32* @M_PI
%46 = sdiv i32 %44, %45
%47 = sitofp i32 %46 to double
%48 = icmp slt i32 %46, 0
%49 = fadd double %47, 3.600000e+02
%50 = select i1 %48, double %49, double %47
%51 = fptrunc double %35 to float
br label %52
52: ; preds = %29, %9
%53 = phi float [ 0.000000e+00, %9 ], [ %51, %29 ]
%54 = phi double [ %13, %9 ], [ %50, %29 ]
%55 = fptrunc double %54 to float
%56 = fneg float %55
store float %56, float* %1
%57 = getelementptr inbounds float, float* %1, i64 1
store float %53, float* %57
%58 = getelementptr inbounds float, float* %1, i64 2
store float 0.000000e+00, float* %58
ret void
}