#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 *);
double 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] = 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>
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x38(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11b7 <doubles_quat_to_angleaxis+0x77>
jp     11b7 <doubles_quat_to_angleaxis+0x77>
jmp    11f5 <doubles_quat_to_angleaxis+0xb5>
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    121e <doubles_quat_to_angleaxis+0xde>
mov    -0x10(%rbp),%rax
movsd  0xdff(%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>
movapd %xmm0,0x20(%rsp)
movsd  (%rsp),%xmm1
call   1040 <atan2@plt>
lea    (%rax,%rax,1),%edi
call   1030 <mod2pi@plt>
movapd 0x20(%rsp),%xmm2
movsd  %xmm0,(%rbx)
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm2
jne    1192 <doubles_quat_to_angleaxis+0x52>
jnp    11b0 <doubles_quat_to_angleaxis+0x70>
movupd 0x8(%rsp),%xmm1
movapd %xmm2,%xmm0
unpcklpd %xmm2,%xmm0
divpd  %xmm0,%xmm1
movsd  0x18(%rsp),%xmm0
divsd  %xmm2,%xmm0
jmp    11b8 <doubles_quat_to_angleaxis+0x78>
movsd  0xe48(%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 double @mod2pi(i32 %16)
%18 = load double*, double** %4
%19 = getelementptr inbounds double, double* %18, i64 0
store double %17, double* %19
%20 = load double, double* %6
%21 = fcmp une double %20, 0.000000e+00
br i1 %21, label %22, label %41
22: ; preds = %2
%23 = getelementptr inbounds [4 x double], [4 x double]* %5, i64 0, i64 1
%24 = load double, double* %23
%25 = load double, double* %6
%26 = fdiv double %24, %25
%27 = load double*, double** %4
%28 = getelementptr inbounds double, double* %27, i64 1
store double %26, double* %28
%29 = getelementptr inbounds [4 x double], [4 x double]* %5, i64 0, i64 2
%30 = load double, double* %29
%31 = load double, double* %6
%32 = fdiv double %30, %31
%33 = load double*, double** %4
%34 = getelementptr inbounds double, double* %33, i64 2
store double %32, double* %34
%35 = getelementptr inbounds [4 x double], [4 x double]* %5, i64 0, i64 3
%36 = load double, double* %35
%37 = load double, double* %6
%38 = fdiv double %36, %37
%39 = load double*, double** %4
%40 = getelementptr inbounds double, double* %39, i64 3
store double %38, double* %40
br label %48
41: ; preds = %2
%42 = load double*, double** %4
%43 = getelementptr inbounds double, double* %42, i64 1
store double 1.000000e+00, double* %43
%44 = load double*, double** %4
%45 = getelementptr inbounds double, double* %44, i64 2
store double 0.000000e+00, double* %45
%46 = load double*, double** %4
%47 = getelementptr inbounds double, double* %46, i64 3
store double 0.000000e+00, double* %47
br label %48
48: ; preds = %41, %22
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 double @mod2pi(i32 %11)
store double %12, double* %1
%13 = fcmp une double %8, 0.000000e+00
br i1 %13, label %14, label %23
14: ; preds = %2
%15 = bitcast double* %7 to <2 x double>*
%16 = load <2 x double>, <2 x double>* %15
%17 = insertelement <2 x double> poison, double %8, i64 0
%18 = shufflevector <2 x double> %17, <2 x double> poison, <2 x i32> zeroinitializer
%19 = fdiv <2 x double> %16, %18
%20 = getelementptr inbounds [4 x double], [4 x double]* %3, i64 0, i64 3
%21 = load double, double* %20
%22 = fdiv double %21, %8
br label %23
23: ; preds = %2, %14
%24 = phi double [ %22, %14 ], [ 0.000000e+00, %2 ]
%25 = phi <2 x double> [ %19, %14 ], [ <double 1.000000e+00, double 0.000000e+00>, %2 ]
%26 = getelementptr inbounds double, double* %1, i64 1
%27 = bitcast double* %26 to <2 x double>*
store <2 x double> %25, <2 x double>* %27
%28 = getelementptr inbounds double, double* %1, i64 3
store double %24, double* %28
ret void
}