#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 M_PI;
double acos(double);
double sin(double);
int /*<<< orphan*/ vec4d_add_new(double *, double *, double *);
int /*<<< orphan*/ vec4d_copy(double *, double const *);
double vec4d_dot(double const *, double const *);
int /*<<< orphan*/ vec4d_normalize(double *);
int /*<<< orphan*/ vec4d_scalarMult(double *, int);
int /*<<< orphan*/ vec4d_scalarMult_new(double *, double const *, double);
int /*<<< orphan*/ vec4d_set(double *, double, double, double, double);
void quatd_slerp_new(double result[4], const double start[4],
                     const double end[4], double t) {
  double copyOfStart[4];
  vec4d_copy(copyOfStart, start);
  double cosOmega = vec4d_dot(start, end);
  if (cosOmega < 0) {
    cosOmega = -cosOmega;
    vec4d_scalarMult(copyOfStart, -1);
  }
  if (1 + cosOmega > 1e-10) {
    double startScale, endScale;
    if (1 - cosOmega > 1e-10) {
      double omega = acos(cosOmega);
      double sinOmega = sin(omega);
      startScale = sin((1.0 - t) * omega / sinOmega);
      endScale = sin(t * omega) / sinOmega;
    } else {
      startScale = 1.0 - t;
      endScale = t;
    }
    double scaledStart[4], scaledEnd[4];
    vec4d_scalarMult_new(scaledStart, copyOfStart, startScale);
    vec4d_scalarMult_new(scaledEnd, end, endScale);
    vec4d_add_new(result, scaledStart, scaledEnd);
  } else {
    vec4d_set(result, -copyOfStart[1], copyOfStart[0], -copyOfStart[3],
              copyOfStart[2]);
    double startScale = sin((0.5 - t) * M_PI);
    double endScale = sin(t * M_PI);
    double scaledStart[4], scaledEnd[4];
    vec4d_scalarMult_new(scaledStart, copyOfStart, startScale);
    vec4d_scalarMult_new(scaledEnd, result, endScale);
    vec4d_add_new(result, scaledStart, scaledEnd);
  }
  vec4d_normalize(result);
}


