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

; 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.ImGuiStoragePair = type { i32, %union.anon.35 }
%union.anon.35 = 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 nounwind uwtable
define dso_local noundef ptr @_Z12ImLowerBoundP16ImGuiStoragePairS0_j(ptr noundef %0, ptr noundef %1, i32 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %11, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = load ptr, ptr %7, align 8, !tbaa !5
  %14 = ptrtoint ptr %12 to i64
  %15 = ptrtoint ptr %13 to i64
  %16 = sub i64 %14, %15
  %17 = sdiv exact i64 %16, 16
  store i64 %17, ptr %8, align 8, !tbaa !11
  br label %18

18:                                               ; preds = %42, %3
  %19 = load i64, ptr %8, align 8, !tbaa !11
  %20 = icmp ugt i64 %19, 0
  br i1 %20, label %22, label %21

21:                                               ; preds = %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  br label %43

22:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %23 = load i64, ptr %8, align 8, !tbaa !11
  %24 = lshr i64 %23, 1
  store i64 %24, ptr %9, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = load i64, ptr %9, align 8, !tbaa !11
  %27 = getelementptr inbounds %struct.ImGuiStoragePair, ptr %25, i64 %26
  store ptr %27, ptr %10, align 8, !tbaa !5
  %28 = load ptr, ptr %10, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.ImGuiStoragePair, ptr %28, i32 0, i32 0
  %30 = load i32, ptr %29, align 8, !tbaa !13
  %31 = load i32, ptr %6, align 4, !tbaa !9
  %32 = icmp ult i32 %30, %31
  br i1 %32, label %33, label %40

33:                                               ; preds = %22
  %34 = load ptr, ptr %10, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.ImGuiStoragePair, ptr %34, i32 1
  store ptr %35, ptr %10, align 8, !tbaa !5
  store ptr %35, ptr %7, align 8, !tbaa !5
  %36 = load i64, ptr %9, align 8, !tbaa !11
  %37 = add i64 %36, 1
  %38 = load i64, ptr %8, align 8, !tbaa !11
  %39 = sub i64 %38, %37
  store i64 %39, ptr %8, align 8, !tbaa !11
  br label %42

40:                                               ; preds = %22
  %41 = load i64, ptr %9, align 8, !tbaa !11
  store i64 %41, ptr %8, align 8, !tbaa !11
  br label %42

42:                                               ; preds = %40, %33
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  br label %18, !llvm.loop !15

43:                                               ; preds = %21
  %44 = load ptr, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  ret ptr %44
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 = !{!"long", !7, i64 0}
!13 = !{!14, !10, i64 0}
!14 = !{!"_ZTS16ImGuiStoragePair", !10, i64 0, !7, i64 8}
!15 = distinct !{!15, !16}
!16 = !{!"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"

%struct.ImGuiStoragePair = type { i32, %union.anon.35 }
%union.anon.35 = type { ptr }

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) uwtable
define dso_local noundef ptr @_Z12ImLowerBoundP16ImGuiStoragePairS0_j(ptr noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %.not15 = icmp eq ptr %1, %0
  br i1 %.not15, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %3
  %4 = ptrtoint ptr %1 to i64
  %5 = ptrtoint ptr %0 to i64
  %6 = sub i64 %4, %5
  %7 = ashr exact i64 %6, 4
  br label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %3
  %.0.lcssa = phi ptr [ %0, %3 ], [ %.1, %.lr.ph ]
  ret ptr %.0.lcssa

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %.017 = phi ptr [ %.1, %.lr.ph ], [ %0, %.lr.ph.preheader ]
  %.01316 = phi i64 [ %.114, %.lr.ph ], [ %7, %.lr.ph.preheader ]
  %8 = lshr i64 %.01316, 1
  %9 = getelementptr inbounds %struct.ImGuiStoragePair, ptr %.017, i64 %8
  %10 = load i32, ptr %9, align 8, !tbaa !5
  %11 = icmp ult i32 %10, %2
  %12 = getelementptr inbounds i8, ptr %9, i64 16
  %.neg = xor i64 %8, -1
  %13 = add i64 %.01316, %.neg
  %.114 = select i1 %11, i64 %13, i64 %8
  %.1 = select i1 %11, ptr %12, ptr %.017
  %.not = icmp eq i64 %.114, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !10
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) 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 = !{!"_ZTS16ImGuiStoragePair", !7, i64 0, !8, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass