; LLVM IR from jrouwe/JoltPhysics :: Jolt/Physics/Constraints (ContactConstraintManager)

; 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::BodyPair" = type { %"class.JPH::BodyID", %"class.JPH::BodyID" }
%"class.JPH::BodyID" = type { i32 }
%"class.JPH::ContactConstraintManager" = type { [8 x i8], [2 x %"class.JPH::ContactConstraintManager::ManifoldCache"], i32, ptr, ptr, ptr, ptr, ptr, i32, %"struct.std::atomic", ptr }
%"class.JPH::ContactConstraintManager::ManifoldCache" = type <{ %"class.JPH::LFHMAllocator", %"class.JPH::LockFreeHashMap", %"class.JPH::LockFreeHashMap.0", i8, [7 x i8] }>
%"class.JPH::LFHMAllocator" = type { ptr, i32, %"struct.std::atomic" }
%"class.JPH::LockFreeHashMap" = type { ptr, %"struct.std::atomic", ptr, i32, i32 }
%"class.JPH::LockFreeHashMap.0" = type { ptr, %"struct.std::atomic", ptr, i32, i32 }
%"struct.std::atomic" = type { %"struct.std::__atomic_base" }
%"struct.std::__atomic_base" = type { i32 }
%"class.JPH::ContactConstraintManager::CachedBodyPair" = type { %"class.JPH::Float3", %"class.JPH::Float3", i32 }
%"class.JPH::Float3" = type { float, float, float }

; 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: 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: mustprogress uwtable
declare dso_local noundef ptr @_ZNK3JPH24ContactConstraintManager13ManifoldCache4FindERKNS_8BodyPairEm(ptr noundef nonnull align 8 dereferenceable(81), ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(28) ptr @_ZNK3JPH15LockFreeHashMapINS_8BodyPairENS_24ContactConstraintManager14CachedBodyPairEE8KeyValue8GetValueEv(ptr noundef nonnull align 8 dereferenceable(40)) #3 align 2

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK3JPH6BodyIDltERKS0_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #4 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZNK3JPH24ContactConstraintManager19WereBodiesInContactERKNS_6BodyIDES3_(ptr noundef nonnull align 8 dereferenceable(248) %0, ptr noundef nonnull align 4 dereferenceable(4) %1, ptr noundef nonnull align 4 dereferenceable(4) %2) #2 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca %"struct.JPH::BodyPair", align 8
  %9 = alloca %"struct.JPH::BodyPair", align 8
  %10 = alloca %"class.JPH::BodyID", align 4
  %11 = alloca %"class.JPH::BodyID", align 4
  %12 = alloca %"struct.JPH::BodyPair", align 8
  %13 = alloca %"class.JPH::BodyID", align 4
  %14 = alloca %"class.JPH::BodyID", align 4
  %15 = alloca i64, align 8
  %16 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  %17 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %18 = getelementptr inbounds %"class.JPH::ContactConstraintManager", ptr %17, i32 0, i32 1
  %19 = getelementptr inbounds %"class.JPH::ContactConstraintManager", ptr %17, i32 0, i32 2
  %20 = load i32, ptr %19, align 8, !tbaa !9
  %21 = xor i32 %20, 1
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [2 x %"class.JPH::ContactConstraintManager::ManifoldCache"], ptr %18, i64 0, i64 %22
  store ptr %23, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  call void @_ZN3JPH8BodyPairC2Ev(ptr noundef nonnull align 8 dereferenceable(8) %8)
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = call noundef zeroext i1 @_ZNK3JPH6BodyIDltERKS0_(ptr noundef nonnull align 4 dereferenceable(4) %24, ptr noundef nonnull align 4 dereferenceable(4) %25)
  br i1 %26, label %27, label %34

27:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %10, ptr align 4 %28, i64 4, i1 false), !tbaa.struct !14
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %11, ptr align 4 %29, i64 4, i1 false), !tbaa.struct !14
  %30 = getelementptr inbounds %"class.JPH::BodyID", ptr %10, i32 0, i32 0
  %31 = load i32, ptr %30, align 4
  %32 = getelementptr inbounds %"class.JPH::BodyID", ptr %11, i32 0, i32 0
  %33 = load i32, ptr %32, align 4
  call void @_ZN3JPH8BodyPairC2ENS_6BodyIDES1_(ptr noundef nonnull align 8 dereferenceable(8) %9, i32 %31, i32 %33)
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %8, ptr align 8 %9, i64 8, i1 false), !tbaa.struct !16
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  br label %41

34:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %13, ptr align 4 %35, i64 4, i1 false), !tbaa.struct !14
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %14, ptr align 4 %36, i64 4, i1 false), !tbaa.struct !14
  %37 = getelementptr inbounds %"class.JPH::BodyID", ptr %13, i32 0, i32 0
  %38 = load i32, ptr %37, align 4
  %39 = getelementptr inbounds %"class.JPH::BodyID", ptr %14, i32 0, i32 0
  %40 = load i32, ptr %39, align 4
  call void @_ZN3JPH8BodyPairC2ENS_6BodyIDES1_(ptr noundef nonnull align 8 dereferenceable(8) %12, i32 %38, i32 %40)
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %8, ptr align 8 %12, i64 8, i1 false), !tbaa.struct !16
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  br label %41

41:                                               ; preds = %34, %27
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #5
  %42 = call noundef i64 @_ZNK3JPH8BodyPair7GetHashEv(ptr noundef nonnull align 8 dereferenceable(8) %8)
  store i64 %42, ptr %15, align 8, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #5
  %43 = load ptr, ptr %7, align 8, !tbaa !5
  %44 = load i64, ptr %15, align 8, !tbaa !17
  %45 = call noundef ptr @_ZNK3JPH24ContactConstraintManager13ManifoldCache4FindERKNS_8BodyPairEm(ptr noundef nonnull align 8 dereferenceable(81) %43, ptr noundef nonnull align 8 dereferenceable(8) %8, i64 noundef %44)
  store ptr %45, ptr %16, align 8, !tbaa !5
  %46 = load ptr, ptr %16, align 8, !tbaa !5
  %47 = icmp ne ptr %46, null
  br i1 %47, label %48, label %54

48:                                               ; preds = %41
  %49 = load ptr, ptr %16, align 8, !tbaa !5
  %50 = call noundef nonnull align 4 dereferenceable(28) ptr @_ZNK3JPH15LockFreeHashMapINS_8BodyPairENS_24ContactConstraintManager14CachedBodyPairEE8KeyValue8GetValueEv(ptr noundef nonnull align 8 dereferenceable(40) %49)
  %51 = getelementptr inbounds %"class.JPH::ContactConstraintManager::CachedBodyPair", ptr %50, i32 0, i32 2
  %52 = load i32, ptr %51, align 4, !tbaa !19
  %53 = icmp ne i32 %52, -1
  br label %54

54:                                               ; preds = %48, %41
  %55 = phi i1 [ false, %41 ], [ %53, %48 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  ret i1 %55
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree 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 = { 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 #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, !11, i64 184}
!10 = !{!"_ZTSN3JPH24ContactConstraintManagerE", !7, i64 8, !11, i64 184, !6, i64 192, !6, i64 200, !6, i64 208, !6, i64 216, !6, i64 224, !11, i64 232, !12, i64 236, !6, i64 240}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_ZTSSt6atomicIjE", !13, i64 0}
!13 = !{!"_ZTSSt13__atomic_baseIjE", !11, i64 0}
!14 = !{i64 0, i64 4, !15}
!15 = !{!11, !11, i64 0}
!16 = !{i64 0, i64 4, !15, i64 4, i64 4, !15}
!17 = !{!18, !18, i64 0}
!18 = !{!"long", !7, i64 0}
!19 = !{!20, !11, i64 24}
!20 = !{!"_ZTSN3JPH24ContactConstraintManager14CachedBodyPairE", !21, i64 0, !21, i64 12, !11, i64 24}
!21 = !{!"_ZTSN3JPH6Float3E", !22, i64 0, !22, i64 4, !22, i64 8}
!22 = !{!"float", !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"

%"struct.JPH::BodyPair" = type { %"class.JPH::BodyID", %"class.JPH::BodyID" }
%"class.JPH::BodyID" = type { i32 }
%"class.JPH::ContactConstraintManager::ManifoldCache" = type <{ %"class.JPH::LFHMAllocator", %"class.JPH::LockFreeHashMap", %"class.JPH::LockFreeHashMap.0", i8, [7 x i8] }>
%"class.JPH::LFHMAllocator" = type { ptr, i32, %"struct.std::atomic" }
%"struct.std::atomic" = type { %"struct.std::__atomic_base" }
%"struct.std::__atomic_base" = type { i32 }
%"class.JPH::LockFreeHashMap" = type { ptr, %"struct.std::atomic", ptr, i32, i32 }
%"class.JPH::LockFreeHashMap.0" = type { ptr, %"struct.std::atomic", ptr, i32, i32 }

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

; 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 uwtable
declare dso_local noundef ptr @_ZNK3JPH24ContactConstraintManager13ManifoldCache4FindERKNS_8BodyPairEm(ptr noundef nonnull align 8 dereferenceable(81), ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(28) ptr @_ZNK3JPH15LockFreeHashMapINS_8BodyPairENS_24ContactConstraintManager14CachedBodyPairEE8KeyValue8GetValueEv(ptr noundef nonnull align 8 dereferenceable(40)) local_unnamed_addr #2 align 2

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK3JPH6BodyIDltERKS0_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #3 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZNK3JPH24ContactConstraintManager19WereBodiesInContactERKNS_6BodyIDES3_(ptr noundef nonnull align 8 dereferenceable(248) %0, ptr noundef nonnull align 4 dereferenceable(4) %1, ptr noundef nonnull align 4 dereferenceable(4) %2) local_unnamed_addr #1 align 2 {
  %4 = alloca %"struct.JPH::BodyPair", align 8
  %5 = alloca %"struct.JPH::BodyPair", align 8
  %6 = alloca %"struct.JPH::BodyPair", align 8
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  %8 = getelementptr inbounds i8, ptr %0, i64 184
  %9 = load i32, ptr %8, align 8, !tbaa !5
  %10 = xor i32 %9, 1
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [2 x %"class.JPH::ContactConstraintManager::ManifoldCache"], ptr %7, i64 0, i64 %11
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #4
  call void @_ZN3JPH8BodyPairC2Ev(ptr noundef nonnull align 8 dereferenceable(8) %4)
  %13 = call noundef zeroext i1 @_ZNK3JPH6BodyIDltERKS0_(ptr noundef nonnull align 4 dereferenceable(4) %1, ptr noundef nonnull align 4 dereferenceable(4) %2)
  br i1 %13, label %14, label %16

14:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #4
  %.sroa.04.0.copyload = load i32, ptr %1, align 4, !tbaa !13
  %.sroa.03.0.copyload = load i32, ptr %2, align 4, !tbaa !13
  call void @_ZN3JPH8BodyPairC2ENS_6BodyIDES1_(ptr noundef nonnull align 8 dereferenceable(8) %5, i32 %.sroa.04.0.copyload, i32 %.sroa.03.0.copyload)
  %15 = load i64, ptr %5, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #4
  br label %18

16:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #4
  %.sroa.02.0.copyload = load i32, ptr %2, align 4, !tbaa !13
  %.sroa.0.0.copyload = load i32, ptr %1, align 4, !tbaa !13
  call void @_ZN3JPH8BodyPairC2ENS_6BodyIDES1_(ptr noundef nonnull align 8 dereferenceable(8) %6, i32 %.sroa.02.0.copyload, i32 %.sroa.0.0.copyload)
  %17 = load i64, ptr %6, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #4
  br label %18

18:                                               ; preds = %16, %14
  %.sink = phi i64 [ %15, %14 ], [ %17, %16 ]
  store i64 %.sink, ptr %4, align 8
  %19 = call noundef i64 @_ZNK3JPH8BodyPair7GetHashEv(ptr noundef nonnull align 8 dereferenceable(8) %4)
  %20 = call noundef ptr @_ZNK3JPH24ContactConstraintManager13ManifoldCache4FindERKNS_8BodyPairEm(ptr noundef nonnull align 8 dereferenceable(81) %12, ptr noundef nonnull align 8 dereferenceable(8) %4, i64 noundef %19)
  %.not = icmp eq ptr %20, null
  br i1 %.not, label %26, label %21

21:                                               ; preds = %18
  %22 = call noundef nonnull align 4 dereferenceable(28) ptr @_ZNK3JPH15LockFreeHashMapINS_8BodyPairENS_24ContactConstraintManager14CachedBodyPairEE8KeyValue8GetValueEv(ptr noundef nonnull align 8 dereferenceable(40) %20)
  %23 = getelementptr inbounds i8, ptr %22, i64 24
  %24 = load i32, ptr %23, align 4, !tbaa !14
  %25 = icmp ne i32 %24, -1
  br label %26

26:                                               ; preds = %21, %18
  %27 = phi i1 [ false, %18 ], [ %25, %21 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #4
  ret i1 %27
}

attributes #0 = { mustprogress 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 = { 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 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)"}
!5 = !{!6, !9, i64 184}
!6 = !{!"_ZTSN3JPH24ContactConstraintManagerE", !7, i64 8, !9, i64 184, !10, i64 192, !10, i64 200, !10, i64 208, !10, i64 216, !10, i64 224, !9, i64 232, !11, i64 236, !10, i64 240}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!"_ZTSSt6atomicIjE", !12, i64 0}
!12 = !{!"_ZTSSt13__atomic_baseIjE", !9, i64 0}
!13 = !{!9, !9, i64 0}
!14 = !{!15, !9, i64 24}
!15 = !{!"_ZTSN3JPH24ContactConstraintManager14CachedBodyPairE", !16, i64 0, !16, i64 12, !9, i64 24}
!16 = !{!"_ZTSN3JPH6Float3E", !17, i64 0, !17, i64 4, !17, i64 8}
!17 = !{!"float", !7, i64 0}


; Effective O3 passes: GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,MergedLoadStoreMotionPass,SROAPass