; LLVM IR from software-mansion/react-native-audio-api :: packages/react-native-audio-api/common/cpp/audioapi/utils (AudioBus)

; 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
declare dso_local noundef i32 @_ZNK8audioapi8AudioBus19getNumberOfChannelsEv(ptr noundef nonnull align 8 dereferenceable(40)) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK8audioapi8AudioBus10getChannelEi(ptr noundef nonnull align 8 dereferenceable(40), i32 noundef) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN8audioapi8AudioBus4zeroEmm(ptr noundef nonnull align 8 dereferenceable(40), i64 noundef, i64 noundef) #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN8audioapi8AudioBus3sumEPKS0_mmmNS_21ChannelInterpretationE(ptr noundef nonnull align 8 dereferenceable(40), ptr noundef, i64 noundef, i64 noundef, i64 noundef, i32 noundef) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN8audioapi8AudioBus4copyEPKS0_mmm(ptr noundef nonnull align 8 dereferenceable(40) %0, ptr noundef %1, i64 noundef %2, i64 noundef %3, i64 noundef %4) #2 align 2 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i64 %2, ptr %8, align 8, !tbaa !9
  store i64 %3, ptr %9, align 8, !tbaa !9
  store i64 %4, ptr %10, align 8, !tbaa !9
  %12 = load ptr, ptr %6, align 8
  %13 = load ptr, ptr %7, align 8, !tbaa !5
  %14 = icmp eq ptr %13, %12
  br i1 %14, label %15, label %16

15:                                               ; preds = %5
  br label %47

16:                                               ; preds = %5
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = call noundef i32 @_ZNK8audioapi8AudioBus19getNumberOfChannelsEv(ptr noundef nonnull align 8 dereferenceable(40) %17)
  %19 = call noundef i32 @_ZNK8audioapi8AudioBus19getNumberOfChannelsEv(ptr noundef nonnull align 8 dereferenceable(40) %12)
  %20 = icmp eq i32 %18, %19
  br i1 %20, label %21, label %40

21:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  store i32 0, ptr %11, align 4, !tbaa !11
  br label %22

22:                                               ; preds = %36, %21
  %23 = load i32, ptr %11, align 4, !tbaa !11
  %24 = call noundef i32 @_ZNK8audioapi8AudioBus19getNumberOfChannelsEv(ptr noundef nonnull align 8 dereferenceable(40) %12)
  %25 = icmp slt i32 %23, %24
  br i1 %25, label %27, label %26

26:                                               ; preds = %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  br label %39

27:                                               ; preds = %22
  %28 = load i32, ptr %11, align 4, !tbaa !11
  %29 = call noundef ptr @_ZNK8audioapi8AudioBus10getChannelEi(ptr noundef nonnull align 8 dereferenceable(40) %12, i32 noundef %28)
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  %31 = load i32, ptr %11, align 4, !tbaa !11
  %32 = call noundef ptr @_ZNK8audioapi8AudioBus10getChannelEi(ptr noundef nonnull align 8 dereferenceable(40) %30, i32 noundef %31)
  %33 = load i64, ptr %8, align 8, !tbaa !9
  %34 = load i64, ptr %9, align 8, !tbaa !9
  %35 = load i64, ptr %10, align 8, !tbaa !9
  call void @_ZN8audioapi10AudioArray4copyEPKS0_mmm(ptr noundef nonnull align 8 dereferenceable(16) %29, ptr noundef %32, i64 noundef %33, i64 noundef %34, i64 noundef %35)
  br label %36

36:                                               ; preds = %27
  %37 = load i32, ptr %11, align 4, !tbaa !11
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr %11, align 4, !tbaa !11
  br label %22, !llvm.loop !13

39:                                               ; preds = %26
  br label %47

40:                                               ; preds = %16
  %41 = load i64, ptr %9, align 8, !tbaa !9
  %42 = load i64, ptr %10, align 8, !tbaa !9
  call void @_ZN8audioapi8AudioBus4zeroEmm(ptr noundef nonnull align 8 dereferenceable(40) %12, i64 noundef %41, i64 noundef %42)
  %43 = load ptr, ptr %7, align 8, !tbaa !5
  %44 = load i64, ptr %8, align 8, !tbaa !9
  %45 = load i64, ptr %9, align 8, !tbaa !9
  %46 = load i64, ptr %10, align 8, !tbaa !9
  call void @_ZN8audioapi8AudioBus3sumEPKS0_mmmNS_21ChannelInterpretationE(ptr noundef nonnull align 8 dereferenceable(40) %12, ptr noundef %43, i64 noundef %44, i64 noundef %45, i64 noundef %46, i32 noundef 0)
  br label %47

47:                                               ; preds = %40, %39, %15
  ret void
}

declare void @_ZN8audioapi10AudioArray4copyEPKS0_mmm(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef, i64 noundef, i64 noundef, i64 noundef) #3

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 = { 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 = { "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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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
declare dso_local noundef i32 @_ZNK8audioapi8AudioBus19getNumberOfChannelsEv(ptr noundef nonnull align 8 dereferenceable(40)) local_unnamed_addr #0 align 2

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN8audioapi8AudioBus4zeroEmm(ptr noundef nonnull align 8 dereferenceable(40), i64 noundef, i64 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN8audioapi8AudioBus3sumEPKS0_mmmNS_21ChannelInterpretationE(ptr noundef nonnull align 8 dereferenceable(40), ptr noundef, i64 noundef, i64 noundef, i64 noundef, i32 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN8audioapi8AudioBus4copyEPKS0_mmm(ptr noundef nonnull align 8 dereferenceable(40) %0, ptr noundef %1, i64 noundef %2, i64 noundef %3, i64 noundef %4) local_unnamed_addr #1 align 2 {
  %6 = icmp eq ptr %1, %0
  br i1 %6, label %.loopexit, label %7

7:                                                ; preds = %5
  %8 = tail call noundef i32 @_ZNK8audioapi8AudioBus19getNumberOfChannelsEv(ptr noundef nonnull align 8 dereferenceable(40) %1)
  %9 = tail call noundef i32 @_ZNK8audioapi8AudioBus19getNumberOfChannelsEv(ptr noundef nonnull align 8 dereferenceable(40) %0)
  %10 = icmp eq i32 %8, %9
  br i1 %10, label %.preheader, label %18

.preheader:                                       ; preds = %7
  %11 = tail call noundef i32 @_ZNK8audioapi8AudioBus19getNumberOfChannelsEv(ptr noundef nonnull align 8 dereferenceable(40) %0)
  %12 = icmp sgt i32 %11, 0
  br i1 %12, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.018 = phi i32 [ %15, %.lr.ph ], [ 0, %.preheader ]
  %13 = tail call noundef ptr @_ZNK8audioapi8AudioBus10getChannelEi(ptr noundef nonnull align 8 dereferenceable(40) %0, i32 noundef %.018)
  %14 = tail call noundef ptr @_ZNK8audioapi8AudioBus10getChannelEi(ptr noundef nonnull align 8 dereferenceable(40) %1, i32 noundef %.018)
  tail call void @_ZN8audioapi10AudioArray4copyEPKS0_mmm(ptr noundef nonnull align 8 dereferenceable(16) %13, ptr noundef %14, i64 noundef %2, i64 noundef %3, i64 noundef %4)
  %15 = add nuw nsw i32 %.018, 1
  %16 = tail call noundef i32 @_ZNK8audioapi8AudioBus19getNumberOfChannelsEv(ptr noundef nonnull align 8 dereferenceable(40) %0)
  %17 = icmp slt i32 %15, %16
  br i1 %17, label %.lr.ph, label %.loopexit, !llvm.loop !5

18:                                               ; preds = %7
  tail call void @_ZN8audioapi8AudioBus4zeroEmm(ptr noundef nonnull align 8 dereferenceable(40) %0, i64 noundef %3, i64 noundef %4)
  tail call void @_ZN8audioapi8AudioBus3sumEPKS0_mmmNS_21ChannelInterpretationE(ptr noundef nonnull align 8 dereferenceable(40) %0, ptr noundef nonnull %1, i64 noundef %2, i64 noundef %3, i64 noundef %4, i32 noundef 0)
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph, %.preheader, %5, %18
  ret void
}

declare void @_ZN8audioapi10AudioArray4copyEPKS0_mmm(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef, i64 noundef, i64 noundef, i64 noundef) local_unnamed_addr #2

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 = { 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 = { "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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


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