; LLVM IR from modlfo/AudioEngine :: AudioEngine/JuceLibraryCode (juce_audio_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::MPEInstrument" = type { ptr, %"class.juce::CriticalSection", %"class.juce::Array.61", %"class.juce::MPEZoneLayout", %"class.juce::ListenerList.66", [16 x i8], [16 x i8], [16 x i8], %"struct.juce::MPEInstrument::LegacyMode", %"struct.juce::MPEInstrument::MPEDimension", %"struct.juce::MPEInstrument::MPEDimension", %"struct.juce::MPEInstrument::MPEDimension" }
%"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 }
%"class.juce::Array.61" = type { %"class.juce::ArrayAllocationBase.62", i32, [4 x i8] }
%"class.juce::ArrayAllocationBase.62" = type <{ %"class.juce::HeapBlock.63", i32, [4 x i8] }>
%"class.juce::HeapBlock.63" = type { ptr }
%"class.juce::MPEZoneLayout" = type { %"class.juce::Array.51", %"class.juce::MidiRPNDetector", %"class.juce::ListenerList" }
%"class.juce::Array.51" = type { %"class.juce::ArrayAllocationBase.52", i32, [4 x i8] }
%"class.juce::ArrayAllocationBase.52" = type <{ %"class.juce::HeapBlock.53", i32, [4 x i8] }>
%"class.juce::HeapBlock.53" = type { ptr }
%"class.juce::MidiRPNDetector" = type { [16 x %"struct.juce::MidiRPNDetector::ChannelState"] }
%"struct.juce::MidiRPNDetector::ChannelState" = type { i8, i8, i8, i8, i8 }
%"class.juce::ListenerList" = type { %"class.juce::Array.56" }
%"class.juce::Array.56" = type { %"class.juce::ArrayAllocationBase.57", i32, [4 x i8] }
%"class.juce::ArrayAllocationBase.57" = type <{ %"class.juce::HeapBlock.58", i32, [4 x i8] }>
%"class.juce::HeapBlock.58" = type { ptr }
%"class.juce::ListenerList.66" = type { %"class.juce::Array.67" }
%"class.juce::Array.67" = type { %"class.juce::ArrayAllocationBase.68", i32, [4 x i8] }
%"class.juce::ArrayAllocationBase.68" = type <{ %"class.juce::HeapBlock.69", i32, [4 x i8] }>
%"class.juce::HeapBlock.69" = type { ptr }
%"struct.juce::MPEInstrument::LegacyMode" = type { i8, %"class.juce::Range.50", i32 }
%"class.juce::Range.50" = type { i32, i32 }
%"struct.juce::MPEInstrument::MPEDimension" = type { i32, [16 x %"class.juce::MPEValue"], i64 }
%"class.juce::MPEValue" = type { i32 }
%"struct.juce::MPENote" = type <{ i16, i8, i8, %"class.juce::MPEValue", %"class.juce::MPEValue", %"class.juce::MPEValue", %"class.juce::MPEValue", %"class.juce::MPEValue", double, i32, [4 x i8] }>

; 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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK4juce5ArrayINS_7MPENoteENS_20DummyCriticalSectionELi0EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(20)) #1 align 2

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef ptr @_ZNK4juce13MPEInstrument16getLowestNotePtrEi(ptr noundef nonnull align 8 dereferenceable(528) %0, i32 noundef %1) #2 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %9 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 128, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store ptr null, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %10 = getelementptr inbounds %"class.juce::MPEInstrument", ptr %9, i32 0, i32 2
  %11 = call noundef i32 @_ZNK4juce5ArrayINS_7MPENoteENS_20DummyCriticalSectionELi0EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(20) %10) #3
  store i32 %11, ptr %7, align 4, !tbaa !9
  br label %12

12:                                               ; preds = %50, %2
  %13 = load i32, ptr %7, align 4, !tbaa !9
  %14 = add nsw i32 %13, -1
  store i32 %14, ptr %7, align 4, !tbaa !9
  %15 = icmp sge i32 %14, 0
  br i1 %15, label %17, label %16

16:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %51

17:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %18 = getelementptr inbounds %"class.juce::MPEInstrument", ptr %9, i32 0, i32 2
  %19 = load i32, ptr %7, align 4, !tbaa !9
  %20 = call noundef nonnull align 8 dereferenceable(36) ptr @_ZNK4juce5ArrayINS_7MPENoteENS_20DummyCriticalSectionELi0EE12getReferenceEi(ptr noundef nonnull align 8 dereferenceable(20) %18, i32 noundef %19) #3
  store ptr %20, ptr %8, align 8, !tbaa !5
  %21 = load ptr, ptr %8, align 8, !tbaa !5
  %22 = getelementptr inbounds %"struct.juce::MPENote", ptr %21, i32 0, i32 1
  %23 = load i8, ptr %22, align 2, !tbaa !11
  %24 = zext i8 %23 to i32
  %25 = load i32, ptr %4, align 4, !tbaa !9
  %26 = icmp eq i32 %24, %25
  br i1 %26, label %27, label %50

27:                                               ; preds = %17
  %28 = load ptr, ptr %8, align 8, !tbaa !5
  %29 = getelementptr inbounds %"struct.juce::MPENote", ptr %28, i32 0, i32 9
  %30 = load i32, ptr %29, align 8, !tbaa !17
  %31 = icmp eq i32 %30, 1
  br i1 %31, label %37, label %32

