#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);
double doubles_dot(double const *, double const *, int);
int /*<<< orphan*/ doubles_normalize(double *, int, double *);
int /*<<< orphan*/ memcpy(double *, double const *, int);
double sin(double);
void doubles_quat_slerp(const double q0[4], const double _q1[4], double r[4],
                        double w) {
  double dot = doubles_dot(q0, _q1, 4);
  double q1[4];
  memcpy(q1, _q1, sizeof(double) * 4);
  if (dot < 0) {
    dot = -dot;
    for (int i = 0; i < 4; i++)
      q1[i] *= -1;
  }
  if (dot > 0.95) {
    for (int i = 0; i < 4; i++)
      r[i] = q0[i] * (1 - w) + q1[i] * w;
  } else {
    double angle = acos(dot);
    double w0 = sin(angle * (1 - w)), w1 = sin(angle * w);
    for (int i = 0; i < 4; i++)
      r[i] = q0[i] * w0 + q1[i] * w1;
    doubles_normalize(r, 4, r);
  }
}


x86 assembly (clang, -O0):
<doubles_quat_slerp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   1030 <doubles_dot@plt>
movsd  %xmm0,-0x28(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x20,%edx
call   1060 <memcpy@plt>
xorps  %xmm0,%xmm0
ucomisd -0x28(%rbp),%xmm0
jbe    1200 <doubles_quat_slerp+0xb0>
movsd  -0x28(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x54(%rbp)
cmpl   $0x4,-0x54(%rbp)
jge    11fb <doubles_quat_slerp+0xab>
movslq -0x54(%rbp),%rax
movsd  0xe2f(%rip),%xmm0
mulsd  -0x50(%rbp,%rax,8),%xmm0
movsd  %xmm0,-0x50(%rbp,%rax,8)
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    11cb <doubles_quat_slerp+0x7b>
jmp    1200 <doubles_quat_slerp+0xb0>
movsd  -0x28(%rbp),%xmm0
movsd  0xdf3(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1279 <doubles_quat_slerp+0x129>
movl   $0x0,-0x58(%rbp)
cmpl   $0x4,-0x58(%rbp)
jge    1274 <doubles_quat_slerp+0x124>
mov    -0x8(%rbp),%rax
movslq -0x58(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  0xdcb(%rip),%xmm2
subsd  -0x20(%rbp),%xmm2
movslq -0x58(%rbp),%rax
movsd  -0x50(%rbp,%rax,8),%xmm1
mulsd  -0x20(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movslq -0x58(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    121e <doubles_quat_slerp+0xce>
jmp    1323 <doubles_quat_slerp+0x1d3>
movsd  -0x28(%rbp),%xmm0
call   1040 <acos@plt>
movsd  %xmm0,-0x60(%rbp)
movsd  -0x60(%rbp),%xmm0
movsd  0xd73(%rip),%xmm1
subsd  -0x20(%rbp),%xmm1
mulsd  %xmm1,%xmm0
call   1050 <sin@plt>
movsd  %xmm0,-0x68(%rbp)
movsd  -0x60(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
call   1050 <sin@plt>
movsd  %xmm0,-0x70(%rbp)
movl   $0x0,-0x74(%rbp)
cmpl   $0x4,-0x74(%rbp)
jge    1311 <doubles_quat_slerp+0x1c1>
mov    -0x8(%rbp),%rax
movslq -0x74(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  -0x68(%rbp),%xmm2
movslq -0x74(%rbp),%rax
movsd  -0x50(%rbp,%rax,8),%xmm1
mulsd  -0x70(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movslq -0x74(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
jmp    12c3 <doubles_quat_slerp+0x173>
mov    -0x18(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x4,%esi
call   1070 <doubles_normalize@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<doubles_quat_slerp>:
push   %r15
push   %r14
push   %rbx
sub    $0x50,%rsp
movsd  %xmm0,0x8(%rsp)
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
mov    $0x4,%edx
call   1030 <doubles_dot@plt>
movaps %xmm0,0x30(%rsp)
lea    0x10(%rsp),%rdi
mov    %rbx,%rsi
mov    $0x20,%edx
call   1060 <memcpy@plt>
movapd 0x30(%rsp),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jbe    11c1 <doubles_quat_slerp+0x71>
movapd 0xe5f(%rip),%xmm2
movapd 0x10(%rsp),%xmm1
xorpd  %xmm2,%xmm1
movapd %xmm1,0x10(%rsp)
xorpd  %xmm2,%xmm0
xorpd  0x20(%rsp),%xmm2
movapd %xmm2,0x20(%rsp)
ucomisd 0xe47(%rip),%xmm0
jbe    1254 <doubles_quat_slerp+0x104>
movsd  0xe41(%rip),%xmm0
movsd  0x8(%rsp),%xmm3
subsd  %xmm3,%xmm0
movsd  0x10(%rsp),%xmm1
mulsd  %xmm3,%xmm1
movsd  (%r15),%xmm2
mulsd  %xmm0,%xmm2
addsd  %xmm1,%xmm2
movsd  %xmm2,(%r14)
movsd  0x18(%rsp),%xmm1
mulsd  %xmm3,%xmm1
movsd  0x8(%r15),%xmm2
mulsd  %xmm0,%xmm2
addsd  %xmm1,%xmm2
movsd  %xmm2,0x8(%r14)
movsd  0x20(%rsp),%xmm1
mulsd  %xmm3,%xmm1
movsd  0x10(%r15),%xmm2
mulsd  %xmm0,%xmm2
addsd  %xmm1,%xmm2
movsd  %xmm2,0x10(%r14)
mulsd  0x28(%rsp),%xmm3
mulsd  0x18(%r15),%xmm0
addsd  %xmm3,%xmm0
movsd  %xmm0,0x18(%r14)
jmp    1319 <doubles_quat_slerp+0x1c9>
call   1040 <acos@plt>
movapd %xmm0,%xmm1
movsd  %xmm0,0x48(%rsp)
movsd  0xdad(%rip),%xmm0
subsd  0x8(%rsp),%xmm0
mulsd  %xmm1,%xmm0
call   1050 <sin@plt>
movsd  %xmm0,0x30(%rsp)
movsd  0x48(%rsp),%xmm0
mulsd  0x8(%rsp),%xmm0
call   1050 <sin@plt>
movsd  0x10(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  (%r15),%xmm2
movsd  0x30(%rsp),%xmm3
mulsd  %xmm3,%xmm2
addsd  %xmm1,%xmm2
movsd  %xmm2,(%r14)
movsd  0x18(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  0x8(%r15),%xmm2
mulsd  %xmm3,%xmm2
addsd  %xmm1,%xmm2
movsd  %xmm2,0x8(%r14)
movsd  0x20(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  0x10(%r15),%xmm2
mulsd  %xmm3,%xmm2
addsd  %xmm1,%xmm2
movsd  %xmm2,0x10(%r14)
mulsd  0x28(%rsp),%xmm0
movapd %xmm3,%xmm1
mulsd  0x18(%r15),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x18(%r14)
mov    %r14,%rdi
mov    $0x4,%esi
mov    %r14,%rdx
call   1070 <doubles_normalize@plt>
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @doubles_quat_slerp(double* %0, double* %1, double* %2, double %3) {
%5 = alloca double*
%6 = alloca double*
%7 = alloca double*
%8 = alloca double
%9 = alloca double
%10 = alloca [4 x double]
%11 = alloca i32
%12 = alloca i32
%13 = alloca double
%14 = alloca double
%15 = alloca double
%16 = alloca i32
store double* %0, double** %5
store double* %1, double** %6
store double* %2, double** %7
store double %3, double* %8
%17 = load double*, double** %5
%18 = load double*, double** %6
%19 = call double @doubles_dot(double* %17, double* %18, i32 4)
store double %19, double* %9
%20 = getelementptr inbounds [4 x double], [4 x double]* %10, i64 0, i64 0
%21 = load double*, double** %6
%22 = call i32 @memcpy(double* %20, double* %21, i32 32)
%23 = load double, double* %9
%24 = fcmp olt double %23, 0.000000e+00
br i1 %24, label %25, label %41
25: ; preds = %4
%26 = load double, double* %9
%27 = fneg double %26
store double %27, double* %9
store i32 0, i32* %11
br label %28
28: ; preds = %37, %25
%29 = load i32, i32* %11
%30 = icmp slt i32 %29, 4
br i1 %30, label %31, label %40
31: ; preds = %28
%32 = load i32, i32* %11
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [4 x double], [4 x double]* %10, i64 0, i64 %33
%35 = load double, double* %34
%36 = fmul double %35, -1.000000e+00
store double %36, double* %34
br label %37
37: ; preds = %31
%38 = load i32, i32* %11
%39 = add nsw i32 %38, 1
store i32 %39, i32* %11
br label %28
40: ; preds = %28
br label %41
41: ; preds = %40, %4
%42 = load double, double* %9
%43 = fcmp ogt double %42, 0x3FEE666666666666
br i1 %43, label %44, label %71
44: ; preds = %41
store i32 0, i32* %12
br label %45
45: ; preds = %67, %44
%46 = load i32, i32* %12
%47 = icmp slt i32 %46, 4
br i1 %47, label %48, label %70
48: ; preds = %45
%49 = load double*, double** %5
%50 = load i32, i32* %12
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds double, double* %49, i64 %51
%53 = load double, double* %52
%54 = load double, double* %8
%55 = fsub double 1.000000e+00, %54
%56 = load i32, i32* %12
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds [4 x double], [4 x double]* %10, i64 0, i64 %57
%59 = load double, double* %58
%60 = load double, double* %8
%61 = fmul double %59, %60
%62 = call double @llvm.fmuladd.f64(double %53, double %55, double %61)
%63 = load double*, double** %7
%64 = load i32, i32* %12
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds double, double* %63, i64 %65
store double %62, double* %66
br label %67
67: ; preds = %48
%68 = load i32, i32* %12
%69 = add nsw i32 %68, 1
store i32 %69, i32* %12
br label %45
70: ; preds = %45
br label %111
71: ; preds = %41
%72 = load double, double* %9
%73 = call double @acos(double %72)
store double %73, double* %13
%74 = load double, double* %13
%75 = load double, double* %8
%76 = fsub double 1.000000e+00, %75
%77 = fmul double %74, %76
%78 = call double @sin(double %77)
store double %78, double* %14
%79 = load double, double* %13
%80 = load double, double* %8
%81 = fmul double %79, %80
%82 = call double @sin(double %81)
store double %82, double* %15
store i32 0, i32* %16
br label %83
83: ; preds = %104, %71
%84 = load i32, i32* %16
%85 = icmp slt i32 %84, 4
br i1 %85, label %86, label %107
86: ; preds = %83
%87 = load double*, double** %5
%88 = load i32, i32* %16
%89 = sext i32 %88 to i64
%90 = getelementptr inbounds double, double* %87, i64 %89
%91 = load double, double* %90
%92 = load double, double* %14
%93 = load i32, i32* %16
%94 = sext i32 %93 to i64
%95 = getelementptr inbounds [4 x double], [4 x double]* %10, i64 0, i64 %94
%96 = load double, double* %95
%97 = load double, double* %15
%98 = fmul double %96, %97
%99 = call double @llvm.fmuladd.f64(double %91, double %92, double %98)
%100 = load double*, double** %7
%101 = load i32, i32* %16
%102 = sext i32 %101 to i64
%103 = getelementptr inbounds double, double* %100, i64 %102
store double %99, double* %103
br label %104
104: ; preds = %86
%105 = load i32, i32* %16
%106 = add nsw i32 %105, 1
store i32 %106, i32* %16
br label %83
107: ; preds = %83
%108 = load double*, double** %7
%109 = load double*, double** %7
%110 = call i32 @doubles_normalize(double* %108, i32 4, double* %109)
br label %111
111: ; preds = %107, %70
ret void
}

LLVM IR (-O2):
define void @doubles_quat_slerp(double* %0, double* %1, double* %2, double %3) {
%5 = alloca [4 x double]
%6 = tail call double @doubles_dot(double* %0, double* %1, i32 4)
%7 = bitcast [4 x double]* %5 to i8*
%8 = getelementptr inbounds [4 x double], [4 x double]* %5, i64 0, i64 0
%9 = call i32 @memcpy(double* %8, double* %1, i32 32)
%10 = fcmp olt double %6, 0.000000e+00
br i1 %10, label %11, label %22
11: ; preds = %4
%12 = bitcast [4 x double]* %5 to <2 x double>*
%13 = load <2 x double>, <2 x double>* %12
%14 = fneg <2 x double> %13
%15 = bitcast [4 x double]* %5 to <2 x double>*
store <2 x double> %14, <2 x double>* %15
%16 = getelementptr inbounds [4 x double], [4 x double]* %5, i64 0, i64 2
%17 = bitcast double* %16 to <2 x double>*
%18 = load <2 x double>, <2 x double>* %17
%19 = fneg <2 x double> %18
%20 = bitcast double* %16 to <2 x double>*
store <2 x double> %19, <2 x double>* %20
%21 = fneg double %6
br label %22
22: ; preds = %11, %4
%23 = phi double [ %6, %4 ], [ %21, %11 ]
%24 = fcmp ogt double %23, 0x3FEE666666666666
br i1 %24, label %25, label %52
25: ; preds = %22
%26 = fsub double 1.000000e+00, %3
%27 = load double, double* %0
%28 = load double, double* %8
%29 = fmul double %28, %3
%30 = call double @llvm.fmuladd.f64(double %27, double %26, double %29)
store double %30, double* %2
%31 = getelementptr inbounds double, double* %0, i64 1
%32 = load double, double* %31
%33 = getelementptr inbounds [4 x double], [4 x double]* %5, i64 0, i64 1
%34 = load double, double* %33
%35 = fmul double %34, %3
%36 = call double @llvm.fmuladd.f64(double %32, double %26, double %35)
%37 = getelementptr inbounds double, double* %2, i64 1
store double %36, double* %37
%38 = getelementptr inbounds double, double* %0, i64 2
%39 = load double, double* %38
%40 = getelementptr inbounds [4 x double], [4 x double]* %5, i64 0, i64 2
%41 = load double, double* %40
%42 = fmul double %41, %3
%43 = call double @llvm.fmuladd.f64(double %39, double %26, double %42)
%44 = getelementptr inbounds double, double* %2, i64 2
store double %43, double* %44
%45 = getelementptr inbounds double, double* %0, i64 3
%46 = load double, double* %45
%47 = getelementptr inbounds [4 x double], [4 x double]* %5, i64 0, i64 3
%48 = load double, double* %47
%49 = fmul double %48, %3
%50 = call double @llvm.fmuladd.f64(double %46, double %26, double %49)
%51 = getelementptr inbounds double, double* %2, i64 3
store double %50, double* %51
br label %85
52: ; preds = %22
%53 = call double @acos(double %23)
%54 = fsub double 1.000000e+00, %3
%55 = fmul double %54, %53
%56 = call double @sin(double %55)
%57 = fmul double %53, %3
%58 = call double @sin(double %57)
%59 = load double, double* %0
%60 = load double, double* %8
%61 = fmul double %58, %60
%62 = call double @llvm.fmuladd.f64(double %59, double %56, double %61)
store double %62, double* %2
%63 = getelementptr inbounds double, double* %0, i64 1
%64 = load double, double* %63
%65 = getelementptr inbounds [4 x double], [4 x double]* %5, i64 0, i64 1
%66 = load double, double* %65
%67 = fmul double %58, %66
%68 = call double @llvm.fmuladd.f64(double %64, double %56, double %67)
%69 = getelementptr inbounds double, double* %2, i64 1
store double %68, double* %69
%70 = getelementptr inbounds double, double* %0, i64 2
%71 = load double, double* %70
%72 = getelementptr inbounds [4 x double], [4 x double]* %5, i64 0, i64 2
%73 = load double, double* %72
%74 = fmul double %58, %73
%75 = call double @llvm.fmuladd.f64(double %71, double %56, double %74)
%76 = getelementptr inbounds double, double* %2, i64 2
store double %75, double* %76
%77 = getelementptr inbounds double, double* %0, i64 3
%78 = load double, double* %77
%79 = getelementptr inbounds [4 x double], [4 x double]* %5, i64 0, i64 3
%80 = load double, double* %79
%81 = fmul double %58, %80
%82 = call double @llvm.fmuladd.f64(double %78, double %56, double %81)
%83 = getelementptr inbounds double, double* %2, i64 3
store double %82, double* %83
%84 = call i32 @doubles_normalize(double* %2, i32 4, double* %2)
br label %85
85: ; preds = %25, %52
ret void
}