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

%"class.audioapi::AudioBus" = type { %"class.std::vector", i32, float, i64 }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<std::shared_ptr<audioapi::AudioArray>, std::allocator<std::shared_ptr<audioapi::AudioArray>>>::_Vector_impl" }
%"struct.std::_Vector_base<std::shared_ptr<audioapi::AudioArray>, std::allocator<std::shared_ptr<audioapi::AudioArray>>>::_Vector_impl" = type { %"struct.std::_Vector_base<std::shared_ptr<audioapi::AudioArray>, std::allocator<std::shared_ptr<audioapi::AudioArray>>>::_Vector_impl_data" }
%"struct.std::_Vector_base<std::shared_ptr<audioapi::AudioArray>, std::allocator<std::shared_ptr<audioapi::AudioArray>>>::_Vector_impl_data" = type { ptr, ptr, 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 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
define dso_local void @_ZN8audioapi8AudioBus3sumEPKS0_mmmNS_21ChannelInterpretationE(ptr noundef nonnull align 8 dereferenceable(40) %0, ptr noundef %1, i64 noundef %2, i64 noundef %3, i64 noundef %4, i32 noundef %5) #2 align 2 {
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store i64 %2, ptr %9, align 8, !tbaa !9
  store i64 %3, ptr %10, align 8, !tbaa !9
  store i64 %4, ptr %11, align 8, !tbaa !9
  store i32 %5, ptr %12, align 4, !tbaa !11
  %17 = load ptr, ptr %7, align 8
  %18 = load ptr, ptr %8, align 8, !tbaa !5
  %19 = icmp eq ptr %18, %17
  br i1 %19, label %20, label %21

20:                                               ; preds = %6
  br label %72

21:                                               ; preds = %6
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  %22 = load ptr, ptr %8, align 8, !tbaa !5
  %23 = call noundef i32 @_ZNK8audioapi8AudioBus19getNumberOfChannelsEv(ptr noundef nonnull align 8 dereferenceable(40) %22)
  store i32 %23, ptr %13, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  %24 = call noundef i32 @_ZNK8audioapi8AudioBus19getNumberOfChannelsEv(ptr noundef nonnull align 8 dereferenceable(40) %17)
  store i32 %24, ptr %14, align 4, !tbaa !13
  %25 = load i32, ptr %12, align 4, !tbaa !11
  %26 = icmp eq i32 %25, 1
  br i1 %26, label %27, label %32

27:                                               ; preds = %21
  %28 = load ptr, ptr %8, align 8, !tbaa !5
  %29 = load i64, ptr %9, align 8, !tbaa !9
  %30 = load i64, ptr %10, align 8, !tbaa !9
  %31 = load i64, ptr %11, align 8, !tbaa !9
  call void @_ZNK8audioapi8AudioBus11discreteSumEPKS0_mmm(ptr noundef nonnull align 8 dereferenceable(40) %17, ptr noundef %28, i64 noundef %29, i64 noundef %30, i64 noundef %31)
  store i32 1, ptr %15, align 4
  br label %70

32:                                               ; preds = %21
  %33 = load i32, ptr %13, align 4, !tbaa !13
  %34 = load i32, ptr %14, align 4, !tbaa !13
  %35 = icmp slt i32 %33, %34
  br i1 %35, label %36, label %41

36:                                               ; preds = %32
  %37 = load ptr, ptr %8, align 8, !tbaa !5
  %38 = load i64, ptr %9, align 8, !tbaa !9
  %39 = load i64, ptr %10, align 8, !tbaa !9
  %40 = load i64, ptr %11, align 8, !tbaa !9
  call void @_ZN8audioapi8AudioBus13sumByUpMixingEPKS0_mmm(ptr noundef nonnull align 8 dereferenceable(40) %17, ptr noundef %37, i64 noundef %38, i64 noundef %39, i64 noundef %40)
  store i32 1, ptr %15, align 4
  br label %70

41:                                               ; preds = %32
  %42 = load i32, ptr %13, align 4, !tbaa !13
  %43 = load i32, ptr %14, align 4, !tbaa !13
  %44 = icmp sgt i32 %42, %43
  br i1 %44, label %45, label %50

45:                                               ; preds = %41
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  %47 = load i64, ptr %9, align 8, !tbaa !9
  %48 = load i64, ptr %10, align 8, !tbaa !9
  %49 = load i64, ptr %11, align 8, !tbaa !9
  call void @_ZN8audioapi8AudioBus15sumByDownMixingEPKS0_mmm(ptr noundef nonnull align 8 dereferenceable(40) %17, ptr noundef %46, i64 noundef %47, i64 noundef %48, i64 noundef %49)
  store i32 1, ptr %15, align 4
  br label %70

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

51:                                               ; preds = %66, %50
  %52 = load i32, ptr %16, align 4, !tbaa !13
  %53 = getelementptr inbounds %"class.audioapi::AudioBus", ptr %17, i32 0, i32 1
  %54 = load i32, ptr %53, align 8, !tbaa !15
  %55 = icmp slt i32 %52, %54
  br i1 %55, label %57, label %56

56:                                               ; preds = %51
  store i32 2, ptr %15, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #4
  br label %69

57:                                               ; preds = %51
  %58 = load i32, ptr %16, align 4, !tbaa !13
  %59 = call noundef ptr @_ZNK8audioapi8AudioBus10getChannelEi(ptr noundef nonnull align 8 dereferenceable(40) %17, i32 noundef %58)
  %60 = load ptr, ptr %8, align 8, !tbaa !5
  %61 = load i32, ptr %16, align 4, !tbaa !13
  %62 = call noundef ptr @_ZNK8audioapi8AudioBus10getChannelEi(ptr noundef nonnull align 8 dereferenceable(40) %60, i32 noundef %61)
  %63 = load i64, ptr %9, align 8, !tbaa !9
  %64 = load i64, ptr %10, align 8, !tbaa !9
  %65 = load i64, ptr %11, align 8, !tbaa !9
  call void @_ZN8audioapi10AudioArray3sumEPKS0_mmm(ptr noundef nonnull align 8 dereferenceable(16) %59, ptr noundef %62, i64 noundef %63, i64 noundef %64, i64 noundef %65)
  br label %66

66:                                               ; preds = %57
  %67 = load i32, ptr %16, align 4, !tbaa !13
  %68 = add nsw i32 %67, 1
  store i32 %68, ptr %16, align 4, !tbaa !13
  br label %51, !llvm.loop !22

69:                                               ; preds = %56
  store i32 0, ptr %15, align 4
  br label %70

70:                                               ; preds = %69, %45, %36, %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  %71 = load i32, ptr %15, align 4
  switch i32 %71, label %73 [
    i32 0, label %72
    i32 1, label %72
  ]

72:                                               ; preds = %70, %70, %20
  ret void

73:                                               ; preds = %70
  unreachable
}

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

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

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

