; LLVM IR from johnb003/PlasmaSim :: adMath/src/adQuaternion.ll (ZN2ad10Quaternion4LerpERKS0_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: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

; 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 @_ZN2ad10Quaternion4LerpERKS0_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) #2 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
  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) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = getelementptr inbounds %"class.ad::Quaternion", ptr %13, i32 0, i32 0
  %15 = load double, ptr %14, align 8, !tbaa !11
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = getelementptr inbounds %"class.ad::Quaternion", ptr %16, i32 0, i32 0
  %18 = load double, ptr %17, align 8, !tbaa !11
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = getelementptr inbounds %"class.ad::Quaternion", ptr %19, i32 0, i32 1
  %21 = load double, ptr %20, align 8, !tbaa !13
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = getelementptr inbounds %"class.ad::Quaternion", ptr %22, i32 0, i32 1
  %24 = load double, ptr %23, align 8, !tbaa !13
  %25 = fmul double %21, %24
  %26 = call double @llvm.fmuladd.f64(double %15, double %18, double %25)
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = getelementptr inbounds %"class.ad::Quaternion", ptr %27, i32 0, i32 2
  %29 = load double, ptr %28, align 8, !tbaa !14
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  %31 = getelementptr inbounds %"class.ad::Quaternion", ptr %30, i32 0, i32 2
  %32 = load double, ptr %31, align 8, !tbaa !14
  %33 = call double @llvm.fmuladd.f64(double %29, double %32, double %26)
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = getelementptr inbounds %"class.ad::Quaternion", ptr %34, i32 0, i32 3
  %36 = load double, ptr %35, align 8, !tbaa !15
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = getelementptr inbounds %"class.ad::Quaternion", ptr %37, i32 0, i32 3
  %39 = load double, ptr %38, align 8, !tbaa !15
  %40 = call double @llvm.fmuladd.f64(double %36, double %39, double %33)
  store double %40, ptr %10, align 8, !tbaa !9
  %41 = load double, ptr %10, align 8, !tbaa !9
  %42 = fcmp olt double %41, 0.000000e+00
  br i1 %42, label %43, label %64

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

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

81:                                               ; preds = %64, %43
  %82 = load double, ptr %8, align 8, !tbaa !9
  %83 = fsub double 1.000000e+00, %82
  store double %83, ptr %11, align 8, !tbaa !9
  %84 = load double, ptr %8, align 8, !tbaa !9
  store double %84, ptr %12, align 8, !tbaa !9
  %85 = load double, ptr %11, align 8, !tbaa !9
  %86 = load ptr, ptr %6, align 8, !tbaa !5
  %87 = getelementptr inbounds %"class.ad::Quaternion", ptr %86, i32 0, i32 0
  %88 = load double, ptr %87, align 8, !tbaa !11
  %89 = load double, ptr %12, align 8, !tbaa !9
  %90 = getelementptr inbounds [4 x double], ptr %9, i64 0, i64 0
  %91 = load double, ptr %90, align 16, !tbaa !9
  %92 = fmul double %89, %91
  %93 = call double @llvm.fmuladd.f64(double %85, double %88, double %92)
  %94 = getelementptr inbounds %"class.ad::Quaternion", ptr %0, i32 0, i32 0
  store double %93, ptr %94, align 8, !tbaa !11
  %95 = load double, ptr %11, align 8, !tbaa !9
  %96 = load ptr, ptr %6, align 8, !tbaa !5
  %97 = getelementptr inbounds %"class.ad::Quaternion", ptr %96, i32 0, i32 1
  %98 = load double, ptr %97, align 8, !tbaa !13
  %99 = load double, ptr %12, align 8, !tbaa !9
  %100 = getelementptr inbounds [4 x double], ptr %9, i64 0, i64 1
  %101 = load double, ptr %100, align 8, !tbaa !9
  %102 = fmul double %99, %101
  %103 = call double @llvm.fmuladd.f64(double %95, double %98, double %102)
  %104 = getelementptr inbounds %"class.ad::Quaternion", ptr %0, i32 0, i32 1
  store double %103, ptr %104, align 8, !tbaa !13
  %105 = load double, ptr %11, align 8, !tbaa !9
  %106 = load ptr, ptr %6, align 8, !tbaa !5
  %107 = getelementptr inbounds %"class.ad::Quaternion", ptr %106, i32 0, i32 2
  %108 = load double, ptr %107, align 8, !tbaa !14
  %109 = load double, ptr %12, align 8, !tbaa !9
  %110 = getelementptr inbounds [4 x double], ptr %9, i64 0, i64 2
  %111 = load double, ptr %110, align 16, !tbaa !9
  %112 = fmul double %109, %111
  %113 = call double @llvm.fmuladd.f64(double %105, double %108, double %112)
  %114 = getelementptr inbounds %"class.ad::Quaternion", ptr %0, i32 0, i32 2
  store double %113, ptr %114, align 8, !tbaa !14
  %115 = load double, ptr %11, align 8, !tbaa !9
  %116 = load ptr, ptr %6, align 8, !tbaa !5
  %117 = getelementptr inbounds %"class.ad::Quaternion", ptr %116, i32 0, i32 3
  %118 = load double, ptr %117, align 8, !tbaa !15
  %119 = load double, ptr %12, align 8, !tbaa !9
  %120 = getelementptr inbounds [4 x double], ptr %9, i64 0, i64 3
  %121 = load double, ptr %120, align 8, !tbaa !9
  %122 = fmul double %119, %121
  %123 = call double @llvm.fmuladd.f64(double %115, double %118, double %122)
  %124 = getelementptr inbounds %"class.ad::Quaternion", ptr %0, i32 0, i32 3
  store double %123, ptr %124, align 8, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr %9) #3
  ret void
}

declare void @_ZN2ad10QuaternionC1Ev(ptr)

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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 nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN2ad10Quaternion4LerpERKS0_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 #1 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 <2 x double> %6
  %24 = fneg <2 x double> %15
  %25 = select i1 %22, <2 x double> %23, <2 x double> %6
  %26 = select i1 %22, <2 x double> %24, <2 x double> %15
  %27 = fsub double 1.000000e+00, %3
  %28 = insertelement <2 x double> poison, double %3, i64 0
  %29 = shufflevector <2 x double> %28, <2 x double> poison, <2 x i32> zeroinitializer
  %30 = fmul <2 x double> %25, %29
  %31 = insertelement <2 x double> poison, double %27, i64 0
  %32 = shufflevector <2 x double> %31, <2 x double> poison, <2 x i32> zeroinitializer
  %33 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %32, <2 x double> %5, <2 x double> %30)
  store <2 x double> %33, ptr %0, align 8, !tbaa !5
  %34 = fmul <2 x double> %26, %29
  %35 = getelementptr inbounds i8, ptr %0, i64 16
  %36 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %32, <2 x double> %14, <2 x double> %34)
  store <2 x double> %36, ptr %35, align 8, !tbaa !5
  ret void
}

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>) #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { 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 #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass,VectorCombinePass