#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;
float acosf(float);
float sin(float);
float sinf(float);
int /*<<< orphan*/ vec4f_add_new(float *, float *, float *);
int /*<<< orphan*/ vec4f_copy(float *, float const *);
float vec4f_dot(float const *, float const *);
int /*<<< orphan*/ vec4f_scalarMult(float *, int);
int /*<<< orphan*/ vec4f_scalarMult_new(float *, float const *, float);
int /*<<< orphan*/ vec4f_set(float *, float, float, float, float);
void quatf_slerp_new(float result[4], const float start[4], const float end[4],
                     float t) {
  float copyOfStart[4];
  vec4f_copy(copyOfStart, start);
  float cosOmega = vec4f_dot(start, end);
  if (cosOmega < 0) {
    cosOmega = -cosOmega;
    vec4f_scalarMult(copyOfStart, -1);
  }
  if (1 + cosOmega > 1e-10) {
    float startScale, endScale;
    if (1 - cosOmega > 1e-10) {
      float omega = acosf(cosOmega);
      float sinOmega = sinf(omega);
      startScale = sinf((1.0 - t) * omega / sinOmega);
      endScale = sinf(t * omega) / sinOmega;
    } else {
      startScale = 1.0 - t;
      endScale = t;
    }
    float scaledStart[4], scaledEnd[4];
    vec4f_scalarMult_new(scaledStart, copyOfStart, startScale);
    vec4f_scalarMult_new(scaledEnd, end, endScale);
    vec4f_add_new(result, scaledStart, scaledEnd);
  } else {
    vec4f_set(result, -copyOfStart[1], copyOfStart[0], -copyOfStart[3],
              copyOfStart[2]);
    float startScale = sin((0.5 - t) * M_PI);
    float endScale = sin(t * M_PI);
    float scaledStart[4], scaledEnd[4];
    vec4f_scalarMult_new(scaledStart, copyOfStart, startScale);
    vec4f_scalarMult_new(scaledEnd, result, endScale);
    vec4f_add_new(result, scaledStart, scaledEnd);
  }
}


