; LLVM IR from modlfo/AudioEngine :: AudioEngine/JuceLibraryCode/juce_audio_basics.ll (ZN4juce10MidiBuffer5clearEii)

; 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::MidiBuffer" = type { %"class.juce::Array" }
%"class.juce::Array" = type { %"class.juce::ArrayAllocationBase", i32, [4 x i8] }
%"class.juce::ArrayAllocationBase" = type <{ %"class.juce::HeapBlock", i32, [4 x i8] }>
%"class.juce::HeapBlock" = 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 uwtable
define dso_local void @_ZN4juce10MidiBuffer5clearEii(ptr noundef nonnull align 8 dereferenceable(24) %0, i32 noundef %1, i32 noundef %2) #1 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !9
  %9 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %10 = getelementptr inbounds %"class.juce::MidiBuffer", ptr %9, i32 0, i32 0
  %11 = call noundef ptr @_ZNK4juce5ArrayIhNS_20DummyCriticalSectionELi0EE5beginEv(ptr noundef nonnull align 8 dereferenceable(20) %10) #4
  %12 = getelementptr inbounds %"class.juce::MidiBuffer", ptr %9, i32 0, i32 0
  %13 = call noundef ptr @_ZNK4juce5ArrayIhNS_20DummyCriticalSectionELi0EE3endEv(ptr noundef nonnull align 8 dereferenceable(20) %12) #4
  %14 = load i32, ptr %5, align 4, !tbaa !9
  %15 = sub nsw i32 %14, 1
  %16 = call noundef ptr @_ZN4juce17MidiBufferHelpersL14findEventAfterEPhS1_i(ptr noundef %11, ptr noundef %13, i32 noundef %15) #4
  store ptr %16, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = getelementptr inbounds %"class.juce::MidiBuffer", ptr %9, i32 0, i32 0
  %19 = call noundef ptr @_ZNK4juce5ArrayIhNS_20DummyCriticalSectionELi0EE3endEv(ptr noundef nonnull align 8 dereferenceable(20) %18) #4
  %20 = load i32, ptr %5, align 4, !tbaa !9
  %21 = load i32, ptr %6, align 4, !tbaa !9
  %22 = add nsw i32 %20, %21
  %23 = sub nsw i32 %22, 1
  %24 = call noundef ptr @_ZN4juce17MidiBufferHelpersL14findEventAfterEPhS1_i(ptr noundef %17, ptr noundef %19, i32 noundef %23) #4
  store ptr %24, ptr %8, align 8, !tbaa !5
  %25 = getelementptr inbounds %"class.juce::MidiBuffer", ptr %9, i32 0, i32 0
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = getelementptr inbounds %"class.juce::MidiBuffer", ptr %9, i32 0, i32 0
  %28 = call noundef ptr @_ZNK4juce5ArrayIhNS_20DummyCriticalSectionELi0EE5beginEv(ptr noundef nonnull align 8 dereferenceable(20) %27) #4
  %29 = ptrtoint ptr %26 to i64
  %30 = ptrtoint ptr %28 to i64
  %31 = sub i64 %29, %30
  %32 = trunc i64 %31 to i32
  %33 = load ptr, ptr %8, align 8, !tbaa !5
  %34 = getelementptr inbounds %"class.juce::MidiBuffer", ptr %9, i32 0, i32 0
  %35 = call noundef ptr @_ZNK4juce5ArrayIhNS_20DummyCriticalSectionELi0EE5beginEv(ptr noundef nonnull align 8 dereferenceable(20) %34) #4
  %36 = ptrtoint ptr %33 to i64
  %37 = ptrtoint ptr %35 to i64
  %38 = sub i64 %36, %37
  %39 = trunc i64 %38 to i32
  call void @_ZN4juce5ArrayIhNS_20DummyCriticalSectionELi0EE11removeRangeEii(ptr noundef nonnull align 8 dereferenceable(20) %25, i32 noundef %32, i32 noundef %39)
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef ptr @_ZN4juce17MidiBufferHelpersL14findEventAfterEPhS1_i(ptr noundef, ptr noundef, i32 noundef) #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK4juce5ArrayIhNS_20DummyCriticalSectionELi0EE5beginEv(ptr noundef nonnull align 8 dereferenceable(20)) #3 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK4juce5ArrayIhNS_20DummyCriticalSectionELi0EE3endEv(ptr noundef nonnull align 8 dereferenceable(20)) #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4juce5ArrayIhNS_20DummyCriticalSectionELi0EE11removeRangeEii(ptr noundef nonnull align 8 dereferenceable(20), i32 noundef, i32 noundef) #1 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = { 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 #4 = { 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}


; 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 @_ZN4juce10MidiBuffer5clearEii(ptr noundef nonnull align 8 dereferenceable(24) %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 align 2 {
  %4 = tail call noundef ptr @_ZNK4juce5ArrayIhNS_20DummyCriticalSectionELi0EE5beginEv(ptr noundef nonnull align 8 dereferenceable(20) %0) #3
  %5 = tail call noundef ptr @_ZNK4juce5ArrayIhNS_20DummyCriticalSectionELi0EE3endEv(ptr noundef nonnull align 8 dereferenceable(20) %0) #3
  %6 = add i32 %1, -1
  %7 = tail call noundef ptr @_ZN4juce17MidiBufferHelpersL14findEventAfterEPhS1_i(ptr noundef %4, ptr noundef %5, i32 noundef %6) #3
  %8 = tail call noundef ptr @_ZNK4juce5ArrayIhNS_20DummyCriticalSectionELi0EE3endEv(ptr noundef nonnull align 8 dereferenceable(20) %0) #3
  %9 = add i32 %6, %2
  %10 = tail call noundef ptr @_ZN4juce17MidiBufferHelpersL14findEventAfterEPhS1_i(ptr noundef %7, ptr noundef %8, i32 noundef %9) #3
  %11 = tail call noundef ptr @_ZNK4juce5ArrayIhNS_20DummyCriticalSectionELi0EE5beginEv(ptr noundef nonnull align 8 dereferenceable(20) %0) #3
  %12 = ptrtoint ptr %7 to i64
  %13 = ptrtoint ptr %11 to i64
  %14 = sub i64 %12, %13
  %15 = trunc i64 %14 to i32
  %16 = tail call noundef ptr @_ZNK4juce5ArrayIhNS_20DummyCriticalSectionELi0EE5beginEv(ptr noundef nonnull align 8 dereferenceable(20) %0) #3
  %17 = ptrtoint ptr %10 to i64
  %18 = ptrtoint ptr %16 to i64
  %19 = sub i64 %17, %18
  %20 = trunc i64 %19 to i32
  tail call void @_ZN4juce5ArrayIhNS_20DummyCriticalSectionELi0EE11removeRangeEii(ptr noundef nonnull align 8 dereferenceable(20) %0, i32 noundef %15, i32 noundef %20)
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef ptr @_ZN4juce17MidiBufferHelpersL14findEventAfterEPhS1_i(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK4juce5ArrayIhNS_20DummyCriticalSectionELi0EE5beginEv(ptr noundef nonnull align 8 dereferenceable(20)) local_unnamed_addr #2 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK4juce5ArrayIhNS_20DummyCriticalSectionELi0EE3endEv(ptr noundef nonnull align 8 dereferenceable(20)) local_unnamed_addr #2 align 2

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

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 = { 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)"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,TailCallElimPass