#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 */
scalar_t__ acos(double);
double doubles_dot(double const *, double const *, int);
int /*<<< orphan*/ doubles_normalize(double *, int, double *);
int /*<<< orphan*/ memcpy(double *, double const *, int);
scalar_t__ 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 = (double)acos(dot);
    double w0 = (double)sin(angle * (1 - w)), w1 = (double)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    1332 <doubles_quat_slerp+0x1e2>
movsd  -0x28(%rbp),%xmm0
call   1040 <acos@plt>
cvtsi2sd %rax,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x60(%rbp),%xmm0
movsd  0xd6e(%rip),%xmm1
subsd  -0x20(%rbp),%xmm1
mulsd  %xmm1,%xmm0
call   1050 <sin@plt>
cvtsi2sd %rax,%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x60(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
call   1050 <sin@plt>
cvtsi2sd %rax,%xmm0
movsd  %xmm0,-0x70(%rbp)
movl   $0x0,-0x74(%rbp)
cmpl   $0x4,-0x74(%rbp)
jge    1320 <doubles_quat_slerp+0x1d0>
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    12d2 <doubles_quat_slerp+0x182>
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    132d <doubles_quat_slerp+0x1dd>
call   1040 <acos@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
movsd  %xmm1,0x48(%rsp)
movsd  0xda9(%rip),%xmm0
subsd  0x8(%rsp),%xmm0
mulsd  %xmm1,%xmm0
call   1050 <sin@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  %xmm0,0x30(%rsp)
movsd  0x48(%rsp),%xmm0
mulsd  0x8(%rsp),%xmm0
call   1050 <sin@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
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 %114
71: ; preds = %41
%72 = load double, double* %9
%73 = call i64 @acos(double %72)
%74 = sitofp i64 %73 to double
store double %74, double* %13
%75 = load double, double* %13
%76 = load double, double* %8
%77 = fsub double 1.000000e+00, %76
%78 = fmul double %75, %77
%79 = call i64 @sin(double %78)
%80 = sitofp i64 %79 to double
store double %80, double* %14
%81 = load double, double* %13
%82 = load double, double* %8
%83 = fmul double %81, %82
%84 = call i64 @sin(double %83)
%85 = sitofp i64 %84 to double
store double %85, double* %15
store i32 0, i32* %16
br label %86
86: ; preds = %107, %71
%87 = load i32, i32* %16
%88 = icmp slt i32 %87, 4
br i1 %88, label %89, label %110
89: ; preds = %86
%90 = load double*, double** %5
%91 = load i32, i32* %16
%92 = sext i32 %91 to i64
%93 = getelementptr inbounds double, double* %90, i64 %92
%94 = load double, double* %93
%95 = load double, double* %14
%96 = load i32, i32* %16
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds [4 x double], [4 x double]* %10, i64 0, i64 %97
%99 = load double, double* %98
%100 = load double, double* %15
%101 = fmul double %99, %100
%102 = call double @llvm.fmuladd.f64(double %94, double %95, double %101)
%103 = load double*, double** %7
%104 = load i32, i32* %16
%105 = sext i32 %104 to i64
%106 = getelementptr inbounds double, double* %103, i64 %105
store double %102, double* %106
br label %107
107: ; preds = %89
%108 = load i32, i32* %16
%109 = add nsw i32 %108, 1
store i32 %109, i32* %16
br label %86
110: ; preds = %86
%111 = load double*, double** %7
%112 = load double*, double** %7
%113 = call i32 @doubles_normalize(double* %111, i32 4, double* %112)
br label %114
114: ; preds = %110, %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 %88
52: ; preds = %22
%53 = call i64 @acos(double %23)
%54 = sitofp i64 %53 to double
%55 = fsub double 1.000000e+00, %3
%56 = fmul double %55, %54
%57 = call i64 @sin(double %56)
%58 = sitofp i64 %57 to double
%59 = fmul double %54, %3
%60 = call i64 @sin(double %59)
%61 = sitofp i64 %60 to double
%62 = load double, double* %0
%63 = load double, double* %8
%64 = fmul double %63, %61
%65 = call double @llvm.fmuladd.f64(double %62, double %58, double %64)
store double %65, double* %2
%66 = getelementptr inbounds double, double* %0, i64 1
%67 = load double, double* %66
%68 = getelementptr inbounds [4 x double], [4 x double]* %5, i64 0, i64 1
%69 = load double, double* %68
%70 = fmul double %69, %61
%71 = call double @llvm.fmuladd.f64(double %67, double %58, double %70)
%72 = getelementptr inbounds double, double* %2, i64 1
store double %71, double* %72
%73 = getelementptr inbounds double, double* %0, i64 2
%74 = load double, double* %73
%75 = getelementptr inbounds [4 x double], [4 x double]* %5, i64 0, i64 2
%76 = load double, double* %75
%77 = fmul double %76, %61
%78 = call double @llvm.fmuladd.f64(double %74, double %58, double %77)
%79 = getelementptr inbounds double, double* %2, i64 2
store double %78, double* %79
%80 = getelementptr inbounds double, double* %0, i64 3
%81 = load double, double* %80
%82 = getelementptr inbounds [4 x double], [4 x double]* %5, i64 0, i64 3
%83 = load double, double* %82
%84 = fmul double %83, %61
%85 = call double @llvm.fmuladd.f64(double %81, double %58, double %84)
%86 = getelementptr inbounds double, double* %2, i64 3
store double %85, double* %86
%87 = call i32 @doubles_normalize(double* %2, i32 4, double* %2)
br label %88
88: ; preds = %25, %52
ret void
}