declare void @_ZN8audioapi10AudioArray3sumEPKS0_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 = !{!"_ZTSN8audioapi21ChannelInterpretationE", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!16, !14, i64 24}
!16 = !{!"_ZTSN8audioapi8AudioBusE", !17, i64 0, !14, i64 24, !21, i64 28, !10, i64 32}
!17 = !{!"_ZTSSt6vectorISt10shared_ptrIN8audioapi10AudioArrayEESaIS3_EE", !18, i64 0}
!18 = !{!"_ZTSSt12_Vector_baseISt10shared_ptrIN8audioapi10AudioArrayEESaIS3_EE", !19, i64 0}
!19 = !{!"_ZTSNSt12_Vector_baseISt10shared_ptrIN8audioapi10AudioArrayEESaIS3_EE12_Vector_implE", !20, i64 0}
!20 = !{!"_ZTSNSt12_Vector_baseISt10shared_ptrIN8audioapi10AudioArrayEESaIS3_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!21 = !{!"float", !7, i64 0}
!22 = distinct !{!22, !23}
!23 = !{!"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
define dso_local void @_ZN8audioapi8AudioBus3sumEPKS0_mmmNS_21ChannelInterpretationE(ptr noundef nonnull align 8 dereferenceable(40) %0, ptr noundef %1, i64 noundef %2, i64 noundef %3, i64 noundef %4, i32 noundef %5) local_unnamed_addr #1 align 2 {
  %7 = icmp eq ptr %1, %0
  br i1 %7, label %.loopexit, label %8

8:                                                ; preds = %6
  %9 = tail call noundef i32 @_ZNK8audioapi8AudioBus19getNumberOfChannelsEv(ptr noundef nonnull align 8 dereferenceable(40) %1)
  %10 = tail call noundef i32 @_ZNK8audioapi8AudioBus19getNumberOfChannelsEv(ptr noundef nonnull align 8 dereferenceable(40) %0)
  %11 = icmp eq i32 %5, 1
  br i1 %11, label %12, label %13

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

13:                                               ; preds = %8
  %14 = icmp slt i32 %9, %10
  br i1 %14, label %15, label %16

15:                                               ; preds = %13
  tail call void @_ZN8audioapi8AudioBus13sumByUpMixingEPKS0_mmm(ptr noundef nonnull align 8 dereferenceable(40) %0, ptr noundef nonnull %1, i64 noundef %2, i64 noundef %3, i64 noundef %4)
  br label %.loopexit

16:                                               ; preds = %13
  %17 = icmp sgt i32 %9, %10
  br i1 %17, label %21, label %.preheader

.preheader:                                       ; preds = %16
  %18 = getelementptr inbounds i8, ptr %0, i64 24
  %19 = load i32, ptr %18, align 8, !tbaa !5
  %20 = icmp sgt i32 %19, 0
  br i1 %20, label %.lr.ph, label %.loopexit

21:                                               ; preds = %16
  tail call void @_ZN8audioapi8AudioBus15sumByDownMixingEPKS0_mmm(ptr noundef nonnull align 8 dereferenceable(40) %0, ptr noundef nonnull %1, i64 noundef %2, i64 noundef %3, i64 noundef %4)
  br label %.loopexit

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.031 = phi i32 [ %24, %.lr.ph ], [ 0, %.preheader ]
  %22 = tail call noundef ptr @_ZNK8audioapi8AudioBus10getChannelEi(ptr noundef nonnull align 8 dereferenceable(40) %0, i32 noundef %.031)
  %23 = tail call noundef ptr @_ZNK8audioapi8AudioBus10getChannelEi(ptr noundef nonnull align 8 dereferenceable(40) %1, i32 noundef %.031)
  tail call void @_ZN8audioapi10AudioArray3sumEPKS0_mmm(ptr noundef nonnull align 8 dereferenceable(16) %22, ptr noundef %23, i64 noundef %2, i64 noundef %3, i64 noundef %4)
  %24 = add nuw nsw i32 %.031, 1
  %25 = load i32, ptr %18, align 8, !tbaa !5
  %26 = icmp slt i32 %24, %25
  br i1 %26, label %.lr.ph, label %.loopexit, !llvm.loop !17

.loopexit:                                        ; preds = %.lr.ph, %.preheader, %12, %15, %21, %6
  ret void
}

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

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

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

declare void @_ZN8audioapi10AudioArray3sumEPKS0_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 = !{!6, !14, i64 24}
!6 = !{!"_ZTSN8audioapi8AudioBusE", !7, i64 0, !14, i64 24, !15, i64 28, !16, i64 32}
!7 = !{!"_ZTSSt6vectorISt10shared_ptrIN8audioapi10AudioArrayEESaIS3_EE", !8, i64 0}
!8 = !{!"_ZTSSt12_Vector_baseISt10shared_ptrIN8audioapi10AudioArrayEESaIS3_EE", !9, i64 0}
!9 = !{!"_ZTSNSt12_Vector_baseISt10shared_ptrIN8audioapi10AudioArrayEESaIS3_EE12_Vector_implE", !10, i64 0}
!10 = !{!"_ZTSNSt12_Vector_baseISt10shared_ptrIN8audioapi10AudioArrayEESaIS3_EE17_Vector_impl_dataE", !11, i64 0, !11, i64 8, !11, i64 16}
!11 = !{!"any pointer", !12, i64 0}
!12 = !{!"omnipotent char", !13, i64 0}
!13 = !{!"Simple C++ TBAA"}
!14 = !{!"int", !12, i64 0}
!15 = !{!"float", !12, i64 0}
!16 = !{!"long", !12, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


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