#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 *);
float 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] = 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>
mov    -0x10(%rbp),%rax
movss  %xmm0,(%rax)
movss  -0x24(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    11b6 <floats_quat_to_angleaxis+0x76>
jp     11b6 <floats_quat_to_angleaxis+0x76>
jmp    11f4 <floats_quat_to_angleaxis+0xb4>
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    121d <floats_quat_to_angleaxis+0xdd>
mov    -0x10(%rbp),%rax
movss  0xe00(%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
movss  %xmm0,(%rbx)
xorps  %xmm0,%xmm0
ucomiss %xmm0,%xmm2
jne    118e <floats_quat_to_angleaxis+0x4e>
jnp    11a7 <floats_quat_to_angleaxis+0x67>
movss  0x4(%rsp),%xmm1
divss  %xmm2,%xmm1
movsd  0x8(%rsp),%xmm0
shufps $0x0,%xmm2,%xmm2
divps  %xmm2,%xmm0
jmp    11b2 <floats_quat_to_angleaxis+0x72>
xorps  %xmm0,%xmm0
movss  0xe4e(%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 float @mod2pi(i32 %16)
%18 = load float*, float** %4
%19 = getelementptr inbounds float, float* %18, i64 0
store float %17, float* %19
%20 = load float, float* %6
%21 = fcmp une float %20, 0.000000e+00
br i1 %21, label %22, label %41
22: ; preds = %2
%23 = getelementptr inbounds [4 x float], [4 x float]* %5, i64 0, i64 1
%24 = load float, float* %23
%25 = load float, float* %6
%26 = fdiv float %24, %25
%27 = load float*, float** %4
%28 = getelementptr inbounds float, float* %27, i64 1
store float %26, float* %28
%29 = getelementptr inbounds [4 x float], [4 x float]* %5, i64 0, i64 2
%30 = load float, float* %29
%31 = load float, float* %6
%32 = fdiv float %30, %31
%33 = load float*, float** %4
%34 = getelementptr inbounds float, float* %33, i64 2
store float %32, float* %34
%35 = getelementptr inbounds [4 x float], [4 x float]* %5, i64 0, i64 3
%36 = load float, float* %35
%37 = load float, float* %6
%38 = fdiv float %36, %37
%39 = load float*, float** %4
%40 = getelementptr inbounds float, float* %39, i64 3
store float %38, float* %40
br label %48
41: ; preds = %2
%42 = load float*, float** %4
%43 = getelementptr inbounds float, float* %42, i64 1
store float 1.000000e+00, float* %43
%44 = load float*, float** %4
%45 = getelementptr inbounds float, float* %44, i64 2
store float 0.000000e+00, float* %45
%46 = load float*, float** %4
%47 = getelementptr inbounds float, float* %46, i64 3
store float 0.000000e+00, float* %47
br label %48
48: ; preds = %41, %22
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 float @mod2pi(i32 %11)
store float %12, float* %1
%13 = fcmp une float %8, 0.000000e+00
br i1 %13, label %14, label %23
14: ; preds = %2
%15 = load float, float* %7
%16 = fdiv float %15, %8
%17 = getelementptr inbounds [4 x float], [4 x float]* %3, i64 0, i64 2
%18 = bitcast float* %17 to <2 x float>*
%19 = load <2 x float>, <2 x float>* %18
%20 = insertelement <2 x float> poison, float %8, i64 0
%21 = shufflevector <2 x float> %20, <2 x float> poison, <2 x i32> zeroinitializer
%22 = fdiv <2 x float> %19, %21
br label %23
23: ; preds = %2, %14
%24 = phi float [ %16, %14 ], [ 1.000000e+00, %2 ]
%25 = phi <2 x float> [ %22, %14 ], [ zeroinitializer, %2 ]
%26 = getelementptr inbounds float, float* %1, i64 1
store float %24, float* %26
%27 = getelementptr inbounds float, float* %1, i64 2
%28 = extractelement <2 x float> %25, i64 0
store float %28, float* %27
%29 = getelementptr inbounds float, float* %1, i64 3
%30 = extractelement <2 x float> %25, i64 1
store float %30, float* %29
ret void
}