; LLVM IR from cieslarmichal/rpg :: src/Menu.ll (ZN4Menu10chooseModeEv)

; 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.Menu = type { ptr, %"class.sf::Event", %"class.sf::Font", [3 x %"class.sf::Text"], i32, i32 }
%"class.sf::Event" = type { i32, %union.anon }
%union.anon = type { %"struct.sf::Event::MouseWheelScrollEvent" }
%"struct.sf::Event::MouseWheelScrollEvent" = type { i32, float, i32, i32 }
%"class.sf::Font" = type { ptr, ptr, ptr, ptr, ptr, %"struct.sf::Font::Info", %"class.std::map", %"class.std::vector" }
%"struct.sf::Font::Info" = type { %"class.std::__cxx11::basic_string" }
%"class.std::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon.0 }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon.0 = type { i64, [8 x i8] }
%"class.std::map" = type { %"class.std::_Rb_tree" }
%"class.std::_Rb_tree" = type { %"struct.std::_Rb_tree<unsigned int, std::pair<const unsigned int, sf::Font::Page>, std::_Select1st<std::pair<const unsigned int, sf::Font::Page>>, std::less<unsigned int>>::_Rb_tree_impl" }
%"struct.std::_Rb_tree<unsigned int, std::pair<const unsigned int, sf::Font::Page>, std::_Select1st<std::pair<const unsigned int, sf::Font::Page>>, std::less<unsigned int>>::_Rb_tree_impl" = type { [8 x i8], %"struct.std::_Rb_tree_header" }
%"struct.std::_Rb_tree_header" = type { %"struct.std::_Rb_tree_node_base", i64 }
%"struct.std::_Rb_tree_node_base" = type { i32, ptr, ptr, ptr }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<unsigned char, std::allocator<unsigned char>>::_Vector_impl" }
%"struct.std::_Vector_base<unsigned char, std::allocator<unsigned char>>::_Vector_impl" = type { %"struct.std::_Vector_base<unsigned char, std::allocator<unsigned char>>::_Vector_impl_data" }
%"struct.std::_Vector_base<unsigned char, std::allocator<unsigned char>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.sf::Text" = type { %"class.sf::Drawable", %"class.sf::Transformable.base", %"class.sf::String", ptr, i32, float, float, i32, %"class.sf::Color", %"class.sf::Color", float, [4 x i8], %"class.sf::VertexArray", %"class.sf::VertexArray", %"class.sf::Rect", i8, i64 }
%"class.sf::Drawable" = type { ptr }
%"class.sf::Transformable.base" = type <{ ptr, %"class.sf::Vector2", %"class.sf::Vector2", float, %"class.sf::Vector2", %"class.sf::Transform", i8, [3 x i8], %"class.sf::Transform", i8 }>
%"class.sf::Vector2" = type { float, float }
%"class.sf::Transform" = type { [16 x float] }
%"class.sf::String" = type { %"class.std::__cxx11::basic_string.7" }
%"class.std::__cxx11::basic_string.7" = type { %"struct.std::__cxx11::basic_string<unsigned int>::_Alloc_hider", i64, %union.anon.11 }
%"struct.std::__cxx11::basic_string<unsigned int>::_Alloc_hider" = type { ptr }
%union.anon.11 = type { i64, [8 x i8] }
%"class.sf::Color" = type { i8, i8, i8, i8 }
%"class.sf::VertexArray" = type <{ %"class.sf::Drawable", %"class.std::vector.12", i32, [4 x i8] }>
%"class.std::vector.12" = type { %"struct.std::_Vector_base.13" }
%"struct.std::_Vector_base.13" = type { %"struct.std::_Vector_base<sf::Vertex, std::allocator<sf::Vertex>>::_Vector_impl" }
%"struct.std::_Vector_base<sf::Vertex, std::allocator<sf::Vertex>>::_Vector_impl" = type { %"struct.std::_Vector_base<sf::Vertex, std::allocator<sf::Vertex>>::_Vector_impl_data" }
%"struct.std::_Vector_base<sf::Vertex, std::allocator<sf::Vertex>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.sf::Rect" = type { float, float, float, float }

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN4Menu10chooseModeEv(ptr noundef nonnull align 8 dereferenceable(1288) %0) #0 align 2 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %4 = load ptr, ptr %3, align 8
  br label %5

5:                                                ; preds = %24, %1
  %6 = getelementptr inbounds %class.Menu, ptr %4, i32 0, i32 0
  %7 = load ptr, ptr %6, align 8, !tbaa !9
  %8 = call noundef zeroext i1 @_ZNK2sf6Window6isOpenEv(ptr noundef nonnull align 8 dereferenceable(48) %7)
  br i1 %8, label %9, label %25

9:                                                ; preds = %5
  call void @_ZN4Menu5clearEv(ptr noundef nonnull align 8 dereferenceable(1288) %4)
  %10 = call noundef i32 @_ZN4Menu6eventsEv(ptr noundef nonnull align 8 dereferenceable(1288) %4)
  switch i32 %10, label %24 [
    i32 1, label %11
    i32 0, label %23
  ]

11:                                               ; preds = %9
  %12 = getelementptr inbounds %class.Menu, ptr %4, i32 0, i32 4
  %13 = load i32, ptr %12, align 8, !tbaa !31
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %15, label %16

15:                                               ; preds = %11
  store i32 1, ptr %2, align 4
  br label %26

16:                                               ; preds = %11
  %17 = getelementptr inbounds %class.Menu, ptr %4, i32 0, i32 4
  %18 = load i32, ptr %17, align 8, !tbaa !31
  %19 = icmp eq i32 %18, 2
  br i1 %19, label %20, label %21

20:                                               ; preds = %16
  store i32 2, ptr %2, align 4
  br label %26

21:                                               ; preds = %16
  br label %22

22:                                               ; preds = %21
  br label %24

23:                                               ; preds = %9
  store i32 2, ptr %2, align 4
  br label %26

24:                                               ; preds = %22, %9
  call void @_ZN4Menu6updateEv(ptr noundef nonnull align 8 dereferenceable(1288) %4)
  call void @_ZN4Menu4drawEv(ptr noundef nonnull align 8 dereferenceable(1288) %4)
  br label %5, !llvm.loop !32

25:                                               ; preds = %5
  store i32 0, ptr %2, align 4
  br label %26

26:                                               ; preds = %25, %23, %20, %15
  %27 = load i32, ptr %2, align 4
  ret i32 %27
}

declare noundef zeroext i1 @_ZNK2sf6Window6isOpenEv(ptr noundef nonnull align 8 dereferenceable(48)) #1

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4Menu5clearEv(ptr noundef nonnull align 8 dereferenceable(1288)) #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN4Menu6eventsEv(ptr noundef nonnull align 8 dereferenceable(1288)) #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4Menu6updateEv(ptr noundef nonnull align 8 dereferenceable(1288)) #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4Menu4drawEv(ptr noundef nonnull align 8 dereferenceable(1288)) #0 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 = { "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, !6, i64 0}
!10 = !{!"_ZTS4Menu", !6, i64 0, !11, i64 8, !13, i64 32, !7, i64 176, !30, i64 1280, !30, i64 1284}
!11 = !{!"_ZTSN2sf5EventE", !12, i64 0, !7, i64 4}
!12 = !{!"_ZTSN2sf5Event9EventTypeE", !7, i64 0}
!13 = !{!"_ZTSN2sf4FontE", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !14, i64 40, !18, i64 72, !26, i64 120}
!14 = !{!"_ZTSN2sf4Font4InfoE", !15, i64 0}
!15 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !16, i64 0, !17, i64 8, !7, i64 16}
!16 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !6, i64 0}
!17 = !{!"long", !7, i64 0}
!18 = !{!"_ZTSSt3mapIjN2sf4Font4PageESt4lessIjESaISt4pairIKjS2_EEE", !19, i64 0}
!19 = !{!"_ZTSSt8_Rb_treeIjSt4pairIKjN2sf4Font4PageEESt10_Select1stIS5_ESt4lessIjESaIS5_EE", !20, i64 0}
!20 = !{!"_ZTSNSt8_Rb_treeIjSt4pairIKjN2sf4Font4PageEESt10_Select1stIS5_ESt4lessIjESaIS5_EE13_Rb_tree_implIS9_Lb1EEE", !21, i64 0, !23, i64 8}
!21 = !{!"_ZTSSt20_Rb_tree_key_compareISt4lessIjEE", !22, i64 0}
!22 = !{!"_ZTSSt4lessIjE"}
!23 = !{!"_ZTSSt15_Rb_tree_header", !24, i64 0, !17, i64 32}
!24 = !{!"_ZTSSt18_Rb_tree_node_base", !25, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!25 = !{!"_ZTSSt14_Rb_tree_color", !7, i64 0}
!26 = !{!"_ZTSSt6vectorIhSaIhEE", !27, i64 0}
!27 = !{!"_ZTSSt12_Vector_baseIhSaIhEE", !28, i64 0}
!28 = !{!"_ZTSNSt12_Vector_baseIhSaIhEE12_Vector_implE", !29, i64 0}
!29 = !{!"_ZTSNSt12_Vector_baseIhSaIhEE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!30 = !{!"int", !7, i64 0}
!31 = !{!10, !30, i64 1280}
!32 = distinct !{!32, !33}
!33 = !{!"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 uwtable
define dso_local noundef range(i32 0, 3) i32 @_ZN4Menu10chooseModeEv(ptr noundef nonnull align 8 dereferenceable(1288) %0) local_unnamed_addr #0 align 2 {
  %2 = load ptr, ptr %0, align 8, !tbaa !5
  %3 = tail call noundef zeroext i1 @_ZNK2sf6Window6isOpenEv(ptr noundef nonnull align 8 dereferenceable(48) %2)
  br i1 %3, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %1
  %4 = getelementptr inbounds i8, ptr %0, i64 1280
  br label %5

5:                                                ; preds = %.lr.ph, %9
  tail call void @_ZN4Menu5clearEv(ptr noundef nonnull align 8 dereferenceable(1288) %0)
  %6 = tail call noundef i32 @_ZN4Menu6eventsEv(ptr noundef nonnull align 8 dereferenceable(1288) %0)
  switch i32 %6, label %9 [
    i32 1, label %7
    i32 0, label %.loopexit
  ]

7:                                                ; preds = %5
  %8 = load i32, ptr %4, align 8, !tbaa !30
  switch i32 %8, label %9 [
    i32 0, label %.loopexit.loopexit
    i32 2, label %.loopexit
  ]

9:                                                ; preds = %7, %5
  tail call void @_ZN4Menu6updateEv(ptr noundef nonnull align 8 dereferenceable(1288) %0)
  tail call void @_ZN4Menu4drawEv(ptr noundef nonnull align 8 dereferenceable(1288) %0)
  %10 = load ptr, ptr %0, align 8, !tbaa !5
  %11 = tail call noundef zeroext i1 @_ZNK2sf6Window6isOpenEv(ptr noundef nonnull align 8 dereferenceable(48) %10)
  br i1 %11, label %5, label %.loopexit, !llvm.loop !31

.loopexit.loopexit:                               ; preds = %7
  br label %.loopexit

.loopexit:                                        ; preds = %5, %9, %7, %.loopexit.loopexit, %1
  %.0 = phi i32 [ 0, %1 ], [ %8, %7 ], [ 2, %5 ], [ 0, %9 ], [ 1, %.loopexit.loopexit ]
  ret i32 %.0
}

declare noundef zeroext i1 @_ZNK2sf6Window6isOpenEv(ptr noundef nonnull align 8 dereferenceable(48)) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4Menu5clearEv(ptr noundef nonnull align 8 dereferenceable(1288)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN4Menu6eventsEv(ptr noundef nonnull align 8 dereferenceable(1288)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4Menu6updateEv(ptr noundef nonnull align 8 dereferenceable(1288)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4Menu4drawEv(ptr noundef nonnull align 8 dereferenceable(1288)) local_unnamed_addr #0 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 = { "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 = !{!"_ZTS4Menu", !7, i64 0, !10, i64 8, !12, i64 32, !8, i64 176, !29, i64 1280, !29, i64 1284}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSN2sf5EventE", !11, i64 0, !8, i64 4}
!11 = !{!"_ZTSN2sf5Event9EventTypeE", !8, i64 0}
!12 = !{!"_ZTSN2sf4FontE", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !13, i64 40, !17, i64 72, !25, i64 120}
!13 = !{!"_ZTSN2sf4Font4InfoE", !14, i64 0}
!14 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !15, i64 0, !16, i64 8, !8, i64 16}
!15 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !7, i64 0}
!16 = !{!"long", !8, i64 0}
!17 = !{!"_ZTSSt3mapIjN2sf4Font4PageESt4lessIjESaISt4pairIKjS2_EEE", !18, i64 0}
!18 = !{!"_ZTSSt8_Rb_treeIjSt4pairIKjN2sf4Font4PageEESt10_Select1stIS5_ESt4lessIjESaIS5_EE", !19, i64 0}
!19 = !{!"_ZTSNSt8_Rb_treeIjSt4pairIKjN2sf4Font4PageEESt10_Select1stIS5_ESt4lessIjESaIS5_EE13_Rb_tree_implIS9_Lb1EEE", !20, i64 0, !22, i64 8}
!20 = !{!"_ZTSSt20_Rb_tree_key_compareISt4lessIjEE", !21, i64 0}
!21 = !{!"_ZTSSt4lessIjE"}
!22 = !{!"_ZTSSt15_Rb_tree_header", !23, i64 0, !16, i64 32}
!23 = !{!"_ZTSSt18_Rb_tree_node_base", !24, i64 0, !7, i64 8, !7, i64 16, !7, i64 24}
!24 = !{!"_ZTSSt14_Rb_tree_color", !8, i64 0}
!25 = !{!"_ZTSSt6vectorIhSaIhEE", !26, i64 0}
!26 = !{!"_ZTSSt12_Vector_baseIhSaIhEE", !27, i64 0}
!27 = !{!"_ZTSNSt12_Vector_baseIhSaIhEE12_Vector_implE", !28, i64 0}
!28 = !{!"_ZTSNSt12_Vector_baseIhSaIhEE17_Vector_impl_dataE", !7, i64 0, !7, i64 8, !7, i64 16}
!29 = !{!"int", !8, i64 0}
!30 = !{!6, !29, i64 1280}
!31 = distinct !{!31, !32}
!32 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass