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

; 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::BodyID" = type { i32 }
%"class.JPH::TwoBodyConstraint" = type { %"class.JPH::Constraint", ptr, ptr }
%"class.JPH::Constraint" = type { ptr, %"class.JPH::RefTarget.0", i32, i32, i8, i8, i8, i64 }
%"class.JPH::RefTarget.0" = type { %"struct.std::atomic" }
%"struct.std::atomic" = type { %"struct.std::__atomic_base" }
%"struct.std::__atomic_base" = type { i32 }

; 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
define dso_local void @_ZN3JPH17TwoBodyConstraint12BuildIslandsEjRNS_13IslandBuilderERNS_11BodyManagerE(ptr noundef nonnull align 8 dereferenceable(48) %0, i32 noundef %1, ptr noundef nonnull align 8 dereferenceable(112) %2, ptr noundef nonnull align 8 dereferenceable(297) %3) unnamed_addr #1 align 2 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca [2 x %"class.JPH::BodyID"], align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !5
  %11 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #6
  %12 = getelementptr inbounds [2 x %"class.JPH::BodyID"], ptr %9, i32 0, i32 0
  %13 = getelementptr inbounds %"class.JPH::BodyID", ptr %12, i64 2
  br label %14

14:                                               ; preds = %14, %4
  %15 = phi ptr [ %12, %4 ], [ %16, %14 ]
  call void @_ZN3JPH6BodyIDC2Ev(ptr noundef nonnull align 4 dereferenceable(4) %15)
  %16 = getelementptr inbounds %"class.JPH::BodyID", ptr %15, i64 1
  %17 = icmp eq ptr %16, %13
  br i1 %17, label %18, label %14

18:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #6
  store i32 0, ptr %10, align 4, !tbaa !9
  %19 = getelementptr inbounds %"class.JPH::TwoBodyConstraint", ptr %11, i32 0, i32 1
  %20 = load ptr, ptr %19, align 8, !tbaa !11
  %21 = call noundef zeroext i1 @_ZNK3JPH4Body9IsDynamicEv(ptr noundef nonnull align 16 dereferenceable(122) %20)
  br i1 %21, label %22, label %34

22:                                               ; preds = %18
  %23 = getelementptr inbounds %"class.JPH::TwoBodyConstraint", ptr %11, i32 0, i32 1
  %24 = load ptr, ptr %23, align 8, !tbaa !11
  %25 = call noundef zeroext i1 @_ZNK3JPH4Body8IsActiveEv(ptr noundef nonnull align 16 dereferenceable(122) %24)
  br i1 %25, label %34, label %26

26:                                               ; preds = %22
  %27 = getelementptr inbounds %"class.JPH::TwoBodyConstraint", ptr %11, i32 0, i32 1
  %28 = load ptr, ptr %27, align 8, !tbaa !11
  %29 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNK3JPH4Body5GetIDEv(ptr noundef nonnull align 16 dereferenceable(122) %28)
  %30 = load i32, ptr %10, align 4, !tbaa !9
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr %10, align 4, !tbaa !9
  %32 = sext i32 %30 to i64
  %33 = getelementptr inbounds [2 x %"class.JPH::BodyID"], ptr %9, i64 0, i64 %32
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %33, ptr align 4 %29, i64 4, i1 false), !tbaa.struct !19
  br label %34

34:                                               ; preds = %26, %22, %18
  %35 = getelementptr inbounds %"class.JPH::TwoBodyConstraint", ptr %11, i32 0, i32 2
  %36 = load ptr, ptr %35, align 8, !tbaa !20
  %37 = call noundef zeroext i1 @_ZNK3JPH4Body9IsDynamicEv(ptr noundef nonnull align 16 dereferenceable(122) %36)
  br i1 %37, label %38, label %50

38:                                               ; preds = %34
  %39 = getelementptr inbounds %"class.JPH::TwoBodyConstraint", ptr %11, i32 0, i32 2
  %40 = load ptr, ptr %39, align 8, !tbaa !20
  %41 = call noundef zeroext i1 @_ZNK3JPH4Body8IsActiveEv(ptr noundef nonnull align 16 dereferenceable(122) %40)
  br i1 %41, label %50, label %42

42:                                               ; preds = %38
  %43 = getelementptr inbounds %"class.JPH::TwoBodyConstraint", ptr %11, i32 0, i32 2
  %44 = load ptr, ptr %43, align 8, !tbaa !20
  %45 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNK3JPH4Body5GetIDEv(ptr noundef nonnull align 16 dereferenceable(122) %44)
  %46 = load i32, ptr %10, align 4, !tbaa !9
  %47 = add nsw i32 %46, 1
  store i32 %47, ptr %10, align 4, !tbaa !9
  %48 = sext i32 %46 to i64
  %49 = getelementptr inbounds [2 x %"class.JPH::BodyID"], ptr %9, i64 0, i64 %48
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %49, ptr align 4 %45, i64 4, i1 false), !tbaa.struct !19
  br label %50

