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

@_ZTIN4juce9ComponentE = external dso_local constant { ptr, ptr, ptr }, align 8
@_ZTIN4juce14TopLevelWindowE = external dso_local constant { ptr, ptr, ptr }, align 8

; 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: nounwind willreturn memory(read)
declare ptr @__dynamic_cast(ptr, ptr, ptr, i64) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK4juce9Component18getParentComponentEv(ptr noundef nonnull align 8 dereferenceable(197)) #2 align 2

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef ptr @_ZN4juce14TopLevelWindow23getActiveTopLevelWindowEv() #2 align 2 {
  %1 = alloca ptr, align 8
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #3
  store ptr null, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 -1, ptr %2, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %8 = call noundef i32 @_ZN4juce14TopLevelWindow21getNumTopLevelWindowsEv() #3
  store i32 %8, ptr %3, align 4, !tbaa !9
  br label %9

9:                                                ; preds = %50, %0
  %10 = load i32, ptr %3, align 4, !tbaa !9
  %11 = add nsw i32 %10, -1
  store i32 %11, ptr %3, align 4, !tbaa !9
  %12 = icmp sge i32 %11, 0
  br i1 %12, label %14, label %13

13:                                               ; preds = %9
  store i32 2, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %51

14:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %15 = load i32, ptr %3, align 4, !tbaa !9
  %16 = call noundef ptr @_ZN4juce14TopLevelWindow17getTopLevelWindowEi(i32 noundef %15) #3
  store ptr %16, ptr %5, align 8, !tbaa !5
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = call noundef zeroext i1 @_ZNK4juce14TopLevelWindow14isActiveWindowEv(ptr noundef nonnull align 8 dereferenceable(208) %17) #3
  br i1 %18, label %19, label %50

19:                                               ; preds = %14
  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
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = call noundef ptr @_ZNK4juce9Component18getParentComponentEv(ptr noundef nonnull align 8 dereferenceable(197) %20) #3
  store ptr %21, ptr %7, align 8, !tbaa !5
  br label %22

22:                                               ; preds = %39, %19
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = icmp ne ptr %23, null
  br i1 %24, label %26, label %25

25:                                               ; preds = %22
  store i32 4, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  br label %42

26:                                               ; preds = %22
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = icmp eq ptr %27, null
  br i1 %28, label %31, label %29

29:                                               ; preds = %26
  %30 = call ptr @__dynamic_cast(ptr %27, ptr @_ZTIN4juce9ComponentE, ptr @_ZTIN4juce14TopLevelWindowE, i64 0) #3
  br label %32

31:                                               ; preds = %26
  br label %32

32:                                               ; preds = %31, %29
  %33 = phi ptr [ %30, %29 ], [ null, %31 ]
  %34 = icmp ne ptr %33, null
  br i1 %34, label %35, label %38

35:                                               ; preds = %32
  %36 = load i32, ptr %6, align 4, !tbaa !9
  %37 = add nsw i32 %36, 1
  store i32 %37, ptr %6, align 4, !tbaa !9
  br label %38

38:                                               ; preds = %35, %32
  br label %39

39:                                               ; preds = %38
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = call noundef ptr @_ZNK4juce9Component18getParentComponentEv(ptr noundef nonnull align 8 dereferenceable(197) %40) #3
  store ptr %41, ptr %7, align 8, !tbaa !5
  br label %22, !llvm.loop !11

42:                                               ; preds = %25
  %43 = load i32, ptr %2, align 4, !tbaa !9
  %44 = load i32, ptr %6, align 4, !tbaa !9
  %45 = icmp slt i32 %43, %44
  br i1 %45, label %46, label %49

46:                                               ; preds = %42
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %47, ptr %1, align 8, !tbaa !5
  %48 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %48, ptr %2, align 4, !tbaa !9
  br label %49

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

50:                                               ; preds = %49, %14
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  br label %9, !llvm.loop !13

51:                                               ; preds = %13
  %52 = load ptr, ptr %1, align 8, !tbaa !5
  store i32 1, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #3
  ret ptr %52
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN4juce14TopLevelWindow21getNumTopLevelWindowsEv() #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN4juce14TopLevelWindow17getTopLevelWindowEi(i32 noundef) #2 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind willreturn memory(read) }
attributes #2 = { 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"}
!13 = distinct !{!13, !12}


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

@_ZTIN4juce9ComponentE = external dso_local constant { ptr, ptr, ptr }, align 8
@_ZTIN4juce14TopLevelWindowE = external dso_local constant { ptr, ptr, ptr }, align 8

; Function Attrs: mustprogress nofree nounwind willreturn memory(read)
declare ptr @__dynamic_cast(ptr, ptr, ptr, i64) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK4juce9Component18getParentComponentEv(ptr noundef nonnull align 8 dereferenceable(197)) local_unnamed_addr #1 align 2

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef ptr @_ZN4juce14TopLevelWindow23getActiveTopLevelWindowEv() local_unnamed_addr #1 align 2 {
  %1 = tail call noundef i32 @_ZN4juce14TopLevelWindow21getNumTopLevelWindowsEv() #3
  %2 = icmp sgt i32 %1, 0
  br i1 %2, label %.lr.ph29, label %._crit_edge30

._crit_edge30:                                    ; preds = %12, %0
  %.013.lcssa = phi ptr [ null, %0 ], [ %.2, %12 ]
  ret ptr %.013.lcssa

.lr.ph29:                                         ; preds = %0, %12
  %.in = phi i32 [ %3, %12 ], [ %1, %0 ]
  %.01327 = phi ptr [ %.2, %12 ], [ null, %0 ]
  %.01626 = phi i32 [ %.218, %12 ], [ -1, %0 ]
  %3 = add nsw i32 %.in, -1
  %4 = tail call noundef ptr @_ZN4juce14TopLevelWindow17getTopLevelWindowEi(i32 noundef %3) #3
  %5 = tail call noundef zeroext i1 @_ZNK4juce14TopLevelWindow14isActiveWindowEv(ptr noundef nonnull align 8 dereferenceable(208) %4) #3
  br i1 %5, label %6, label %12

6:                                                ; preds = %.lr.ph29
  %7 = tail call noundef ptr @_ZNK4juce9Component18getParentComponentEv(ptr noundef nonnull align 8 dereferenceable(197) %4) #3
  %.not23 = icmp eq ptr %7, null
  br i1 %.not23, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %6
  %.012.lcssa = phi i32 [ 0, %6 ], [ %spec.select22, %.lr.ph ]
  %8 = icmp slt i32 %.01626, %.012.lcssa
  %spec.select = tail call i32 @llvm.smax.i32(i32 %.01626, i32 %.012.lcssa)
  %spec.select21 = select i1 %8, ptr %4, ptr %.01327
  br label %12

.lr.ph:                                           ; preds = %6, %.lr.ph
  %.025 = phi ptr [ %11, %.lr.ph ], [ %7, %6 ]
  %.01224 = phi i32 [ %spec.select22, %.lr.ph ], [ 0, %6 ]
  %9 = tail call ptr @__dynamic_cast(ptr nonnull %.025, ptr nonnull @_ZTIN4juce9ComponentE, ptr nonnull @_ZTIN4juce14TopLevelWindowE, i64 0) #3
  %.not20 = icmp ne ptr %9, null
  %10 = zext i1 %.not20 to i32
  %spec.select22 = add nuw nsw i32 %.01224, %10
  %11 = tail call noundef ptr @_ZNK4juce9Component18getParentComponentEv(ptr noundef nonnull align 8 dereferenceable(197) %.025) #3
  %.not = icmp eq ptr %11, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !5

12:                                               ; preds = %._crit_edge, %.lr.ph29
  %.218 = phi i32 [ %spec.select, %._crit_edge ], [ %.01626, %.lr.ph29 ]
  %.2 = phi ptr [ %spec.select21, %._crit_edge ], [ %.01327, %.lr.ph29 ]
  %13 = icmp sgt i32 %.in, 1
  br i1 %13, label %.lr.ph29, label %._crit_edge30, !llvm.loop !7
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN4juce14TopLevelWindow21getNumTopLevelWindowsEv() local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN4juce14TopLevelWindow17getTopLevelWindowEi(i32 noundef) local_unnamed_addr #1 align 2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #2

attributes #0 = { mustprogress nofree nounwind willreturn memory(read) }
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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}


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