; LLVM IR from kdrag0n/fxdsp :: external/oboe/src/flowgraph/resampler (MultiChannelResampler)

; 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.resampler::MultiChannelResampler" = type <{ ptr, %"class.std::vector", i32, i32, %"class.std::vector", %"class.std::vector", i32, i32, i32, [4 x i8], %"class.resampler::HyperbolicCosineWindow", i32, [4 x i8] }>
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<float, std::allocator<float>>::_Vector_impl" }
%"struct.std::_Vector_base<float, std::allocator<float>>::_Vector_impl" = type { %"struct.std::_Vector_base<float, std::allocator<float>>::_Vector_impl_data" }
%"struct.std::_Vector_base<float, std::allocator<float>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.resampler::HyperbolicCosineWindow" = type { double, double }

; 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 uwtable
define dso_local void @_ZN9resampler21MultiChannelResampler10writeFrameEPKf(ptr noundef nonnull align 8 dereferenceable(124) %0, ptr noundef %1) unnamed_addr #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %8 = load ptr, ptr %3, align 8
  %9 = getelementptr inbounds %"class.resampler::MultiChannelResampler", ptr %8, i32 0, i32 3
  %10 = load i32, ptr %9, align 4, !tbaa !9
  %11 = add nsw i32 %10, -1
  store i32 %11, ptr %9, align 4, !tbaa !9
  %12 = icmp slt i32 %11, 0
  br i1 %12, label %13, label %17

13:                                               ; preds = %2
  %14 = call noundef i32 @_ZNK9resampler21MultiChannelResampler10getNumTapsEv(ptr noundef nonnull align 8 dereferenceable(124) %8)
  %15 = sub nsw i32 %14, 1
  %16 = getelementptr inbounds %"class.resampler::MultiChannelResampler", ptr %8, i32 0, i32 3
  store i32 %15, ptr %16, align 4, !tbaa !9
  br label %17

17:                                               ; preds = %13, %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %18 = getelementptr inbounds %"class.resampler::MultiChannelResampler", ptr %8, i32 0, i32 4
  %19 = getelementptr inbounds %"class.resampler::MultiChannelResampler", ptr %8, i32 0, i32 3
  %20 = load i32, ptr %19, align 4, !tbaa !9
  %21 = call noundef i32 @_ZNK9resampler21MultiChannelResampler15getChannelCountEv(ptr noundef nonnull align 8 dereferenceable(124) %8)
  %22 = mul nsw i32 %20, %21
  %23 = sext i32 %22 to i64
  %24 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIfSaIfEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %18, i64 noundef %23) #3
  store ptr %24, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %25 = call noundef i32 @_ZNK9resampler21MultiChannelResampler10getNumTapsEv(ptr noundef nonnull align 8 dereferenceable(124) %8)
  %26 = call noundef i32 @_ZNK9resampler21MultiChannelResampler15getChannelCountEv(ptr noundef nonnull align 8 dereferenceable(124) %8)
  %27 = mul nsw i32 %25, %26
  store i32 %27, ptr %6, align 4, !tbaa !18
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !18
  br label %28

28:                                               ; preds = %49, %17
  %29 = load i32, ptr %7, align 4, !tbaa !18
  %30 = call noundef i32 @_ZNK9resampler21MultiChannelResampler15getChannelCountEv(ptr noundef nonnull align 8 dereferenceable(124) %8)
  %31 = icmp slt i32 %29, %30
  br i1 %31, label %33, label %32

32:                                               ; preds = %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %52

33:                                               ; preds = %28
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = load i32, ptr %7, align 4, !tbaa !18
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds float, ptr %34, i64 %36
  %38 = load float, ptr %37, align 4, !tbaa !19
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = load i32, ptr %7, align 4, !tbaa !18
  %41 = load i32, ptr %6, align 4, !tbaa !18
  %42 = add nsw i32 %40, %41
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds float, ptr %39, i64 %43
  store float %38, ptr %44, align 4, !tbaa !19
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = load i32, ptr %7, align 4, !tbaa !18
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds float, ptr %45, i64 %47
  store float %38, ptr %48, align 4, !tbaa !19
  br label %49

49:                                               ; preds = %33
  %50 = load i32, ptr %7, align 4, !tbaa !18
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %7, align 4, !tbaa !18
  br label %28, !llvm.loop !21

