#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*/ axis_to_quat(double *, double, double *);
int /*<<< orphan*/ vcopy(double *, double *);
int /*<<< orphan*/ vcross(double *, double *, double *);
double vdot(double *, double *);
double vlength(double *);
int /*<<< orphan*/ vnormal(double *);
void vects_to_quat(double v1[3], double v2[3], double q[4]) {
  double axis[3];
  double phi;
  double denom;
  vnormal(v1);
  vnormal(v2);
  if ((v1[0] == v2[0]) && (v1[1] == v2[1]) && (v1[2] == v2[2])) {
    vcopy(axis, v1);
    phi = 0.0;
  } else {
    vcross(axis, v2, v1);
    denom = vlength(v1) * vlength(v2);
    if (denom == 0) {
      phi = 0.0;
    } else {
      phi = acos(vdot(v1, v2) / denom);
    }
  }
  axis_to_quat(axis, phi, q);
}


x86 assembly (clang, -O0):
<vects_to_quat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <vnormal@plt>
mov    -0x10(%rbp),%rdi
call   1050 <vnormal@plt>
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
ucomisd (%rax),%xmm0
jne    1208 <vects_to_quat+0x98>
jp     1208 <vects_to_quat+0x98>
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x10(%rbp),%rax
ucomisd 0x8(%rax),%xmm0
jne    1208 <vects_to_quat+0x98>
jp     1208 <vects_to_quat+0x98>
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm0
mov    -0x10(%rbp),%rax
ucomisd 0x10(%rax),%xmm0
jne    1208 <vects_to_quat+0x98>
jp     1208 <vects_to_quat+0x98>
lea    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1090 <vcopy@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    1287 <vects_to_quat+0x117>
lea    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x8(%rbp),%rdx
call   1070 <vcross@plt>
mov    -0x8(%rbp),%rdi
call   1030 <vlength@plt>
movsd  %xmm0,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <vlength@plt>
movaps %xmm0,%xmm1
movsd  -0x48(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1266 <vects_to_quat+0xf6>
jp     1266 <vects_to_quat+0xf6>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    1282 <vects_to_quat+0x112>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1080 <vdot@plt>
divsd  -0x40(%rbp),%xmm0
call   1040 <acos@plt>
movsd  %xmm0,-0x38(%rbp)
jmp    1287 <vects_to_quat+0x117>
lea    -0x30(%rbp),%rdi
movsd  -0x38(%rbp),%xmm0
mov    -0x18(%rbp),%rsi
call   1060 <axis_to_quat@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vects_to_quat>:
push   %r15
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
call   1050 <vnormal@plt>
mov    %r15,%rdi
call   1050 <vnormal@plt>
movsd  (%rbx),%xmm0
ucomisd (%r15),%xmm0
jne    11cd <vects_to_quat+0x5d>
jp     11cd <vects_to_quat+0x5d>
movsd  0x8(%rbx),%xmm0
ucomisd 0x8(%r15),%xmm0
jne    11cd <vects_to_quat+0x5d>
jp     11cd <vects_to_quat+0x5d>
movsd  0x10(%rbx),%xmm0
ucomisd 0x10(%r15),%xmm0
jne    11cd <vects_to_quat+0x5d>
jp     11cd <vects_to_quat+0x5d>
lea    0x10(%rsp),%rdi
mov    %rbx,%rsi
call   1090 <vcopy@plt>
xorpd  %xmm0,%xmm0
jmp    1225 <vects_to_quat+0xb5>
lea    0x10(%rsp),%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1070 <vcross@plt>
mov    %rbx,%rdi
call   1030 <vlength@plt>
movsd  %xmm0,0x8(%rsp)
mov    %r15,%rdi
call   1030 <vlength@plt>
movapd %xmm0,%xmm1
mulsd  0x8(%rsp),%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jne    1209 <vects_to_quat+0x99>
jnp    1225 <vects_to_quat+0xb5>
mov    %rbx,%rdi
mov    %r15,%rsi
movsd  %xmm1,0x8(%rsp)
call   1080 <vdot@plt>
divsd  0x8(%rsp),%xmm0
call   1040 <acos@plt>
lea    0x10(%rsp),%rdi
mov    %r14,%rsi
call   1060 <axis_to_quat@plt>
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @vects_to_quat(double* %0, double* %1, double* %2) {
%4 = alloca double*
%5 = alloca double*
%6 = alloca double*
%7 = alloca [3 x double]
%8 = alloca double
%9 = alloca double
store double* %0, double** %4
store double* %1, double** %5
store double* %2, double** %6
%10 = load double*, double** %4
%11 = call i32 @vnormal(double* %10)
%12 = load double*, double** %5
%13 = call i32 @vnormal(double* %12)
%14 = load double*, double** %4
%15 = getelementptr inbounds double, double* %14, i64 0
%16 = load double, double* %15
%17 = load double*, double** %5
%18 = getelementptr inbounds double, double* %17, i64 0
%19 = load double, double* %18
%20 = fcmp oeq double %16, %19
br i1 %20, label %21, label %41
21: ; preds = %3
%22 = load double*, double** %4
%23 = getelementptr inbounds double, double* %22, i64 1
%24 = load double, double* %23
%25 = load double*, double** %5
%26 = getelementptr inbounds double, double* %25, i64 1
%27 = load double, double* %26
%28 = fcmp oeq double %24, %27
br i1 %28, label %29, label %41
29: ; preds = %21
%30 = load double*, double** %4
%31 = getelementptr inbounds double, double* %30, i64 2
%32 = load double, double* %31
%33 = load double*, double** %5
%34 = getelementptr inbounds double, double* %33, i64 2
%35 = load double, double* %34
%36 = fcmp oeq double %32, %35
br i1 %36, label %37, label %41
37: ; preds = %29
%38 = getelementptr inbounds [3 x double], [3 x double]* %7, i64 0, i64 0
%39 = load double*, double** %4
%40 = call i32 @vcopy(double* %38, double* %39)
store double 0.000000e+00, double* %8
br label %62
41: ; preds = %29, %21, %3
%42 = getelementptr inbounds [3 x double], [3 x double]* %7, i64 0, i64 0
%43 = load double*, double** %5
%44 = load double*, double** %4
%45 = call i32 @vcross(double* %42, double* %43, double* %44)
%46 = load double*, double** %4
%47 = call double @vlength(double* %46)
%48 = load double*, double** %5
%49 = call double @vlength(double* %48)
%50 = fmul double %47, %49
store double %50, double* %9
%51 = load double, double* %9
%52 = fcmp oeq double %51, 0.000000e+00
br i1 %52, label %53, label %54
53: ; preds = %41
store double 0.000000e+00, double* %8
br label %61
54: ; preds = %41
%55 = load double*, double** %4
%56 = load double*, double** %5
%57 = call double @vdot(double* %55, double* %56)
%58 = load double, double* %9
%59 = fdiv double %57, %58
%60 = call double @acos(double %59)
store double %60, double* %8
br label %61
61: ; preds = %54, %53
br label %62
62: ; preds = %61, %37
%63 = getelementptr inbounds [3 x double], [3 x double]* %7, i64 0, i64 0
%64 = load double, double* %8
%65 = load double*, double** %6
%66 = call i32 @axis_to_quat(double* %63, double %64, double* %65)
ret void
}

LLVM IR (-O2):
define void @vects_to_quat(double* %0, double* %1, double* %2) {
%4 = alloca [3 x double]
%5 = bitcast [3 x double]* %4 to i8*
%6 = tail call i32 @vnormal(double* %0)
%7 = tail call i32 @vnormal(double* %1)
%8 = load double, double* %0
%9 = load double, double* %1
%10 = fcmp oeq double %8, %9
br i1 %10, label %11, label %26
11: ; preds = %3
%12 = getelementptr inbounds double, double* %0, i64 1
%13 = load double, double* %12
%14 = getelementptr inbounds double, double* %1, i64 1
%15 = load double, double* %14
%16 = fcmp oeq double %13, %15
br i1 %16, label %17, label %26
17: ; preds = %11
%18 = getelementptr inbounds double, double* %0, i64 2
%19 = load double, double* %18
%20 = getelementptr inbounds double, double* %1, i64 2
%21 = load double, double* %20
%22 = fcmp oeq double %19, %21
br i1 %22, label %23, label %26
23: ; preds = %17
%24 = getelementptr inbounds [3 x double], [3 x double]* %4, i64 0, i64 0
%25 = call i32 @vcopy(double* %24, double* %0)
br label %37
26: ; preds = %17, %11, %3
%27 = getelementptr inbounds [3 x double], [3 x double]* %4, i64 0, i64 0
%28 = call i32 @vcross(double* %27, double* %1, double* %0)
%29 = call double @vlength(double* %0)
%30 = call double @vlength(double* %1)
%31 = fmul double %29, %30
%32 = fcmp oeq double %31, 0.000000e+00
br i1 %32, label %37, label %33
33: ; preds = %26
%34 = call double @vdot(double* %0, double* %1)
%35 = fdiv double %34, %31
%36 = call double @acos(double %35)
br label %37
37: ; preds = %26, %33, %23
%38 = phi double [ 0.000000e+00, %23 ], [ %36, %33 ], [ 0.000000e+00, %26 ]
%39 = getelementptr inbounds [3 x double], [3 x double]* %4, i64 0, i64 0
%40 = call i32 @axis_to_quat(double* %39, double %38, double* %2)
ret void
}