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

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

%"struct.std::pair" = type <{ double, i8, [7 x i8] }>
%"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

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

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

; Function Attrs: mustprogress uwtable
define dso_local { double, i8 } @_ZN3PiE13UpdateLimiter4pollEv(ptr noundef nonnull align 8 dereferenceable(128) %0) #1 align 2 {
  %2 = alloca %"struct.std::pair", align 8
  %3 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %4 = load ptr, ptr %3, align 8
  call void @_ZNSt4pairIdbEC2IdbTnNSt9enable_ifIXsr6__and_ISt37__is_implicitly_default_constructibleIT_ES3_IT0_EEE5valueEbE4typeELb1EEEv(ptr noundef nonnull align 8 dereferenceable(9) %2)
  %5 = call i32 @SDL_GetTicks()
  %6 = getelementptr inbounds %"class.PiE::UpdateLimiter", ptr %4, i32 0, i32 0
  %7 = load double, ptr %6, align 8, !tbaa !9
  %8 = fptoui double %7 to i32
  %9 = icmp uge i32 %5, %8
  %10 = getelementptr inbounds %"struct.std::pair", ptr %2, i32 0, i32 1
  %11 = zext i1 %9 to i8
  store i8 %11, ptr %10, align 8, !tbaa !22
  %12 = getelementptr inbounds %"class.PiE::UpdateLimiter", ptr %4, i32 0, i32 4
  %13 = call noundef float @_ZN3PiE10FPSCounter6getFPSEv(ptr noundef nonnull align 8 dereferenceable(80) %12)
  %14 = fpext float %13 to double
  %15 = getelementptr inbounds %"struct.std::pair", ptr %2, i32 0, i32 0
  store double %14, ptr %15, align 8, !tbaa !24
  %16 = getelementptr inbounds %"struct.std::pair", ptr %2, i32 0, i32 1
  %17 = load i8, ptr %16, align 8, !tbaa !22, !range !25, !noundef !26
  %18 = trunc i8 %17 to i1
  br i1 %18, label %19, label %33

19:                                               ; preds = %1
  %20 = getelementptr inbounds %"class.PiE::UpdateLimiter", ptr %4, i32 0, i32 4
  call void @_ZN3PiE10FPSCounter9pushFrameEv(ptr noundef nonnull align 8 dereferenceable(80) %20)
  %21 = getelementptr inbounds %"class.PiE::UpdateLimiter", ptr %4, i32 0, i32 5
  %22 = load double, ptr %21, align 8, !tbaa !27
  %23 = getelementptr inbounds %"class.PiE::UpdateLimiter", ptr %4, i32 0, i32 6
  store double %22, ptr %23, align 8, !tbaa !28
  %24 = getelementptr inbounds %"class.PiE::UpdateLimiter", ptr %4, i32 0, i32 4
  %25 = call noundef float @_ZN3PiE10FPSCounter6getFPSEv(ptr noundef nonnull align 8 dereferenceable(80) %24)
  %26 = fpext float %25 to double
  %27 = getelementptr inbounds %"class.PiE::UpdateLimiter", ptr %4, i32 0, i32 1
  store double %26, ptr %27, align 8, !tbaa !29
  %28 = getelementptr inbounds %"class.PiE::UpdateLimiter", ptr %4, i32 0, i32 5
  %29 = load double, ptr %28, align 8, !tbaa !27
  %30 = getelementptr inbounds %"class.PiE::UpdateLimiter", ptr %4, i32 0, i32 0
  %31 = load double, ptr %30, align 8, !tbaa !9
  %32 = fadd double %31, %29
  store double %32, ptr %30, align 8, !tbaa !9
  br label %33

33:                                               ; preds = %19, %1
  %34 = load { double, i8 }, ptr %2, align 8
  ret { double, i8 } %34
}

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

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 = { 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" }

!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 0}
!10 = !{!"_ZTSN3PiE13UpdateLimiterE", !11, i64 0, !11, i64 8, !12, i64 16, !13, i64 24, !14, i64 32, !11, i64 112, !11, i64 120}
!11 = !{!"double", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!"bool", !7, i64 0}
!14 = !{!"_ZTSN3PiE10FPSCounterE", !15, i64 0, !12, i64 24, !12, i64 32, !20, i64 40}
!15 = !{!"_ZTSNSt7__cxx114listISt4pairIllESaIS2_EEE", !16, i64 0}
!16 = !{!"_ZTSNSt7__cxx1110_List_baseISt4pairIllESaIS2_EEE", !17, i64 0}
!17 = !{!"_ZTSNSt7__cxx1110_List_baseISt4pairIllESaIS2_EE10_List_implE", !18, i64 0}
!18 = !{!"_ZTSNSt8__detail17_List_node_headerE", !19, i64 0, !12, i64 16}
!19 = !{!"_ZTSNSt8__detail15_List_node_baseE", !6, i64 0, !6, i64 8}
!20 = !{!"_ZTSSt5mutex", !21, i64 0}
!21 = !{!"_ZTSSt12__mutex_base", !7, i64 0}
!22 = !{!23, !13, i64 8}
!23 = !{!"_ZTSSt4pairIdbE", !11, i64 0, !13, i64 8}
!24 = !{!23, !11, i64 0}
!25 = !{i8 0, i8 2}
!26 = !{}
!27 = !{!10, !11, i64 112}
!28 = !{!10, !11, i64 120}
!29 = !{!10, !11, i64 8}


