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

; 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 @_ZNK4juce12TreeViewItem29countSelectedItemsRecursivelyEi(ptr noundef nonnull align 8 dereferenceable(73), i32 noundef) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef ptr @_ZN4juce12TreeViewItem24getSelectedItemWithIndexEi(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 ptr, align 8
  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 = call noundef zeroext i1 @_ZNK4juce12TreeViewItem10isSelectedEv(ptr noundef nonnull align 8 dereferenceable(73) %10) #3
  br i1 %11, label %12, label %19

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

15:                                               ; preds = %12
  store ptr %10, ptr %3, align 8
  br label %58

16:                                               ; preds = %12
  %17 = load i32, ptr %5, align 4, !tbaa !9
  %18 = add nsw i32 %17, -1
  store i32 %18, ptr %5, align 4, !tbaa !9
  br label %19

19:                                               ; preds = %16, %2
  %20 = load i32, ptr %5, align 4, !tbaa !9
  %21 = icmp sge i32 %20, 0
  br i1 %21, label %22, label %57

22:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %23

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

28:                                               ; preds = %23
  store i32 2, ptr %7, align 4
  br label %54

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

38:                                               ; preds = %29
  %39 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %39, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %41

40:                                               ; preds = %29
  store i32 0, ptr %7, align 4
  br label %41

41:                                               ; preds = %40, %38
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  %42 = load i32, ptr %7, align 4
  switch i32 %42, label %48 [
    i32 0, label %43
  ]

43:                                               ; preds = %41
  %44 = load ptr, ptr %8, align 8, !tbaa !5
  %45 = call noundef i32 @_ZNK4juce12TreeViewItem29countSelectedItemsRecursivelyEi(ptr noundef nonnull align 8 dereferenceable(73) %44, i32 noundef -1) #3
  %46 = load i32, ptr %5, align 4, !tbaa !9
  %47 = sub nsw i32 %46, %45
  store i32 %47, ptr %5, align 4, !tbaa !9
  store i32 0, ptr %7, align 4
  br label %48

48:                                               ; preds = %43, %41
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %49 = load i32, ptr %7, align 4
  switch i32 %49, label %54 [
    i32 0, label %50
  ]

50:                                               ; preds = %48
  br label %51

51:                                               ; preds = %50
  %52 = load i32, ptr %6, align 4, !tbaa !9
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %6, align 4, !tbaa !9
  br label %23, !llvm.loop !11

54:                                               ; preds = %48, %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %55 = load i32, ptr %7, align 4
  switch i32 %55, label %60 [
    i32 2, label %56
    i32 1, label %58
  ]

56:                                               ; preds = %54
  br label %57

57:                                               ; preds = %56, %19
  store ptr null, ptr %3, align 8
  br label %58

58:                                               ; preds = %57, %54, %15
  %59 = load ptr, ptr %3, align 8
  ret ptr %59

60:                                               ; preds = %54
  unreachable
}

; 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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK4juce12TreeViewItem10isSelectedEv(ptr noundef nonnull align 8 dereferenceable(73)) #1 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 @_ZNK4juce12TreeViewItem29countSelectedItemsRecursivelyEi(ptr noundef nonnull align 8 dereferenceable(73), i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef ptr @_ZN4juce12TreeViewItem24getSelectedItemWithIndexEi(ptr noundef nonnull align 8 dereferenceable(73) %0, i32 noundef %1) local_unnamed_addr #0 align 2 {
  %3 = tail call noundef zeroext i1 @_ZNK4juce12TreeViewItem10isSelectedEv(ptr noundef nonnull align 8 dereferenceable(73) %0) #2
  br i1 %3, label %4, label %8

4:                                                ; preds = %2
  %5 = icmp eq i32 %1, 0
  br i1 %5, label %.thread28, label %6

6:                                                ; preds = %4
  %7 = add nsw i32 %1, -1
  br label %8

8:                                                ; preds = %6, %2
  %.017 = phi i32 [ %7, %6 ], [ %1, %2 ]
  %9 = icmp sgt i32 %.017, -1
  br i1 %9, label %.preheader, label %.thread28

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

.lr.ph:                                           ; preds = %.preheader, %15
  %.11834 = phi i32 [ %17, %15 ], [ %.017, %.preheader ]
  %.02333 = phi i32 [ %18, %15 ], [ 0, %.preheader ]
  %13 = tail call noundef ptr @_ZNK4juce10OwnedArrayINS_12TreeViewItemENS_20DummyCriticalSectionEE12getUncheckedEi(ptr noundef nonnull align 8 dereferenceable(20) %10, i32 noundef %.02333) #2
  %14 = tail call noundef ptr @_ZN4juce12TreeViewItem24getSelectedItemWithIndexEi(ptr noundef nonnull align 8 dereferenceable(73) %13, i32 noundef %.11834) #2
  %.not = icmp eq ptr %14, null
  br i1 %.not, label %15, label %.thread28

15:                                               ; preds = %.lr.ph
  %16 = tail call noundef i32 @_ZNK4juce12TreeViewItem29countSelectedItemsRecursivelyEi(ptr noundef nonnull align 8 dereferenceable(73) %13, i32 noundef -1) #2
  %17 = sub nsw i32 %.11834, %16
  %18 = add nuw nsw i32 %.02333, 1
  %19 = tail call noundef i32 @_ZNK4juce10OwnedArrayINS_12TreeViewItemENS_20DummyCriticalSectionEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(20) %10) #2
  %20 = icmp slt i32 %18, %19
  br i1 %20, label %.lr.ph, label %.thread28, !llvm.loop !5

.thread28:                                        ; preds = %15, %.lr.ph, %.preheader, %8, %4
  %.3 = phi ptr [ %0, %4 ], [ null, %8 ], [ null, %.preheader ], [ null, %15 ], [ %14, %.lr.ph ]
  ret ptr %.3
}

; 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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK4juce12TreeViewItem10isSelectedEv(ptr noundef nonnull align 8 dereferenceable(73)) local_unnamed_addr #0 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,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass