; LLVM IR from Slingshot-Physics/slingshot-community :: common/geometry/src/inertia.ll (ZN8geometry13inertiaTensorENS_5types11shapeCube_tE)

; 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.Matrix33 = type { [9 x float] }
%"struct.geometry::types::shapeCube_t" = type { float, float, float }
%class.Vector3 = type { [3 x float] }

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN8geometry13inertiaTensorENS_5types11shapeCube_tE(ptr dead_on_unwind noalias writable sret(%class.Matrix33) align 4 %0, <2 x float> %1, float %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca %"struct.geometry::types::shapeCube_t", align 4
  %6 = alloca { <2 x float>, float }, align 4
  %7 = alloca %class.Vector3, align 4
  store ptr %0, ptr %4, align 8
  %8 = getelementptr inbounds { <2 x float>, float }, ptr %6, i32 0, i32 0
  store <2 x float> %1, ptr %8, align 4
  %9 = getelementptr inbounds { <2 x float>, float }, ptr %6, i32 0, i32 1
  store float %2, ptr %9, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %5, ptr align 4 %6, i64 12, i1 false)
  call void @llvm.lifetime.start.p0(i64 12, ptr %7) #6
  call void @_ZN7Vector3C2Ev(ptr noundef nonnull align 4 dereferenceable(12) %7)
  %10 = getelementptr inbounds %"struct.geometry::types::shapeCube_t", ptr %5, i32 0, i32 1
  %11 = load float, ptr %10, align 4, !tbaa !5
  %12 = getelementptr inbounds %"struct.geometry::types::shapeCube_t", ptr %5, i32 0, i32 1
  %13 = load float, ptr %12, align 4, !tbaa !5
  %14 = getelementptr inbounds %"struct.geometry::types::shapeCube_t", ptr %5, i32 0, i32 2
  %15 = load float, ptr %14, align 4, !tbaa !10
  %16 = getelementptr inbounds %"struct.geometry::types::shapeCube_t", ptr %5, i32 0, i32 2
  %17 = load float, ptr %16, align 4, !tbaa !10
  %18 = fmul float %15, %17
  %19 = call float @llvm.fmuladd.f32(float %11, float %13, float %18)
  %20 = fmul float 0x3FB5555560000000, %19
  %21 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN7Vector3ixEj(ptr noundef nonnull align 4 dereferenceable(12) %7, i32 noundef 0)
  store float %20, ptr %21, align 4, !tbaa !11
  %22 = getelementptr inbounds %"struct.geometry::types::shapeCube_t", ptr %5, i32 0, i32 0
  %23 = load float, ptr %22, align 4, !tbaa !12
  %24 = getelementptr inbounds %"struct.geometry::types::shapeCube_t", ptr %5, i32 0, i32 0
  %25 = load float, ptr %24, align 4, !tbaa !12
  %26 = getelementptr inbounds %"struct.geometry::types::shapeCube_t", ptr %5, i32 0, i32 2
  %27 = load float, ptr %26, align 4, !tbaa !10
  %28 = getelementptr inbounds %"struct.geometry::types::shapeCube_t", ptr %5, i32 0, i32 2
  %29 = load float, ptr %28, align 4, !tbaa !10
  %30 = fmul float %27, %29
  %31 = call float @llvm.fmuladd.f32(float %23, float %25, float %30)
  %32 = fmul float 0x3FB5555560000000, %31
  %33 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN7Vector3ixEj(ptr noundef nonnull align 4 dereferenceable(12) %7, i32 noundef 1)
  store float %32, ptr %33, align 4, !tbaa !11
  %34 = getelementptr inbounds %"struct.geometry::types::shapeCube_t", ptr %5, i32 0, i32 1
  %35 = load float, ptr %34, align 4, !tbaa !5
  %36 = getelementptr inbounds %"struct.geometry::types::shapeCube_t", ptr %5, i32 0, i32 1
  %37 = load float, ptr %36, align 4, !tbaa !5
  %38 = getelementptr inbounds %"struct.geometry::types::shapeCube_t", ptr %5, i32 0, i32 0
  %39 = load float, ptr %38, align 4, !tbaa !12
  %40 = getelementptr inbounds %"struct.geometry::types::shapeCube_t", ptr %5, i32 0, i32 0
  %41 = load float, ptr %40, align 4, !tbaa !12
  %42 = fmul float %39, %41
  %43 = call float @llvm.fmuladd.f32(float %35, float %37, float %42)
  %44 = fmul float 0x3FB5555560000000, %43
  %45 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN7Vector3ixEj(ptr noundef nonnull align 4 dereferenceable(12) %7, i32 noundef 2)
  store float %44, ptr %45, align 4, !tbaa !11
  call void @_ZN8Matrix334diagERK7Vector3(ptr dead_on_unwind writable sret(%class.Matrix33) align 4 %0, ptr noundef nonnull align 4 dereferenceable(12) %7)
  call void @llvm.lifetime.end.p0(i64 12, ptr %7) #6
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7Vector3C2Ev(ptr noundef nonnull align 4 dereferenceable(12)) unnamed_addr #3 align 2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #4

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZN7Vector3ixEj(ptr noundef nonnull align 4 dereferenceable(12), i32 noundef) #5 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN8Matrix334diagERK7Vector3(ptr dead_on_unwind noalias writable sret(%class.Matrix33) align 4, ptr noundef nonnull align 4 dereferenceable(12)) #3 align 2

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