32:                                               ; preds = %27
  %33 = load ptr, ptr %8, align 8, !tbaa !5
  %34 = getelementptr inbounds %"struct.juce::MPENote", ptr %33, i32 0, i32 9
  %35 = load i32, ptr %34, align 8, !tbaa !17
  %36 = icmp eq i32 %35, 3
  br i1 %36, label %37, label %50

37:                                               ; preds = %32, %27
  %38 = load ptr, ptr %8, align 8, !tbaa !5
  %39 = getelementptr inbounds %"struct.juce::MPENote", ptr %38, i32 0, i32 2
  %40 = load i8, ptr %39, align 1, !tbaa !18
  %41 = zext i8 %40 to i32
  %42 = load i32, ptr %5, align 4, !tbaa !9
  %43 = icmp slt i32 %41, %42
  br i1 %43, label %44, label %50

44:                                               ; preds = %37
  %45 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %45, ptr %6, align 8, !tbaa !5
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  %47 = getelementptr inbounds %"struct.juce::MPENote", ptr %46, i32 0, i32 2
  %48 = load i8, ptr %47, align 1, !tbaa !18
  %49 = zext i8 %48 to i32
  store i32 %49, ptr %5, align 4, !tbaa !9
  br label %50

50:                                               ; preds = %44, %37, %32, %17
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %12, !llvm.loop !19

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = !{!12, !7, i64 2}
!12 = !{!"_ZTSN4juce7MPENoteE", !13, i64 0, !7, i64 2, !7, i64 3, !14, i64 4, !14, i64 8, !14, i64 12, !14, i64 16, !14, i64 20, !15, i64 24, !16, i64 32}
!13 = !{!"short", !7, i64 0}
!14 = !{!"_ZTSN4juce8MPEValueE", !10, i64 0}
!15 = !{!"double", !7, i64 0}
!16 = !{!"_ZTSN4juce7MPENote8KeyStateE", !7, i64 0}
!17 = !{!12, !16, i64 32}
!18 = !{!12, !7, i64 3}
!19 = distinct !{!19, !20}
!20 = !{!"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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK4juce5ArrayINS_7MPENoteENS_20DummyCriticalSectionELi0EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(20)) local_unnamed_addr #0 align 2

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef ptr @_ZNK4juce13MPEInstrument16getLowestNotePtrEi(ptr noundef nonnull align 8 dereferenceable(528) %0, i32 noundef %1) local_unnamed_addr #1 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 48
  %4 = tail call noundef i32 @_ZNK4juce5ArrayINS_7MPENoteENS_20DummyCriticalSectionELi0EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(20) %3) #3
  %5 = icmp sgt i32 %4, 0
  br i1 %5, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %20, %2
  %.012.lcssa = phi ptr [ null, %2 ], [ %.113, %20 ]
  ret ptr %.012.lcssa

.lr.ph:                                           ; preds = %2, %20
  %.in = phi i32 [ %6, %20 ], [ %4, %2 ]
  %.019 = phi i32 [ %.1, %20 ], [ 128, %2 ]
  %.01218 = phi ptr [ %.113, %20 ], [ null, %2 ]
  %6 = add nsw i32 %.in, -1
  %7 = tail call noundef nonnull align 8 dereferenceable(36) ptr @_ZNK4juce5ArrayINS_7MPENoteENS_20DummyCriticalSectionELi0EE12getReferenceEi(ptr noundef nonnull align 8 dereferenceable(20) %3, i32 noundef %6) #3
  %8 = getelementptr inbounds i8, ptr %7, i64 2
  %9 = load i8, ptr %8, align 2, !tbaa !5
  %10 = zext i8 %9 to i32
  %11 = icmp eq i32 %10, %1
  br i1 %11, label %12, label %20

12:                                               ; preds = %.lr.ph
  %13 = getelementptr inbounds i8, ptr %7, i64 32
  %14 = load i32, ptr %13, align 8, !tbaa !14
  switch i32 %14, label %20 [
    i32 1, label %15
    i32 3, label %15
  ]

15:                                               ; preds = %12, %12
  %16 = getelementptr inbounds i8, ptr %7, i64 3
  %17 = load i8, ptr %16, align 1, !tbaa !15
  %18 = zext i8 %17 to i32
  %19 = icmp sgt i32 %.019, %18
  %spec.select = select i1 %19, ptr %7, ptr %.01218
  %spec.select17 = tail call i32 @llvm.smin.i32(i32 %.019, i32 %18)
  br label %20

20:                                               ; preds = %15, %12, %.lr.ph
  %.113 = phi ptr [ %.01218, %.lr.ph ], [ %.01218, %12 ], [ %spec.select, %15 ]
  %.1 = phi i32 [ %.019, %.lr.ph ], [ %.019, %12 ], [ %spec.select17, %15 ]
  %21 = icmp ugt i32 %.in, 1
  br i1 %21, label %.lr.ph, label %._crit_edge, !llvm.loop !16
}

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

attributes #0 = { 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 #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 = !{!6, !8, i64 2}
!6 = !{!"_ZTSN4juce7MPENoteE", !7, i64 0, !8, i64 2, !8, i64 3, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !12, i64 24, !13, i64 32}
!7 = !{!"short", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSN4juce8MPEValueE", !11, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!"double", !8, i64 0}
!13 = !{!"_ZTSN4juce7MPENote8KeyStateE", !8, i64 0}
!14 = !{!6, !13, i64 32}
!15 = !{!6, !8, i64 3}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


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