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

; 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: mustprogress nounwind uwtable
define dso_local void @_ZN2ad10QuaternionC2Eddd(ptr noundef nonnull align 8 dereferenceable(32) %0, double noundef %1, double noundef %2, double noundef %3) unnamed_addr #0 align 2 {
  %5 = alloca ptr, align 8
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  %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
  %15 = alloca double, align 8
  %16 = alloca double, align 8
  %17 = alloca double, align 8
  %18 = alloca double, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store double %1, ptr %6, align 8, !tbaa !9
  store double %2, ptr %7, align 8, !tbaa !9
  store double %3, ptr %8, align 8, !tbaa !9
  %19 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %20 = load double, ptr %6, align 8, !tbaa !9
  %21 = fdiv double %20, 2.000000e+00
  %22 = call double @cos(double noundef %21) #4
  store double %22, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %23 = load double, ptr %7, align 8, !tbaa !9
  %24 = fdiv double %23, 2.000000e+00
  %25 = call double @cos(double noundef %24) #4
  store double %25, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %26 = load double, ptr %8, align 8, !tbaa !9
  %27 = fdiv double %26, 2.000000e+00
  %28 = call double @cos(double noundef %27) #4
  store double %28, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %29 = load double, ptr %6, align 8, !tbaa !9
  %30 = fdiv double %29, 2.000000e+00
  %31 = call double @sin(double noundef %30) #4
  store double %31, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %32 = load double, ptr %7, align 8, !tbaa !9
  %33 = fdiv double %32, 2.000000e+00
  %34 = call double @sin(double noundef %33) #4
  store double %34, ptr %13, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %35 = load double, ptr %8, align 8, !tbaa !9
  %36 = fdiv double %35, 2.000000e+00
  %37 = call double @sin(double noundef %36) #4
  store double %37, ptr %14, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  %38 = load double, ptr %10, align 8, !tbaa !9
  %39 = load double, ptr %11, align 8, !tbaa !9
  %40 = fmul double %38, %39
  store double %40, ptr %15, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  %41 = load double, ptr %13, align 8, !tbaa !9
  %42 = load double, ptr %14, align 8, !tbaa !9
  %43 = fmul double %41, %42
  store double %43, ptr %16, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #4
  %44 = load double, ptr %10, align 8, !tbaa !9
  %45 = load double, ptr %14, align 8, !tbaa !9
  %46 = fmul double %44, %45
  store double %46, ptr %17, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #4
  %47 = load double, ptr %13, align 8, !tbaa !9
  %48 = load double, ptr %11, align 8, !tbaa !9
  %49 = fmul double %47, %48
  store double %49, ptr %18, align 8, !tbaa !9
  %50 = load double, ptr %9, align 8, !tbaa !9
  %51 = load double, ptr %15, align 8, !tbaa !9
  %52 = load double, ptr %12, align 8, !tbaa !9
  %53 = load double, ptr %16, align 8, !tbaa !9
  %54 = fmul double %52, %53
  %55 = call double @llvm.fmuladd.f64(double %50, double %51, double %54)
  %56 = getelementptr inbounds %"class.ad::Quaternion", ptr %19, i32 0, i32 3
  store double %55, ptr %56, align 8, !tbaa !11
  %57 = load double, ptr %12, align 8, !tbaa !9
  %58 = load double, ptr %15, align 8, !tbaa !9
  %59 = load double, ptr %9, align 8, !tbaa !9
  %60 = load double, ptr %16, align 8, !tbaa !9
  %61 = fmul double %59, %60
  %62 = fneg double %61
  %63 = call double @llvm.fmuladd.f64(double %57, double %58, double %62)
  %64 = getelementptr inbounds %"class.ad::Quaternion", ptr %19, i32 0, i32 0
  store double %63, ptr %64, align 8, !tbaa !13
  %65 = load double, ptr %9, align 8, !tbaa !9
  %66 = load double, ptr %18, align 8, !tbaa !9
  %67 = load double, ptr %12, align 8, !tbaa !9
  %68 = load double, ptr %17, align 8, !tbaa !9
  %69 = fmul double %67, %68
  %70 = call double @llvm.fmuladd.f64(double %65, double %66, double %69)
  %71 = getelementptr inbounds %"class.ad::Quaternion", ptr %19, i32 0, i32 1
  store double %70, ptr %71, align 8, !tbaa !14
  %72 = load double, ptr %9, align 8, !tbaa !9
  %73 = load double, ptr %17, align 8, !tbaa !9
  %74 = load double, ptr %12, align 8, !tbaa !9
  %75 = load double, ptr %18, align 8, !tbaa !9
  %76 = fmul double %74, %75
  %77 = fneg double %76
  %78 = call double @llvm.fmuladd.f64(double %72, double %73, double %77)
  %79 = getelementptr inbounds %"class.ad::Quaternion", ptr %19, i32 0, i32 2
  store double %78, ptr %79, align 8, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  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 8, ptr %9) #4
  ret void
}

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