x86 assembly (clang, -O0):
<quatd_slerp_new>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movsd  %xmm0,-0x20(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1080 <vec4d_copy@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10b0 <vec4d_dot@plt>
movsd  %xmm0,-0x48(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x48(%rbp),%xmm0
jbe    1208 <quatd_slerp_new+0x78>
movsd  -0x48(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x48(%rbp)
lea    -0x40(%rbp),%rdi
mov    $0xffffffff,%esi
call   1050 <vec4d_scalarMult@plt>
movsd  0xdf8(%rip),%xmm0
addsd  -0x48(%rbp),%xmm0
movsd  0xde3(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1305 <quatd_slerp_new+0x175>
movsd  0xdd9(%rip),%xmm0
subsd  -0x48(%rbp),%xmm0
movsd  0xdc4(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    12a3 <quatd_slerp_new+0x113>
movsd  -0x48(%rbp),%xmm0
call   1060 <acos@plt>
movsd  %xmm0,-0x60(%rbp)
movsd  -0x60(%rbp),%xmm0
call   1090 <sin@plt>
movsd  %xmm0,-0x68(%rbp)
movsd  0xd9c(%rip),%xmm0
subsd  -0x20(%rbp),%xmm0
mulsd  -0x60(%rbp),%xmm0
divsd  -0x68(%rbp),%xmm0
call   1090 <sin@plt>
movsd  %xmm0,-0x50(%rbp)
movsd  -0x20(%rbp),%xmm0
mulsd  -0x60(%rbp),%xmm0
call   1090 <sin@plt>
divsd  -0x68(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
jmp    12bf <quatd_slerp_new+0x12f>
movsd  0xd5d(%rip),%xmm0
subsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
lea    -0x90(%rbp),%rdi
lea    -0x40(%rbp),%rsi
movsd  -0x50(%rbp),%xmm0
call   1040 <vec4d_scalarMult_new@plt>
lea    -0xb0(%rbp),%rdi
mov    -0x18(%rbp),%rsi
movsd  -0x58(%rbp),%xmm0
call   1040 <vec4d_scalarMult_new@plt>
mov    -0x8(%rbp),%rdi
lea    -0x90(%rbp),%rsi
lea    -0xb0(%rbp),%rdx
call   1070 <vec4d_add_new@plt>
jmp    13d9 <quatd_slerp_new+0x249>
mov    -0x8(%rbp),%rdi
movsd  -0x38(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  -0x40(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm2
movq   %xmm2,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm2
movsd  -0x30(%rbp),%xmm3
call   1030 <vec4d_set@plt>
movsd  0xcb8(%rip),%xmm0
subsd  -0x20(%rbp),%xmm0
mov    0x2c84(%rip),%rax
mulsd  (%rax),%xmm0
call   1090 <sin@plt>
movsd  %xmm0,-0xb8(%rbp)
ff
movsd  -0x20(%rbp),%xmm0
mov    0x2c67(%rip),%rax
mulsd  (%rax),%xmm0
call   1090 <sin@plt>
movsd  %xmm0,-0xc0(%rbp)
ff
lea    -0xe0(%rbp),%rdi
lea    -0x40(%rbp),%rsi
movsd  -0xb8(%rbp),%xmm0
ff
call   1040 <vec4d_scalarMult_new@plt>
lea    -0x100(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movsd  -0xc0(%rbp),%xmm0
ff
call   1040 <vec4d_scalarMult_new@plt>
mov    -0x8(%rbp),%rdi
lea    -0xe0(%rbp),%rsi
lea    -0x100(%rbp),%rdx
call   1070 <vec4d_add_new@plt>
mov    -0x8(%rbp),%rdi
call   10a0 <vec4d_normalize@plt>
add    $0x100,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<quatd_slerp_new>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x98,%rsp
movsd  %xmm0,0x8(%rsp)
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
lea    0x20(%rsp),%rdi
call   1080 <vec4d_copy@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   10b0 <vec4d_dot@plt>
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jbe    11f3 <quatd_slerp_new+0x63>
movapd 0xe2c(%rip),%xmm1
xorpd  %xmm1,%xmm0
movapd %xmm0,0x10(%rsp)
lea    0x20(%rsp),%rdi
mov    $0xffffffff,%esi
call   1050 <vec4d_scalarMult@plt>
movapd 0x10(%rsp),%xmm0
movsd  0xe15(%rip),%xmm1
addsd  %xmm0,%xmm1
ucomisd 0xe11(%rip),%xmm1
jbe    1286 <quatd_slerp_new+0xf6>
movsd  0xdff(%rip),%xmm1
movapd %xmm1,%xmm2
subsd  %xmm0,%xmm2
ucomisd 0xdf7(%rip),%xmm2
jbe    1325 <quatd_slerp_new+0x195>
call   1060 <acos@plt>
movsd  %xmm0,0x10(%rsp)
call   1090 <sin@plt>
movsd  %xmm0,0x48(%rsp)
movsd  0xdcb(%rip),%xmm1
subsd  0x8(%rsp),%xmm1
mulsd  0x10(%rsp),%xmm1
divsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
call   1090 <sin@plt>
movsd  %xmm0,0x40(%rsp)
movsd  0x10(%rsp),%xmm0
mulsd  0x8(%rsp),%xmm0
call   1090 <sin@plt>
movsd  0x40(%rsp),%xmm1
divsd  0x48(%rsp),%xmm0
jmp    132f <quatd_slerp_new+0x19f>
movsd  0x28(%rsp),%xmm0
movapd 0xd6c(%rip),%xmm3
xorpd  %xmm3,%xmm0
movsd  0x20(%rsp),%xmm1
movsd  0x38(%rsp),%xmm2
xorpd  %xmm3,%xmm2
movsd  0x30(%rsp),%xmm3
mov    %r15,%rdi
call   1030 <vec4d_set@plt>
movsd  0xd62(%rip),%xmm0
subsd  0x8(%rsp),%xmm0
mov    0x2d1d(%rip),%rbx
mulsd  (%rbx),%xmm0
call   1090 <sin@plt>
movsd  %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
mulsd  (%rbx),%xmm0
call   1090 <sin@plt>
movsd  %xmm0,0x8(%rsp)
lea    0x70(%rsp),%r14
lea    0x20(%rsp),%rsi
mov    %r14,%rdi
movsd  0x10(%rsp),%xmm0
call   1040 <vec4d_scalarMult_new@plt>
lea    0x50(%rsp),%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
movsd  0x8(%rsp),%xmm0
call   1040 <vec4d_scalarMult_new@plt>
mov    %r15,%rdi
mov    %r14,%rsi
jmp    1367 <quatd_slerp_new+0x1d7>
movsd  0x8(%rsp),%xmm0
subsd  %xmm0,%xmm1
movsd  %xmm0,0x8(%rsp)
lea    0x70(%rsp),%r12
lea    0x20(%rsp),%rsi
mov    %r12,%rdi
movapd %xmm1,%xmm0
call   1040 <vec4d_scalarMult_new@plt>
lea    0x50(%rsp),%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
movsd  0x8(%rsp),%xmm0
call   1040 <vec4d_scalarMult_new@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1070 <vec4d_add_new@plt>
mov    %r15,%rdi
call   10a0 <vec4d_normalize@plt>
add    $0x98,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@M_PI = global double 0.000000e+00
define void @quatd_slerp_new(double* %0, double* %1, double* %2, double %3) {
%5 = alloca [4 x double]
%6 = alloca [4 x double]
%7 = alloca [4 x double]
%8 = alloca [4 x double]
%9 = alloca [4 x double]
%10 = bitcast [4 x double]* %5 to i8*
%11 = getelementptr inbounds [4 x double], [4 x double]* %5, i64 0, i64 0
%12 = call i32 @vec4d_copy(double* %11, double* %1)
%13 = call double @vec4d_dot(double* %1, double* %2)
%14 = fcmp olt double %13, 0.000000e+00
br i1 %14, label %15, label %18
15: ; preds = %4
%16 = fneg double %13
%17 = call i32 @vec4d_scalarMult(double* %11, i32 -1)
br label %18
18: ; preds = %15, %4
%19 = phi double [ %16, %15 ], [ %13, %4 ]
%20 = fadd double %19, 1.000000e+00
%21 = fcmp ogt double %20, 1.000000e-10
br i1 %21, label %22, label %47
22: ; preds = %18
%23 = fsub double 1.000000e+00, %19
%24 = fcmp ogt double %23, 1.000000e-10
br i1 %24, label %25, label %35
25: ; preds = %22
%26 = call double @acos(double %19)
%27 = call double @sin(double %26)
%28 = fsub double 1.000000e+00, %3
%29 = fmul double %28, %26
%30 = fdiv double %29, %27
%31 = call double @sin(double %30)
%32 = fmul double %26, %3
%33 = call double @sin(double %32)
%34 = fdiv double %33, %27
br label %37
35: ; preds = %22
%36 = fsub double 1.000000e+00, %3
br label %37
37: ; preds = %35, %25
%38 = phi double [ %34, %25 ], [ %3, %35 ]
%39 = phi double [ %31, %25 ], [ %36, %35 ]
%40 = bitcast [4 x double]* %6 to i8*
%41 = bitcast [4 x double]* %7 to i8*
%42 = getelementptr inbounds [4 x double], [4 x double]* %6, i64 0, i64 0
%43 = call i32 @vec4d_scalarMult_new(double* %42, double* %11, double %39)
%44 = getelementptr inbounds [4 x double], [4 x double]* %7, i64 0, i64 0
%45 = call i32 @vec4d_scalarMult_new(double* %44, double* %2, double %38)
%46 = call i32 @vec4d_add_new(double* %0, double* %42, double* %44)
br label %72
47: ; preds = %18
%48 = getelementptr inbounds [4 x double], [4 x double]* %5, i64 0, i64 1
%49 = load double, double* %48
%50 = fneg double %49
%51 = load double, double* %11
%52 = getelementptr inbounds [4 x double], [4 x double]* %5, i64 0, i64 3
%53 = load double, double* %52
%54 = fneg double %53
%55 = getelementptr inbounds [4 x double], [4 x double]* %5, i64 0, i64 2
%56 = load double, double* %55
%57 = call i32 @vec4d_set(double* %0, double %50, double %51, double %54, double %56)
%58 = fsub double 5.000000e-01, %3
%59 = load double, double* @M_PI
%60 = fmul double %58, %59
%61 = call double @sin(double %60)
%62 = load double, double* @M_PI
%63 = fmul double %62, %3
%64 = call double @sin(double %63)
%65 = bitcast [4 x double]* %8 to i8*
%66 = bitcast [4 x double]* %9 to i8*
%67 = getelementptr inbounds [4 x double], [4 x double]* %8, i64 0, i64 0
%68 = call i32 @vec4d_scalarMult_new(double* %67, double* %11, double %61)
%69 = getelementptr inbounds [4 x double], [4 x double]* %9, i64 0, i64 0
%70 = call i32 @vec4d_scalarMult_new(double* %69, double* %0, double %64)
%71 = call i32 @vec4d_add_new(double* %0, double* %67, double* %69)
br label %72
72: ; preds = %47, %37
%73 = call i32 @vec4d_normalize(double* %0)
ret void
}