; 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"

; 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 nounwind uwtable
define dso_local noundef i32 @_ZN4juce11MidiMessage21readVariableLengthValEPKhRi(ptr noundef %0, ptr noundef nonnull align 4 dereferenceable(4) %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %7 = load ptr, ptr %4, align 8, !tbaa !5
  store i32 0, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 0, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  br label %8

8:                                                ; preds = %24, %2
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %9, i32 1
  store ptr %10, ptr %3, align 8, !tbaa !5
  %11 = load i8, ptr %9, align 1, !tbaa !11
  %12 = zext i8 %11 to i32
  store i32 %12, ptr %6, align 4, !tbaa !9
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = load i32, ptr %13, align 4, !tbaa !9
  %15 = add nsw i32 %14, 1
  store i32 %15, ptr %13, align 4, !tbaa !9
  %16 = icmp sgt i32 %15, 6
  br i1 %16, label %17, label %18

17:                                               ; preds = %8
  br label %28

18:                                               ; preds = %8
  %19 = load i32, ptr %5, align 4, !tbaa !9
  %20 = shl i32 %19, 7
  %21 = load i32, ptr %6, align 4, !tbaa !9
  %22 = and i32 %21, 127
  %23 = add nsw i32 %20, %22
  store i32 %23, ptr %5, align 4, !tbaa !9
  br label %24

24:                                               ; preds = %18
  %25 = load i32, ptr %6, align 4, !tbaa !9
  %26 = and i32 %25, 128
  %27 = icmp ne i32 %26, 0
  br i1 %27, label %8, label %28, !llvm.loop !12

28:                                               ; preds = %24, %17
  %29 = load i32, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret i32 %29
}

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 = { 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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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 nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local noundef i32 @_ZN4juce11MidiMessage21readVariableLengthValEPKhRi(ptr nocapture noundef readonly %0, ptr nocapture noundef nonnull writeonly align 4 dereferenceable(4) %1) local_unnamed_addr #0 align 2 {
thread-pre-split:
  store i32 0, ptr %1, align 4, !tbaa !5
  %2 = load i8, ptr %0, align 1, !tbaa !9
  store i32 1, ptr %1, align 4, !tbaa !5
  %3 = and i8 %2, 127
  %4 = zext nneg i8 %3 to i32
  %.not = icmp sgt i8 %2, -1
  br i1 %.not, label %35, label %thread-pre-split.1, !llvm.loop !10

thread-pre-split.1:                               ; preds = %thread-pre-split
  %5 = getelementptr inbounds i8, ptr %0, i64 1
  %6 = load i8, ptr %5, align 1, !tbaa !9
  store i32 2, ptr %1, align 4, !tbaa !5
  %7 = shl nuw nsw i32 %4, 7
  %8 = and i8 %6, 127
  %9 = zext nneg i8 %8 to i32
  %10 = or disjoint i32 %7, %9
  %.not.1 = icmp sgt i8 %6, -1
  br i1 %.not.1, label %35, label %thread-pre-split.2, !llvm.loop !10

thread-pre-split.2:                               ; preds = %thread-pre-split.1
  %11 = getelementptr inbounds i8, ptr %0, i64 2
  %12 = load i8, ptr %11, align 1, !tbaa !9
  store i32 3, ptr %1, align 4, !tbaa !5
  %13 = shl nuw nsw i32 %10, 7
  %14 = and i8 %12, 127
  %15 = zext nneg i8 %14 to i32
  %16 = or disjoint i32 %13, %15
  %.not.2 = icmp sgt i8 %12, -1
  br i1 %.not.2, label %35, label %thread-pre-split.3, !llvm.loop !10

thread-pre-split.3:                               ; preds = %thread-pre-split.2
  %17 = getelementptr inbounds i8, ptr %0, i64 3
  %18 = load i8, ptr %17, align 1, !tbaa !9
  store i32 4, ptr %1, align 4, !tbaa !5
  %19 = shl nuw nsw i32 %16, 7
  %20 = and i8 %18, 127
  %21 = zext nneg i8 %20 to i32
  %22 = or disjoint i32 %19, %21
  %.not.3 = icmp sgt i8 %18, -1
  br i1 %.not.3, label %35, label %thread-pre-split.4, !llvm.loop !10

thread-pre-split.4:                               ; preds = %thread-pre-split.3
  %23 = getelementptr inbounds i8, ptr %0, i64 4
  %24 = load i8, ptr %23, align 1, !tbaa !9
  store i32 5, ptr %1, align 4, !tbaa !5
  %25 = shl i32 %22, 7
  %26 = and i8 %24, 127
  %27 = zext nneg i8 %26 to i32
  %28 = or disjoint i32 %25, %27
  %.not.4 = icmp sgt i8 %24, -1
  br i1 %.not.4, label %35, label %thread-pre-split.5, !llvm.loop !10

thread-pre-split.5:                               ; preds = %thread-pre-split.4
  %29 = getelementptr inbounds i8, ptr %0, i64 5
  %30 = load i8, ptr %29, align 1, !tbaa !9
  store i32 6, ptr %1, align 4, !tbaa !5
  %31 = shl i32 %28, 7
  %32 = and i8 %30, 127
  %33 = zext nneg i8 %32 to i32
  %34 = or disjoint i32 %31, %33
  %.not.5 = icmp sgt i8 %30, -1
  %spec.store.select = select i1 %.not.5, i32 6, i32 7
  store i32 %spec.store.select, ptr %1, align 4
  br label %35, !llvm.loop !10

35:                                               ; preds = %thread-pre-split.5, %thread-pre-split.4, %thread-pre-split.3, %thread-pre-split.2, %thread-pre-split.1, %thread-pre-split
  %.lcssa = phi i32 [ %4, %thread-pre-split ], [ %10, %thread-pre-split.1 ], [ %16, %thread-pre-split.2 ], [ %22, %thread-pre-split.3 ], [ %28, %thread-pre-split.4 ], [ %34, %thread-pre-split.5 ]
  ret i32 %.lcssa
}

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

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


; Effective O3 passes: GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass