; 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::MidiFile" = type <{ %"class.juce::OwnedArray.30", i16, [6 x i8] }>
%"class.juce::OwnedArray.30" = type { %"class.juce::ArrayAllocationBase.31", i32, [4 x i8] }
%"class.juce::ArrayAllocationBase.31" = type <{ %"class.juce::HeapBlock.32", i32, [4 x i8] }>
%"class.juce::HeapBlock.32" = type { ptr }

@.str.82 = external hidden unnamed_addr constant [5 x i8], align 1

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN4juce8MidiFile7writeToERNS_12OutputStreamEi(ptr noundef nonnull align 8 dereferenceable(26) %0, ptr noundef nonnull align 8 dereferenceable(16) %1, i32 noundef %2) #2 align 2 {
  %4 = alloca i1, align 1
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  %10 = load ptr, ptr %5, align 8
  br label %11

11:                                               ; preds = %3
  br label %12

12:                                               ; preds = %11
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = call noundef i32 @_ZN4juce9ByteOrder12bigEndianIntEPKv(ptr noundef @.str.82) #3
  %15 = load ptr, ptr %13, align 8, !tbaa !11
  %16 = getelementptr inbounds ptr, ptr %15, i64 11
  %17 = load ptr, ptr %16, align 8
  %18 = call noundef zeroext i1 %17(ptr noundef nonnull align 8 dereferenceable(16) %13, i32 noundef %14)
  br i1 %18, label %20, label %19

19:                                               ; preds = %12
  store i1 false, ptr %4, align 1
  br label %78

20:                                               ; preds = %12
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = load ptr, ptr %21, align 8, !tbaa !11
  %23 = getelementptr inbounds ptr, ptr %22, i64 11
  %24 = load ptr, ptr %23, align 8
  %25 = call noundef zeroext i1 %24(ptr noundef nonnull align 8 dereferenceable(16) %21, i32 noundef 6)
  br i1 %25, label %27, label %26

26:                                               ; preds = %20
  store i1 false, ptr %4, align 1
  br label %78

27:                                               ; preds = %20
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = load i32, ptr %7, align 4, !tbaa !9
  %30 = trunc i32 %29 to i16
  %31 = load ptr, ptr %28, align 8, !tbaa !11
  %32 = getelementptr inbounds ptr, ptr %31, i64 9
  %33 = load ptr, ptr %32, align 8
  %34 = call noundef zeroext i1 %33(ptr noundef nonnull align 8 dereferenceable(16) %28, i16 noundef signext %30)
  br i1 %34, label %36, label %35

35:                                               ; preds = %27
  store i1 false, ptr %4, align 1
  br label %78

36:                                               ; preds = %27
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = getelementptr inbounds %"class.juce::MidiFile", ptr %10, i32 0, i32 0
  %39 = call noundef i32 @_ZNK4juce10OwnedArrayINS_19MidiMessageSequenceENS_20DummyCriticalSectionEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(20) %38) #3
  %40 = trunc i32 %39 to i16
  %41 = load ptr, ptr %37, align 8, !tbaa !11
  %42 = getelementptr inbounds ptr, ptr %41, i64 9
  %43 = load ptr, ptr %42, align 8
  %44 = call noundef zeroext i1 %43(ptr noundef nonnull align 8 dereferenceable(16) %37, i16 noundef signext %40)
  br i1 %44, label %46, label %45

45:                                               ; preds = %36
  store i1 false, ptr %4, align 1
  br label %78

46:                                               ; preds = %36
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = getelementptr inbounds %"class.juce::MidiFile", ptr %10, i32 0, i32 1
  %49 = load i16, ptr %48, align 8, !tbaa !13
  %50 = load ptr, ptr %47, align 8, !tbaa !11
  %51 = getelementptr inbounds ptr, ptr %50, i64 9
  %52 = load ptr, ptr %51, align 8
  %53 = call noundef zeroext i1 %52(ptr noundef nonnull align 8 dereferenceable(16) %47, i16 noundef signext %49)
  br i1 %53, label %55, label %54

54:                                               ; preds = %46
  store i1 false, ptr %4, align 1
  br label %78

55:                                               ; preds = %46
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %56

56:                                               ; preds = %68, %55
  %57 = load i32, ptr %8, align 4, !tbaa !9
  %58 = getelementptr inbounds %"class.juce::MidiFile", ptr %10, i32 0, i32 0
  %59 = call noundef i32 @_ZNK4juce10OwnedArrayINS_19MidiMessageSequenceENS_20DummyCriticalSectionEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(20) %58) #3
  %60 = icmp slt i32 %57, %59
  br i1 %60, label %62, label %61

61:                                               ; preds = %56
  store i32 4, ptr %9, align 4
  br label %71

62:                                               ; preds = %56
  %63 = load ptr, ptr %6, align 8, !tbaa !5
  %64 = load i32, ptr %8, align 4, !tbaa !9
  %65 = call noundef zeroext i1 @_ZN4juce8MidiFile10writeTrackERNS_12OutputStreamEi(ptr noundef nonnull align 8 dereferenceable(26) %10, ptr noundef nonnull align 8 dereferenceable(16) %63, i32 noundef %64)
  br i1 %65, label %67, label %66

66:                                               ; preds = %62
  store i1 false, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %71

67:                                               ; preds = %62
  br label %68

68:                                               ; preds = %67
  %69 = load i32, ptr %8, align 4, !tbaa !9
  %70 = add nsw i32 %69, 1
  store i32 %70, ptr %8, align 4, !tbaa !9
  br label %56, !llvm.loop !19

71:                                               ; preds = %66, %61
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %72 = load i32, ptr %9, align 4
  switch i32 %72, label %80 [
    i32 4, label %73
    i32 1, label %78
  ]

73:                                               ; preds = %71
  %74 = load ptr, ptr %6, align 8, !tbaa !5
  %75 = load ptr, ptr %74, align 8, !tbaa !11
  %76 = getelementptr inbounds ptr, ptr %75, i64 2
  %77 = load ptr, ptr %76, align 8
  call void %77(ptr noundef nonnull align 8 dereferenceable(16) %74)
  store i1 true, ptr %4, align 1
  br label %78

78:                                               ; preds = %73, %71, %54, %45, %35, %26, %19
  %79 = load i1, ptr %4, align 1
  ret i1 %79

80:                                               ; preds = %71
  unreachable
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN4juce8MidiFile10writeTrackERNS_12OutputStreamEi(ptr noundef nonnull align 8 dereferenceable(26), ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) #2 align 2

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 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, !12, i64 0}
!12 = !{!"vtable pointer", !8, i64 0}
!13 = !{!14, !18, i64 24}
!14 = !{!"_ZTSN4juce8MidiFileE", !15, i64 0, !18, i64 24}
!15 = !{!"_ZTSN4juce10OwnedArrayINS_19MidiMessageSequenceENS_20DummyCriticalSectionEEE", !16, i64 0, !10, i64 16}
!16 = !{!"_ZTSN4juce19ArrayAllocationBaseIPNS_19MidiMessageSequenceENS_20DummyCriticalSectionEEE", !17, i64 0, !10, i64 8}
!17 = !{!"_ZTSN4juce9HeapBlockIPNS_19MidiMessageSequenceELb0EEE", !6, i64 0}
!18 = !{!"short", !7, i64 0}
!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"

@.str.82 = external hidden unnamed_addr constant [5 x i8], align 1

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN4juce9ByteOrder12bigEndianIntEPKv(ptr noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN4juce8MidiFile7writeToERNS_12OutputStreamEi(ptr noundef nonnull align 8 dereferenceable(26) %0, ptr noundef nonnull align 8 dereferenceable(16) %1, i32 noundef %2) local_unnamed_addr #1 align 2 {
  %4 = tail call noundef i32 @_ZN4juce9ByteOrder12bigEndianIntEPKv(ptr noundef nonnull @.str.82) #2
  %5 = load ptr, ptr %1, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %5, i64 88
  %7 = load ptr, ptr %6, align 8
  %8 = tail call noundef zeroext i1 %7(ptr noundef nonnull align 8 dereferenceable(16) %1, i32 noundef %4)
  br i1 %8, label %9, label %.loopexit

9:                                                ; preds = %3
  %10 = load ptr, ptr %1, align 8, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %10, i64 88
  %12 = load ptr, ptr %11, align 8
  %13 = tail call noundef zeroext i1 %12(ptr noundef nonnull align 8 dereferenceable(16) %1, i32 noundef 6)
  br i1 %13, label %14, label %.loopexit

14:                                               ; preds = %9
  %15 = trunc i32 %2 to i16
  %16 = load ptr, ptr %1, align 8, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %16, i64 72
  %18 = load ptr, ptr %17, align 8
  %19 = tail call noundef zeroext i1 %18(ptr noundef nonnull align 8 dereferenceable(16) %1, i16 noundef signext %15)
  br i1 %19, label %20, label %.loopexit

20:                                               ; preds = %14
  %21 = tail call noundef i32 @_ZNK4juce10OwnedArrayINS_19MidiMessageSequenceENS_20DummyCriticalSectionEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(20) %0) #2
  %22 = trunc i32 %21 to i16
  %23 = load ptr, ptr %1, align 8, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %23, i64 72
  %25 = load ptr, ptr %24, align 8
  %26 = tail call noundef zeroext i1 %25(ptr noundef nonnull align 8 dereferenceable(16) %1, i16 noundef signext %22)
  br i1 %26, label %27, label %.loopexit

