; LLVM IR from Slingshot-Physics/slingshot-community :: common/geometry/src/inertia.ll (ZN8geometry13inertiaTensorENS_5types7shape_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::shape_t" = type { i32, %union.anon }
%union.anon = type { %"struct.geometry::types::shapeCube_t" }
%"struct.geometry::types::shapeCube_t" = type { float, float, float }
%"struct.geometry::types::shapeSphere_t" = type { float }
%"struct.geometry::types::shapeCapsule_t" = type { float, float }
%"struct.geometry::types::shapeCylinder_t" = type { float, float }

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN8geometry13inertiaTensorENS_5types11shapeCube_tE(ptr dead_on_unwind noalias writable sret(%class.Matrix33) align 4, <2 x float>, float) #0

; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN8geometry13inertiaTensorENS_5types13shapeSphere_tE(ptr dead_on_unwind noalias writable sret(%class.Matrix33) align 4, float) #3

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN8geometry13inertiaTensorENS_5types14shapeCapsule_tE(ptr dead_on_unwind noalias writable sret(%class.Matrix33) align 4, <2 x float>) #0

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN8geometry13inertiaTensorENS_5types15shapeCylinder_tE(ptr dead_on_unwind noalias writable sret(%class.Matrix33) align 4, <2 x float>) #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN8geometry13inertiaTensorENS_5types7shape_tE(ptr dead_on_unwind noalias writable sret(%class.Matrix33) align 4 %0, i64 %1, <2 x float> %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca %"struct.geometry::types::shape_t", align 4
  %6 = alloca %class.Matrix33, align 4
  %7 = alloca %"struct.geometry::types::shapeCube_t", align 4
  %8 = alloca { <2 x float>, float }, align 4
  %9 = alloca %class.Matrix33, align 4
  %10 = alloca %"struct.geometry::types::shapeSphere_t", align 4
  %11 = alloca %class.Matrix33, align 4
  %12 = alloca %"struct.geometry::types::shapeCapsule_t", align 4
  %13 = alloca %class.Matrix33, align 4
  %14 = alloca %"struct.geometry::types::shapeCylinder_t", align 4
  store ptr %0, ptr %4, align 8
  %15 = getelementptr inbounds { i64, <2 x float> }, ptr %5, i32 0, i32 0
  store i64 %1, ptr %15, align 4
  %16 = getelementptr inbounds { i64, <2 x float> }, ptr %5, i32 0, i32 1
  store <2 x float> %2, ptr %16, align 4
  call void @_ZN8Matrix33C2Ev(ptr noundef nonnull align 4 dereferenceable(36) %0)
  %17 = getelementptr inbounds %"struct.geometry::types::shape_t", ptr %5, i32 0, i32 0
  %18 = load i32, ptr %17, align 4, !tbaa !5
  switch i32 %18, label %39 [
    i32 0, label %19
    i32 4, label %26
    i32 7, label %31
    i32 1, label %35
    i32 404, label %39
  ]

19:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 36, ptr %6) #5
  %20 = getelementptr inbounds %"struct.geometry::types::shape_t", ptr %5, i32 0, i32 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %7, ptr align 4 %20, i64 12, i1 false), !tbaa.struct !10
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %8, ptr align 4 %7, i64 12, i1 false)
  %21 = getelementptr inbounds { <2 x float>, float }, ptr %8, i32 0, i32 0
  %22 = load <2 x float>, ptr %21, align 4
  %23 = getelementptr inbounds { <2 x float>, float }, ptr %8, i32 0, i32 1
  %24 = load float, ptr %23, align 4
  call void @_ZN8geometry13inertiaTensorENS_5types11shapeCube_tE(ptr dead_on_unwind writable sret(%class.Matrix33) align 4 %6, <2 x float> %22, float %24)
  %25 = call noundef nonnull align 4 dereferenceable(36) ptr @_ZN8Matrix33aSERKS_(ptr noundef nonnull align 4 dereferenceable(36) %0, ptr noundef nonnull align 4 dereferenceable(36) %6)
  call void @llvm.lifetime.end.p0(i64 36, ptr %6) #5
  br label %39

26:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 36, ptr %9) #5
  %27 = getelementptr inbounds %"struct.geometry::types::shape_t", ptr %5, i32 0, i32 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %10, ptr align 4 %27, i64 4, i1 false), !tbaa.struct !13
  %28 = getelementptr inbounds %"struct.geometry::types::shapeSphere_t", ptr %10, i32 0, i32 0
  %29 = load float, ptr %28, align 4
  call void @_ZN8geometry13inertiaTensorENS_5types13shapeSphere_tE(ptr dead_on_unwind writable sret(%class.Matrix33) align 4 %9, float %29)
  %30 = call noundef nonnull align 4 dereferenceable(36) ptr @_ZN8Matrix33aSERKS_(ptr noundef nonnull align 4 dereferenceable(36) %0, ptr noundef nonnull align 4 dereferenceable(36) %9)
  call void @llvm.lifetime.end.p0(i64 36, ptr %9) #5
  br label %39

31:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 36, ptr %11) #5
  %32 = getelementptr inbounds %"struct.geometry::types::shape_t", ptr %5, i32 0, i32 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %12, ptr align 4 %32, i64 8, i1 false), !tbaa.struct !14
  %33 = load <2 x float>, ptr %12, align 4
  call void @_ZN8geometry13inertiaTensorENS_5types14shapeCapsule_tE(ptr dead_on_unwind writable sret(%class.Matrix33) align 4 %11, <2 x float> %33)
  %34 = call noundef nonnull align 4 dereferenceable(36) ptr @_ZN8Matrix33aSERKS_(ptr noundef nonnull align 4 dereferenceable(36) %0, ptr noundef nonnull align 4 dereferenceable(36) %11)
  call void @llvm.lifetime.end.p0(i64 36, ptr %11) #5
  br label %39

35:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 36, ptr %13) #5
  %36 = getelementptr inbounds %"struct.geometry::types::shape_t", ptr %5, i32 0, i32 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %14, ptr align 4 %36, i64 8, i1 false), !tbaa.struct !14
  %37 = load <2 x float>, ptr %14, align 4
  call void @_ZN8geometry13inertiaTensorENS_5types15shapeCylinder_tE(ptr dead_on_unwind writable sret(%class.Matrix33) align 4 %13, <2 x float> %37)
  %38 = call noundef nonnull align 4 dereferenceable(36) ptr @_ZN8Matrix33aSERKS_(ptr noundef nonnull align 4 dereferenceable(36) %0, ptr noundef nonnull align 4 dereferenceable(36) %13)
  call void @llvm.lifetime.end.p0(i64 36, ptr %13) #5
  br label %39

39:                                               ; preds = %35, %31, %26, %19, %3, %3
  ret void
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(36) ptr @_ZN8Matrix33aSERKS_(ptr noundef nonnull align 4 dereferenceable(36), ptr noundef nonnull align 4 dereferenceable(36)) #4 align 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 = { 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, !7, i64 0}
!6 = !{!"_ZTSN8geometry5types7shape_tE", !7, i64 0, !8, i64 4}
!7 = !{!"_ZTSN8geometry5types11enumShape_tE", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{i64 0, i64 4, !11, i64 4, i64 4, !11, i64 8, i64 4, !11}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !8, i64 0}
!13 = !{i64 0, i64 4, !11}
!14 = !{i64 0, i64 4, !11, i64 4, i64 4, !11}


; 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] }
%"struct.geometry::types::shape_t" = type { i32, %union.anon }
%union.anon = type { %"struct.geometry::types::shapeCube_t" }
%"struct.geometry::types::shapeCube_t" = type { float, float, float }

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN8geometry13inertiaTensorENS_5types11shapeCube_tE(ptr dead_on_unwind noalias writable sret(%class.Matrix33) align 4, <2 x float>, float) local_unnamed_addr #0

; 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN8geometry13inertiaTensorENS_5types13shapeSphere_tE(ptr dead_on_unwind noalias writable sret(%class.Matrix33) align 4, float) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN8geometry13inertiaTensorENS_5types14shapeCapsule_tE(ptr dead_on_unwind noalias writable sret(%class.Matrix33) align 4, <2 x float>) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN8geometry13inertiaTensorENS_5types15shapeCylinder_tE(ptr dead_on_unwind noalias writable sret(%class.Matrix33) align 4, <2 x float>) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN8geometry13inertiaTensorENS_5types7shape_tE(ptr dead_on_unwind noalias nonnull writable sret(%class.Matrix33) align 4 %0, i64 %1, <2 x float> %2) local_unnamed_addr #0 {
  %4 = alloca %"struct.geometry::types::shape_t", align 8
  %5 = alloca %class.Matrix33, align 4
  %6 = alloca %class.Matrix33, align 4
  %7 = alloca %class.Matrix33, align 4
  %8 = alloca %class.Matrix33, align 4
  store i64 %1, ptr %4, align 8
  %.8.sroa_idx22 = getelementptr inbounds i8, ptr %4, i64 8
  store <2 x float> %2, ptr %.8.sroa_idx22, align 8
  tail call void @_ZN8Matrix33C2Ev(ptr noundef nonnull align 4 dereferenceable(36) %0)
  %9 = trunc i64 %1 to i32
  switch i32 %9, label %22 [
    i32 0, label %10
    i32 4, label %13
    i32 7, label %18
    i32 1, label %20
  ]

10:                                               ; preds = %3
  %11 = extractelement <2 x float> %2, i64 1
  call void @llvm.lifetime.start.p0(i64 36, ptr nonnull %5) #4
  %.4.sroa_idx19 = getelementptr inbounds i8, ptr %4, i64 4
  %.4..4..4..4..sroa.04.0.copyload = load <2 x float>, ptr %.4.sroa_idx19, align 4
  call void @_ZN8geometry13inertiaTensorENS_5types11shapeCube_tE(ptr dead_on_unwind nonnull writable sret(%class.Matrix33) align 4 %5, <2 x float> %.4..4..4..4..sroa.04.0.copyload, float %11)
  %12 = call noundef nonnull align 4 dereferenceable(36) ptr @_ZN8Matrix33aSERKS_(ptr noundef nonnull align 4 dereferenceable(36) %0, ptr noundef nonnull align 4 dereferenceable(36) %5)
  call void @llvm.lifetime.end.p0(i64 36, ptr nonnull %5) #4
  br label %22

13:                                               ; preds = %3
  %14 = lshr i64 %1, 32
  %15 = trunc nuw i64 %14 to i32
  %16 = bitcast i32 %15 to float
  call void @llvm.lifetime.start.p0(i64 36, ptr nonnull %6) #4
  call void @_ZN8geometry13inertiaTensorENS_5types13shapeSphere_tE(ptr dead_on_unwind nonnull writable sret(%class.Matrix33) align 4 %6, float %16)
  %17 = call noundef nonnull align 4 dereferenceable(36) ptr @_ZN8Matrix33aSERKS_(ptr noundef nonnull align 4 dereferenceable(36) %0, ptr noundef nonnull align 4 dereferenceable(36) %6)
  call void @llvm.lifetime.end.p0(i64 36, ptr nonnull %6) #4
  br label %22

18:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 36, ptr nonnull %7) #4
  %.4.sroa_idx20 = getelementptr inbounds i8, ptr %4, i64 4
  %.4..4..4..4..sroa.01.0.copyload = load <2 x float>, ptr %.4.sroa_idx20, align 4
  call void @_ZN8geometry13inertiaTensorENS_5types14shapeCapsule_tE(ptr dead_on_unwind nonnull writable sret(%class.Matrix33) align 4 %7, <2 x float> %.4..4..4..4..sroa.01.0.copyload)
  %19 = call noundef nonnull align 4 dereferenceable(36) ptr @_ZN8Matrix33aSERKS_(ptr noundef nonnull align 4 dereferenceable(36) %0, ptr noundef nonnull align 4 dereferenceable(36) %7)
  call void @llvm.lifetime.end.p0(i64 36, ptr nonnull %7) #4
  br label %22

20:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 36, ptr nonnull %8) #4
  %.4.sroa_idx21 = getelementptr inbounds i8, ptr %4, i64 4
  %.4..4..4..4..sroa.0.0.copyload = load <2 x float>, ptr %.4.sroa_idx21, align 4
  call void @_ZN8geometry13inertiaTensorENS_5types15shapeCylinder_tE(ptr dead_on_unwind nonnull writable sret(%class.Matrix33) align 4 %8, <2 x float> %.4..4..4..4..sroa.0.0.copyload)
  %21 = call noundef nonnull align 4 dereferenceable(36) ptr @_ZN8Matrix33aSERKS_(ptr noundef nonnull align 4 dereferenceable(36) %0, ptr noundef nonnull align 4 dereferenceable(36) %8)
  call void @llvm.lifetime.end.p0(i64 36, ptr nonnull %8) #4
  br label %22

22:                                               ; preds = %20, %18, %13, %10, %3
  ret void
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(36) ptr @_ZN8Matrix33aSERKS_(ptr noundef nonnull align 4 dereferenceable(36), ptr noundef nonnull align 4 dereferenceable(36)) local_unnamed_addr #3 align 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 = { 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 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)"}


; Effective O3 passes: BDCEPass,GVNPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass