; LLVM IR from jrouwe/JoltPhysics :: UnitTests/PhysicsTestContext.ll (ZN18PhysicsTestContext8SimulateEfSt8functionIFvvEE)

; 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.PhysicsTestContext = type { ptr, ptr, %class.BPLayerInterfaceImpl, %class.ObjectVsBroadPhaseLayerFilterImpl, %class.ObjectLayerPairFilterImpl, ptr, float, i32 }
%class.BPLayerInterfaceImpl = type <{ %"class.JPH::BroadPhaseLayerInterface", [11 x %"class.JPH::BroadPhaseLayer"], [5 x i8] }>
%"class.JPH::BroadPhaseLayerInterface" = type { ptr }
%"class.JPH::BroadPhaseLayer" = type { i8 }
%class.ObjectVsBroadPhaseLayerFilterImpl = type { %"class.JPH::ObjectVsBroadPhaseLayerFilter" }
%"class.JPH::ObjectVsBroadPhaseLayerFilter" = type { ptr }
%class.ObjectLayerPairFilterImpl = type { %"class.JPH::ObjectLayerPairFilter" }
%"class.JPH::ObjectLayerPairFilter" = type { ptr }

; 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
declare dso_local noundef i32 @_ZN18PhysicsTestContext18SimulateSingleStepEv(ptr noundef nonnull align 8 dereferenceable(72)) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN18PhysicsTestContext8SimulateEfSt8functionIFvvEE(ptr noundef nonnull align 8 dereferenceable(72) %0, float noundef %1, ptr noundef %2) #1 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca float, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store float %1, ptr %5, align 4, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  %10 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %11 = load float, ptr %5, align 4, !tbaa !9
  %12 = getelementptr inbounds %class.PhysicsTestContext, ptr %10, i32 0, i32 6
  %13 = load float, ptr %12, align 8, !tbaa !13
  %14 = fdiv float %11, %13
  %15 = call noundef float @_ZSt5roundf(float noundef %14)
  %16 = fptosi float %15 to i32
  store i32 %16, ptr %8, align 4, !tbaa !22
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 0, ptr %9, align 4, !tbaa !22
  br label %17

17:                                               ; preds = %25, %3
  %18 = load i32, ptr %9, align 4, !tbaa !22
  %19 = load i32, ptr %8, align 4, !tbaa !22
  %20 = icmp slt i32 %18, %19
  br i1 %20, label %22, label %21

21:                                               ; preds = %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  br label %28

22:                                               ; preds = %17
  call void @_ZNKSt8functionIFvvEEclEv(ptr noundef nonnull align 8 dereferenceable(32) %2)
  %23 = call noundef i32 @_ZN18PhysicsTestContext18SimulateSingleStepEv(ptr noundef nonnull align 8 dereferenceable(72) %10)
  %24 = call noundef i32 @_ZN3JPHoRERNS_19EPhysicsUpdateErrorES0_(ptr noundef nonnull align 4 dereferenceable(4) %7, i32 noundef %23)
  br label %25

25:                                               ; preds = %22
  %26 = load i32, ptr %9, align 4, !tbaa !22
  %27 = add nsw i32 %26, 1
  store i32 %27, ptr %9, align 4, !tbaa !22
  br label %17, !llvm.loop !23

28:                                               ; preds = %21
  %29 = load i32, ptr %7, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  ret i32 %29
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef float @_ZSt5roundf(float noundef) #2

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_ZN3JPHoRERNS_19EPhysicsUpdateErrorES0_(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef) #3

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 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 = !{!"_ZTSN3JPH19EPhysicsUpdateErrorE", !7, i64 0}
!13 = !{!14, !10, i64 64}
!14 = !{!"_ZTS18PhysicsTestContext", !6, i64 0, !6, i64 8, !15, i64 16, !17, i64 40, !19, i64 48, !6, i64 56, !10, i64 64, !21, i64 68}
!15 = !{!"_ZTS20BPLayerInterfaceImpl", !16, i64 0, !7, i64 8}
!16 = !{!"_ZTSN3JPH24BroadPhaseLayerInterfaceE"}
!17 = !{!"_ZTS33ObjectVsBroadPhaseLayerFilterImpl", !18, i64 0}
!18 = !{!"_ZTSN3JPH29ObjectVsBroadPhaseLayerFilterE"}
!19 = !{!"_ZTS25ObjectLayerPairFilterImpl", !20, i64 0}
!20 = !{!"_ZTSN3JPH21ObjectLayerPairFilterE"}
!21 = !{!"int", !7, i64 0}
!22 = !{!21, !21, i64 0}
!23 = distinct !{!23, !24}
!24 = !{!"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"

; 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 i32 @_ZN18PhysicsTestContext18SimulateSingleStepEv(ptr noundef nonnull align 8 dereferenceable(72)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN18PhysicsTestContext8SimulateEfSt8functionIFvvEE(ptr noundef nonnull align 8 dereferenceable(72) %0, float noundef %1, ptr noundef %2) local_unnamed_addr #1 align 2 {
  %4 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #4
  store i32 0, ptr %4, align 4, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 64
  %6 = load float, ptr %5, align 8, !tbaa !9
  %7 = fdiv float %1, %6
  %8 = tail call noundef float @_ZSt5roundf(float noundef %7)
  %9 = fptosi float %8 to i32
  %10 = icmp sgt i32 %9, 0
  br i1 %10, label %.lr.ph, label %._crit_edge

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %.pre = load i32, ptr %4, align 4, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %3
  %11 = phi i32 [ %.pre, %._crit_edge.loopexit ], [ 0, %3 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #4
  ret i32 %11

.lr.ph:                                           ; preds = %3, %.lr.ph
  %.04 = phi i32 [ %14, %.lr.ph ], [ 0, %3 ]
  call void @_ZNKSt8functionIFvvEEclEv(ptr noundef nonnull align 8 dereferenceable(32) %2)
  %12 = call noundef i32 @_ZN18PhysicsTestContext18SimulateSingleStepEv(ptr noundef nonnull align 8 dereferenceable(72) %0)
  %13 = call noundef i32 @_ZN3JPHoRERNS_19EPhysicsUpdateErrorES0_(ptr noundef nonnull align 4 dereferenceable(4) %4, i32 noundef %12)
  %14 = add nuw nsw i32 %.04, 1
  %exitcond.not = icmp eq i32 %14, %9
  br i1 %exitcond.not, label %._crit_edge.loopexit, label %.lr.ph, !llvm.loop !20
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef float @_ZSt5roundf(float noundef) local_unnamed_addr #2

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_ZN3JPHoRERNS_19EPhysicsUpdateErrorES0_(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef) local_unnamed_addr #3

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 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 = !{!"_ZTSN3JPH19EPhysicsUpdateErrorE", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !18, i64 64}
!10 = !{!"_ZTS18PhysicsTestContext", !11, i64 0, !11, i64 8, !12, i64 16, !14, i64 40, !16, i64 48, !11, i64 56, !18, i64 64, !19, i64 68}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"_ZTS20BPLayerInterfaceImpl", !13, i64 0, !7, i64 8}
!13 = !{!"_ZTSN3JPH24BroadPhaseLayerInterfaceE"}
!14 = !{!"_ZTS33ObjectVsBroadPhaseLayerFilterImpl", !15, i64 0}
!15 = !{!"_ZTSN3JPH29ObjectVsBroadPhaseLayerFilterE"}
!16 = !{!"_ZTS25ObjectLayerPairFilterImpl", !17, i64 0}
!17 = !{!"_ZTSN3JPH21ObjectLayerPairFilterE"}
!18 = !{!"float", !7, i64 0}
!19 = !{!"int", !7, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass