; LLVM IR from glaretechnologies/substrata :: resonance-audio/resonance_audio/base/audio_buffer.ll (ZN7vraudio11AudioBufferaSERKS0_)

; 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.vraudio::AudioBuffer" = type <{ i64, %"class.std::vector", i64, %"class.std::vector.0", i32, [4 x i8] }>
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<float, vraudio::AlignedAllocator<float, 64>>::_Vector_impl" }
%"struct.std::_Vector_base<float, vraudio::AlignedAllocator<float, 64>>::_Vector_impl" = type { %"struct.std::_Vector_base<float, vraudio::AlignedAllocator<float, 64>>::_Vector_impl_data" }
%"struct.std::_Vector_base<float, vraudio::AlignedAllocator<float, 64>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.std::vector.0" = type { %"struct.std::_Vector_base.1" }
%"struct.std::_Vector_base.1" = type { %"struct.std::_Vector_base<vraudio::ChannelView, std::allocator<vraudio::ChannelView>>::_Vector_impl" }
%"struct.std::_Vector_base<vraudio::ChannelView, std::allocator<vraudio::ChannelView>>::_Vector_impl" = type { %"struct.std::_Vector_base<vraudio::ChannelView, std::allocator<vraudio::ChannelView>>::_Vector_impl_data" }
%"struct.std::_Vector_base<vraudio::ChannelView, std::allocator<vraudio::ChannelView>>::_Vector_impl_data" = type { ptr, ptr, ptr }

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

; Function Attrs: mustprogress uwtable
define dso_local noundef nonnull align 8 dereferenceable(68) ptr @_ZN7vraudio11AudioBufferaSERKS0_(ptr noundef nonnull align 8 dereferenceable(68) %0, ptr noundef nonnull align 8 dereferenceable(68) %1) #0 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8
  %7 = load ptr, ptr %4, align 8, !tbaa !5
  %8 = icmp ne ptr %6, %7
  br i1 %8, label %9, label %38

9:                                                ; preds = %2
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %"class.vraudio::AudioBuffer", ptr %10, i32 0, i32 0
  %12 = load i64, ptr %11, align 8, !tbaa !9
  %13 = getelementptr inbounds %"class.vraudio::AudioBuffer", ptr %6, i32 0, i32 0
  store i64 %12, ptr %13, align 8, !tbaa !9
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %"class.vraudio::AudioBuffer", ptr %14, i32 0, i32 4
  %16 = load i32, ptr %15, align 8, !tbaa !21
  %17 = getelementptr inbounds %"class.vraudio::AudioBuffer", ptr %6, i32 0, i32 4
  store i32 %16, ptr %17, align 8, !tbaa !21
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = call noundef i64 @_ZNK7vraudio11AudioBuffer12num_channelsEv(ptr noundef nonnull align 8 dereferenceable(68) %18)
  call void @_ZN7vraudio11AudioBuffer16InitChannelViewsEm(ptr noundef nonnull align 8 dereferenceable(68) %6, i64 noundef %19)
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store i64 0, ptr %5, align 8, !tbaa !22
  br label %20

20:                                               ; preds = %34, %9
  %21 = load i64, ptr %5, align 8, !tbaa !22
  %22 = call noundef i64 @_ZNK7vraudio11AudioBuffer12num_channelsEv(ptr noundef nonnull align 8 dereferenceable(68) %6)
  %23 = icmp ult i64 %21, %22
  br i1 %23, label %25, label %24

24:                                               ; preds = %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  br label %37

25:                                               ; preds = %20
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %"class.vraudio::AudioBuffer", ptr %26, i32 0, i32 3
  %28 = load i64, ptr %5, align 8, !tbaa !22
  %29 = call noundef nonnull align 8 dereferenceable(17) ptr @_ZNKSt6vectorIN7vraudio11ChannelViewESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %27, i64 noundef %28) #3
  %30 = getelementptr inbounds %"class.vraudio::AudioBuffer", ptr %6, i32 0, i32 3
  %31 = load i64, ptr %5, align 8, !tbaa !22
  %32 = call noundef nonnull align 8 dereferenceable(17) ptr @_ZNSt6vectorIN7vraudio11ChannelViewESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %30, i64 noundef %31) #3
  %33 = call noundef nonnull align 8 dereferenceable(17) ptr @_ZN7vraudio11ChannelViewaSERKS0_(ptr noundef nonnull align 8 dereferenceable(17) %32, ptr noundef nonnull align 8 dereferenceable(17) %29)
  br label %34

34:                                               ; preds = %25
  %35 = load i64, ptr %5, align 8, !tbaa !22
  %36 = add i64 %35, 1
  store i64 %36, ptr %5, align 8, !tbaa !22
  br label %20, !llvm.loop !23

37:                                               ; preds = %24
  br label %38

38:                                               ; preds = %37, %2
  ret ptr %6
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNK7vraudio11AudioBuffer12num_channelsEv(ptr noundef nonnull align 8 dereferenceable(68)) #1 align 2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(17) ptr @_ZNKSt6vectorIN7vraudio11ChannelViewESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(17) ptr @_ZNSt6vectorIN7vraudio11ChannelViewESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(17) ptr @_ZN7vraudio11ChannelViewaSERKS0_(ptr noundef nonnull align 8 dereferenceable(17), ptr noundef nonnull align 8 dereferenceable(17)) #0 align 2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2

attributes #0 = { 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 #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !11, i64 0}
!10 = !{!"_ZTSN7vraudio11AudioBufferE", !11, i64 0, !12, i64 8, !11, i64 32, !16, i64 40, !20, i64 64}
!11 = !{!"long", !7, i64 0}
!12 = !{!"_ZTSSt6vectorIfN7vraudio16AlignedAllocatorIfLm64EEEE", !13, i64 0}
!13 = !{!"_ZTSSt12_Vector_baseIfN7vraudio16AlignedAllocatorIfLm64EEEE", !14, i64 0}
!14 = !{!"_ZTSNSt12_Vector_baseIfN7vraudio16AlignedAllocatorIfLm64EEEE12_Vector_implE", !15, i64 0}
!15 = !{!"_ZTSNSt12_Vector_baseIfN7vraudio16AlignedAllocatorIfLm64EEEE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!16 = !{!"_ZTSSt6vectorIN7vraudio11ChannelViewESaIS1_EE", !17, i64 0}
!17 = !{!"_ZTSSt12_Vector_baseIN7vraudio11ChannelViewESaIS1_EE", !18, i64 0}
!18 = !{!"_ZTSNSt12_Vector_baseIN7vraudio11ChannelViewESaIS1_EE12_Vector_implE", !19, i64 0}
!19 = !{!"_ZTSNSt12_Vector_baseIN7vraudio11ChannelViewESaIS1_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!20 = !{!"int", !7, i64 0}
!21 = !{!10, !20, i64 64}
!22 = !{!11, !11, i64 0}
!23 = distinct !{!23, !24}
!24 = !{!"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 uwtable
declare dso_local void @_ZN7vraudio11AudioBuffer16InitChannelViewsEm(ptr noundef nonnull align 8 dereferenceable(68), i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef nonnull align 8 dereferenceable(68) ptr @_ZN7vraudio11AudioBufferaSERKS0_(ptr noundef nonnull returned align 8 dereferenceable(68) %0, ptr noundef nonnull align 8 dereferenceable(68) %1) local_unnamed_addr #0 align 2 {
  %.not = icmp eq ptr %0, %1
  br i1 %.not, label %.loopexit, label %3

3:                                                ; preds = %2
  %4 = load i64, ptr %1, align 8, !tbaa !5
  store i64 %4, ptr %0, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %1, i64 64
  %6 = load i32, ptr %5, align 8, !tbaa !20
  %7 = getelementptr inbounds i8, ptr %0, i64 64
  store i32 %6, ptr %7, align 8, !tbaa !20
  %8 = tail call noundef i64 @_ZNK7vraudio11AudioBuffer12num_channelsEv(ptr noundef nonnull align 8 dereferenceable(68) %1)
  tail call void @_ZN7vraudio11AudioBuffer16InitChannelViewsEm(ptr noundef nonnull align 8 dereferenceable(68) %0, i64 noundef %8)
  %9 = tail call noundef i64 @_ZNK7vraudio11AudioBuffer12num_channelsEv(ptr noundef nonnull align 8 dereferenceable(68) %0)
  %.not12 = icmp eq i64 %9, 0
  br i1 %.not12, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %3
  %10 = getelementptr inbounds i8, ptr %1, i64 40
  %11 = getelementptr inbounds i8, ptr %0, i64 40
  br label %12

12:                                               ; preds = %.lr.ph, %12
  %.011 = phi i64 [ 0, %.lr.ph ], [ %16, %12 ]
  %13 = tail call noundef nonnull align 8 dereferenceable(17) ptr @_ZNKSt6vectorIN7vraudio11ChannelViewESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %10, i64 noundef %.011) #2
  %14 = tail call noundef nonnull align 8 dereferenceable(17) ptr @_ZNSt6vectorIN7vraudio11ChannelViewESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %11, i64 noundef %.011) #2
  %15 = tail call noundef nonnull align 8 dereferenceable(17) ptr @_ZN7vraudio11ChannelViewaSERKS0_(ptr noundef nonnull align 8 dereferenceable(17) %14, ptr noundef nonnull align 8 dereferenceable(17) %13)
  %16 = add nuw i64 %.011, 1
  %17 = tail call noundef i64 @_ZNK7vraudio11AudioBuffer12num_channelsEv(ptr noundef nonnull align 8 dereferenceable(68) %0)
  %18 = icmp ult i64 %16, %17
  br i1 %18, label %12, label %.loopexit, !llvm.loop !21

.loopexit:                                        ; preds = %12, %3, %2
  ret ptr %0
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNK7vraudio11AudioBuffer12num_channelsEv(ptr noundef nonnull align 8 dereferenceable(68)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(17) ptr @_ZNKSt6vectorIN7vraudio11ChannelViewESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(17) ptr @_ZNSt6vectorIN7vraudio11ChannelViewESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(17) ptr @_ZN7vraudio11ChannelViewaSERKS0_(ptr noundef nonnull align 8 dereferenceable(17), ptr noundef nonnull align 8 dereferenceable(17)) local_unnamed_addr #0 align 2

attributes #0 = { 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 #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, !7, i64 0}
!6 = !{!"_ZTSN7vraudio11AudioBufferE", !7, i64 0, !10, i64 8, !7, i64 32, !15, i64 40, !19, i64 64}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSSt6vectorIfN7vraudio16AlignedAllocatorIfLm64EEEE", !11, i64 0}
!11 = !{!"_ZTSSt12_Vector_baseIfN7vraudio16AlignedAllocatorIfLm64EEEE", !12, i64 0}
!12 = !{!"_ZTSNSt12_Vector_baseIfN7vraudio16AlignedAllocatorIfLm64EEEE12_Vector_implE", !13, i64 0}
!13 = !{!"_ZTSNSt12_Vector_baseIfN7vraudio16AlignedAllocatorIfLm64EEEE17_Vector_impl_dataE", !14, i64 0, !14, i64 8, !14, i64 16}
!14 = !{!"any pointer", !8, i64 0}
!15 = !{!"_ZTSSt6vectorIN7vraudio11ChannelViewESaIS1_EE", !16, i64 0}
!16 = !{!"_ZTSSt12_Vector_baseIN7vraudio11ChannelViewESaIS1_EE", !17, i64 0}
!17 = !{!"_ZTSNSt12_Vector_baseIN7vraudio11ChannelViewESaIS1_EE12_Vector_implE", !18, i64 0}
!18 = !{!"_ZTSNSt12_Vector_baseIN7vraudio11ChannelViewESaIS1_EE17_Vector_impl_dataE", !14, i64 0, !14, i64 8, !14, i64 16}
!19 = !{!"int", !8, i64 0}
!20 = !{!6, !19, i64 64}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}


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