x86 assembly (clang, -O0):
<quatf_slerp_new>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movss  %xmm0,-0x1c(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   10a0 <vec4f_copy@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10b0 <vec4f_dot@plt>
movss  %xmm0,-0x34(%rbp)
xorps  %xmm0,%xmm0
ucomiss -0x34(%rbp),%xmm0
jbe    11fd <quatf_slerp_new+0x6d>
movss  -0x34(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
movss  %xmm0,-0x34(%rbp)
lea    -0x30(%rbp),%rdi
mov    $0xffffffff,%esi
call   1090 <vec4f_scalarMult@plt>
movss  0xe13(%rip),%xmm0
addss  -0x34(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xdea(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    131e <quatf_slerp_new+0x18e>
movss  0xdf0(%rip),%xmm0
subss  -0x34(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xdc7(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    12bc <quatf_slerp_new+0x12c>
movss  -0x34(%rbp),%xmm0
call   1050 <acosf@plt>
movss  %xmm0,-0x40(%rbp)
movss  -0x40(%rbp),%xmm0
call   1030 <sinf@plt>
movss  %xmm0,-0x44(%rbp)
movss  -0x1c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xd9e(%rip),%xmm0
subsd  %xmm1,%xmm0
movss  -0x40(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
mulsd  %xmm1,%xmm0
movss  -0x44(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
call   1030 <sinf@plt>
movss  %xmm0,-0x38(%rbp)
movss  -0x1c(%rbp),%xmm0
mulss  -0x40(%rbp),%xmm0
call   1030 <sinf@plt>
divss  -0x44(%rbp),%xmm0
movss  %xmm0,-0x3c(%rbp)
jmp    12e4 <quatf_slerp_new+0x154>
movss  -0x1c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xd43(%rip),%xmm0
subsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x38(%rbp)
movss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x3c(%rbp)
lea    -0x60(%rbp),%rdi
lea    -0x30(%rbp),%rsi
movss  -0x38(%rbp),%xmm0
call   1070 <vec4f_scalarMult_new@plt>
lea    -0x70(%rbp),%rdi
mov    -0x18(%rbp),%rsi
movss  -0x3c(%rbp),%xmm0
call   1070 <vec4f_scalarMult_new@plt>
mov    -0x8(%rbp),%rdi
lea    -0x60(%rbp),%rsi
lea    -0x70(%rbp),%rdx
call   1060 <vec4f_add_new@plt>
jmp    13e6 <quatf_slerp_new+0x256>
mov    -0x8(%rbp),%rdi
movss  -0x2c(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
movss  -0x30(%rbp),%xmm1
movss  -0x24(%rbp),%xmm2
movd   %xmm2,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm2
movss  -0x28(%rbp),%xmm3
call   1040 <vec4f_set@plt>
movss  -0x1c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xca2(%rip),%xmm0
subsd  %xmm1,%xmm0
mov    0x2c77(%rip),%rax
mulsd  (%rax),%xmm0
cvtsd2ss %xmm0,%xmm0
call   1080 <sin@plt>
movss  %xmm0,-0x74(%rbp)
movss  -0x1c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
mov    0x2c55(%rip),%rax
mulsd  (%rax),%xmm0
cvtsd2ss %xmm0,%xmm0
call   1080 <sin@plt>
movss  %xmm0,-0x78(%rbp)
lea    -0x90(%rbp),%rdi
lea    -0x30(%rbp),%rsi
movss  -0x74(%rbp),%xmm0
call   1070 <vec4f_scalarMult_new@plt>
lea    -0xa0(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movss  -0x78(%rbp),%xmm0
call   1070 <vec4f_scalarMult_new@plt>
mov    -0x8(%rbp),%rdi
lea    -0x90(%rbp),%rsi
lea    -0xa0(%rbp),%rdx
call   1060 <vec4f_add_new@plt>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<quatf_slerp_new>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x68,%rsp
movss  %xmm0,0xc(%rsp)
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0x20(%rsp),%rdi
call   10a0 <vec4f_copy@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   10b0 <vec4f_dot@plt>
xorps  %xmm1,%xmm1
ucomiss %xmm0,%xmm1
jbe    11ea <quatf_slerp_new+0x5a>
movaps 0xe32(%rip),%xmm1
xorps  %xmm1,%xmm0
movaps %xmm0,0x10(%rsp)
lea    0x20(%rsp),%rdi
mov    $0xffffffff,%esi
call   1090 <vec4f_scalarMult@plt>
movaps 0x10(%rsp),%xmm0
movss  0xe1e(%rip),%xmm1
addss  %xmm0,%xmm1
cvtss2sd %xmm1,%xmm1
ucomisd 0xe16(%rip),%xmm1
jbe    12a5 <quatf_slerp_new+0x115>
movss  0xe00(%rip),%xmm2
movaps %xmm2,%xmm1
subss  %xmm0,%xmm1
cvtss2sd %xmm1,%xmm1
ucomisd 0xdf5(%rip),%xmm1
jbe    135a <quatf_slerp_new+0x1ca>
call   1050 <acosf@plt>
movss  %xmm0,0x10(%rsp)
call   1030 <sinf@plt>
movss  %xmm0,0x3c(%rsp)
movss  0xc(%rsp),%xmm1
xorps  %xmm2,%xmm2
cvtss2sd %xmm1,%xmm2
movsd  0xdd4(%rip),%xmm1
subsd  %xmm2,%xmm1
movss  0x10(%rsp),%xmm2
cvtss2sd %xmm2,%xmm2
mulsd  %xmm1,%xmm2
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
divsd  %xmm1,%xmm2
xorps  %xmm0,%xmm0
cvtsd2ss %xmm2,%xmm0
call   1030 <sinf@plt>
movss  %xmm0,0x38(%rsp)
movss  0x10(%rsp),%xmm0
mulss  0xc(%rsp),%xmm0
call   1030 <sinf@plt>
movss  0x38(%rsp),%xmm2
divss  0x3c(%rsp),%xmm0
jmp    1364 <quatf_slerp_new+0x1d4>
movss  0x24(%rsp),%xmm0
movaps 0xd4e(%rip),%xmm3
xorps  %xmm3,%xmm0
movss  0x20(%rsp),%xmm1
movss  0x2c(%rsp),%xmm2
xorps  %xmm3,%xmm2
movss  0x28(%rsp),%xmm3
mov    %r14,%rdi
call   1040 <vec4f_set@plt>
movss  0xc(%rsp),%xmm0
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
movsd  0xd33(%rip),%xmm0
subsd  %xmm1,%xmm0
mov    0x2cf0(%rip),%rbx
mulsd  (%rbx),%xmm0
cvtsd2ss %xmm0,%xmm0
call   1080 <sin@plt>
movss  %xmm0,0xc(%rsp)
movsd  0x10(%rsp),%xmm0
mulsd  (%rbx),%xmm0
cvtsd2ss %xmm0,%xmm0
call   1080 <sin@plt>
movss  %xmm0,0x10(%rsp)
lea    0x50(%rsp),%r15
lea    0x20(%rsp),%rsi
mov    %r15,%rdi
movss  0xc(%rsp),%xmm0
call   1070 <vec4f_scalarMult_new@plt>
lea    0x40(%rsp),%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
movss  0x10(%rsp),%xmm0
call   1070 <vec4f_scalarMult_new@plt>
mov    %r14,%rdi
mov    %r15,%rsi
jmp    139b <quatf_slerp_new+0x20b>
movss  0xc(%rsp),%xmm0
subss  %xmm0,%xmm2
movss  %xmm0,0xc(%rsp)
lea    0x50(%rsp),%r12
lea    0x20(%rsp),%rsi
mov    %r12,%rdi
movaps %xmm2,%xmm0
call   1070 <vec4f_scalarMult_new@plt>
lea    0x40(%rsp),%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
movss  0xc(%rsp),%xmm0
call   1070 <vec4f_scalarMult_new@plt>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1060 <vec4f_add_new@plt>
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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