; LLVM IR from jrouwe/JoltPhysics :: Jolt/Physics/Ragdoll/Ragdoll.ll (ZN3JPH7Ragdoll10SetGroupIDEjb)

; 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.JPH::BodyLockMultiWrite" = type { %"class.JPH::BodyLockMultiBase.base.98", [4 x i8] }
%"class.JPH::BodyLockMultiBase.base.98" = type <{ ptr, i64, ptr, i32 }>
%"class.JPH::Ragdoll" = type { %"class.JPH::RefTarget.76", %"class.JPH::RefConst.77", %"class.JPH::Array.78", %"class.JPH::Array.81", ptr }
%"class.JPH::RefTarget.76" = type { %"struct.std::atomic" }
%"struct.std::atomic" = type { %"struct.std::__atomic_base" }
%"struct.std::__atomic_base" = type { i32 }
%"class.JPH::RefConst.77" = type { ptr }
%"class.JPH::Array.78" = type { i64, i64, ptr }
%"class.JPH::Array.81" = type { i64, i64, ptr }

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

declare i32 @__gxx_personality_v0(...)

; 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
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZN3JPH4Body17GetCollisionGroupEv(ptr noundef nonnull align 16 dereferenceable(122)) #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN3JPH14CollisionGroup10SetGroupIDEj(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) #2 align 2

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare hidden noundef nonnull align 8 dereferenceable(16) ptr @_ZN3JPHL21sGetBodyLockInterfaceEPKNS_13PhysicsSystemEb(ptr noundef, i1 noundef zeroext) #3

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3JPH7Ragdoll10SetGroupIDEjb(ptr noundef nonnull align 8 dereferenceable(72) %0, i32 noundef %1, i1 noundef zeroext %2) #4 align 2 personality ptr @__gxx_personality_v0 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i8, align 1
  %7 = alloca i32, align 4
  %8 = alloca %"class.JPH::BodyLockMultiWrite", align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %13 = zext i1 %2 to i8
  store i8 %13, ptr %6, align 1, !tbaa !11
  %14 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  %15 = getelementptr inbounds %"class.JPH::Ragdoll", ptr %14, i32 0, i32 2
  %16 = call noundef i64 @_ZNK3JPH5ArrayINS_6BodyIDENS_12STLAllocatorIS1_EEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %15)
  %17 = trunc i64 %16 to i32
  store i32 %17, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 32, ptr %8) #5
  %18 = getelementptr inbounds %"class.JPH::Ragdoll", ptr %14, i32 0, i32 4
  %19 = load ptr, ptr %18, align 8, !tbaa !13
  %20 = load i8, ptr %6, align 1, !tbaa !11, !range !22, !noundef !23
  %21 = trunc i8 %20 to i1
  %22 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZN3JPHL21sGetBodyLockInterfaceEPKNS_13PhysicsSystemEb(ptr noundef %19, i1 noundef zeroext %21)
  %23 = getelementptr inbounds %"class.JPH::Ragdoll", ptr %14, i32 0, i32 2
  %24 = call noundef ptr @_ZN3JPH5ArrayINS_6BodyIDENS_12STLAllocatorIS1_EEE4dataEv(ptr noundef nonnull align 8 dereferenceable(24) %23)
  %25 = load i32, ptr %7, align 4, !tbaa !9
  call void @_ZN3JPH18BodyLockMultiWriteCI2NS_17BodyLockMultiBaseILb1ENS_4BodyEEEERKNS_17BodyLockInterfaceEPKNS_6BodyIDEi(ptr noundef nonnull align 8 dereferenceable(28) %8, ptr noundef nonnull align 8 dereferenceable(16) %22, ptr noundef %24, i32 noundef %25)
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %26

26:                                               ; preds = %40, %3
  %27 = load i32, ptr %9, align 4, !tbaa !9
  %28 = load i32, ptr %7, align 4, !tbaa !9
  %29 = icmp slt i32 %27, %28
  br i1 %29, label %31, label %30

30:                                               ; preds = %26
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  br label %47

31:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %32 = load i32, ptr %9, align 4, !tbaa !9
  %33 = invoke noundef ptr @_ZNK3JPH17BodyLockMultiBaseILb1ENS_4BodyEE7GetBodyEi(ptr noundef nonnull align 8 dereferenceable(28) %8, i32 noundef %32)
          to label %34 unwind label %43

34:                                               ; preds = %31
  store ptr %33, ptr %10, align 8, !tbaa !5
  %35 = load ptr, ptr %10, align 8, !tbaa !5
  %36 = invoke noundef nonnull align 8 dereferenceable(16) ptr @_ZN3JPH4Body17GetCollisionGroupEv(ptr noundef nonnull align 16 dereferenceable(122) %35)
          to label %37 unwind label %43

37:                                               ; preds = %34
  %38 = load i32, ptr %5, align 4, !tbaa !9
  invoke void @_ZN3JPH14CollisionGroup10SetGroupIDEj(ptr noundef nonnull align 8 dereferenceable(16) %36, i32 noundef %38)
          to label %39 unwind label %43

39:                                               ; preds = %37
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  br label %40

40:                                               ; preds = %39
  %41 = load i32, ptr %9, align 4, !tbaa !9
  %42 = add nsw i32 %41, 1
  store i32 %42, ptr %9, align 4, !tbaa !9
  br label %26, !llvm.loop !24

43:                                               ; preds = %37, %34, %31
  %44 = landingpad { ptr, i32 }
          cleanup
  %45 = extractvalue { ptr, i32 } %44, 0
  store ptr %45, ptr %11, align 8
  %46 = extractvalue { ptr, i32 } %44, 1
  store i32 %46, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  call void @_ZN3JPH17BodyLockMultiBaseILb1ENS_4BodyEED2Ev(ptr noundef nonnull align 8 dereferenceable(28) %8) #5
  call void @llvm.lifetime.end.p0(i64 32, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  br label %48

47:                                               ; preds = %30
  call void @_ZN3JPH17BodyLockMultiBaseILb1ENS_4BodyEED2Ev(ptr noundef nonnull align 8 dereferenceable(28) %8) #5
  call void @llvm.lifetime.end.p0(i64 32, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  ret void

48:                                               ; preds = %43
  %49 = load ptr, ptr %11, align 8
  %50 = load i32, ptr %12, align 4
  %51 = insertvalue { ptr, i32 } poison, ptr %49, 0
  %52 = insertvalue { ptr, i32 } %51, i32 %50, 1
  resume { ptr, i32 } %52
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN3JPH18BodyLockMultiWriteCI2NS_17BodyLockMultiBaseILb1ENS_4BodyEEEERKNS_17BodyLockInterfaceEPKNS_6BodyIDEi(ptr noundef nonnull align 8 dereferenceable(28), ptr noundef nonnull align 8 dereferenceable(16), ptr noundef, i32 noundef) unnamed_addr #3 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZNK3JPH17BodyLockMultiBaseILb1ENS_4BodyEE7GetBodyEi(ptr noundef nonnull align 8 dereferenceable(28), i32 noundef) #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3JPH17BodyLockMultiBaseILb1ENS_4BodyEED2Ev(ptr noundef nonnull align 8 dereferenceable(28)) unnamed_addr #1 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 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 = { 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 #4 = { 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 = { 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 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{!14, !6, i64 64}
!14 = !{!"_ZTSN3JPH7RagdollE", !15, i64 0, !18, i64 8, !19, i64 16, !21, i64 40, !6, i64 64}
!15 = !{!"_ZTSN3JPH9RefTargetINS_7RagdollEEE", !16, i64 0}
!16 = !{!"_ZTSSt6atomicIjE", !17, i64 0}
!17 = !{!"_ZTSSt13__atomic_baseIjE", !10, i64 0}
!18 = !{!"_ZTSN3JPH8RefConstINS_15RagdollSettingsEEE", !6, i64 0}
!19 = !{!"_ZTSN3JPH5ArrayINS_6BodyIDENS_12STLAllocatorIS1_EEEE", !20, i64 0, !20, i64 8, !6, i64 16}
!20 = !{!"long", !7, i64 0}
!21 = !{!"_ZTSN3JPH5ArrayINS_3RefINS_17TwoBodyConstraintEEENS_12STLAllocatorIS3_EEEE", !20, i64 0, !20, i64 8, !6, i64 16}
!22 = !{i8 0, i8 2}
!23 = !{}
!24 = distinct !{!24, !25}
!25 = !{!"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"

%"class.JPH::BodyLockMultiWrite" = type { %"class.JPH::BodyLockMultiBase.base.98", [4 x i8] }
%"class.JPH::BodyLockMultiBase.base.98" = type <{ ptr, i64, ptr, i32 }>

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

declare i32 @__gxx_personality_v0(...)

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZN3JPH4Body17GetCollisionGroupEv(ptr noundef nonnull align 16 dereferenceable(122)) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN3JPH14CollisionGroup10SetGroupIDEj(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) local_unnamed_addr #2 align 2

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare hidden noundef nonnull align 8 dereferenceable(16) ptr @_ZN3JPHL21sGetBodyLockInterfaceEPKNS_13PhysicsSystemEb(ptr noundef, i1 noundef zeroext) local_unnamed_addr #3

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3JPH7Ragdoll10SetGroupIDEjb(ptr noundef nonnull align 8 dereferenceable(72) %0, i32 noundef %1, i1 noundef zeroext %2) local_unnamed_addr #4 align 2 personality ptr @__gxx_personality_v0 {
  %4 = alloca %"class.JPH::BodyLockMultiWrite", align 8
  %5 = getelementptr inbounds i8, ptr %0, i64 16
  %6 = tail call noundef i64 @_ZNK3JPH5ArrayINS_6BodyIDENS_12STLAllocatorIS1_EEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %5)
  %7 = trunc i64 %6 to i32
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %4) #5
  %8 = getelementptr inbounds i8, ptr %0, i64 64
  %9 = load ptr, ptr %8, align 8, !tbaa !5
  %10 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZN3JPHL21sGetBodyLockInterfaceEPKNS_13PhysicsSystemEb(ptr noundef %9, i1 noundef zeroext %2)
  %11 = tail call noundef ptr @_ZN3JPH5ArrayINS_6BodyIDENS_12STLAllocatorIS1_EEE4dataEv(ptr noundef nonnull align 8 dereferenceable(24) %5)
  call void @_ZN3JPH18BodyLockMultiWriteCI2NS_17BodyLockMultiBaseILb1ENS_4BodyEEEERKNS_17BodyLockInterfaceEPKNS_6BodyIDEi(ptr noundef nonnull align 8 dereferenceable(28) %4, ptr noundef nonnull align 8 dereferenceable(16) %10, ptr noundef %11, i32 noundef %7)
  %12 = icmp sgt i32 %7, 0
  br i1 %12, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %14, %3
  call void @_ZN3JPH17BodyLockMultiBaseILb1ENS_4BodyEED2Ev(ptr noundef nonnull align 8 dereferenceable(28) %4) #5
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %4) #5
  ret void

.lr.ph:                                           ; preds = %3, %14
  %.010 = phi i32 [ %16, %14 ], [ 0, %3 ]
  %13 = invoke noundef ptr @_ZNK3JPH17BodyLockMultiBaseILb1ENS_4BodyEE7GetBodyEi(ptr noundef nonnull align 8 dereferenceable(28) %4, i32 noundef %.010)
          to label %14 unwind label %17

14:                                               ; preds = %.lr.ph
  %15 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZN3JPH4Body17GetCollisionGroupEv(ptr noundef nonnull align 16 dereferenceable(122) %13)
  call void @_ZN3JPH14CollisionGroup10SetGroupIDEj(ptr noundef nonnull align 8 dereferenceable(16) %15, i32 noundef %1)
  %16 = add nuw nsw i32 %.010, 1
  %exitcond.not = icmp eq i32 %16, %7
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !18

17:                                               ; preds = %.lr.ph
  %18 = landingpad { ptr, i32 }
          cleanup
  call void @_ZN3JPH17BodyLockMultiBaseILb1ENS_4BodyEED2Ev(ptr noundef nonnull align 8 dereferenceable(28) %4) #5
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %4) #5
  resume { ptr, i32 } %18
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN3JPH18BodyLockMultiWriteCI2NS_17BodyLockMultiBaseILb1ENS_4BodyEEEERKNS_17BodyLockInterfaceEPKNS_6BodyIDEi(ptr noundef nonnull align 8 dereferenceable(28), ptr noundef nonnull align 8 dereferenceable(16), ptr noundef, i32 noundef) unnamed_addr #3 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZNK3JPH17BodyLockMultiBaseILb1ENS_4BodyEE7GetBodyEi(ptr noundef nonnull align 8 dereferenceable(28), i32 noundef) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3JPH17BodyLockMultiBaseILb1ENS_4BodyEED2Ev(ptr noundef nonnull align 8 dereferenceable(28)) unnamed_addr #1 align 2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 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 = { 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 #4 = { 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 = { 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, !14, i64 64}
!6 = !{!"_ZTSN3JPH7RagdollE", !7, i64 0, !13, i64 8, !15, i64 16, !17, i64 40, !14, i64 64}
!7 = !{!"_ZTSN3JPH9RefTargetINS_7RagdollEEE", !8, i64 0}
!8 = !{!"_ZTSSt6atomicIjE", !9, i64 0}
!9 = !{!"_ZTSSt13__atomic_baseIjE", !10, i64 0}
!10 = !{!"int", !11, i64 0}
!11 = !{!"omnipotent char", !12, i64 0}
!12 = !{!"Simple C++ TBAA"}
!13 = !{!"_ZTSN3JPH8RefConstINS_15RagdollSettingsEEE", !14, i64 0}
!14 = !{!"any pointer", !11, i64 0}
!15 = !{!"_ZTSN3JPH5ArrayINS_6BodyIDENS_12STLAllocatorIS1_EEEE", !16, i64 0, !16, i64 8, !14, i64 16}
!16 = !{!"long", !11, i64 0}
!17 = !{!"_ZTSN3JPH5ArrayINS_3RefINS_17TwoBodyConstraintEEENS_12STLAllocatorIS3_EEEE", !16, i64 0, !16, i64 8, !14, i64 16}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


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