; 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.std::pair" = type <{ double, i8, [7 x i8] }>

declare i32 @SDL_GetTicks() local_unnamed_addr #0

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

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

; Function Attrs: mustprogress uwtable
define dso_local { double, i8 } @_ZN3PiE13UpdateLimiter4pollEv(ptr noundef nonnull align 8 dereferenceable(128) %0) local_unnamed_addr #1 align 2 {
  %2 = alloca %"struct.std::pair", align 8
  call void @_ZNSt4pairIdbEC2IdbTnNSt9enable_ifIXsr6__and_ISt37__is_implicitly_default_constructibleIT_ES3_IT0_EEE5valueEbE4typeELb1EEEv(ptr noundef nonnull align 8 dereferenceable(9) %2)
  %3 = call i32 @SDL_GetTicks()
  %4 = load double, ptr %0, align 8, !tbaa !5
  %5 = fptoui double %4 to i32
  %6 = icmp uge i32 %3, %5
  %7 = getelementptr inbounds i8, ptr %2, i64 8
  %8 = zext i1 %6 to i8
  store i8 %8, ptr %7, align 8, !tbaa !21
  %9 = getelementptr inbounds i8, ptr %0, i64 32
  %10 = call noundef float @_ZN3PiE10FPSCounter6getFPSEv(ptr noundef nonnull align 8 dereferenceable(80) %9)
  %11 = fpext float %10 to double
  store double %11, ptr %2, align 8, !tbaa !23
  %12 = load i8, ptr %7, align 8, !range !24, !noundef !25
  %13 = trunc nuw i8 %12 to i1
  br i1 %13, label %14, label %24

14:                                               ; preds = %1
  call void @_ZN3PiE10FPSCounter9pushFrameEv(ptr noundef nonnull align 8 dereferenceable(80) %9)
  %15 = getelementptr inbounds i8, ptr %0, i64 112
  %16 = load double, ptr %15, align 8, !tbaa !26
  %17 = getelementptr inbounds i8, ptr %0, i64 120
  store double %16, ptr %17, align 8, !tbaa !27
  %18 = call noundef float @_ZN3PiE10FPSCounter6getFPSEv(ptr noundef nonnull align 8 dereferenceable(80) %9)
  %19 = fpext float %18 to double
  %20 = getelementptr inbounds i8, ptr %0, i64 8
  store double %19, ptr %20, align 8, !tbaa !28
  %21 = load double, ptr %15, align 8, !tbaa !26
  %22 = load double, ptr %0, align 8, !tbaa !5
  %23 = fadd double %21, %22
  store double %23, ptr %0, align 8, !tbaa !5
  %.fca.0.load.pre = load double, ptr %2, align 8
  %.fca.1.load.pre = load i8, ptr %7, align 8
  br label %24

24:                                               ; preds = %14, %1
  %.fca.1.load = phi i8 [ %.fca.1.load.pre, %14 ], [ %12, %1 ]
  %.fca.0.load = phi double [ %.fca.0.load.pre, %14 ], [ %11, %1 ]
  %.fca.0.insert = insertvalue { double, i8 } poison, double %.fca.0.load, 0
  %.fca.1.insert = insertvalue { double, i8 } %.fca.0.insert, i8 %.fca.1.load, 1
  ret { double, i8 } %.fca.1.insert
}

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

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 = { 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" }

!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, !7, i64 0}
!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 = !{!22, !11, i64 8}
!22 = !{!"_ZTSSt4pairIdbE", !7, i64 0, !11, i64 8}
!23 = !{!22, !7, i64 0}
!24 = !{i8 0, i8 2}
!25 = !{}
!26 = !{!6, !7, i64 112}
!27 = !{!6, !7, i64 120}
!28 = !{!6, !7, i64 8}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InstCombinePass,ReassociatePass,SROAPass