#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 atan2(float, float);
float floats_magnitude(float *, int);
int /*<<< orphan*/ floats_normalize(float const *, int, float *);
scalar_t__ mod2pi(int);
void floats_quat_to_angleaxis(const float _q[4], float r[4]) {
  float q[4];
  floats_normalize(_q, 4, q);
  float mag = floats_magnitude(&q[1], 3);
  r[0] = (float)mod2pi(2 * atan2(mag, q[0]));
  if (mag != 0) {
    r[1] = q[1] / mag;
    r[2] = q[2] / mag;
    r[3] = q[3] / mag;
  } else {
    r[1] = 1;
    r[2] = 0;
    r[3] = 0;
  }
}


x86 assembly (clang, -O0):
<floats_quat_to_angleaxis>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rdx
mov    $0x4,%esi
call   1060 <floats_normalize@plt>
lea    -0x20(%rbp),%rdi
add    $0x4,%rdi
mov    $0x3,%esi
call   1050 <floats_magnitude@plt>
movss  %xmm0,-0x24(%rbp)
movss  -0x24(%rbp),%xmm0
movss  -0x20(%rbp),%xmm1
call   1040 <atan2@plt>
mov    %eax,%edi
shl    $0x1,%edi
call   1030 <mod2pi@plt>
cvtsi2ss %rax,%xmm0
mov    -0x10(%rbp),%rax
movss  %xmm0,(%rax)
movss  -0x24(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    11bb <floats_quat_to_angleaxis+0x7b>
jp     11bb <floats_quat_to_angleaxis+0x7b>
jmp    11f9 <floats_quat_to_angleaxis+0xb9>
movss  -0x1c(%rbp),%xmm0
divss  -0x24(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movss  %xmm0,0x4(%rax)
movss  -0x18(%rbp),%xmm0
divss  -0x24(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movss  %xmm0,0x8(%rax)
movss  -0x14(%rbp),%xmm0
divss  -0x24(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movss  %xmm0,0xc(%rax)
jmp    1222 <floats_quat_to_angleaxis+0xe2>
mov    -0x10(%rbp),%rax
movss  0xdfb(%rip),%xmm0
movss  %xmm0,0x4(%rax)
mov    -0x10(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,0x8(%rax)
mov    -0x10(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,0xc(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<floats_quat_to_angleaxis>:
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%rbx
mov    %rsp,%rdx
mov    $0x4,%esi
call   1060 <floats_normalize@plt>
lea    0x4(%rsp),%rdi
mov    $0x3,%esi
call   1050 <floats_magnitude@plt>
movaps %xmm0,0x10(%rsp)
movss  (%rsp),%xmm1
call   1040 <atan2@plt>
lea    (%rax,%rax,1),%edi
call   1030 <mod2pi@plt>
movaps 0x10(%rsp),%xmm2
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
movss  %xmm0,(%rbx)
xorps  %xmm0,%xmm0
ucomiss %xmm0,%xmm2
jne    1196 <floats_quat_to_angleaxis+0x56>
jnp    11af <floats_quat_to_angleaxis+0x6f>
movss  0x4(%rsp),%xmm1
divss  %xmm2,%xmm1
movsd  0x8(%rsp),%xmm0
shufps $0x0,%xmm2,%xmm2
divps  %xmm2,%xmm0
jmp    11ba <floats_quat_to_angleaxis+0x7a>
xorps  %xmm0,%xmm0
movss  0xe46(%rip),%xmm1
movss  %xmm1,0x4(%rbx)
movss  %xmm0,0x8(%rbx)
shufps $0x55,%xmm0,%xmm0
movss  %xmm0,0xc(%rbx)
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define void @floats_quat_to_angleaxis(float* %0, float* %1) {
%3 = alloca float*
%4 = alloca float*
%5 = alloca [4 x float]
%6 = alloca float
store float* %0, float** %3
store float* %1, float** %4
%7 = load float*, float** %3
%8 = getelementptr inbounds [4 x float], [4 x float]* %5, i64 0, i64 0
%9 = call i32 @floats_normalize(float* %7, i32 4, float* %8)
%10 = getelementptr inbounds [4 x float], [4 x float]* %5, i64 0, i64 1
%11 = call float @floats_magnitude(float* %10, i32 3)
store float %11, float* %6
%12 = load float, float* %6
%13 = getelementptr inbounds [4 x float], [4 x float]* %5, i64 0, i64 0
%14 = load float, float* %13
%15 = call i32 @atan2(float %12, float %14)
%16 = mul nsw i32 2, %15
%17 = call i64 @mod2pi(i32 %16)
%18 = sitofp i64 %17 to float
%19 = load float*, float** %4
%20 = getelementptr inbounds float, float* %19, i64 0
store float %18, float* %20
%21 = load float, float* %6
%22 = fcmp une float %21, 0.000000e+00
br i1 %22, label %23, label %42
23: ; preds = %2
%24 = getelementptr inbounds [4 x float], [4 x float]* %5, i64 0, i64 1
%25 = load float, float* %24
%26 = load float, float* %6
%27 = fdiv float %25, %26
%28 = load float*, float** %4
%29 = getelementptr inbounds float, float* %28, i64 1
store float %27, float* %29
%30 = getelementptr inbounds [4 x float], [4 x float]* %5, i64 0, i64 2
%31 = load float, float* %30
%32 = load float, float* %6
%33 = fdiv float %31, %32
%34 = load float*, float** %4
%35 = getelementptr inbounds float, float* %34, i64 2
store float %33, float* %35
%36 = getelementptr inbounds [4 x float], [4 x float]* %5, i64 0, i64 3
%37 = load float, float* %36
%38 = load float, float* %6
%39 = fdiv float %37, %38
%40 = load float*, float** %4
%41 = getelementptr inbounds float, float* %40, i64 3
store float %39, float* %41
br label %49
42: ; preds = %2
%43 = load float*, float** %4
%44 = getelementptr inbounds float, float* %43, i64 1
store float 1.000000e+00, float* %44
%45 = load float*, float** %4
%46 = getelementptr inbounds float, float* %45, i64 2
store float 0.000000e+00, float* %46
%47 = load float*, float** %4
%48 = getelementptr inbounds float, float* %47, i64 3
store float 0.000000e+00, float* %48
br label %49
49: ; preds = %42, %23
ret void
}

LLVM IR (-O2):
define void @floats_quat_to_angleaxis(float* %0, float* nocapture writeonly %1) {
%3 = alloca [4 x float]
%4 = bitcast [4 x float]* %3 to i8*
%5 = getelementptr inbounds [4 x float], [4 x float]* %3, i64 0, i64 0
%6 = call i32 @floats_normalize(float* %0, i32 4, float* %5)
%7 = getelementptr inbounds [4 x float], [4 x float]* %3, i64 0, i64 1
%8 = call float @floats_magnitude(float* %7, i32 3)
%9 = load float, float* %5
%10 = call i32 @atan2(float %8, float %9)
%11 = shl nsw i32 %10, 1
%12 = call i64 @mod2pi(i32 %11)
%13 = sitofp i64 %12 to float
store float %13, float* %1
%14 = fcmp une float %8, 0.000000e+00
br i1 %14, label %15, label %24
15: ; preds = %2
%16 = load float, float* %7
%17 = fdiv float %16, %8
%18 = getelementptr inbounds [4 x float], [4 x float]* %3, i64 0, i64 2
%19 = bitcast float* %18 to <2 x float>*
%20 = load <2 x float>, <2 x float>* %19
%21 = insertelement <2 x float> poison, float %8, i64 0
%22 = shufflevector <2 x float> %21, <2 x float> poison, <2 x i32> zeroinitializer
%23 = fdiv <2 x float> %20, %22
br label %24
24: ; preds = %2, %15
%25 = phi float [ %17, %15 ], [ 1.000000e+00, %2 ]
%26 = phi <2 x float> [ %23, %15 ], [ zeroinitializer, %2 ]
%27 = getelementptr inbounds float, float* %1, i64 1
store float %25, float* %27
%28 = getelementptr inbounds float, float* %1, i64 2
%29 = extractelement <2 x float> %26, i64 0
store float %29, float* %28
%30 = getelementptr inbounds float, float* %1, i64 3
%31 = extractelement <2 x float> %26, i64 1
store float %31, float* %30
ret void
}