#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 */
double acos(double);
int /*<<< orphan*/ vcopy(double *, double *);
int /*<<< orphan*/ vnormal(double *);
int /*<<< orphan*/ vscale(double *, double);
void quat_to_axis(double vec[3], double *phi, double quat[4]) {
  double scale;
  scale = quat[0] * quat[0] + quat[1] * quat[1] + quat[2] * quat[2];
  if (scale == 0) {
    vec[0] = 0;
    vec[1] = 0;
    vec[2] = 1;
    *phi = 0;
  } else {
    vcopy(vec, quat);
    vscale(vec, 1.0 / scale);
    vnormal(vec);
    *phi = 2.0 * acos(quat[3]);
  }
}


x86 assembly (clang, -O0):
<quat_to_axis>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm1
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm2
mov    -0x18(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x18(%rbp),%rax
mulsd  0x8(%rax),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x18(%rbp),%rax
movsd  0x10(%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  0x10(%rax),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11ed <quat_to_axis+0xad>
jp     11ed <quat_to_axis+0xad>
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,0x8(%rax)
mov    -0x8(%rbp),%rax
movsd  0xe30(%rip),%xmm0
movsd  %xmm0,0x10(%rax)
mov    -0x10(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
jmp    123e <quat_to_axis+0xfe>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <vcopy@plt>
mov    -0x8(%rbp),%rdi
movsd  0xe02(%rip),%xmm0
divsd  -0x20(%rbp),%xmm0
call   1050 <vscale@plt>
mov    -0x8(%rbp),%rdi
call   1040 <vnormal@plt>
mov    -0x18(%rbp),%rax
movsd  0x18(%rax),%xmm0
call   1030 <acos@plt>
movaps %xmm0,%xmm1
movsd  0xdce(%rip),%xmm0
mulsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<quat_to_axis>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
movsd  (%rdx),%xmm0
movsd  0x8(%rdx),%xmm1
mulsd  %xmm1,%xmm1
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  0x10(%rdx),%xmm1
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jne    1196 <quat_to_axis+0x56>
jp     1196 <quat_to_axis+0x56>
xorpd  %xmm1,%xmm1
movupd %xmm1,(%r15)
movabs $0x3ff0000000000000,%rax
mov    %rax,0x10(%r15)
jmp    11d6 <quat_to_axis+0x96>
mov    %rdx,%rbx
mov    %r15,%rdi
mov    %rdx,%rsi
movsd  %xmm1,0x8(%rsp)
call   1060 <vcopy@plt>
movsd  0xe4e(%rip),%xmm0
divsd  0x8(%rsp),%xmm0
mov    %r15,%rdi
call   1050 <vscale@plt>
mov    %r15,%rdi
call   1040 <vnormal@plt>
movsd  0x18(%rbx),%xmm0
call   1030 <acos@plt>
addsd  %xmm0,%xmm0
movsd  %xmm0,(%r14)
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @quat_to_axis(double* %0, double* %1, double* %2) {
%4 = alloca double*
%5 = alloca double*
%6 = alloca double*
%7 = alloca double
store double* %0, double** %4
store double* %1, double** %5
store double* %2, double** %6
%8 = load double*, double** %6
%9 = getelementptr inbounds double, double* %8, i64 0
%10 = load double, double* %9
%11 = load double*, double** %6
%12 = getelementptr inbounds double, double* %11, i64 0
%13 = load double, double* %12
%14 = load double*, double** %6
%15 = getelementptr inbounds double, double* %14, i64 1
%16 = load double, double* %15
%17 = load double*, double** %6
%18 = getelementptr inbounds double, double* %17, i64 1
%19 = load double, double* %18
%20 = fmul double %16, %19
%21 = call double @llvm.fmuladd.f64(double %10, double %13, double %20)
%22 = load double*, double** %6
%23 = getelementptr inbounds double, double* %22, i64 2
%24 = load double, double* %23
%25 = load double*, double** %6
%26 = getelementptr inbounds double, double* %25, i64 2
%27 = load double, double* %26
%28 = call double @llvm.fmuladd.f64(double %24, double %27, double %21)
store double %28, double* %7
%29 = load double, double* %7
%30 = fcmp oeq double %29, 0.000000e+00
br i1 %30, label %31, label %39
31: ; preds = %3
%32 = load double*, double** %4
%33 = getelementptr inbounds double, double* %32, i64 0
store double 0.000000e+00, double* %33
%34 = load double*, double** %4
%35 = getelementptr inbounds double, double* %34, i64 1
store double 0.000000e+00, double* %35
%36 = load double*, double** %4
%37 = getelementptr inbounds double, double* %36, i64 2
store double 1.000000e+00, double* %37
%38 = load double*, double** %5
store double 0.000000e+00, double* %38
br label %55
39: ; preds = %3
%40 = load double*, double** %4
%41 = load double*, double** %6
%42 = call i32 @vcopy(double* %40, double* %41)
%43 = load double*, double** %4
%44 = load double, double* %7
%45 = fdiv double 1.000000e+00, %44
%46 = call i32 @vscale(double* %43, double %45)
%47 = load double*, double** %4
%48 = call i32 @vnormal(double* %47)
%49 = load double*, double** %6
%50 = getelementptr inbounds double, double* %49, i64 3
%51 = load double, double* %50
%52 = call double @acos(double %51)
%53 = fmul double 2.000000e+00, %52
%54 = load double*, double** %5
store double %53, double* %54
br label %55
55: ; preds = %39, %31
ret void
}

LLVM IR (-O2):
define void @quat_to_axis(double* %0, double* nocapture writeonly %1, double* %2) {
%4 = load double, double* %2
%5 = getelementptr inbounds double, double* %2, i64 1
%6 = load double, double* %5
%7 = fmul double %6, %6
%8 = tail call double @llvm.fmuladd.f64(double %4, double %4, double %7)
%9 = getelementptr inbounds double, double* %2, i64 2
%10 = load double, double* %9
%11 = tail call double @llvm.fmuladd.f64(double %10, double %10, double %8)
%12 = fcmp oeq double %11, 0.000000e+00
br i1 %12, label %13, label %16
13: ; preds = %3
%14 = getelementptr inbounds double, double* %0, i64 2
%15 = bitcast double* %0 to i8*
store double 1.000000e+00, double* %14
br label %25
16: ; preds = %3
%17 = tail call i32 @vcopy(double* %0, double* %2)
%18 = fdiv double 1.000000e+00, %11
%19 = tail call i32 @vscale(double* %0, double %18)
%20 = tail call i32 @vnormal(double* %0)
%21 = getelementptr inbounds double, double* %2, i64 3
%22 = load double, double* %21
%23 = tail call double @acos(double %22)
%24 = fmul double %23, 2.000000e+00
br label %25
25: ; preds = %16, %13
%26 = phi double [ %24, %16 ], [ 0.000000e+00, %13 ]
store double %26, double* %1
ret void
}