52:                                               ; preds = %32
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK9resampler21MultiChannelResampler10getNumTapsEv(ptr noundef nonnull align 8 dereferenceable(124)) #2 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK9resampler21MultiChannelResampler15getChannelCountEv(ptr noundef nonnull align 8 dereferenceable(124)) #2 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #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, !15, i64 36}
!10 = !{!"_ZTSN9resampler21MultiChannelResamplerE", !11, i64 8, !15, i64 32, !15, i64 36, !11, i64 40, !11, i64 64, !15, i64 88, !15, i64 92, !15, i64 96, !16, i64 104, !15, i64 120}
!11 = !{!"_ZTSSt6vectorIfSaIfEE", !12, i64 0}
!12 = !{!"_ZTSSt12_Vector_baseIfSaIfEE", !13, i64 0}
!13 = !{!"_ZTSNSt12_Vector_baseIfSaIfEE12_Vector_implE", !14, i64 0}
!14 = !{!"_ZTSNSt12_Vector_baseIfSaIfEE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!15 = !{!"int", !7, i64 0}
!16 = !{!"_ZTSN9resampler22HyperbolicCosineWindowE", !17, i64 0, !17, i64 8}
!17 = !{!"double", !7, i64 0}
!18 = !{!15, !15, i64 0}
!19 = !{!20, !20, i64 0}
!20 = !{!"float", !7, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"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
define dso_local void @_ZN9resampler21MultiChannelResampler10writeFrameEPKf(ptr noundef nonnull align 8 dereferenceable(124) %0, ptr nocapture noundef readonly %1) unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 36
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = add nsw i32 %4, -1
  store i32 %5, ptr %3, align 4, !tbaa !5
  %6 = icmp slt i32 %4, 1
  br i1 %6, label %7, label %10

7:                                                ; preds = %2
  %8 = tail call noundef i32 @_ZNK9resampler21MultiChannelResampler10getNumTapsEv(ptr noundef nonnull align 8 dereferenceable(124) %0)
  %9 = add nsw i32 %8, -1
  store i32 %9, ptr %3, align 4, !tbaa !5
  br label %10

10:                                               ; preds = %7, %2
  %11 = phi i32 [ %9, %7 ], [ %5, %2 ]
  %12 = getelementptr inbounds i8, ptr %0, i64 40
  %13 = tail call noundef i32 @_ZNK9resampler21MultiChannelResampler15getChannelCountEv(ptr noundef nonnull align 8 dereferenceable(124) %0)
  %14 = mul nsw i32 %13, %11
  %15 = sext i32 %14 to i64
  %16 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIfSaIfEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %12, i64 noundef %15) #1
  %17 = tail call noundef i32 @_ZNK9resampler21MultiChannelResampler10getNumTapsEv(ptr noundef nonnull align 8 dereferenceable(124) %0)
  %18 = tail call noundef i32 @_ZNK9resampler21MultiChannelResampler15getChannelCountEv(ptr noundef nonnull align 8 dereferenceable(124) %0)
  %19 = tail call noundef i32 @_ZNK9resampler21MultiChannelResampler15getChannelCountEv(ptr noundef nonnull align 8 dereferenceable(124) %0)
  %20 = icmp sgt i32 %19, 0
  br i1 %20, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %10
  %21 = mul nsw i32 %18, %17
  %22 = sext i32 %21 to i64
  %invariant.gep = getelementptr float, ptr %16, i64 %22
  br label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %10
  ret void

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %23 = getelementptr inbounds float, ptr %1, i64 %indvars.iv
  %24 = load float, ptr %23, align 4, !tbaa !17
  %gep = getelementptr float, ptr %invariant.gep, i64 %indvars.iv
  store float %24, ptr %gep, align 4, !tbaa !17
  %25 = getelementptr inbounds float, ptr %16, i64 %indvars.iv
  store float %24, ptr %25, align 4, !tbaa !17
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %26 = tail call noundef i32 @_ZNK9resampler21MultiChannelResampler15getChannelCountEv(ptr noundef nonnull align 8 dereferenceable(124) %0)
  %27 = sext i32 %26 to i64
  %28 = icmp slt i64 %indvars.iv.next, %27
  br i1 %28, label %.lr.ph, label %._crit_edge, !llvm.loop !19
}

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK9resampler21MultiChannelResampler15getChannelCountEv(ptr noundef nonnull align 8 dereferenceable(124)) local_unnamed_addr #0 align 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 = { 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, !14, i64 36}
!6 = !{!"_ZTSN9resampler21MultiChannelResamplerE", !7, i64 8, !14, i64 32, !14, i64 36, !7, i64 40, !7, i64 64, !14, i64 88, !14, i64 92, !14, i64 96, !15, i64 104, !14, i64 120}
!7 = !{!"_ZTSSt6vectorIfSaIfEE", !8, i64 0}
!8 = !{!"_ZTSSt12_Vector_baseIfSaIfEE", !9, i64 0}
!9 = !{!"_ZTSNSt12_Vector_baseIfSaIfEE12_Vector_implE", !10, i64 0}
!10 = !{!"_ZTSNSt12_Vector_baseIfSaIfEE17_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 = !{!"_ZTSN9resampler22HyperbolicCosineWindowE", !16, i64 0, !16, i64 8}
!16 = !{!"double", !12, i64 0}
!17 = !{!18, !18, i64 0}
!18 = !{!"float", !12, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


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