; LLVM IR from atlantis13579/Riemann :: Src/RigidBodyDynamics/MassSpring.ll (ZN7Riemann16MassSpringSolver15SolveCollisionsEi)

; 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.Riemann::MassSpringSolver" = type { %"class.std::vector", %"class.std::vector", %"class.std::vector", %"class.std::vector", %"class.std::vector.0", float, float, float, %"class.std::vector.5", %"class.std::vector.10" }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<Maths::TVector3<float>, std::allocator<Maths::TVector3<float>>>::_Vector_impl" }
%"struct.std::_Vector_base<Maths::TVector3<float>, std::allocator<Maths::TVector3<float>>>::_Vector_impl" = type { %"struct.std::_Vector_base<Maths::TVector3<float>, std::allocator<Maths::TVector3<float>>>::_Vector_impl_data" }
%"struct.std::_Vector_base<Maths::TVector3<float>, std::allocator<Maths::TVector3<float>>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.std::vector.0" = type { %"struct.std::_Vector_base.1" }
%"struct.std::_Vector_base.1" = type { %"struct.std::_Vector_base<float, std::allocator<float>>::_Vector_impl" }
%"struct.std::_Vector_base<float, std::allocator<float>>::_Vector_impl" = type { %"struct.std::_Vector_base<float, std::allocator<float>>::_Vector_impl_data" }
%"struct.std::_Vector_base<float, std::allocator<float>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.std::vector.5" = type { %"struct.std::_Vector_base.6" }
%"struct.std::_Vector_base.6" = type { %"struct.std::_Vector_base<Riemann::MSConstraint *, std::allocator<Riemann::MSConstraint *>>::_Vector_impl" }
%"struct.std::_Vector_base<Riemann::MSConstraint *, std::allocator<Riemann::MSConstraint *>>::_Vector_impl" = type { %"struct.std::_Vector_base<Riemann::MSConstraint *, std::allocator<Riemann::MSConstraint *>>::_Vector_impl_data" }
%"struct.std::_Vector_base<Riemann::MSConstraint *, std::allocator<Riemann::MSConstraint *>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.std::vector.10" = type { %"struct.std::_Vector_base.11" }
%"struct.std::_Vector_base.11" = type { %"struct.std::_Vector_base<Riemann::MSCollision *, std::allocator<Riemann::MSCollision *>>::_Vector_impl" }
%"struct.std::_Vector_base<Riemann::MSCollision *, std::allocator<Riemann::MSCollision *>>::_Vector_impl" = type { %"struct.std::_Vector_base<Riemann::MSCollision *, std::allocator<Riemann::MSCollision *>>::_Vector_impl_data" }
%"struct.std::_Vector_base<Riemann::MSCollision *, std::allocator<Riemann::MSCollision *>>::_Vector_impl_data" = type { ptr, ptr, ptr }

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7Riemann16MassSpringSolver15SolveCollisionsEi(ptr noundef nonnull align 8 dereferenceable(184) %0, i32 noundef %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  %7 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %8 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store i64 0, ptr %5, align 8, !tbaa !11
  br label %9

9:                                                ; preds = %36, %2
  %10 = load i64, ptr %5, align 8, !tbaa !11
  %11 = getelementptr inbounds %"class.Riemann::MassSpringSolver", ptr %8, i32 0, i32 0
  %12 = call noundef i64 @_ZNKSt6vectorIN5Maths8TVector3IfEESaIS2_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %11) #3
  %13 = icmp ult i64 %10, %12
  br i1 %13, label %15, label %14

14:                                               ; preds = %9
  store i32 2, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  br label %39

15:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store i64 0, ptr %7, align 8, !tbaa !11
  br label %16

16:                                               ; preds = %32, %15
  %17 = load i64, ptr %7, align 8, !tbaa !11
  %18 = getelementptr inbounds %"class.Riemann::MassSpringSolver", ptr %8, i32 0, i32 9
  %19 = call noundef i64 @_ZNKSt6vectorIPN7Riemann11MSCollisionESaIS2_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %18) #3
  %20 = icmp ult i64 %17, %19
  br i1 %20, label %22, label %21

21:                                               ; preds = %16
  store i32 5, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  br label %35

22:                                               ; preds = %16
  %23 = getelementptr inbounds %"class.Riemann::MassSpringSolver", ptr %8, i32 0, i32 9
  %24 = load i64, ptr %7, align 8, !tbaa !11
  %25 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIPN7Riemann11MSCollisionESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %23, i64 noundef %24) #3
  %26 = load ptr, ptr %25, align 8, !tbaa !5
  %27 = load i64, ptr %7, align 8, !tbaa !11
  %28 = trunc i64 %27 to i32
  %29 = load ptr, ptr %26, align 8, !tbaa !13
  %30 = getelementptr inbounds ptr, ptr %29, i64 2
  %31 = load ptr, ptr %30, align 8
  call void %31(ptr noundef nonnull align 8 dereferenceable(16) %26, i32 noundef %28)
  br label %32

32:                                               ; preds = %22
  %33 = load i64, ptr %7, align 8, !tbaa !11
  %34 = add i64 %33, 1
  store i64 %34, ptr %7, align 8, !tbaa !11
  br label %16, !llvm.loop !15

35:                                               ; preds = %21
  br label %36

36:                                               ; preds = %35
  %37 = load i64, ptr %5, align 8, !tbaa !11
  %38 = add i64 %37, 1
  store i64 %38, ptr %5, align 8, !tbaa !11
  br label %9, !llvm.loop !17

39:                                               ; preds = %14
  ret void
}

; 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 i64 @_ZNKSt6vectorIN5Maths8TVector3IfEESaIS2_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) #2 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIPN7Riemann11MSCollisionESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #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 = { 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 = !{!"long", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"vtable pointer", !8, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7Riemann16MassSpringSolver15SolveCollisionsEi(ptr noundef nonnull align 8 dereferenceable(184) %0, i32 noundef %1) local_unnamed_addr #0 align 2 {
  %3 = tail call noundef i64 @_ZNKSt6vectorIN5Maths8TVector3IfEESaIS2_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #2
  %.not = icmp eq i64 %3, 0
  br i1 %.not, label %._crit_edge9, label %.preheader.lr.ph

.preheader.lr.ph:                                 ; preds = %2
  %4 = getelementptr inbounds i8, ptr %0, i64 160
  br label %.preheader

.preheader:                                       ; preds = %.preheader.lr.ph, %._crit_edge
  %.068 = phi i64 [ 0, %.preheader.lr.ph ], [ %6, %._crit_edge ]
  %5 = tail call noundef i64 @_ZNKSt6vectorIPN7Riemann11MSCollisionESaIS2_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %4) #2
  %.not10 = icmp eq i64 %5, 0
  br i1 %.not10, label %._crit_edge, label %.lr.ph

._crit_edge9:                                     ; preds = %._crit_edge, %2
  ret void

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  %6 = add nuw i64 %.068, 1
  %7 = tail call noundef i64 @_ZNKSt6vectorIN5Maths8TVector3IfEESaIS2_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #2
  %8 = icmp ult i64 %6, %7
  br i1 %8, label %.preheader, label %._crit_edge9, !llvm.loop !5

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.07 = phi i64 [ %15, %.lr.ph ], [ 0, %.preheader ]
  %9 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIPN7Riemann11MSCollisionESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %4, i64 noundef %.07) #2
  %10 = load ptr, ptr %9, align 8, !tbaa !7
  %11 = trunc i64 %.07 to i32
  %12 = load ptr, ptr %10, align 8, !tbaa !11
  %13 = getelementptr inbounds i8, ptr %12, i64 16
  %14 = load ptr, ptr %13, align 8
  tail call void %14(ptr noundef nonnull align 8 dereferenceable(16) %10, i32 noundef %11)
  %15 = add nuw i64 %.07, 1
  %16 = tail call noundef i64 @_ZNKSt6vectorIPN7Riemann11MSCollisionESaIS2_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %4) #2
  %17 = icmp ult i64 %15, %16
  br i1 %17, label %.lr.ph, label %._crit_edge, !llvm.loop !13
}

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIPN7Riemann11MSCollisionESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #1 align 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 = { 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 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!12, !12, i64 0}
!12 = !{!"vtable pointer", !10, i64 0}
!13 = distinct !{!13, !6}


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