50:                                               ; preds = %42, %38, %34
  %51 = load i32, ptr %10, align 4, !tbaa !9
  %52 = icmp sgt i32 %51, 0
  br i1 %52, label %53, label %57

53:                                               ; preds = %50
  %54 = load ptr, ptr %8, align 8, !tbaa !5
  %55 = getelementptr inbounds [2 x %"class.JPH::BodyID"], ptr %9, i64 0, i64 0
  %56 = load i32, ptr %10, align 4, !tbaa !9
  call void @_ZN3JPH11BodyManager14ActivateBodiesEPKNS_6BodyIDEi(ptr noundef nonnull align 8 dereferenceable(297) %54, ptr noundef %55, i32 noundef %56)
  br label %57

57:                                               ; preds = %53, %50
  %58 = load ptr, ptr %7, align 8, !tbaa !5
  %59 = load i32, ptr %6, align 4, !tbaa !9
  %60 = getelementptr inbounds %"class.JPH::TwoBodyConstraint", ptr %11, i32 0, i32 1
  %61 = load ptr, ptr %60, align 8, !tbaa !11
  %62 = call noundef i32 @_ZNK3JPH4Body30GetIndexInActiveBodiesInternalEv(ptr noundef nonnull align 16 dereferenceable(122) %61)
  %63 = getelementptr inbounds %"class.JPH::TwoBodyConstraint", ptr %11, i32 0, i32 2
  %64 = load ptr, ptr %63, align 8, !tbaa !20
  %65 = call noundef i32 @_ZNK3JPH4Body30GetIndexInActiveBodiesInternalEv(ptr noundef nonnull align 16 dereferenceable(122) %64)
  call void @_ZN3JPH13IslandBuilder14LinkConstraintEjjj(ptr noundef nonnull align 8 dereferenceable(112) %58, i32 noundef %59, i32 noundef %62, i32 noundef %65)
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #6
  ret void
}

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

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNK3JPH4Body5GetIDEv(ptr noundef nonnull align 16 dereferenceable(122)) #3 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) #4

declare void @_ZN3JPH11BodyManager14ActivateBodiesEPKNS_6BodyIDEi(ptr noundef nonnull align 8 dereferenceable(297), ptr noundef, i32 noundef) #5

declare void @_ZN3JPH13IslandBuilder14LinkConstraintEjjj(ptr noundef nonnull align 8 dereferenceable(112), i32 noundef, i32 noundef, i32 noundef) #5

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK3JPH4Body30GetIndexInActiveBodiesInternalEv(ptr noundef nonnull align 16 dereferenceable(122)) #2 align 2

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 = { 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { "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 = !{!12, !6, i64 32}
!12 = !{!"_ZTSN3JPH17TwoBodyConstraintE", !13, i64 0, !6, i64 32, !6, i64 40}
!13 = !{!"_ZTSN3JPH10ConstraintE", !14, i64 8, !10, i64 12, !10, i64 16, !7, i64 20, !7, i64 21, !17, i64 22, !18, i64 24}
!14 = !{!"_ZTSN3JPH9RefTargetINS_10ConstraintEEE", !15, i64 0}
!15 = !{!"_ZTSSt6atomicIjE", !16, i64 0}
!16 = !{!"_ZTSSt13__atomic_baseIjE", !10, i64 0}
!17 = !{!"bool", !7, i64 0}
!18 = !{!"long", !7, i64 0}
!19 = !{i64 0, i64 4, !9}
!20 = !{!12, !6, i64 40}


; 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::BodyID" = type { 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
define dso_local void @_ZN3JPH17TwoBodyConstraint12BuildIslandsEjRNS_13IslandBuilderERNS_11BodyManagerE(ptr nocapture noundef nonnull readonly align 8 dereferenceable(48) %0, i32 noundef %1, ptr noundef nonnull align 8 dereferenceable(112) %2, ptr noundef nonnull align 8 dereferenceable(297) %3) unnamed_addr #1 align 2 {
  %5 = alloca [2 x %"class.JPH::BodyID"], align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #5
  call void @_ZN3JPH6BodyIDC2Ev(ptr noundef nonnull align 4 dereferenceable(4) %5)
  %.ptr.1 = getelementptr inbounds i8, ptr %5, i64 4
  call void @_ZN3JPH6BodyIDC2Ev(ptr noundef nonnull align 4 dereferenceable(4) %.ptr.1)
  %6 = getelementptr inbounds i8, ptr %0, i64 32
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %8 = call noundef zeroext i1 @_ZNK3JPH4Body9IsDynamicEv(ptr noundef nonnull align 16 dereferenceable(122) %7)
  br i1 %8, label %9, label %16

9:                                                ; preds = %4
  %10 = load ptr, ptr %6, align 8, !tbaa !5
  %11 = call noundef zeroext i1 @_ZNK3JPH4Body8IsActiveEv(ptr noundef nonnull align 16 dereferenceable(122) %10)
  br i1 %11, label %16, label %12

12:                                               ; preds = %9
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNK3JPH4Body5GetIDEv(ptr noundef nonnull align 16 dereferenceable(122) %13)
  %15 = load i32, ptr %14, align 4, !tbaa !17
  store i32 %15, ptr %5, align 4, !tbaa !17
  br label %16

16:                                               ; preds = %12, %9, %4
  %17 = phi i1 [ false, %9 ], [ true, %12 ], [ false, %4 ]
  %.0 = phi i32 [ 0, %9 ], [ 1, %12 ], [ 0, %4 ]
  %18 = getelementptr inbounds i8, ptr %0, i64 40
  %19 = load ptr, ptr %18, align 8, !tbaa !18
  %20 = call noundef zeroext i1 @_ZNK3JPH4Body9IsDynamicEv(ptr noundef nonnull align 16 dereferenceable(122) %19)
  br i1 %20, label %21, label %30

21:                                               ; preds = %16
  %22 = load ptr, ptr %18, align 8, !tbaa !18
  %23 = call noundef zeroext i1 @_ZNK3JPH4Body8IsActiveEv(ptr noundef nonnull align 16 dereferenceable(122) %22)
  br i1 %23, label %30, label %.thread

.thread:                                          ; preds = %21
  %24 = load ptr, ptr %18, align 8, !tbaa !18
  %25 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNK3JPH4Body5GetIDEv(ptr noundef nonnull align 16 dereferenceable(122) %24)
  %26 = add nuw nsw i32 %.0, 1
  %27 = zext nneg i32 %.0 to i64
  %28 = getelementptr inbounds [2 x %"class.JPH::BodyID"], ptr %5, i64 0, i64 %27
  %29 = load i32, ptr %25, align 4, !tbaa !17
  store i32 %29, ptr %28, align 4, !tbaa !17
  br label %31

30:                                               ; preds = %21, %16
  br i1 %17, label %31, label %32

31:                                               ; preds = %.thread, %30
  %.19 = phi i32 [ %26, %.thread ], [ 1, %30 ]
  call void @_ZN3JPH11BodyManager14ActivateBodiesEPKNS_6BodyIDEi(ptr noundef nonnull align 8 dereferenceable(297) %3, ptr noundef nonnull %5, i32 noundef %.19)
  br label %32

32:                                               ; preds = %31, %30
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = call noundef i32 @_ZNK3JPH4Body30GetIndexInActiveBodiesInternalEv(ptr noundef nonnull align 16 dereferenceable(122) %33)
  %35 = load ptr, ptr %18, align 8, !tbaa !18
  %36 = call noundef i32 @_ZNK3JPH4Body30GetIndexInActiveBodiesInternalEv(ptr noundef nonnull align 16 dereferenceable(122) %35)
  call void @_ZN3JPH13IslandBuilder14LinkConstraintEjjj(ptr noundef nonnull align 8 dereferenceable(112) %2, i32 noundef %1, i32 noundef %34, i32 noundef %36)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #5
  ret void
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK3JPH4Body9IsDynamicEv(ptr noundef nonnull align 16 dereferenceable(122)) 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 #3 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNK3JPH4Body5GetIDEv(ptr noundef nonnull align 16 dereferenceable(122)) local_unnamed_addr #3 align 2

declare void @_ZN3JPH11BodyManager14ActivateBodiesEPKNS_6BodyIDEi(ptr noundef nonnull align 8 dereferenceable(297), ptr noundef, i32 noundef) local_unnamed_addr #4

declare void @_ZN3JPH13IslandBuilder14LinkConstraintEjjj(ptr noundef nonnull align 8 dereferenceable(112), i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #4

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

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 = { "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, !16, i64 32}
!6 = !{!"_ZTSN3JPH17TwoBodyConstraintE", !7, i64 0, !16, i64 32, !16, i64 40}
!7 = !{!"_ZTSN3JPH10ConstraintE", !8, i64 8, !11, i64 12, !11, i64 16, !12, i64 20, !12, i64 21, !14, i64 22, !15, i64 24}
!8 = !{!"_ZTSN3JPH9RefTargetINS_10ConstraintEEE", !9, i64 0}
!9 = !{!"_ZTSSt6atomicIjE", !10, i64 0}
!10 = !{!"_ZTSSt13__atomic_baseIjE", !11, i64 0}
!11 = !{!"int", !12, i64 0}
!12 = !{!"omnipotent char", !13, i64 0}
!13 = !{!"Simple C++ TBAA"}
!14 = !{!"bool", !12, i64 0}
!15 = !{!"long", !12, i64 0}
!16 = !{!"any pointer", !12, i64 0}
!17 = !{!11, !11, i64 0}
!18 = !{!6, !16, i64 40}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SROAPass