; LLVM IR from Pi-Man/PiE :: source/UpdateLimiter.ll (ZN3PiE13UpdateLimiter4pushEv)

; 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.PiE::UpdateLimiter" = type { double, double, i64, i8, %"struct.PiE::FPSCounter", double, double }
%"struct.PiE::FPSCounter" = type { %"class.std::__cxx11::list", i64, i64, %"class.std::mutex" }
%"class.std::__cxx11::list" = type { %"class.std::__cxx11::_List_base" }
%"class.std::__cxx11::_List_base" = type { %"struct.std::__cxx11::_List_base<std::pair<long, long>, std::allocator<std::pair<long, long>>>::_List_impl" }
%"struct.std::__cxx11::_List_base<std::pair<long, long>, std::allocator<std::pair<long, long>>>::_List_impl" = type { %"struct.std::__detail::_List_node_header" }
%"struct.std::__detail::_List_node_header" = type { %"struct.std::__detail::_List_node_base", i64 }
%"struct.std::__detail::_List_node_base" = type { ptr, ptr }
%"class.std::mutex" = type { %"class.std::__mutex_base" }
%"class.std::__mutex_base" = type { %union.pthread_mutex_t }
%union.pthread_mutex_t = type { %struct.__pthread_mutex_s }
%struct.__pthread_mutex_s = type { i32, i32, i32, i32, i32, i16, i16, %struct.__pthread_internal_list }
%struct.__pthread_internal_list = type { ptr, ptr }

declare i32 @SDL_GetTicks() #0

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_ZN3PiE13UpdateLimiter4pushEv(ptr noundef nonnull align 8 dereferenceable(128) %0) #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %5 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %6 = call i32 @SDL_GetTicks()
  store i32 %6, ptr %3, align 4, !tbaa !9
  %7 = getelementptr inbounds %"class.PiE::UpdateLimiter", ptr %5, i32 0, i32 4
  call void @_ZN3PiE10FPSCounter9pushFrameEv(ptr noundef nonnull align 8 dereferenceable(80) %7)
  %8 = getelementptr inbounds %"class.PiE::UpdateLimiter", ptr %5, i32 0, i32 3
  %9 = load i8, ptr %8, align 8, !tbaa !11, !range !24, !noundef !25
  %10 = trunc i8 %9 to i1
  br i1 %10, label %11, label %20

11:                                               ; preds = %1
  br label %12

12:                                               ; preds = %18, %11
  %13 = call i32 @SDL_GetTicks()
  %14 = getelementptr inbounds %"class.PiE::UpdateLimiter", ptr %5, i32 0, i32 0
  %15 = load double, ptr %14, align 8, !tbaa !26
  %16 = fptoui double %15 to i32
  %17 = icmp ult i32 %13, %16
  br i1 %17, label %18, label %19

18:                                               ; preds = %12
  br label %12, !llvm.loop !27

19:                                               ; preds = %12
  br label %31

20:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %21 = getelementptr inbounds %"class.PiE::UpdateLimiter", ptr %5, i32 0, i32 0
  %22 = load double, ptr %21, align 8, !tbaa !26
  %23 = fptoui double %22 to i32
  %24 = call i32 @SDL_GetTicks()
  %25 = sub i32 %23, %24
  store i32 %25, ptr %4, align 4, !tbaa !9
  %26 = load i32, ptr %4, align 4, !tbaa !9
  %27 = icmp ugt i32 %26, 0
  br i1 %27, label %28, label %30

28:                                               ; preds = %20
  %29 = load i32, ptr %4, align 4, !tbaa !9
  call void @SDL_Delay(i32 noundef %29)
  br label %30

30:                                               ; preds = %28, %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %31

31:                                               ; preds = %30, %19
  %32 = getelementptr inbounds %"class.PiE::UpdateLimiter", ptr %5, i32 0, i32 5
  %33 = load double, ptr %32, align 8, !tbaa !29
  %34 = getelementptr inbounds %"class.PiE::UpdateLimiter", ptr %5, i32 0, i32 0
  %35 = load double, ptr %34, align 8, !tbaa !26
  %36 = fadd double %35, %33
  store double %36, ptr %34, align 8, !tbaa !26
  %37 = getelementptr inbounds %"class.PiE::UpdateLimiter", ptr %5, i32 0, i32 4
  %38 = call noundef float @_ZN3PiE10FPSCounter6getFPSEv(ptr noundef nonnull align 8 dereferenceable(80) %37)
  %39 = fpext float %38 to double
  %40 = getelementptr inbounds %"class.PiE::UpdateLimiter", ptr %5, i32 0, i32 1
  store double %39, ptr %40, align 8, !tbaa !30
  %41 = call i32 @SDL_GetTicks()
  %42 = load i32, ptr %3, align 4, !tbaa !9
  %43 = sub i32 %41, %42
  %44 = uitofp i32 %43 to double
  %45 = getelementptr inbounds %"class.PiE::UpdateLimiter", ptr %5, i32 0, i32 6
  store double %44, ptr %45, align 8, !tbaa !31
  %46 = getelementptr inbounds %"class.PiE::UpdateLimiter", ptr %5, i32 0, i32 1
  %47 = load double, ptr %46, align 8, !tbaa !30
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret double %47
}

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

declare void @_ZN3PiE10FPSCounter9pushFrameEv(ptr noundef nonnull align 8 dereferenceable(80)) #0

declare void @SDL_Delay(i32 noundef) #0

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

declare noundef float @_ZN3PiE10FPSCounter6getFPSEv(ptr noundef nonnull align 8 dereferenceable(80)) #0

attributes #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 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !15, i64 24}
!12 = !{!"_ZTSN3PiE13UpdateLimiterE", !13, i64 0, !13, i64 8, !14, i64 16, !15, i64 24, !16, i64 32, !13, i64 112, !13, i64 120}
!13 = !{!"double", !7, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!"bool", !7, i64 0}
!16 = !{!"_ZTSN3PiE10FPSCounterE", !17, i64 0, !14, i64 24, !14, i64 32, !22, i64 40}
!17 = !{!"_ZTSNSt7__cxx114listISt4pairIllESaIS2_EEE", !18, i64 0}
!18 = !{!"_ZTSNSt7__cxx1110_List_baseISt4pairIllESaIS2_EEE", !19, i64 0}
!19 = !{!"_ZTSNSt7__cxx1110_List_baseISt4pairIllESaIS2_EE10_List_implE", !20, i64 0}
!20 = !{!"_ZTSNSt8__detail17_List_node_headerE", !21, i64 0, !14, i64 16}
!21 = !{!"_ZTSNSt8__detail15_List_node_baseE", !6, i64 0, !6, i64 8}
!22 = !{!"_ZTSSt5mutex", !23, i64 0}
!23 = !{!"_ZTSSt12__mutex_base", !7, i64 0}
!24 = !{i8 0, i8 2}
!25 = !{}
!26 = !{!12, !13, i64 0}
!27 = distinct !{!27, !28}
!28 = !{!"llvm.loop.mustprogress"}
!29 = !{!12, !13, i64 112}
!30 = !{!12, !13, i64 8}
!31 = !{!12, !13, i64 120}


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

declare i32 @SDL_GetTicks() local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_ZN3PiE13UpdateLimiter4pushEv(ptr noundef nonnull align 8 dereferenceable(128) %0) local_unnamed_addr #1 align 2 {
  %2 = tail call i32 @SDL_GetTicks()
  %3 = getelementptr inbounds i8, ptr %0, i64 32
  tail call void @_ZN3PiE10FPSCounter9pushFrameEv(ptr noundef nonnull align 8 dereferenceable(80) %3)
  %4 = getelementptr inbounds i8, ptr %0, i64 24
  %5 = load i8, ptr %4, align 8, !tbaa !5, !range !21, !noundef !22
  %6 = trunc nuw i8 %5 to i1
  br i1 %6, label %.preheader, label %11

