; LLVM IR from johnb003/PlasmaSim :: adMath/src/adQuaternion.ll (ZN2ad10Quaternion5SlerpERKS0_S2_d)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%"class.ad::Quaternion" = type { double, double, double, double }

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind
declare double @sin(double noundef) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN2ad10Quaternion5SlerpERKS0_S2_d(ptr dead_on_unwind noalias writable sret(%"class.ad::Quaternion") align 8 %0, ptr noundef nonnull align 8 dereferenceable(32) %1, ptr noundef nonnull align 8 dereferenceable(32) %2, double noundef %3) #3 align 2 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca double, align 8
  %9 = alloca [4 x double], align 16
  %10 = alloca double, align 8
  %11 = alloca double, align 8
  %12 = alloca double, align 8
  %13 = alloca double, align 8
  %14 = alloca double, align 8
  store ptr %0, ptr %5, align 8
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  store double %3, ptr %8, align 8, !tbaa !9
  call void @_ZN2ad10QuaternionC1Ev(ptr noundef nonnull align 8 dereferenceable(32) %0)
  call void @llvm.lifetime.start.p0(i64 32, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = getelementptr inbounds %"class.ad::Quaternion", ptr %15, i32 0, i32 0
  %17 = load double, ptr %16, align 8, !tbaa !11
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = getelementptr inbounds %"class.ad::Quaternion", ptr %18, i32 0, i32 0
  %20 = load double, ptr %19, align 8, !tbaa !11
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = getelementptr inbounds %"class.ad::Quaternion", ptr %21, i32 0, i32 1
  %23 = load double, ptr %22, align 8, !tbaa !13
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  %25 = getelementptr inbounds %"class.ad::Quaternion", ptr %24, i32 0, i32 1
  %26 = load double, ptr %25, align 8, !tbaa !13
  %27 = fmul double %23, %26
  %28 = call double @llvm.fmuladd.f64(double %17, double %20, double %27)
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = getelementptr inbounds %"class.ad::Quaternion", ptr %29, i32 0, i32 2
  %31 = load double, ptr %30, align 8, !tbaa !14
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = getelementptr inbounds %"class.ad::Quaternion", ptr %32, i32 0, i32 2
  %34 = load double, ptr %33, align 8, !tbaa !14
  %35 = call double @llvm.fmuladd.f64(double %31, double %34, double %28)
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = getelementptr inbounds %"class.ad::Quaternion", ptr %36, i32 0, i32 3
  %38 = load double, ptr %37, align 8, !tbaa !15
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = getelementptr inbounds %"class.ad::Quaternion", ptr %39, i32 0, i32 3
  %41 = load double, ptr %40, align 8, !tbaa !15
  %42 = call double @llvm.fmuladd.f64(double %38, double %41, double %35)
  store double %42, ptr %11, align 8, !tbaa !9
  %43 = load double, ptr %11, align 8, !tbaa !9
  %44 = fcmp olt double %43, 0.000000e+00
  br i1 %44, label %45, label %68

45:                                               ; preds = %4
  %46 = load double, ptr %11, align 8, !tbaa !9
  %47 = fneg double %46
  store double %47, ptr %11, align 8, !tbaa !9
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  %49 = getelementptr inbounds %"class.ad::Quaternion", ptr %48, i32 0, i32 0
  %50 = load double, ptr %49, align 8, !tbaa !11
  %51 = fneg double %50
  %52 = getelementptr inbounds [4 x double], ptr %9, i64 0, i64 0
  store double %51, ptr %52, align 16, !tbaa !9
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  %54 = getelementptr inbounds %"class.ad::Quaternion", ptr %53, i32 0, i32 1
  %55 = load double, ptr %54, align 8, !tbaa !13
  %56 = fneg double %55
  %57 = getelementptr inbounds [4 x double], ptr %9, i64 0, i64 1
  store double %56, ptr %57, align 8, !tbaa !9
  %58 = load ptr, ptr %7, align 8, !tbaa !5
  %59 = getelementptr inbounds %"class.ad::Quaternion", ptr %58, i32 0, i32 2
  %60 = load double, ptr %59, align 8, !tbaa !14
  %61 = fneg double %60
  %62 = getelementptr inbounds [4 x double], ptr %9, i64 0, i64 2
  store double %61, ptr %62, align 16, !tbaa !9
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  %64 = getelementptr inbounds %"class.ad::Quaternion", ptr %63, i32 0, i32 3
  %65 = load double, ptr %64, align 8, !tbaa !15
  %66 = fneg double %65
  %67 = getelementptr inbounds [4 x double], ptr %9, i64 0, i64 3
  store double %66, ptr %67, align 8, !tbaa !9
  br label %85

68:                                               ; preds = %4
  %69 = load ptr, ptr %7, align 8, !tbaa !5
  %70 = getelementptr inbounds %"class.ad::Quaternion", ptr %69, i32 0, i32 0
  %71 = load double, ptr %70, align 8, !tbaa !11
  %72 = getelementptr inbounds [4 x double], ptr %9, i64 0, i64 0
  store double %71, ptr %72, align 16, !tbaa !9
  %73 = load ptr, ptr %7, align 8, !tbaa !5
  %74 = getelementptr inbounds %"class.ad::Quaternion", ptr %73, i32 0, i32 1
  %75 = load double, ptr %74, align 8, !tbaa !13
  %76 = getelementptr inbounds [4 x double], ptr %9, i64 0, i64 1
  store double %75, ptr %76, align 8, !tbaa !9
  %77 = load ptr, ptr %7, align 8, !tbaa !5
  %78 = getelementptr inbounds %"class.ad::Quaternion", ptr %77, i32 0, i32 2
  %79 = load double, ptr %78, align 8, !tbaa !14
  %80 = getelementptr inbounds [4 x double], ptr %9, i64 0, i64 2
  store double %79, ptr %80, align 16, !tbaa !9
  %81 = load ptr, ptr %7, align 8, !tbaa !5
  %82 = getelementptr inbounds %"class.ad::Quaternion", ptr %81, i32 0, i32 3
  %83 = load double, ptr %82, align 8, !tbaa !15
  %84 = getelementptr inbounds [4 x double], ptr %9, i64 0, i64 3
  store double %83, ptr %84, align 8, !tbaa !9
  br label %85

85:                                               ; preds = %68, %45
  %86 = load double, ptr %11, align 8, !tbaa !9
  %87 = fsub double 1.000000e+00, %86
  %88 = fcmp ogt double %87, 1.000000e-10
  br i1 %88, label %89, label %107

89:                                               ; preds = %85
  %90 = load double, ptr %11, align 8, !tbaa !9
  %91 = call double @acos(double noundef %90) #4
  store double %91, ptr %10, align 8, !tbaa !9
  %92 = load double, ptr %10, align 8, !tbaa !9
  %93 = call double @sin(double noundef %92) #4
  store double %93, ptr %12, align 8, !tbaa !9
  %94 = load double, ptr %8, align 8, !tbaa !9
  %95 = fsub double 1.000000e+00, %94
  %96 = load double, ptr %10, align 8, !tbaa !9
  %97 = fmul double %95, %96
  %98 = call double @sin(double noundef %97) #4
  %99 = load double, ptr %12, align 8, !tbaa !9
  %100 = fdiv double %98, %99
  store double %100, ptr %13, align 8, !tbaa !9
  %101 = load double, ptr %8, align 8, !tbaa !9
  %102 = load double, ptr %10, align 8, !tbaa !9
  %103 = fmul double %101, %102
  %104 = call double @sin(double noundef %103) #4
  %105 = load double, ptr %12, align 8, !tbaa !9
  %106 = fdiv double %104, %105
  store double %106, ptr %14, align 8, !tbaa !9
  br label %111

107:                                              ; preds = %85
  %108 = load double, ptr %8, align 8, !tbaa !9
  %109 = fsub double 1.000000e+00, %108
  store double %109, ptr %13, align 8, !tbaa !9
  %110 = load double, ptr %8, align 8, !tbaa !9
  store double %110, ptr %14, align 8, !tbaa !9
  br label %111

111:                                              ; preds = %107, %89
  %112 = load double, ptr %13, align 8, !tbaa !9
  %113 = load ptr, ptr %6, align 8, !tbaa !5
  %114 = getelementptr inbounds %"class.ad::Quaternion", ptr %113, i32 0, i32 0
  %115 = load double, ptr %114, align 8, !tbaa !11
  %116 = load double, ptr %14, align 8, !tbaa !9
  %117 = getelementptr inbounds [4 x double], ptr %9, i64 0, i64 0
  %118 = load double, ptr %117, align 16, !tbaa !9
  %119 = fmul double %116, %118
  %120 = call double @llvm.fmuladd.f64(double %112, double %115, double %119)
  %121 = getelementptr inbounds %"class.ad::Quaternion", ptr %0, i32 0, i32 0
  store double %120, ptr %121, align 8, !tbaa !11
  %122 = load double, ptr %13, align 8, !tbaa !9
  %123 = load ptr, ptr %6, align 8, !tbaa !5
  %124 = getelementptr inbounds %"class.ad::Quaternion", ptr %123, i32 0, i32 1
  %125 = load double, ptr %124, align 8, !tbaa !13
  %126 = load double, ptr %14, align 8, !tbaa !9
  %127 = getelementptr inbounds [4 x double], ptr %9, i64 0, i64 1
  %128 = load double, ptr %127, align 8, !tbaa !9
  %129 = fmul double %126, %128
  %130 = call double @llvm.fmuladd.f64(double %122, double %125, double %129)
  %131 = getelementptr inbounds %"class.ad::Quaternion", ptr %0, i32 0, i32 1
  store double %130, ptr %131, align 8, !tbaa !13
  %132 = load double, ptr %13, align 8, !tbaa !9
  %133 = load ptr, ptr %6, align 8, !tbaa !5
  %134 = getelementptr inbounds %"class.ad::Quaternion", ptr %133, i32 0, i32 2
  %135 = load double, ptr %134, align 8, !tbaa !14
  %136 = load double, ptr %14, align 8, !tbaa !9
  %137 = getelementptr inbounds [4 x double], ptr %9, i64 0, i64 2
  %138 = load double, ptr %137, align 16, !tbaa !9
  %139 = fmul double %136, %138
  %140 = call double @llvm.fmuladd.f64(double %132, double %135, double %139)
  %141 = getelementptr inbounds %"class.ad::Quaternion", ptr %0, i32 0, i32 2
  store double %140, ptr %141, align 8, !tbaa !14
  %142 = load double, ptr %13, align 8, !tbaa !9
  %143 = load ptr, ptr %6, align 8, !tbaa !5
  %144 = getelementptr inbounds %"class.ad::Quaternion", ptr %143, i32 0, i32 3
  %145 = load double, ptr %144, align 8, !tbaa !15
  %146 = load double, ptr %14, align 8, !tbaa !9
  %147 = getelementptr inbounds [4 x double], ptr %9, i64 0, i64 3
  %148 = load double, ptr %147, align 8, !tbaa !9
  %149 = fmul double %146, %148
  %150 = call double @llvm.fmuladd.f64(double %142, double %145, double %149)
  %151 = getelementptr inbounds %"class.ad::Quaternion", ptr %0, i32 0, i32 3
  store double %150, ptr %151, align 8, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %9) #4
  ret void
}

; Function Attrs: nounwind
declare double @acos(double noundef) #1

declare void @_ZN2ad10QuaternionC1Ev(ptr)

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { mustprogress uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #4 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"_ZTSN2ad10QuaternionE", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24}
!13 = !{!12, !10, i64 8}
!14 = !{!12, !10, i64 16}
!15 = !{!12, !10, i64 24}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%"class.ad::Quaternion" = type { double, double, double, double }

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @sin(double noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN2ad10Quaternion5SlerpERKS0_S2_d(ptr dead_on_unwind noalias writable sret(%"class.ad::Quaternion") align 8 %0, ptr nocapture noundef nonnull readonly align 8 dereferenceable(32) %1, ptr nocapture noundef nonnull readonly align 8 dereferenceable(32) %2, double noundef %3) local_unnamed_addr #2 align 2 {
  tail call void @_ZN2ad10QuaternionC1Ev(ptr noundef nonnull align 8 dereferenceable(32) %0)
  %5 = load <2 x double>, ptr %1, align 8, !tbaa !5
  %6 = load <2 x double>, ptr %2, align 8, !tbaa !5
  %7 = fmul <2 x double> %5, %6
  %8 = extractelement <2 x double> %7, i64 1
  %9 = extractelement <2 x double> %5, i64 0
  %10 = extractelement <2 x double> %6, i64 0
  %11 = tail call double @llvm.fmuladd.f64(double %9, double %10, double %8)
  %12 = getelementptr inbounds i8, ptr %1, i64 16
  %13 = getelementptr inbounds i8, ptr %2, i64 16
  %14 = load <2 x double>, ptr %12, align 8, !tbaa !5
  %15 = load <2 x double>, ptr %13, align 8, !tbaa !5
  %16 = extractelement <2 x double> %14, i64 0
  %17 = extractelement <2 x double> %15, i64 0
  %18 = tail call double @llvm.fmuladd.f64(double %16, double %17, double %11)
  %19 = extractelement <2 x double> %14, i64 1
  %20 = extractelement <2 x double> %15, i64 1
  %21 = tail call double @llvm.fmuladd.f64(double %19, double %20, double %18)
  %22 = fcmp olt double %21, 0.000000e+00
  %23 = fneg double %21
  %24 = fneg <2 x double> %6
  %25 = fneg <2 x double> %15
  %.042 = select i1 %22, double %23, double %21
  %26 = select i1 %22, <2 x double> %24, <2 x double> %6
  %27 = select i1 %22, <2 x double> %25, <2 x double> %15
  %28 = fsub double 1.000000e+00, %.042
  %29 = fcmp ogt double %28, 1.000000e-10
  br i1 %29, label %30, label %45

30:                                               ; preds = %4
  %31 = tail call double @acos(double noundef %.042) #4
  %32 = tail call double @sin(double noundef %31) #4
  %33 = fsub double 1.000000e+00, %3
  %34 = fmul double %33, %31
  %35 = tail call double @sin(double noundef %34) #4
  %36 = fmul double %31, %3
  %37 = tail call double @sin(double noundef %36) #4
  %38 = insertelement <2 x double> poison, double %35, i64 0
  %39 = insertelement <2 x double> %38, double %37, i64 1
  %40 = insertelement <2 x double> poison, double %32, i64 0
  %41 = shufflevector <2 x double> %40, <2 x double> poison, <2 x i32> zeroinitializer
  %42 = fdiv <2 x double> %39, %41
  %43 = load <2 x double>, ptr %1, align 8, !tbaa !5
  %44 = load <2 x double>, ptr %12, align 8, !tbaa !5
  br label %49

45:                                               ; preds = %4
  %46 = fsub double 1.000000e+00, %3
  %47 = insertelement <2 x double> poison, double %46, i64 0
  %48 = insertelement <2 x double> %47, double %3, i64 1
  br label %49

49:                                               ; preds = %45, %30
  %50 = phi <2 x double> [ %43, %30 ], [ %5, %45 ]
  %51 = phi <2 x double> [ %44, %30 ], [ %14, %45 ]
  %52 = phi <2 x double> [ %42, %30 ], [ %48, %45 ]
  %53 = shufflevector <2 x double> %52, <2 x double> poison, <2 x i32> <i32 1, i32 1>
  %54 = fmul <2 x double> %26, %53
  %55 = shufflevector <2 x double> %52, <2 x double> poison, <2 x i32> zeroinitializer
  %56 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %55, <2 x double> %50, <2 x double> %54)
  store <2 x double> %56, ptr %0, align 8, !tbaa !5
  %57 = fmul <2 x double> %27, %53
  %58 = getelementptr inbounds i8, ptr %0, i64 16
  %59 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %55, <2 x double> %51, <2 x double> %57)
  store <2 x double> %59, ptr %58, align 8, !tbaa !5
  ret void
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @acos(double noundef) local_unnamed_addr #0

declare void @_ZN2ad10QuaternionC1Ev(ptr) local_unnamed_addr

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <2 x double> @llvm.fmuladd.v2f64(<2 x double>, <2 x double>, <2 x double>) #3

attributes #0 = { mustprogress nofree nounwind willreturn memory(write) "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { mustprogress uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass,VectorCombinePass