; Function Attrs: nounwind
declare double @cos(double noundef) #2

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

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

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

attributes #0 = { mustprogress nounwind 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 = !{!"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 24}
!12 = !{!"_ZTSN2ad10QuaternionE", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24}
!13 = !{!12, !10, i64 0}
!14 = !{!12, !10, i64 8}
!15 = !{!12, !10, i64 16}


; 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"

; Function Attrs: mustprogress nofree nounwind willreturn memory(write) uwtable
define dso_local void @_ZN2ad10QuaternionC2Eddd(ptr nocapture noundef nonnull writeonly align 8 dereferenceable(32) %0, double noundef %1, double noundef %2, double noundef %3) unnamed_addr #0 align 2 {
  %5 = fmul double %1, 5.000000e-01
  %6 = tail call double @cos(double noundef %5) #3
  %7 = fmul double %2, 5.000000e-01
  %8 = tail call double @cos(double noundef %7) #3
  %9 = fmul double %3, 5.000000e-01
  %10 = tail call double @cos(double noundef %9) #3
  %11 = tail call double @sin(double noundef %5) #3
  %12 = tail call double @sin(double noundef %7) #3
  %13 = tail call double @sin(double noundef %9) #3
  %14 = fneg double %6
  %15 = insertelement <2 x double> poison, double %12, i64 0
  %16 = insertelement <2 x double> %15, double %8, i64 1
  %17 = insertelement <2 x double> poison, double %13, i64 0
  %18 = shufflevector <2 x double> %17, <2 x double> poison, <2 x i32> zeroinitializer
  %19 = fmul <2 x double> %16, %18
  %20 = insertelement <2 x double> poison, double %10, i64 0
  %21 = shufflevector <2 x double> %20, <2 x double> poison, <2 x i32> zeroinitializer
  %22 = fmul <2 x double> %21, %16
  %23 = shufflevector <2 x double> %22, <2 x double> poison, <2 x i32> <i32 1, i32 0>
  %24 = insertelement <2 x double> poison, double %14, i64 0
  %25 = insertelement <2 x double> %24, double %11, i64 1
  %26 = fmul <2 x double> %19, %25
  %27 = insertelement <2 x double> poison, double %11, i64 0
  %28 = insertelement <2 x double> %27, double %6, i64 1
  %29 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %28, <2 x double> %23, <2 x double> %26)
  store <2 x double> %29, ptr %0, align 8, !tbaa !5
  %30 = fneg double %11
  %31 = getelementptr inbounds i8, ptr %0, i64 16
  %32 = shufflevector <2 x double> %22, <2 x double> %19, <2 x i32> <i32 0, i32 2>
  %33 = insertelement <2 x double> poison, double %30, i64 0
  %34 = insertelement <2 x double> %33, double %11, i64 1
  %35 = fmul <2 x double> %32, %34
  %36 = insertelement <2 x double> poison, double %6, i64 0
  %37 = shufflevector <2 x double> %36, <2 x double> poison, <2 x i32> zeroinitializer
  %38 = shufflevector <2 x double> %19, <2 x double> %22, <2 x i32> <i32 1, i32 3>
  %39 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %37, <2 x double> %38, <2 x double> %35)
  store <2 x double> %39, ptr %31, align 8, !tbaa !5
  ret void
}

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

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

; 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 nofree nounwind willreturn memory(write) 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 #1 = { 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 #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GlobalDCEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SLPVectorizerPass,SROAPass,TailCallElimPass