27:                                               ; preds = %20
  %28 = getelementptr inbounds i8, ptr %0, i64 24
  %29 = load i16, ptr %28, align 8, !tbaa !8
  %30 = load ptr, ptr %1, align 8, !tbaa !5
  %31 = getelementptr inbounds i8, ptr %30, i64 72
  %32 = load ptr, ptr %31, align 8
  %33 = tail call noundef zeroext i1 %32(ptr noundef nonnull align 8 dereferenceable(16) %1, i16 noundef signext %29)
  br i1 %33, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %27
  %34 = tail call noundef i32 @_ZNK4juce10OwnedArrayINS_19MidiMessageSequenceENS_20DummyCriticalSectionEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(20) %0) #2
  %35 = icmp sgt i32 %34, 0
  br i1 %35, label %.lr.ph, label %._crit_edge

36:                                               ; preds = %.lr.ph
  %37 = add nuw nsw i32 %.01318, 1
  %38 = tail call noundef i32 @_ZNK4juce10OwnedArrayINS_19MidiMessageSequenceENS_20DummyCriticalSectionEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(20) %0) #2
  %39 = icmp slt i32 %37, %38
  br i1 %39, label %.lr.ph, label %._crit_edge, !llvm.loop !17

.lr.ph:                                           ; preds = %.preheader, %36
  %.01318 = phi i32 [ %37, %36 ], [ 0, %.preheader ]
  %40 = tail call noundef zeroext i1 @_ZN4juce8MidiFile10writeTrackERNS_12OutputStreamEi(ptr noundef nonnull align 8 dereferenceable(26) %0, ptr noundef nonnull align 8 dereferenceable(16) %1, i32 noundef %.01318)
  br i1 %40, label %36, label %.loopexit

._crit_edge:                                      ; preds = %36, %.preheader
  %41 = load ptr, ptr %1, align 8, !tbaa !5
  %42 = getelementptr inbounds i8, ptr %41, i64 16
  %43 = load ptr, ptr %42, align 8
  tail call void %43(ptr noundef nonnull align 8 dereferenceable(16) %1)
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph, %27, %20, %14, %9, %3, %._crit_edge
  %.1 = phi i1 [ true, %._crit_edge ], [ false, %3 ], [ false, %9 ], [ false, %14 ], [ false, %20 ], [ false, %27 ], [ false, %.lr.ph ]
  ret i1 %.1
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN4juce8MidiFile10writeTrackERNS_12OutputStreamEi(ptr noundef nonnull align 8 dereferenceable(26), ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) local_unnamed_addr #1 align 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 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, !6, i64 0}
!6 = !{!"vtable pointer", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !16, i64 24}
!9 = !{!"_ZTSN4juce8MidiFileE", !10, i64 0, !16, i64 24}
!10 = !{!"_ZTSN4juce10OwnedArrayINS_19MidiMessageSequenceENS_20DummyCriticalSectionEEE", !11, i64 0, !15, i64 16}
!11 = !{!"_ZTSN4juce19ArrayAllocationBaseIPNS_19MidiMessageSequenceENS_20DummyCriticalSectionEEE", !12, i64 0, !15, i64 8}
!12 = !{!"_ZTSN4juce9HeapBlockIPNS_19MidiMessageSequenceELb0EEE", !13, i64 0}
!13 = !{!"any pointer", !14, i64 0}
!14 = !{!"omnipotent char", !7, i64 0}
!15 = !{!"int", !14, i64 0}
!16 = !{!"short", !14, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


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