; LLVM IR from atlantis13579/Riemann :: Src/RigidBodyDynamics (WarmStart)

; 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::ContactManifold" = type { i32, i32, [5 x %"struct.Riemann::Contact"], i32, ptr }
%"struct.Riemann::Contact" = type { %"class.Maths::TVector3", %"class.Maths::TVector3", %"class.Maths::TVector3", %"class.Maths::TVector3", %"class.Maths::TVector3", %"class.Maths::TVector3", %"class.Maths::TVector3", float, float, float, float }
%"class.Maths::TVector3" = type { float, float, float }

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

13:                                               ; preds = %60, %3
  %14 = load i64, ptr %7, align 8, !tbaa !11
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = call noundef i64 @_ZNKSt6vectorIPN7Riemann15ContactManifoldESaIS2_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %15) #4
  %17 = icmp ult i64 %14, %16
  br i1 %17, label %19, label %18

18:                                               ; preds = %13
  store i32 2, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  br label %63

19:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = load i64, ptr %7, align 8, !tbaa !11
  %22 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIPN7Riemann15ContactManifoldESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %20, i64 noundef %21) #4
  %23 = load ptr, ptr %22, align 8, !tbaa !5
  store ptr %23, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  store i32 0, ptr %10, align 4, !tbaa !13
  br label %24

24:                                               ; preds = %56, %19
  %25 = load i32, ptr %10, align 4, !tbaa !13
  %26 = load ptr, ptr %9, align 8, !tbaa !5
  %27 = getelementptr inbounds %"class.Riemann::ContactManifold", ptr %26, i32 0, i32 3
  %28 = load i32, ptr %27, align 4, !tbaa !15
  %29 = icmp slt i32 %25, %28
  br i1 %29, label %31, label %30

30:                                               ; preds = %24
  store i32 5, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  br label %59

31:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = load ptr, ptr %9, align 8, !tbaa !5
  %34 = getelementptr inbounds %"class.Riemann::ContactManifold", ptr %33, i32 0, i32 0
  %35 = load i32, ptr %34, align 8, !tbaa !17
  %36 = sext i32 %35 to i64
  %37 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIPN7Riemann8GeometryESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %32, i64 noundef %36) #4
  %38 = load ptr, ptr %37, align 8, !tbaa !5
  %39 = call noundef ptr @_ZN7Riemann8Geometry9GetParentINS_9RigidBodyEEEPT_v(ptr noundef nonnull align 8 dereferenceable(204) %38)
  store ptr %39, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = load ptr, ptr %9, align 8, !tbaa !5
  %42 = getelementptr inbounds %"class.Riemann::ContactManifold", ptr %41, i32 0, i32 1
  %43 = load i32, ptr %42, align 4, !tbaa !18
  %44 = sext i32 %43 to i64
  %45 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIPN7Riemann8GeometryESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %40, i64 noundef %44) #4
  %46 = load ptr, ptr %45, align 8, !tbaa !5
  %47 = call noundef ptr @_ZN7Riemann8Geometry9GetParentINS_9RigidBodyEEEPT_v(ptr noundef nonnull align 8 dereferenceable(204) %46)
  store ptr %47, ptr %12, align 8, !tbaa !5
  %48 = load ptr, ptr %11, align 8, !tbaa !5
  %49 = load ptr, ptr %12, align 8, !tbaa !5
  %50 = load ptr, ptr %9, align 8, !tbaa !5
  %51 = getelementptr inbounds %"class.Riemann::ContactManifold", ptr %50, i32 0, i32 2
  %52 = load i32, ptr %10, align 4, !tbaa !13
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [5 x %"struct.Riemann::Contact"], ptr %51, i64 0, i64 %53
  %55 = load float, ptr %6, align 4, !tbaa !9
  call void @_ZN7Riemann9WarmStart5ApplyEPNS_9RigidBodyES2_RNS_7ContactEf(ptr noundef %48, ptr noundef %49, ptr noundef nonnull align 4 dereferenceable(100) %54, float noundef %55)
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  br label %56

56:                                               ; preds = %31
  %57 = load i32, ptr %10, align 4, !tbaa !13
  %58 = add nsw i32 %57, 1
  store i32 %58, ptr %10, align 4, !tbaa !13
  br label %24, !llvm.loop !19

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

60:                                               ; preds = %59
  %61 = load i64, ptr %7, align 8, !tbaa !11
  %62 = add i64 %61, 1
  store i64 %62, ptr %7, align 8, !tbaa !11
  br label %13, !llvm.loop !21

63:                                               ; preds = %18
  ret void
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorIPN7Riemann15ContactManifoldESaIS2_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 @_ZNSt6vectorIPN7Riemann15ContactManifoldESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #2 align 2

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN7Riemann9WarmStart5ApplyEPNS_9RigidBodyES2_RNS_7ContactEf(ptr noundef, ptr noundef, ptr noundef nonnull align 4 dereferenceable(100), float noundef) #2 align 2

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !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 = !{!"float", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!16, !14, i64 508}
!16 = !{!"_ZTSN7Riemann15ContactManifoldE", !14, i64 0, !14, i64 4, !7, i64 8, !14, i64 508, !6, i64 512}
!17 = !{!16, !14, i64 0}
!18 = !{!16, !14, i64 4}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = distinct !{!21, !20}


; 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.Riemann::Contact" = type { %"class.Maths::TVector3", %"class.Maths::TVector3", %"class.Maths::TVector3", %"class.Maths::TVector3", %"class.Maths::TVector3", %"class.Maths::TVector3", %"class.Maths::TVector3", float, float, float, float }
%"class.Maths::TVector3" = type { float, float, float }

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN7Riemann9WarmStart23ApplyVelocityConstraintERKSt6vectorIPNS_8GeometryESaIS3_EERS1_IPNS_15ContactManifoldESaIS9_EEf(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef nonnull align 8 dereferenceable(24) %1, float noundef %2) local_unnamed_addr #0 align 2 {
  %4 = tail call noundef i64 @_ZNKSt6vectorIPN7Riemann15ContactManifoldESaIS2_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %1) #2
  %.not = icmp eq i64 %4, 0
  br i1 %.not, label %._crit_edge21, label %.lr.ph20

._crit_edge21:                                    ; preds = %._crit_edge, %3
  ret void

.lr.ph20:                                         ; preds = %3, %._crit_edge
  %.018 = phi i64 [ %12, %._crit_edge ], [ 0, %3 ]
  %5 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIPN7Riemann15ContactManifoldESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %1, i64 noundef %.018) #2
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %6, i64 508
  %8 = load i32, ptr %7, align 4, !tbaa !9
  %9 = icmp sgt i32 %8, 0
  br i1 %9, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.lr.ph20
  %10 = getelementptr inbounds i8, ptr %6, i64 4
  %11 = getelementptr inbounds i8, ptr %6, i64 8
  br label %15

._crit_edge:                                      ; preds = %15, %.lr.ph20
  %12 = add nuw i64 %.018, 1
  %13 = tail call noundef i64 @_ZNKSt6vectorIPN7Riemann15ContactManifoldESaIS2_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %1) #2
  %14 = icmp ult i64 %12, %13
  br i1 %14, label %.lr.ph20, label %._crit_edge21, !llvm.loop !12

15:                                               ; preds = %.lr.ph, %15
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %15 ]
  %16 = load i32, ptr %6, align 8, !tbaa !14
  %17 = sext i32 %16 to i64
  %18 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIPN7Riemann8GeometryESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %17) #2
  %19 = load ptr, ptr %18, align 8, !tbaa !5
  %20 = tail call noundef ptr @_ZN7Riemann8Geometry9GetParentINS_9RigidBodyEEEPT_v(ptr noundef nonnull align 8 dereferenceable(204) %19)
  %21 = load i32, ptr %10, align 4, !tbaa !15
  %22 = sext i32 %21 to i64
  %23 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIPN7Riemann8GeometryESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %22) #2
  %24 = load ptr, ptr %23, align 8, !tbaa !5
  %25 = tail call noundef ptr @_ZN7Riemann8Geometry9GetParentINS_9RigidBodyEEEPT_v(ptr noundef nonnull align 8 dereferenceable(204) %24)
  %26 = getelementptr inbounds [5 x %"struct.Riemann::Contact"], ptr %11, i64 0, i64 %indvars.iv
  tail call void @_ZN7Riemann9WarmStart5ApplyEPNS_9RigidBodyES2_RNS_7ContactEf(ptr noundef %20, ptr noundef %25, ptr noundef nonnull align 4 dereferenceable(100) %26, float noundef %2)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %27 = load i32, ptr %7, align 4, !tbaa !9
  %28 = sext i32 %27 to i64
  %29 = icmp slt i64 %indvars.iv.next, %28
  br i1 %29, label %15, label %._crit_edge, !llvm.loop !16
}

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

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

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN7Riemann9WarmStart5ApplyEPNS_9RigidBodyES2_RNS_7ContactEf(ptr noundef, ptr noundef, ptr noundef nonnull align 4 dereferenceable(100), float noundef) local_unnamed_addr #0 align 2

attributes #0 = { 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 #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 = { 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 508}
!10 = !{!"_ZTSN7Riemann15ContactManifoldE", !11, i64 0, !11, i64 4, !7, i64 8, !11, i64 508, !6, i64 512}
!11 = !{!"int", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!10, !11, i64 0}
!15 = !{!10, !11, i64 4}
!16 = distinct !{!16, !13}


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