; LLVM IR from modlfo/AudioEngine :: AudioEngine/JuceLibraryCode/juce_events.ll (ZN4juce14MessageManager15runDispatchLoopEv)

; 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::MessageManager" = type { %"class.juce::ScopedPointer.1", i8, i8, ptr, ptr, %"class.juce::CriticalSection" }
%"class.juce::ScopedPointer.1" = type { ptr }
%"class.juce::CriticalSection" = type { %union.pthread_mutex_t }
%union.pthread_mutex_t = type { %struct.__pthread_mutex_s }
%struct.__pthread_mutex_s = type { i32, i32, i32, i32, i32, i16, i16, %struct.__pthread_internal_list }
%struct.__pthread_internal_list = type { ptr, ptr }

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4juce14MessageManager15runDispatchLoopEv(ptr noundef nonnull align 8 dereferenceable(72) %0) #0 align 2 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %3 = load ptr, ptr %2, align 8
  br label %4

4:                                                ; preds = %1
  br label %5

5:                                                ; preds = %4
  br label %6

6:                                                ; preds = %14, %5
  %7 = getelementptr inbounds %"class.juce::MessageManager", ptr %3, i32 0, i32 2
  %8 = load i8, ptr %7, align 1, !tbaa !9, !range !14, !noundef !15
  %9 = trunc i8 %8 to i1
  %10 = xor i1 %9, true
  br i1 %10, label %11, label %15

11:                                               ; preds = %6
  %12 = call noundef zeroext i1 @_ZN4juce14MessageManager32dispatchNextMessageOnSystemQueueEb(i1 noundef zeroext false)
  br i1 %12, label %14, label %13

13:                                               ; preds = %11
  call void @_ZN4juce6Thread5sleepEi(i32 noundef 1)
  br label %14

14:                                               ; preds = %13, %11
  br label %6, !llvm.loop !16

15:                                               ; preds = %6
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN4juce14MessageManager32dispatchNextMessageOnSystemQueueEb(i1 noundef zeroext) #0 align 2

declare void @_ZN4juce6Thread5sleepEi(i32 noundef) #1

attributes #0 = { 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 #1 = { "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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !12, i64 9}
!10 = !{!"_ZTSN4juce14MessageManagerE", !11, i64 0, !12, i64 8, !12, i64 9, !6, i64 16, !6, i64 24, !13, i64 32}
!11 = !{!"_ZTSN4juce13ScopedPointerINS_17ActionBroadcasterEEE", !6, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{!"_ZTSN4juce15CriticalSectionE", !7, i64 0}
!14 = !{i8 0, i8 2}
!15 = !{}
!16 = distinct !{!16, !17}
!17 = !{!"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 uwtable
define dso_local void @_ZN4juce14MessageManager15runDispatchLoopEv(ptr nocapture noundef nonnull readonly align 8 dereferenceable(72) %0) local_unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 9
  %3 = load i8, ptr %2, align 1, !tbaa !5, !range !13, !noundef !14
  %4 = trunc nuw i8 %3 to i1
  br i1 %4, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1, %7
  %5 = tail call noundef zeroext i1 @_ZN4juce14MessageManager32dispatchNextMessageOnSystemQueueEb(i1 noundef zeroext false)
  br i1 %5, label %7, label %6

6:                                                ; preds = %.lr.ph
  tail call void @_ZN4juce6Thread5sleepEi(i32 noundef 1)
  br label %7

7:                                                ; preds = %6, %.lr.ph
  %8 = load i8, ptr %2, align 1, !tbaa !5, !range !13, !noundef !14
  %9 = trunc nuw i8 %8 to i1
  br i1 %9, label %._crit_edge, label %.lr.ph, !llvm.loop !15

._crit_edge:                                      ; preds = %7, %1
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN4juce14MessageManager32dispatchNextMessageOnSystemQueueEb(i1 noundef zeroext) local_unnamed_addr #0 align 2

declare void @_ZN4juce6Thread5sleepEi(i32 noundef) local_unnamed_addr #1

attributes #0 = { 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 #1 = { "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, !11, i64 9}
!6 = !{!"_ZTSN4juce14MessageManagerE", !7, i64 0, !11, i64 8, !11, i64 9, !8, i64 16, !8, i64 24, !12, i64 32}
!7 = !{!"_ZTSN4juce13ScopedPointerINS_17ActionBroadcasterEEE", !8, i64 0}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"bool", !9, i64 0}
!12 = !{!"_ZTSN4juce15CriticalSectionE", !9, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GlobalOptPass,IPSCCPPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass