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

; 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 @cos(double noundef) #1

; 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 nounwind uwtable
define dso_local void @_ZN2ad10Quaternion9FromEulerEddd(ptr noundef nonnull align 8 dereferenceable(32) %0, double noundef %1, double noundef %2, double noundef %3) #3 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 %6, align 8, !tbaa !9
  %24 = fdiv double %23, 2.000000e+00
  %25 = call double @sin(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 %8, 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 @cos(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 %7, 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 %9, 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 %9, align 8, !tbaa !9
  %42 = load double, ptr %12, 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 %11, 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 %10, align 8, !tbaa !9
  %48 = load double, ptr %12, align 8, !tbaa !9
  %49 = fmul double %47, %48
  store double %49, ptr %18, align 8, !tbaa !9
  %50 = load double, ptr %15, align 8, !tbaa !9
  %51 = load double, ptr %14, align 8, !tbaa !9
  %52 = load double, ptr %18, align 8, !tbaa !9
  %53 = load double, ptr %13, 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 0
  store double %55, ptr %56, align 8, !tbaa !11
  %57 = load double, ptr %17, align 8, !tbaa !9
  %58 = load double, ptr %13, align 8, !tbaa !9
  %59 = load double, ptr %16, align 8, !tbaa !9
  %60 = load double, ptr %14, align 8, !tbaa !9
  %61 = fmul double %59, %60
  %62 = call double @llvm.fmuladd.f64(double %57, double %58, double %61)
  %63 = getelementptr inbounds %"class.ad::Quaternion", ptr %19, i32 0, i32 1
  store double %62, ptr %63, align 8, !tbaa !13
  %64 = load double, ptr %16, align 8, !tbaa !9
  %65 = load double, ptr %13, align 8, !tbaa !9
  %66 = load double, ptr %17, align 8, !tbaa !9
  %67 = load double, ptr %14, align 8, !tbaa !9
  %68 = fmul double %66, %67
  %69 = fneg double %68
  %70 = call double @llvm.fmuladd.f64(double %64, double %65, double %69)
  %71 = getelementptr inbounds %"class.ad::Quaternion", ptr %19, i32 0, i32 2
  store double %70, ptr %71, align 8, !tbaa !14
  %72 = load double, ptr %15, align 8, !tbaa !9
  %73 = load double, ptr %13, align 8, !tbaa !9
  %74 = load double, ptr %18, align 8, !tbaa !9
  %75 = load double, ptr %14, 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 3
  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
}

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

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

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

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

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