attributes #0 = { mustprogress uwtable "min-legal-vector-width"="64" "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 nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { 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 #6 = { 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, !7, i64 4}
!6 = !{!"_ZTSN8geometry5types11shapeCube_tE", !7, i64 0, !7, i64 4, !7, i64 8}
!7 = !{!"float", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!6, !7, i64 8}
!11 = !{!7, !7, i64 0}
!12 = !{!6, !7, i64 0}


; 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.Matrix33 = type { [9 x float] }
%class.Vector3 = type { [3 x float] }

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN8geometry13inertiaTensorENS_5types11shapeCube_tE(ptr dead_on_unwind noalias writable sret(%class.Matrix33) align 4 %0, <2 x float> %1, float %2) local_unnamed_addr #0 {
  %4 = alloca %class.Vector3, align 4
  call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %4) #5
  call void @_ZN7Vector3C2Ev(ptr noundef nonnull align 4 dereferenceable(12) %4)
  %.sroa.01.4.vec.extract = extractelement <2 x float> %1, i64 1
  %5 = fmul float %2, %2
  %6 = call float @llvm.fmuladd.f32(float %.sroa.01.4.vec.extract, float %.sroa.01.4.vec.extract, float %5)
  %7 = fmul float %6, 0x3FB5555560000000
  %8 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN7Vector3ixEj(ptr noundef nonnull align 4 dereferenceable(12) %4, i32 noundef 0)
  store float %7, ptr %8, align 4, !tbaa !5
  %.sroa.01.0.vec.extract = extractelement <2 x float> %1, i64 0
  %9 = call float @llvm.fmuladd.f32(float %.sroa.01.0.vec.extract, float %.sroa.01.0.vec.extract, float %5)
  %10 = fmul float %9, 0x3FB5555560000000
  %11 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN7Vector3ixEj(ptr noundef nonnull align 4 dereferenceable(12) %4, i32 noundef 1)
  store float %10, ptr %11, align 4, !tbaa !5
  %12 = fmul <2 x float> %1, %1
  %13 = extractelement <2 x float> %12, i64 0
  %14 = call float @llvm.fmuladd.f32(float %.sroa.01.4.vec.extract, float %.sroa.01.4.vec.extract, float %13)
  %15 = fmul float %14, 0x3FB5555560000000
  %16 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN7Vector3ixEj(ptr noundef nonnull align 4 dereferenceable(12) %4, i32 noundef 2)
  store float %15, ptr %16, align 4, !tbaa !5
  call void @_ZN8Matrix334diagERK7Vector3(ptr dead_on_unwind writable sret(%class.Matrix33) align 4 %0, ptr noundef nonnull align 4 dereferenceable(12) %4)
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %4) #5
  ret void
}

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7Vector3C2Ev(ptr noundef nonnull align 4 dereferenceable(12)) unnamed_addr #2 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZN7Vector3ixEj(ptr noundef nonnull align 4 dereferenceable(12), i32 noundef) local_unnamed_addr #4 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN8Matrix334diagERK7Vector3(ptr dead_on_unwind noalias writable sret(%class.Matrix33) align 4, ptr noundef nonnull align 4 dereferenceable(12)) local_unnamed_addr #2 align 2

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

attributes #0 = { mustprogress uwtable "min-legal-vector-width"="64" "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 willreturn memory(argmem: readwrite) }
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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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 #5 = { 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 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,VectorCombinePass