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

; 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::BodyLockMultiRead" = type { %"class.JPH::BodyLockMultiBase.base", [4 x i8] }
%"class.JPH::BodyLockMultiBase.base" = 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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNK3JPH5ArrayINS_6BodyIDENS_12STLAllocatorIS1_EEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZNK3JPH7Ragdoll8IsActiveEb(ptr noundef nonnull align 8 dereferenceable(72) %0, i1 noundef zeroext %1) #2 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca i1, align 1
  %4 = alloca ptr, align 8
  %5 = alloca i8, align 1
  %6 = alloca i32, align 4
  %7 = alloca %"class.JPH::BodyLockMultiRead", align 8
  %8 = alloca i32, align 4
  %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
  %13 = zext i1 %1 to i8
  store i8 %13, ptr %5, align 1, !tbaa !9
  %14 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #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 %6, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 32, ptr %7) #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 %5, align 1, !tbaa !9, !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 @_ZNK3JPH5ArrayINS_6BodyIDENS_12STLAllocatorIS1_EEE4dataEv(ptr noundef nonnull align 8 dereferenceable(24) %23)
  %25 = load i32, ptr %6, align 4, !tbaa !11
  call void @_ZN3JPH17BodyLockMultiReadCI2NS_17BodyLockMultiBaseILb0EKNS_4BodyEEEERKNS_17BodyLockInterfaceEPKNS_6BodyIDEi(ptr noundef nonnull align 8 dereferenceable(28) %7, ptr noundef nonnull align 8 dereferenceable(16) %22, ptr noundef %24, i32 noundef %25)
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  store i32 0, ptr %8, align 4, !tbaa !11
  br label %26

26:                                               ; preds = %47, %2
  %27 = load i32, ptr %8, align 4, !tbaa !11
  %28 = load i32, ptr %6, align 4, !tbaa !11
  %29 = icmp slt i32 %27, %28
  br i1 %29, label %31, label %30

30:                                               ; preds = %26
  store i32 2, ptr %9, align 4
  br label %50

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

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

37:                                               ; preds = %34
  br i1 %36, label %38, label %43

38:                                               ; preds = %37
  store i1 true, ptr %3, align 1
  store i32 1, ptr %9, align 4
  br label %44

39:                                               ; preds = %34, %31
  %40 = landingpad { ptr, i32 }
          cleanup
  %41 = extractvalue { ptr, i32 } %40, 0
  store ptr %41, ptr %11, align 8
  %42 = extractvalue { ptr, i32 } %40, 1
  store i32 %42, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  call void @_ZN3JPH17BodyLockMultiBaseILb0EKNS_4BodyEED2Ev(ptr noundef nonnull align 8 dereferenceable(28) %7) #5
  call void @llvm.lifetime.end.p0(i64 32, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  br label %55

43:                                               ; preds = %37
  store i32 0, ptr %9, align 4
  br label %44

44:                                               ; preds = %43, %38
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  %45 = load i32, ptr %9, align 4
  switch i32 %45, label %50 [
    i32 0, label %46
  ]

46:                                               ; preds = %44
  br label %47

47:                                               ; preds = %46
  %48 = load i32, ptr %8, align 4, !tbaa !11
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %8, align 4, !tbaa !11
  br label %26, !llvm.loop !24

50:                                               ; preds = %44, %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  %51 = load i32, ptr %9, align 4
  switch i32 %51, label %53 [
    i32 2, label %52
  ]

52:                                               ; preds = %50
  store i1 false, ptr %3, align 1
  store i32 1, ptr %9, align 4
  br label %53

53:                                               ; preds = %52, %50
  call void @_ZN3JPH17BodyLockMultiBaseILb0EKNS_4BodyEED2Ev(ptr noundef nonnull align 8 dereferenceable(28) %7) #5
  call void @llvm.lifetime.end.p0(i64 32, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  %54 = load i1, ptr %3, align 1
  ret i1 %54

55:                                               ; preds = %39
  %56 = load ptr, ptr %11, align 8
  %57 = load i32, ptr %12, align 4
  %58 = insertvalue { ptr, i32 } poison, ptr %56, 0
  %59 = insertvalue { ptr, i32 } %58, i32 %57, 1
  resume { ptr, i32 } %59
}

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN3JPH17BodyLockMultiReadCI2NS_17BodyLockMultiBaseILb0EKNS_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 @_ZNK3JPH17BodyLockMultiBaseILb0EKNS_4BodyEE7GetBodyEi(ptr noundef nonnull align 8 dereferenceable(28), i32 noundef) #3 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK3JPH4Body8IsActiveEv(ptr noundef nonnull align 16 dereferenceable(122)) #1 align 2

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = { 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 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !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", !12, 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::BodyLockMultiRead" = type { %"class.JPH::BodyLockMultiBase.base", [4 x i8] }
%"class.JPH::BodyLockMultiBase.base" = 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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNK3JPH5ArrayINS_6BodyIDENS_12STLAllocatorIS1_EEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #1 align 2

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

11:                                               ; preds = %14
  %12 = add nuw nsw i32 %.01318, 1
  %.not = icmp slt i32 %12, %6
  %exitcond.not = icmp eq i32 %12, %6
  br i1 %exitcond.not, label %.critedge, label %.lr.ph, !llvm.loop !18

.lr.ph:                                           ; preds = %2, %11
  %.not19 = phi i1 [ %.not, %11 ], [ true, %2 ]
  %.01318 = phi i32 [ %12, %11 ], [ 0, %2 ]
  %13 = invoke noundef ptr @_ZNK3JPH17BodyLockMultiBaseILb0EKNS_4BodyEE7GetBodyEi(ptr noundef nonnull align 8 dereferenceable(28) %3, i32 noundef %.01318)
          to label %14 unwind label %16

14:                                               ; preds = %.lr.ph
  %15 = call noundef zeroext i1 @_ZNK3JPH4Body8IsActiveEv(ptr noundef nonnull align 16 dereferenceable(122) %13)
  br i1 %15, label %.critedge, label %11

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

.critedge:                                        ; preds = %14, %11, %2
  %.not.lcssa = phi i1 [ false, %2 ], [ %.not, %11 ], [ %.not19, %14 ]
  call void @_ZN3JPH17BodyLockMultiBaseILb0EKNS_4BodyEED2Ev(ptr noundef nonnull align 8 dereferenceable(28) %3) #5
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %3) #5
  ret i1 %.not.lcssa
}

; 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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK3JPH5ArrayINS_6BodyIDENS_12STLAllocatorIS1_EEE4dataEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN3JPH17BodyLockMultiReadCI2NS_17BodyLockMultiBaseILb0EKNS_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 @_ZNK3JPH17BodyLockMultiBaseILb0EKNS_4BodyEE7GetBodyEi(ptr noundef nonnull align 8 dereferenceable(28), i32 noundef) local_unnamed_addr #3 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK3JPH4Body8IsActiveEv(ptr noundef nonnull align 16 dereferenceable(122)) local_unnamed_addr #1 align 2

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = { 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 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, !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,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass