; LLVM IR from jrouwe/JoltPhysics :: Jolt/Physics/Collision/Shape (MutableCompoundShape)

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

%"struct.JPH::AssertLastParam" = type { i8 }
%"class.JPH::Vec3" = type { %union.anon.6 }
%union.anon.6 = type { <4 x float> }
%"class.JPH::Quat" = type { %"class.JPH::Vec4" }
%"class.JPH::Vec4" = type { %union.anon.14 }
%union.anon.14 = type { <4 x float> }
%"class.JPH::CompoundShape" = type <{ %"class.JPH::Shape.base", [6 x i8], %"class.JPH::Vec3", %"class.JPH::AABox", %"class.JPH::Array.7", float, [4 x i8] }>
%"class.JPH::Shape.base" = type <{ ptr, %"class.JPH::RefTarget.5", [4 x i8], i64, i8, i8 }>
%"class.JPH::RefTarget.5" = type { %"struct.std::atomic" }
%"struct.std::atomic" = type { %"struct.std::__atomic_base" }
%"struct.std::__atomic_base" = type { i32 }
%"class.JPH::AABox" = type { %"class.JPH::Vec3", %"class.JPH::Vec3" }
%"class.JPH::Array.7" = type { i64, i64, ptr }
%"struct.JPH::CompoundShape::SubShape" = type <{ %"class.JPH::RefConst.13", %"class.JPH::Float3", %"class.JPH::Float3", i32, i8, [3 x i8] }>
%"class.JPH::RefConst.13" = type { ptr }
%"class.JPH::Float3" = type { float, float, float }

@.str.2 = external hidden unnamed_addr constant [45 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [106 x i8], align 1

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3JPH20MutableCompoundShape23CalculateSubShapeBoundsEjj(ptr noundef nonnull align 16 dereferenceable(144), i32 noundef, i32 noundef) #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNK3JPH5ArrayINS_13CompoundShape8SubShapeENS_12STLAllocatorIS2_EEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) #2 align 2

; 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) #3

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(37) ptr @_ZN3JPH5ArrayINS_13CompoundShape8SubShapeENS_12STLAllocatorIS2_EEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #4 align 2

; Function Attrs: alwaysinline mustprogress uwtable
declare dso_local void @_ZN3JPH13CompoundShape8SubShape12SetTransformENS_4Vec3ENS_4QuatES2_(ptr noundef nonnull align 8 dereferenceable(37), double, double, double, double, double, double) #5 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3JPH20MutableCompoundShape12ModifyShapesEjjPKNS_4Vec3EPKNS_4QuatEjj(ptr noundef nonnull align 16 dereferenceable(144) %0, i32 noundef %1, i32 noundef %2, ptr noundef %3, ptr noundef %4, i32 noundef %5, i32 noundef %6) #1 align 2 {
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca %"struct.JPH::AssertLastParam", align 1
  %16 = alloca ptr, align 8
  %17 = alloca ptr, align 8
  %18 = alloca ptr, align 8
  %19 = alloca ptr, align 8
  %20 = alloca %"class.JPH::Vec3", align 16
  %21 = alloca %"class.JPH::Quat", align 16
  %22 = alloca %"class.JPH::Vec3", align 16
  store ptr %0, ptr %8, align 8, !tbaa !5
  store i32 %1, ptr %9, align 4, !tbaa !9
  store i32 %2, ptr %10, align 4, !tbaa !9
  store ptr %3, ptr %11, align 8, !tbaa !5
  store ptr %4, ptr %12, align 8, !tbaa !5
  store i32 %5, ptr %13, align 4, !tbaa !9
  store i32 %6, ptr %14, align 4, !tbaa !9
  %23 = load ptr, ptr %8, align 8
  br label %24

24:                                               ; preds = %7
  %25 = load i32, ptr %9, align 4, !tbaa !9
  %26 = load i32, ptr %10, align 4, !tbaa !9
  %27 = add i32 %25, %26
  %28 = zext i32 %27 to i64
  %29 = getelementptr inbounds %"class.JPH::CompoundShape", ptr %23, i32 0, i32 4
  %30 = call noundef i64 @_ZNK3JPH5ArrayINS_13CompoundShape8SubShapeENS_12STLAllocatorIS2_EEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %29)
  %31 = icmp ule i64 %28, %30
  br i1 %31, label %35, label %32

32:                                               ; preds = %24
  %33 = call noundef zeroext i1 @_ZN3JPH23AssertFailedParamHelperEPKcS1_jNS_15AssertLastParamE(ptr noundef @.str.2, ptr noundef @.str.3, i32 noundef 261)
  br i1 %33, label %34, label %35

34:                                               ; preds = %32
  call void asm sideeffect "int $$0x3", "~{dirflag},~{fpsr},~{flags}"() #6, !srcloc !11
  br label %35

35:                                               ; preds = %34, %32, %24
  br label %36

36:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #6
  %37 = load ptr, ptr %11, align 8, !tbaa !5
  store ptr %37, ptr %16, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #6
  %38 = load ptr, ptr %12, align 8, !tbaa !5
  store ptr %38, ptr %17, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #6
  %39 = getelementptr inbounds %"class.JPH::CompoundShape", ptr %23, i32 0, i32 4
  %40 = load i32, ptr %9, align 4, !tbaa !9
  %41 = zext i32 %40 to i64
  %42 = call noundef nonnull align 8 dereferenceable(37) ptr @_ZN3JPH5ArrayINS_13CompoundShape8SubShapeENS_12STLAllocatorIS2_EEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %39, i64 noundef %41)
  store ptr %42, ptr %18, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #6
  %43 = load ptr, ptr %18, align 8, !tbaa !5
  %44 = load i32, ptr %10, align 4, !tbaa !9
  %45 = zext i32 %44 to i64
  %46 = getelementptr inbounds %"struct.JPH::CompoundShape::SubShape", ptr %43, i64 %45
  store ptr %46, ptr %19, align 8, !tbaa !5
  br label %47

47:                                               ; preds = %77, %36
  %48 = load ptr, ptr %18, align 8, !tbaa !5
  %49 = load ptr, ptr %19, align 8, !tbaa !5
  %50 = icmp ult ptr %48, %49
  br i1 %50, label %52, label %51

51:                                               ; preds = %47
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #6
  br label %80

52:                                               ; preds = %47
  %53 = load ptr, ptr %18, align 8, !tbaa !5
  %54 = load ptr, ptr %16, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %20, ptr align 16 %54, i64 16, i1 false), !tbaa.struct !12
  %55 = load ptr, ptr %17, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %21, ptr align 16 %55, i64 16, i1 false), !tbaa.struct !12
  %56 = getelementptr inbounds %"class.JPH::CompoundShape", ptr %23, i32 0, i32 2
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %22, ptr align 16 %56, i64 16, i1 false), !tbaa.struct !12
  %57 = getelementptr inbounds { double, double }, ptr %20, i32 0, i32 0
  %58 = load double, ptr %57, align 16
  %59 = getelementptr inbounds { double, double }, ptr %20, i32 0, i32 1
  %60 = load double, ptr %59, align 8
  %61 = getelementptr inbounds { double, double }, ptr %21, i32 0, i32 0
  %62 = load double, ptr %61, align 16
  %63 = getelementptr inbounds { double, double }, ptr %21, i32 0, i32 1
  %64 = load double, ptr %63, align 8
  %65 = getelementptr inbounds { double, double }, ptr %22, i32 0, i32 0
  %66 = load double, ptr %65, align 16
  %67 = getelementptr inbounds { double, double }, ptr %22, i32 0, i32 1
  %68 = load double, ptr %67, align 8
  call void @_ZN3JPH13CompoundShape8SubShape12SetTransformENS_4Vec3ENS_4QuatES2_(ptr noundef nonnull align 8 dereferenceable(37) %53, double %58, double %60, double %62, double %64, double %66, double %68)
  %69 = load ptr, ptr %16, align 8, !tbaa !5
  %70 = load i32, ptr %13, align 4, !tbaa !9
  %71 = zext i32 %70 to i64
  %72 = getelementptr inbounds i8, ptr %69, i64 %71
  store ptr %72, ptr %16, align 8, !tbaa !5
  %73 = load ptr, ptr %17, align 8, !tbaa !5
  %74 = load i32, ptr %14, align 4, !tbaa !9
  %75 = zext i32 %74 to i64
  %76 = getelementptr inbounds i8, ptr %73, i64 %75
  store ptr %76, ptr %17, align 8, !tbaa !5
  br label %77

77:                                               ; preds = %52
  %78 = load ptr, ptr %18, align 8, !tbaa !5
  %79 = getelementptr inbounds %"struct.JPH::CompoundShape::SubShape", ptr %78, i32 1
  store ptr %79, ptr %18, align 8, !tbaa !5
  br label %47, !llvm.loop !14

80:                                               ; preds = %51
  %81 = load i32, ptr %9, align 4, !tbaa !9
  %82 = load i32, ptr %10, align 4, !tbaa !9
  call void @_ZN3JPH20MutableCompoundShape23CalculateSubShapeBoundsEjj(ptr noundef nonnull align 16 dereferenceable(144) %23, i32 noundef %81, i32 noundef %82)
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #6
  ret void
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN3JPH23AssertFailedParamHelperEPKcS1_jNS_15AssertLastParamE(ptr noundef, ptr noundef, i32 noundef) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { inlinehint 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 #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { inlinehint 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 #5 = { alwaysinline 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 #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, !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 = !{!"int", !7, i64 0}
!11 = !{i64 2158221149}
!12 = !{i64 0, i64 16, !13}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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

%"struct.JPH::CompoundShape::SubShape" = type <{ %"class.JPH::RefConst.13", %"class.JPH::Float3", %"class.JPH::Float3", i32, i8, [3 x i8] }>
%"class.JPH::RefConst.13" = type { ptr }
%"class.JPH::Float3" = type { float, float, float }

@.str.2 = external hidden unnamed_addr constant [45 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [106 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3JPH20MutableCompoundShape23CalculateSubShapeBoundsEjj(ptr noundef nonnull align 16 dereferenceable(144), i32 noundef, i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNK3JPH5ArrayINS_13CompoundShape8SubShapeENS_12STLAllocatorIS2_EEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(37) ptr @_ZN3JPH5ArrayINS_13CompoundShape8SubShapeENS_12STLAllocatorIS2_EEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #2 align 2

; Function Attrs: alwaysinline mustprogress uwtable
declare dso_local void @_ZN3JPH13CompoundShape8SubShape12SetTransformENS_4Vec3ENS_4QuatES2_(ptr noundef nonnull align 8 dereferenceable(37), double, double, double, double, double, double) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3JPH20MutableCompoundShape12ModifyShapesEjjPKNS_4Vec3EPKNS_4QuatEjj(ptr noundef nonnull align 16 dereferenceable(144) %0, i32 noundef %1, i32 noundef %2, ptr nocapture noundef readonly %3, ptr nocapture noundef readonly %4, i32 noundef %5, i32 noundef %6) local_unnamed_addr #0 align 2 {
  %8 = add i32 %2, %1
  %9 = zext i32 %8 to i64
  %10 = getelementptr inbounds i8, ptr %0, i64 80
  %11 = tail call noundef i64 @_ZNK3JPH5ArrayINS_13CompoundShape8SubShapeENS_12STLAllocatorIS2_EEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %10)
  %.not = icmp ult i64 %11, %9
  br i1 %.not, label %12, label %15

12:                                               ; preds = %7
  %13 = tail call noundef zeroext i1 @_ZN3JPH23AssertFailedParamHelperEPKcS1_jNS_15AssertLastParamE(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.3, i32 noundef 261)
  br i1 %13, label %14, label %15

14:                                               ; preds = %12
  tail call void asm sideeffect "int $$0x3", "~{dirflag},~{fpsr},~{flags}"() #4, !srcloc !5
  br label %15

15:                                               ; preds = %7, %12, %14
  %16 = zext i32 %1 to i64
  %17 = tail call noundef nonnull align 8 dereferenceable(37) ptr @_ZN3JPH5ArrayINS_13CompoundShape8SubShapeENS_12STLAllocatorIS2_EEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %10, i64 noundef %16)
  %18 = zext i32 %2 to i64
  %19 = getelementptr inbounds %"struct.JPH::CompoundShape::SubShape", ptr %17, i64 %18
  %.not28 = icmp eq i32 %2, 0
  br i1 %.not28, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %15
  %20 = getelementptr inbounds i8, ptr %0, i64 32
  %.sroa.2.0..sroa_idx = getelementptr inbounds i8, ptr %0, i64 40
  %21 = zext i32 %5 to i64
  %22 = zext i32 %6 to i64
  br label %23

._crit_edge:                                      ; preds = %23, %15
  tail call void @_ZN3JPH20MutableCompoundShape23CalculateSubShapeBoundsEjj(ptr noundef nonnull align 16 dereferenceable(144) %0, i32 noundef %1, i32 noundef %2)
  ret void

23:                                               ; preds = %.lr.ph, %23
  %.027 = phi ptr [ %3, %.lr.ph ], [ %24, %23 ]
  %.02326 = phi ptr [ %4, %.lr.ph ], [ %25, %23 ]
  %.02425 = phi ptr [ %17, %.lr.ph ], [ %26, %23 ]
  %.sroa.03.0.copyload = load double, ptr %.027, align 16
  %.sroa.24.0..sroa_idx = getelementptr inbounds i8, ptr %.027, i64 8
  %.sroa.24.0.copyload = load double, ptr %.sroa.24.0..sroa_idx, align 8, !tbaa !6
  %.sroa.01.0.copyload = load double, ptr %.02326, align 16
  %.sroa.22.0..sroa_idx = getelementptr inbounds i8, ptr %.02326, i64 8
  %.sroa.22.0.copyload = load double, ptr %.sroa.22.0..sroa_idx, align 8, !tbaa !6
  %.sroa.0.0.copyload = load double, ptr %20, align 16
  %.sroa.2.0.copyload = load double, ptr %.sroa.2.0..sroa_idx, align 8, !tbaa !6
  tail call void @_ZN3JPH13CompoundShape8SubShape12SetTransformENS_4Vec3ENS_4QuatES2_(ptr noundef nonnull align 8 dereferenceable(37) %.02425, double %.sroa.03.0.copyload, double %.sroa.24.0.copyload, double %.sroa.01.0.copyload, double %.sroa.22.0.copyload, double %.sroa.0.0.copyload, double %.sroa.2.0.copyload)
  %24 = getelementptr inbounds i8, ptr %.027, i64 %21
  %25 = getelementptr inbounds i8, ptr %.02326, i64 %22
  %26 = getelementptr inbounds i8, ptr %.02425, i64 40
  %27 = icmp ult ptr %26, %19
  br i1 %27, label %23, label %._crit_edge, !llvm.loop !9
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN3JPH23AssertFailedParamHelperEPKcS1_jNS_15AssertLastParamE(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

attributes #0 = { 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 #1 = { inlinehint 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 #2 = { inlinehint 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 = { alwaysinline 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 = { 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 = !{i64 2158221149}
!6 = !{!7, !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass