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

; 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"

; 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 @_ZN4juce6jlimitIiEET_S1_S1_S1_(i32 noundef, i32 noundef, i32 noundef) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK4juce8TreeView15getSelectedItemEi(ptr noundef nonnull align 8 dereferenceable(313), i32 noundef) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK4juce8TreeView16getNumRowsInTreeEv(ptr noundef nonnull align 8 dereferenceable(313)) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK4juce8TreeView12getItemOnRowEi(ptr noundef nonnull align 8 dereferenceable(313), i32 noundef) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4juce12TreeViewItem11setSelectedEbbNS_16NotificationTypeE(ptr noundef nonnull align 8 dereferenceable(73), i1 noundef zeroext, i1 noundef zeroext, i32 noundef) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4juce8TreeView15moveSelectedRowEi(ptr noundef nonnull align 8 dereferenceable(313) %0, i32 noundef %1) #2 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %11 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %12 = call noundef i32 @_ZNK4juce8TreeView16getNumRowsInTreeEv(ptr noundef nonnull align 8 dereferenceable(313) %11)
  store i32 %12, ptr %5, align 4, !tbaa !9
  %13 = load i32, ptr %5, align 4, !tbaa !9
  %14 = icmp sgt i32 %13, 0
  br i1 %14, label %15, label %65

15:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %16 = call noundef ptr @_ZNK4juce8TreeView15getSelectedItemEi(ptr noundef nonnull align 8 dereferenceable(313) %11, i32 noundef 0) #3
  store ptr %16, ptr %7, align 8, !tbaa !5
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = icmp ne ptr %17, null
  br i1 %18, label %19, label %22

19:                                               ; preds = %15
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = call noundef i32 @_ZNK4juce12TreeViewItem18getRowNumberInTreeEv(ptr noundef nonnull align 8 dereferenceable(73) %20) #3
  store i32 %21, ptr %6, align 4, !tbaa !9
  br label %22

22:                                               ; preds = %19, %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  %23 = load i32, ptr %5, align 4, !tbaa !9
  %24 = sub nsw i32 %23, 1
  %25 = load i32, ptr %6, align 4, !tbaa !9
  %26 = load i32, ptr %4, align 4, !tbaa !9
  %27 = add nsw i32 %25, %26
  %28 = call noundef i32 @_ZN4juce6jlimitIiEET_S1_S1_S1_(i32 noundef 0, i32 noundef %24, i32 noundef %27) #3
  store i32 %28, ptr %6, align 4, !tbaa !9
  br label %29

29:                                               ; preds = %61, %22
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %30 = load i32, ptr %6, align 4, !tbaa !9
  %31 = call noundef ptr @_ZNK4juce8TreeView12getItemOnRowEi(ptr noundef nonnull align 8 dereferenceable(313) %11, i32 noundef %30)
  store ptr %31, ptr %8, align 8, !tbaa !5
  %32 = load ptr, ptr %8, align 8, !tbaa !5
  %33 = icmp ne ptr %32, null
  br i1 %33, label %34, label %60

34:                                               ; preds = %29
  %35 = load ptr, ptr %8, align 8, !tbaa !5
  %36 = load ptr, ptr %35, align 8, !tbaa !11
  %37 = getelementptr inbounds ptr, ptr %36, i64 7
  %38 = load ptr, ptr %37, align 8
  %39 = call noundef zeroext i1 %38(ptr noundef nonnull align 8 dereferenceable(73) %35)
  br i1 %39, label %57, label %40

40:                                               ; preds = %34
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %41 = load i32, ptr %5, align 4, !tbaa !9
  %42 = sub nsw i32 %41, 1
  %43 = load i32, ptr %6, align 4, !tbaa !9
  %44 = load i32, ptr %4, align 4, !tbaa !9
  %45 = icmp slt i32 %44, 0
  %46 = zext i1 %45 to i64
  %47 = select i1 %45, i32 -1, i32 1
  %48 = add nsw i32 %43, %47
  %49 = call noundef i32 @_ZN4juce6jlimitIiEET_S1_S1_S1_(i32 noundef 0, i32 noundef %42, i32 noundef %48) #3
  store i32 %49, ptr %9, align 4, !tbaa !9
  %50 = load i32, ptr %6, align 4, !tbaa !9
  %51 = load i32, ptr %9, align 4, !tbaa !9
  %52 = icmp ne i32 %50, %51
  br i1 %52, label %53, label %55

53:                                               ; preds = %40
  %54 = load i32, ptr %9, align 4, !tbaa !9
  store i32 %54, ptr %6, align 4, !tbaa !9
  store i32 3, ptr %10, align 4
  br label %56, !llvm.loop !13

55:                                               ; preds = %40
  store i32 2, ptr %10, align 4
  br label %56

56:                                               ; preds = %55, %53
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %61

57:                                               ; preds = %34
  %58 = load ptr, ptr %8, align 8, !tbaa !5
  call void @_ZN4juce12TreeViewItem11setSelectedEbbNS_16NotificationTypeE(ptr noundef nonnull align 8 dereferenceable(73) %58, i1 noundef zeroext true, i1 noundef zeroext true, i32 noundef 1)
  %59 = load ptr, ptr %8, align 8, !tbaa !5
  call void @_ZN4juce8TreeView23scrollToKeepItemVisibleEPNS_12TreeViewItemE(ptr noundef nonnull align 8 dereferenceable(313) %11, ptr noundef %59)
  br label %60

60:                                               ; preds = %57, %29
  store i32 0, ptr %10, align 4
  br label %61

61:                                               ; preds = %60, %56
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %62 = load i32, ptr %10, align 4
  switch i32 %62, label %66 [
    i32 0, label %63
    i32 3, label %29
    i32 2, label %64
  ]

63:                                               ; preds = %61
  br label %64

64:                                               ; preds = %63, %61
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %65

65:                                               ; preds = %64, %2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret void

66:                                               ; preds = %61
  unreachable
}

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4juce8TreeView23scrollToKeepItemVisibleEPNS_12TreeViewItemE(ptr noundef nonnull align 8 dereferenceable(313), ptr 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 = { 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 #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 = !{!"vtable pointer", !8, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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 @_ZN4juce6jlimitIiEET_S1_S1_S1_(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK4juce8TreeView15getSelectedItemEi(ptr noundef nonnull align 8 dereferenceable(313), i32 noundef) local_unnamed_addr #0 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK4juce8TreeView12getItemOnRowEi(ptr noundef nonnull align 8 dereferenceable(313), i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4juce12TreeViewItem11setSelectedEbbNS_16NotificationTypeE(ptr noundef nonnull align 8 dereferenceable(73), i1 noundef zeroext, i1 noundef zeroext, i32 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4juce8TreeView15moveSelectedRowEi(ptr noundef nonnull align 8 dereferenceable(313) %0, i32 noundef %1) local_unnamed_addr #1 align 2 {
  %3 = tail call noundef i32 @_ZNK4juce8TreeView16getNumRowsInTreeEv(ptr noundef nonnull align 8 dereferenceable(313) %0)
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %5, label %.thread

5:                                                ; preds = %2
  %6 = tail call noundef ptr @_ZNK4juce8TreeView15getSelectedItemEi(ptr noundef nonnull align 8 dereferenceable(313) %0, i32 noundef 0) #2
  %.not = icmp eq ptr %6, null
  br i1 %.not, label %9, label %7

7:                                                ; preds = %5
  %8 = tail call noundef i32 @_ZNK4juce12TreeViewItem18getRowNumberInTreeEv(ptr noundef nonnull align 8 dereferenceable(73) %6) #2
  br label %9

9:                                                ; preds = %7, %5
  %.018 = phi i32 [ %8, %7 ], [ 0, %5 ]
  %10 = add nsw i32 %3, -1
  %11 = add nsw i32 %.018, %1
  %12 = tail call noundef i32 @_ZN4juce6jlimitIiEET_S1_S1_S1_(i32 noundef 0, i32 noundef %10, i32 noundef %11) #2
  %.inv = icmp sgt i32 %1, -1
  %13 = select i1 %.inv, i32 1, i32 -1
  br label %14

14:                                               ; preds = %22, %9
  %.119 = phi i32 [ %12, %9 ], [ %24, %22 ]
  %15 = tail call noundef ptr @_ZNK4juce8TreeView12getItemOnRowEi(ptr noundef nonnull align 8 dereferenceable(313) %0, i32 noundef %.119)
  %.not24 = icmp eq ptr %15, null
  br i1 %.not24, label %.thread, label %16

16:                                               ; preds = %14
  %17 = load ptr, ptr %15, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %17, i64 56
  %19 = load ptr, ptr %18, align 8
  %20 = tail call noundef zeroext i1 %19(ptr noundef nonnull align 8 dereferenceable(73) %15)
  br i1 %20, label %21, label %22

21:                                               ; preds = %16
  tail call void @_ZN4juce12TreeViewItem11setSelectedEbbNS_16NotificationTypeE(ptr noundef nonnull align 8 dereferenceable(73) %15, i1 noundef zeroext true, i1 noundef zeroext true, i32 noundef 1)
  tail call void @_ZN4juce8TreeView23scrollToKeepItemVisibleEPNS_12TreeViewItemE(ptr noundef nonnull align 8 dereferenceable(313) %0, ptr noundef nonnull %15)
  br label %.thread

22:                                               ; preds = %16
  %23 = add nsw i32 %.119, %13
  %24 = tail call noundef i32 @_ZN4juce6jlimitIiEET_S1_S1_S1_(i32 noundef 0, i32 noundef %10, i32 noundef %23) #2
  %.not25.not = icmp eq i32 %.119, %24
  br i1 %.not25.not, label %.thread, label %14

.thread:                                          ; preds = %14, %22, %21, %2
  ret void
}

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4juce8TreeView23scrollToKeepItemVisibleEPNS_12TreeViewItemE(ptr noundef nonnull align 8 dereferenceable(313), ptr 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 = { 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 = { 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 = !{!"vtable pointer", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}


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