; 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::MidiBuffer::Iterator" = type { ptr, ptr }
%"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: mustprogress nounwind uwtable
define dso_local void @_ZN4juce10MidiBuffer8Iterator21setNextSamplePositionEi(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %6 = load ptr, ptr %3, align 8
  %7 = getelementptr inbounds %"class.juce::MidiBuffer::Iterator", ptr %6, i32 0, i32 0
  %8 = load ptr, ptr %7, align 8, !tbaa !11
  %9 = getelementptr inbounds %"class.juce::MidiBuffer", ptr %8, i32 0, i32 0
  %10 = call noundef ptr @_ZNK4juce5ArrayIhNS_20DummyCriticalSectionELi0EE5beginEv(ptr noundef nonnull align 8 dereferenceable(20) %9) #3
  %11 = getelementptr inbounds %"class.juce::MidiBuffer::Iterator", ptr %6, i32 0, i32 1
  store ptr %10, ptr %11, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %12 = getelementptr inbounds %"class.juce::MidiBuffer::Iterator", ptr %6, i32 0, i32 0
  %13 = load ptr, ptr %12, align 8, !tbaa !11
  %14 = getelementptr inbounds %"class.juce::MidiBuffer", ptr %13, i32 0, i32 0
  %15 = call noundef ptr @_ZNK4juce5ArrayIhNS_20DummyCriticalSectionELi0EE3endEv(ptr noundef nonnull align 8 dereferenceable(20) %14) #3
  store ptr %15, ptr %5, align 8, !tbaa !5
  br label %16

16:                                               ; preds = %29, %2
  %17 = getelementptr inbounds %"class.juce::MidiBuffer::Iterator", ptr %6, i32 0, i32 1
  %18 = load ptr, ptr %17, align 8, !tbaa !13
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = icmp ult ptr %18, %19
  br i1 %20, label %21, label %27

21:                                               ; preds = %16
  %22 = getelementptr inbounds %"class.juce::MidiBuffer::Iterator", ptr %6, i32 0, i32 1
  %23 = load ptr, ptr %22, align 8, !tbaa !13
  %24 = call noundef i32 @_ZN4juce17MidiBufferHelpers12getEventTimeEPKv(ptr noundef %23) #3
  %25 = load i32, ptr %4, align 4, !tbaa !9
  %26 = icmp slt i32 %24, %25
  br label %27

27:                                               ; preds = %21, %16
  %28 = phi i1 [ false, %16 ], [ %26, %21 ]
  br i1 %28, label %29, label %38

29:                                               ; preds = %27
  %30 = getelementptr inbounds %"class.juce::MidiBuffer::Iterator", ptr %6, i32 0, i32 1
  %31 = load ptr, ptr %30, align 8, !tbaa !13
  %32 = call noundef zeroext i16 @_ZN4juce17MidiBufferHelpers17getEventTotalSizeEPKv(ptr noundef %31) #3
  %33 = zext i16 %32 to i32
  %34 = getelementptr inbounds %"class.juce::MidiBuffer::Iterator", ptr %6, i32 0, i32 1
  %35 = load ptr, ptr %34, align 8, !tbaa !13
  %36 = sext i32 %33 to i64
  %37 = getelementptr inbounds i8, ptr %35, i64 %36
  store ptr %37, ptr %34, align 8, !tbaa !13
  br label %16, !llvm.loop !14

38:                                               ; preds = %27
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret void
}

; 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 ptr @_ZNK4juce5ArrayIhNS_20DummyCriticalSectionELi0EE5beginEv(ptr noundef nonnull align 8 dereferenceable(20)) #2 align 2

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i16 @_ZN4juce17MidiBufferHelpers17getEventTotalSizeEPKv(ptr noundef) #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN4juce17MidiBufferHelpers12getEventTimeEPKv(ptr noundef) #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 = { 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)"}
!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, !6, i64 0}
!12 = !{!"_ZTSN4juce10MidiBuffer8IteratorE", !6, i64 0, !6, i64 8}
!13 = !{!12, !6, i64 8}
!14 = distinct !{!14, !15}
!15 = !{!"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
define dso_local void @_ZN4juce10MidiBuffer8Iterator21setNextSamplePositionEi(ptr nocapture noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %1) local_unnamed_addr #0 align 2 {
  %3 = load ptr, ptr %0, align 8, !tbaa !5
  %4 = tail call noundef ptr @_ZNK4juce5ArrayIhNS_20DummyCriticalSectionELi0EE5beginEv(ptr noundef nonnull align 8 dereferenceable(20) %3) #2
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %4, ptr %5, align 8, !tbaa !10
  %6 = load ptr, ptr %0, align 8, !tbaa !5
  %7 = tail call noundef ptr @_ZNK4juce5ArrayIhNS_20DummyCriticalSectionELi0EE3endEv(ptr noundef nonnull align 8 dereferenceable(20) %6) #2
  %8 = load ptr, ptr %5, align 8, !tbaa !10
  %9 = icmp ult ptr %8, %7
  br i1 %9, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %2, %13
  %10 = phi ptr [ %18, %13 ], [ %8, %2 ]
  %11 = tail call noundef i32 @_ZN4juce17MidiBufferHelpers12getEventTimeEPKv(ptr noundef %10) #2
  %12 = icmp slt i32 %11, %1
  br i1 %12, label %13, label %.critedge

13:                                               ; preds = %.lr.ph
  %14 = load ptr, ptr %5, align 8, !tbaa !10
  %15 = tail call noundef zeroext i16 @_ZN4juce17MidiBufferHelpers17getEventTotalSizeEPKv(ptr noundef %14) #2
  %16 = load ptr, ptr %5, align 8, !tbaa !10
  %17 = zext i16 %15 to i64
  %18 = getelementptr inbounds i8, ptr %16, i64 %17
  store ptr %18, ptr %5, align 8, !tbaa !10
  %19 = icmp ult ptr %18, %7
  br i1 %19, label %.lr.ph, label %.critedge, !llvm.loop !11

.critedge:                                        ; preds = %.lr.ph, %13, %2
  ret void
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i16 @_ZN4juce17MidiBufferHelpers17getEventTotalSizeEPKv(ptr noundef) local_unnamed_addr #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN4juce17MidiBufferHelpers12getEventTimeEPKv(ptr noundef) local_unnamed_addr #1

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 = { 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 = { 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, !7, i64 0}
!6 = !{!"_ZTSN4juce10MidiBuffer8IteratorE", !7, i64 0, !7, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!6, !7, i64 8}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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