; LLVM IR from xhub/reshop :: gui/external/imgui/imgui_widgets.ll (ZN26ImGuiSelectionBasicStorage15SetItemSelectedEjb)

; 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.ImGuiSelectionBasicStorage = type { i32, i8, ptr, ptr, i32, %struct.ImGuiStorage }
%struct.ImGuiStorage = type { %struct.ImVector.2 }
%struct.ImVector.2 = type { i32, i32, 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
define dso_local void @_ZN26ImGuiSelectionBasicStorage15SetItemSelectedEjb(ptr noundef nonnull align 8 dereferenceable(48) %0, i32 noundef %1, i1 noundef zeroext %2) #1 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i8, align 1
  %7 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %8 = zext i1 %2 to i8
  store i8 %8, ptr %6, align 1, !tbaa !11
  %9 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %10 = getelementptr inbounds %struct.ImGuiSelectionBasicStorage, ptr %9, i32 0, i32 5
  %11 = load i32, ptr %5, align 4, !tbaa !9
  %12 = call noundef ptr @_ZN12ImGuiStorage9GetIntRefEji(ptr noundef nonnull align 8 dereferenceable(16) %10, i32 noundef %11, i32 noundef 0)
  store ptr %12, ptr %7, align 8, !tbaa !5
  %13 = load i8, ptr %6, align 1, !tbaa !11, !range !13, !noundef !14
  %14 = trunc i8 %13 to i1
  br i1 %14, label %15, label %27

15:                                               ; preds = %3
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = load i32, ptr %16, align 4, !tbaa !9
  %18 = icmp eq i32 %17, 0
  br i1 %18, label %19, label %27

19:                                               ; preds = %15
  %20 = getelementptr inbounds %struct.ImGuiSelectionBasicStorage, ptr %9, i32 0, i32 4
  %21 = load i32, ptr %20, align 8, !tbaa !15
  %22 = add nsw i32 %21, 1
  store i32 %22, ptr %20, align 8, !tbaa !15
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 %21, ptr %23, align 4, !tbaa !9
  %24 = getelementptr inbounds %struct.ImGuiSelectionBasicStorage, ptr %9, i32 0, i32 0
  %25 = load i32, ptr %24, align 8, !tbaa !19
  %26 = add nsw i32 %25, 1
  store i32 %26, ptr %24, align 8, !tbaa !19
  br label %40

27:                                               ; preds = %15, %3
  %28 = load i8, ptr %6, align 1, !tbaa !11, !range !13, !noundef !14
  %29 = trunc i8 %28 to i1
  br i1 %29, label %39, label %30

30:                                               ; preds = %27
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = load i32, ptr %31, align 4, !tbaa !9
  %33 = icmp ne i32 %32, 0
  br i1 %33, label %34, label %39

34:                                               ; preds = %30
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 0, ptr %35, align 4, !tbaa !9
  %36 = getelementptr inbounds %struct.ImGuiSelectionBasicStorage, ptr %9, i32 0, i32 0
  %37 = load i32, ptr %36, align 8, !tbaa !19
  %38 = add nsw i32 %37, -1
  store i32 %38, ptr %36, align 8, !tbaa !19
  br label %39

39:                                               ; preds = %34, %30, %27
  br label %40

40:                                               ; preds = %39, %19
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret void
}

declare noundef ptr @_ZN12ImGuiStorage9GetIntRefEji(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef, i32 noundef) #2

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 = { "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 = { 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, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!16, !10, i64 24}
!16 = !{!"_ZTS26ImGuiSelectionBasicStorage", !10, i64 0, !12, i64 4, !6, i64 8, !6, i64 16, !10, i64 24, !17, i64 32}
!17 = !{!"_ZTS12ImGuiStorage", !18, i64 0}
!18 = !{!"_ZTS8ImVectorI16ImGuiStoragePairE", !10, i64 0, !10, i64 4, !6, i64 8}
!19 = !{!16, !10, i64 0}


; 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 void @_ZN26ImGuiSelectionBasicStorage15SetItemSelectedEjb(ptr noundef nonnull align 8 dereferenceable(48) %0, i32 noundef %1, i1 noundef zeroext %2) local_unnamed_addr #0 align 2 {
  %4 = getelementptr inbounds i8, ptr %0, i64 32
  %5 = tail call noundef ptr @_ZN12ImGuiStorage9GetIntRefEji(ptr noundef nonnull align 8 dereferenceable(16) %4, i32 noundef %1, i32 noundef 0)
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %7 = icmp eq i32 %6, 0
  br i1 %2, label %8, label %.critedge

8:                                                ; preds = %3
  br i1 %7, label %9, label %15

9:                                                ; preds = %8
  %10 = getelementptr inbounds i8, ptr %0, i64 24
  %11 = load i32, ptr %10, align 8, !tbaa !9
  %12 = add nsw i32 %11, 1
  store i32 %12, ptr %10, align 8, !tbaa !9
  br label %.sink.split

.critedge:                                        ; preds = %3
  br i1 %7, label %15, label %.sink.split

.sink.split:                                      ; preds = %.critedge, %9
  %.sink = phi i32 [ %11, %9 ], [ 0, %.critedge ]
  %.sink8 = phi i32 [ 1, %9 ], [ -1, %.critedge ]
  store i32 %.sink, ptr %5, align 4, !tbaa !5
  %13 = load i32, ptr %0, align 8, !tbaa !15
  %14 = add nsw i32 %13, %.sink8
  store i32 %14, ptr %0, align 8, !tbaa !15
  br label %15

15:                                               ; preds = %.sink.split, %8, %.critedge
  ret void
}

declare noundef ptr @_ZN12ImGuiStorage9GetIntRefEji(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef, i32 noundef) local_unnamed_addr #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 = { "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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 24}
!10 = !{!"_ZTS26ImGuiSelectionBasicStorage", !6, i64 0, !11, i64 4, !12, i64 8, !12, i64 16, !6, i64 24, !13, i64 32}
!11 = !{!"bool", !7, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!"_ZTS12ImGuiStorage", !14, i64 0}
!14 = !{!"_ZTS8ImVectorI16ImGuiStoragePairE", !6, i64 0, !6, i64 4, !12, i64 8}
!15 = !{!10, !6, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,SROAPass,SimplifyCFGPass,TailCallElimPass