.preheader:                                       ; preds = %1, %.preheader
  %7 = tail call i32 @SDL_GetTicks()
  %8 = load double, ptr %0, align 8, !tbaa !23
  %9 = fptoui double %8 to i32
  %10 = icmp ult i32 %7, %9
  br i1 %10, label %.preheader, label %.loopexit, !llvm.loop !24

11:                                               ; preds = %1
  %12 = load double, ptr %0, align 8, !tbaa !23
  %13 = fptoui double %12 to i32
  %14 = tail call i32 @SDL_GetTicks()
  %.not = icmp eq i32 %14, %13
  br i1 %.not, label %.loopexit, label %15

15:                                               ; preds = %11
  %16 = sub i32 %13, %14
  tail call void @SDL_Delay(i32 noundef %16)
  br label %.loopexit

.loopexit:                                        ; preds = %.preheader, %11, %15
  %17 = getelementptr inbounds i8, ptr %0, i64 112
  %18 = load double, ptr %17, align 8, !tbaa !26
  %19 = load double, ptr %0, align 8, !tbaa !23
  %20 = fadd double %18, %19
  store double %20, ptr %0, align 8, !tbaa !23
  %21 = tail call noundef float @_ZN3PiE10FPSCounter6getFPSEv(ptr noundef nonnull align 8 dereferenceable(80) %3)
  %22 = fpext float %21 to double
  %23 = getelementptr inbounds i8, ptr %0, i64 8
  store double %22, ptr %23, align 8, !tbaa !27
  %24 = tail call i32 @SDL_GetTicks()
  %25 = sub i32 %24, %2
  %26 = uitofp i32 %25 to double
  %27 = getelementptr inbounds i8, ptr %0, i64 120
  store double %26, ptr %27, align 8, !tbaa !28
  %28 = load double, ptr %23, align 8, !tbaa !27
  ret double %28
}

declare void @_ZN3PiE10FPSCounter9pushFrameEv(ptr noundef nonnull align 8 dereferenceable(80)) local_unnamed_addr #0

declare void @SDL_Delay(i32 noundef) local_unnamed_addr #0

declare noundef float @_ZN3PiE10FPSCounter6getFPSEv(ptr noundef nonnull align 8 dereferenceable(80)) local_unnamed_addr #0

attributes #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 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" }

!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, !11, i64 24}
!6 = !{!"_ZTSN3PiE13UpdateLimiterE", !7, i64 0, !7, i64 8, !10, i64 16, !11, i64 24, !12, i64 32, !7, i64 112, !7, i64 120}
!7 = !{!"double", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"bool", !8, i64 0}
!12 = !{!"_ZTSN3PiE10FPSCounterE", !13, i64 0, !10, i64 24, !10, i64 32, !19, i64 40}
!13 = !{!"_ZTSNSt7__cxx114listISt4pairIllESaIS2_EEE", !14, i64 0}
!14 = !{!"_ZTSNSt7__cxx1110_List_baseISt4pairIllESaIS2_EEE", !15, i64 0}
!15 = !{!"_ZTSNSt7__cxx1110_List_baseISt4pairIllESaIS2_EE10_List_implE", !16, i64 0}
!16 = !{!"_ZTSNSt8__detail17_List_node_headerE", !17, i64 0, !10, i64 16}
!17 = !{!"_ZTSNSt8__detail15_List_node_baseE", !18, i64 0, !18, i64 8}
!18 = !{!"any pointer", !8, i64 0}
!19 = !{!"_ZTSSt5mutex", !20, i64 0}
!20 = !{!"_ZTSSt12__mutex_base", !8, i64 0}
!21 = !{i8 0, i8 2}
!22 = !{}
!23 = !{!6, !7, i64 0}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.mustprogress"}
!26 = !{!6, !7, i64 112}
!27 = !{!6, !7, i64 8}
!28 = !{!6, !7, i64 120}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass