; LLVM IR from modlfo/AudioEngine :: AudioEngine/JuceLibraryCode/juce_gui_basics.ll (ZN4juce12TreeViewItem12getItemOnRowEi)

; 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.juce::TreeViewItem" = type <{ ptr, ptr, ptr, %"class.juce::OwnedArray.338", i32, i32, i32, i32, i32, i32, i8, [7 x i8] }>
%"class.juce::OwnedArray.338" = type { %"class.juce::ArrayAllocationBase.339", i32, [4 x i8] }
%"class.juce::ArrayAllocationBase.339" = type <{ %"class.juce::HeapBlock.340", i32, [4 x i8] }>
%"class.juce::HeapBlock.340" = 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
declare dso_local noundef i32 @_ZNK4juce12TreeViewItem10getNumRowsEv(ptr noundef nonnull align 8 dereferenceable(73)) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef ptr @_ZN4juce12TreeViewItem12getItemOnRowEi(ptr noundef nonnull align 8 dereferenceable(73) %0, i32 noundef %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %10 = load ptr, ptr %4, align 8
  %11 = load i32, ptr %5, align 4, !tbaa !9
  %12 = icmp eq i32 %11, 0
  br i1 %12, label %13, label %14

13:                                               ; preds = %2
  store ptr %10, ptr %3, align 8
  br label %61

14:                                               ; preds = %2
  %15 = load i32, ptr %5, align 4, !tbaa !9
  %16 = icmp sgt i32 %15, 0
  br i1 %16, label %17, label %60

17:                                               ; preds = %14
  %18 = call noundef zeroext i1 @_ZNK4juce12TreeViewItem6isOpenEv(ptr noundef nonnull align 8 dereferenceable(73) %10) #3
  br i1 %18, label %19, label %60

19:                                               ; preds = %17
  %20 = load i32, ptr %5, align 4, !tbaa !9
  %21 = add nsw i32 %20, -1
  store i32 %21, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %22

22:                                               ; preds = %54, %19
  %23 = load i32, ptr %6, align 4, !tbaa !9
  %24 = getelementptr inbounds %"class.juce::TreeViewItem", ptr %10, i32 0, i32 3
  %25 = call noundef i32 @_ZNK4juce10OwnedArrayINS_12TreeViewItemENS_20DummyCriticalSectionEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(20) %24) #3
  %26 = icmp slt i32 %23, %25
  br i1 %26, label %28, label %27

27:                                               ; preds = %22
  store i32 2, ptr %7, align 4
  br label %57

28:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %29 = getelementptr inbounds %"class.juce::TreeViewItem", ptr %10, i32 0, i32 3
  %30 = load i32, ptr %6, align 4, !tbaa !9
  %31 = call noundef ptr @_ZNK4juce10OwnedArrayINS_12TreeViewItemENS_20DummyCriticalSectionEE12getUncheckedEi(ptr noundef nonnull align 8 dereferenceable(20) %29, i32 noundef %30) #3
  store ptr %31, ptr %8, align 8, !tbaa !5
  %32 = load i32, ptr %5, align 4, !tbaa !9
  %33 = icmp eq i32 %32, 0
  br i1 %33, label %34, label %36

34:                                               ; preds = %28
  %35 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %35, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %51

36:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %37 = load ptr, ptr %8, align 8, !tbaa !5
  %38 = call noundef i32 @_ZNK4juce12TreeViewItem10getNumRowsEv(ptr noundef nonnull align 8 dereferenceable(73) %37) #3
  store i32 %38, ptr %9, align 4, !tbaa !9
  %39 = load i32, ptr %9, align 4, !tbaa !9
  %40 = load i32, ptr %5, align 4, !tbaa !9
  %41 = icmp sgt i32 %39, %40
  br i1 %41, label %42, label %46

42:                                               ; preds = %36
  %43 = load ptr, ptr %8, align 8, !tbaa !5
  %44 = load i32, ptr %5, align 4, !tbaa !9
  %45 = call noundef ptr @_ZN4juce12TreeViewItem12getItemOnRowEi(ptr noundef nonnull align 8 dereferenceable(73) %43, i32 noundef %44) #3
  store ptr %45, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %50

46:                                               ; preds = %36
  %47 = load i32, ptr %9, align 4, !tbaa !9
  %48 = load i32, ptr %5, align 4, !tbaa !9
  %49 = sub nsw i32 %48, %47
  store i32 %49, ptr %5, align 4, !tbaa !9
  store i32 0, ptr %7, align 4
  br label %50

50:                                               ; preds = %46, %42
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %51

51:                                               ; preds = %50, %34
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %52 = load i32, ptr %7, align 4
  switch i32 %52, label %57 [
    i32 0, label %53
  ]

53:                                               ; preds = %51
  br label %54

54:                                               ; preds = %53
  %55 = load i32, ptr %6, align 4, !tbaa !9
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr %6, align 4, !tbaa !9
  br label %22, !llvm.loop !11

57:                                               ; preds = %51, %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %58 = load i32, ptr %7, align 4
  switch i32 %58, label %63 [
    i32 2, label %59
    i32 1, label %61
  ]

59:                                               ; preds = %57
  br label %60

60:                                               ; preds = %59, %17, %14
  store ptr null, ptr %3, align 8
  br label %61

61:                                               ; preds = %60, %57, %13
  %62 = load ptr, ptr %3, align 8
  ret ptr %62

63:                                               ; preds = %57
  unreachable
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK4juce12TreeViewItem6isOpenEv(ptr noundef nonnull align 8 dereferenceable(73)) #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK4juce10OwnedArrayINS_12TreeViewItemENS_20DummyCriticalSectionEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(20)) #2 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK4juce10OwnedArrayINS_12TreeViewItemENS_20DummyCriticalSectionEE12getUncheckedEi(ptr noundef nonnull align 8 dereferenceable(20), i32 noundef) #2 align 2

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 = { inlinehint 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 #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 = distinct !{!11, !12}
!12 = !{!"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 nounwind uwtable
declare dso_local noundef i32 @_ZNK4juce12TreeViewItem10getNumRowsEv(ptr noundef nonnull align 8 dereferenceable(73)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef ptr @_ZN4juce12TreeViewItem12getItemOnRowEi(ptr noundef nonnull align 8 dereferenceable(73) %0, i32 noundef %1) local_unnamed_addr #0 align 2 {
  br label %tailrecurse

tailrecurse:                                      ; preds = %15, %2
  %.tr = phi ptr [ %0, %2 ], [ %13, %15 ]
  %.tr51 = phi i32 [ %1, %2 ], [ %.01838, %15 ]
  %3 = icmp eq i32 %.tr51, 0
  br i1 %3, label %.thread31, label %4

4:                                                ; preds = %tailrecurse
  %5 = icmp sgt i32 %.tr51, 0
  br i1 %5, label %6, label %.thread31

6:                                                ; preds = %4
  %7 = tail call noundef zeroext i1 @_ZNK4juce12TreeViewItem6isOpenEv(ptr noundef nonnull align 8 dereferenceable(73) %.tr) #2
  br i1 %7, label %8, label %.thread31

8:                                                ; preds = %6
  %9 = getelementptr inbounds i8, ptr %.tr, i64 24
  %10 = tail call noundef i32 @_ZNK4juce10OwnedArrayINS_12TreeViewItemENS_20DummyCriticalSectionEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(20) %9) #2
  %11 = icmp sgt i32 %10, 0
  br i1 %11, label %.lr.ph.preheader, label %.thread31

.lr.ph.preheader:                                 ; preds = %8
  %12 = add nsw i32 %.tr51, -1
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %18
  %.01838 = phi i32 [ %19, %18 ], [ %12, %.lr.ph.preheader ]
  %.02437 = phi i32 [ %20, %18 ], [ 0, %.lr.ph.preheader ]
  %13 = tail call noundef ptr @_ZNK4juce10OwnedArrayINS_12TreeViewItemENS_20DummyCriticalSectionEE12getUncheckedEi(ptr noundef nonnull align 8 dereferenceable(20) %9, i32 noundef %.02437) #2
  %14 = icmp eq i32 %.01838, 0
  br i1 %14, label %.thread31, label %15

15:                                               ; preds = %.lr.ph
  %16 = tail call noundef i32 @_ZNK4juce12TreeViewItem10getNumRowsEv(ptr noundef nonnull align 8 dereferenceable(73) %13) #2
  %17 = icmp sgt i32 %16, %.01838
  br i1 %17, label %tailrecurse, label %18

18:                                               ; preds = %15
  %19 = sub nsw i32 %.01838, %16
  %20 = add nuw nsw i32 %.02437, 1
  %21 = tail call noundef i32 @_ZNK4juce10OwnedArrayINS_12TreeViewItemENS_20DummyCriticalSectionEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(20) %9) #2
  %22 = icmp slt i32 %20, %21
  br i1 %22, label %.lr.ph, label %.thread31, !llvm.loop !5

.thread31:                                        ; preds = %18, %.lr.ph, %8, %4, %6, %tailrecurse
  %.4 = phi ptr [ %.tr, %tailrecurse ], [ null, %6 ], [ null, %4 ], [ null, %8 ], [ null, %18 ], [ %13, %.lr.ph ]
  ret ptr %.4
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK4juce12TreeViewItem6isOpenEv(ptr noundef nonnull align 8 dereferenceable(73)) local_unnamed_addr #0 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK4juce10OwnedArrayINS_12TreeViewItemENS_20DummyCriticalSectionEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(20)) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK4juce10OwnedArrayINS_12TreeViewItemENS_20DummyCriticalSectionEE12getUncheckedEi(ptr noundef nonnull align 8 dereferenceable(20), i32 noundef) local_unnamed_addr #1 align 2

attributes #0 = { 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 #1 = { inlinehint 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


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