#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(double, double);
double doubles_magnitude(double *, int);
int /*<<< orphan*/ doubles_normalize(double const *, int, double *);
scalar_t__ mod2pi(int);
void doubles_quat_to_angleaxis(const double _q[4], double r[4]) {
  double q[4];
  doubles_normalize(_q, 4, q);
  double mag = doubles_magnitude(&q[1], 3);
  r[0] = (double)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):
<doubles_quat_to_angleaxis>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x30(%rbp),%rdx
mov    $0x4,%esi
call   1050 <doubles_normalize@plt>
lea    -0x30(%rbp),%rdi
add    $0x8,%rdi
mov    $0x3,%esi
call   1060 <doubles_magnitude@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
call   1040 <atan2@plt>
mov    %eax,%edi
shl    $0x1,%edi
call   1030 <mod2pi@plt>
cvtsi2sd %rax,%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x38(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11bc <doubles_quat_to_angleaxis+0x7c>
jp     11bc <doubles_quat_to_angleaxis+0x7c>
jmp    11fa <doubles_quat_to_angleaxis+0xba>
movsd  -0x28(%rbp),%xmm0
divsd  -0x38(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x8(%rax)
movsd  -0x20(%rbp),%xmm0
divsd  -0x38(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x10(%rax)
movsd  -0x18(%rbp),%xmm0
divsd  -0x38(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x18(%rax)
jmp    1223 <doubles_quat_to_angleaxis+0xe3>
mov    -0x10(%rbp),%rax
movsd  0xdfa(%rip),%xmm0
movsd  %xmm0,0x8(%rax)
mov    -0x10(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,0x10(%rax)
mov    -0x10(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,0x18(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<doubles_quat_to_angleaxis>:
push   %rbx
sub    $0x30,%rsp
mov    %rsi,%rbx
mov    %rsp,%rdx
mov    $0x4,%esi
call   1050 <doubles_normalize@plt>
lea    0x8(%rsp),%rdi
mov    $0x3,%esi
call   1060 <doubles_magnitude@plt>
movaps %xmm0,0x20(%rsp)
movsd  (%rsp),%xmm1
call   1040 <atan2@plt>
lea    (%rax,%rax,1),%edi
call   1030 <mod2pi@plt>
movapd 0x20(%rsp),%xmm2
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  %xmm0,(%rbx)
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm2
jne    1199 <doubles_quat_to_angleaxis+0x59>
jnp    11b7 <doubles_quat_to_angleaxis+0x77>
movupd 0x8(%rsp),%xmm1
movapd %xmm2,%xmm0
unpcklpd %xmm2,%xmm0
divpd  %xmm0,%xmm1
movsd  0x18(%rsp),%xmm0
divsd  %xmm2,%xmm0
jmp    11bf <doubles_quat_to_angleaxis+0x7f>
movsd  0xe41(%rip),%xmm1
movupd %xmm1,0x8(%rbx)
movsd  %xmm0,0x18(%rbx)
add    $0x30,%rsp
pop    %rbx
ret

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

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