; LLVM IR from glaretechnologies/substrata :: resonance-audio/resonance_audio/utils (buffer_crossfader)

; 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.NullLogger = type { i8 }
%"class.vraudio::BufferCrossfader" = type { %"class.vraudio::AudioBuffer" }
%"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
define dso_local void @_ZN7vraudio16BufferCrossfaderC2Em(ptr noundef nonnull align 8 dereferenceable(72) %0, i64 noundef %1) unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca %class.NullLogger, align 1
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca float, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  %12 = load ptr, ptr %3, align 8
  %13 = getelementptr inbounds %"class.vraudio::BufferCrossfader", ptr %12, i32 0, i32 0
  %14 = load i64, ptr %4, align 8, !tbaa !9
  call void @_ZN7vraudio11AudioBufferC1Emm(ptr noundef nonnull align 8 dereferenceable(68) %13, i64 noundef 2, i64 noundef %14)
  call void @llvm.lifetime.start.p0(i64 1, ptr %5) #4
  %15 = invoke noundef nonnull align 8 dereferenceable(8) ptr @_ZN10NullLogger9GetStreamEv(ptr noundef nonnull align 1 dereferenceable(1) %5)
          to label %16 unwind label %28

16:                                               ; preds = %2
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %17 = getelementptr inbounds %"class.vraudio::BufferCrossfader", ptr %12, i32 0, i32 0
  %18 = invoke noundef nonnull align 8 dereferenceable(17) ptr @_ZN7vraudio11AudioBufferixEm(ptr noundef nonnull align 8 dereferenceable(68) %17, i64 noundef 0)
          to label %19 unwind label %32

19:                                               ; preds = %16
  store ptr %18, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %20 = getelementptr inbounds %"class.vraudio::BufferCrossfader", ptr %12, i32 0, i32 0
  %21 = invoke noundef nonnull align 8 dereferenceable(17) ptr @_ZN7vraudio11AudioBufferixEm(ptr noundef nonnull align 8 dereferenceable(68) %20, i64 noundef 1)
          to label %22 unwind label %36

22:                                               ; preds = %19
  store ptr %21, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  store i64 0, ptr %10, align 8, !tbaa !9
  br label %23

23:                                               ; preds = %57, %22
  %24 = load i64, ptr %10, align 8, !tbaa !9
  %25 = load i64, ptr %4, align 8, !tbaa !9
  %26 = icmp ult i64 %24, %25
  br i1 %26, label %40, label %27

27:                                               ; preds = %23
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br label %64

28:                                               ; preds = %2
  %29 = landingpad { ptr, i32 }
          cleanup
  %30 = extractvalue { ptr, i32 } %29, 0
  store ptr %30, ptr %6, align 8
  %31 = extractvalue { ptr, i32 } %29, 1
  store i32 %31, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #4
  br label %67

32:                                               ; preds = %16
  %33 = landingpad { ptr, i32 }
          cleanup
  %34 = extractvalue { ptr, i32 } %33, 0
  store ptr %34, ptr %6, align 8
  %35 = extractvalue { ptr, i32 } %33, 1
  store i32 %35, ptr %7, align 4
  br label %66

36:                                               ; preds = %19
  %37 = landingpad { ptr, i32 }
          cleanup
  %38 = extractvalue { ptr, i32 } %37, 0
  store ptr %38, ptr %6, align 8
  %39 = extractvalue { ptr, i32 } %37, 1
  store i32 %39, ptr %7, align 4
  br label %65

40:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %41 = load i64, ptr %10, align 8, !tbaa !9
  %42 = uitofp i64 %41 to float
  %43 = load i64, ptr %4, align 8, !tbaa !9
  %44 = uitofp i64 %43 to float
  %45 = fdiv float %42, %44
  store float %45, ptr %11, align 4, !tbaa !11
  %46 = load float, ptr %11, align 4, !tbaa !11
  %47 = load ptr, ptr %8, align 8, !tbaa !5
  %48 = load i64, ptr %10, align 8, !tbaa !9
  %49 = invoke noundef nonnull align 4 dereferenceable(4) ptr @_ZN7vraudio11ChannelViewixEm(ptr noundef nonnull align 8 dereferenceable(17) %47, i64 noundef %48)
          to label %50 unwind label %60

50:                                               ; preds = %40
  store float %46, ptr %49, align 4, !tbaa !11
  %51 = load float, ptr %11, align 4, !tbaa !11
  %52 = fsub float 1.000000e+00, %51
  %53 = load ptr, ptr %9, align 8, !tbaa !5
  %54 = load i64, ptr %10, align 8, !tbaa !9
  %55 = invoke noundef nonnull align 4 dereferenceable(4) ptr @_ZN7vraudio11ChannelViewixEm(ptr noundef nonnull align 8 dereferenceable(17) %53, i64 noundef %54)
          to label %56 unwind label %60

56:                                               ; preds = %50
  store float %52, ptr %55, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  br label %57

57:                                               ; preds = %56
  %58 = load i64, ptr %10, align 8, !tbaa !9
  %59 = add i64 %58, 1
  store i64 %59, ptr %10, align 8, !tbaa !9
  br label %23, !llvm.loop !13

60:                                               ; preds = %50, %40
  %61 = landingpad { ptr, i32 }
          cleanup
  %62 = extractvalue { ptr, i32 } %61, 0
  store ptr %62, ptr %6, align 8
  %63 = extractvalue { ptr, i32 } %61, 1
  store i32 %63, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br label %65

64:                                               ; preds = %27
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  ret void

65:                                               ; preds = %60, %36
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  br label %66

66:                                               ; preds = %65, %32
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %67

67:                                               ; preds = %66, %28
  call void @_ZN7vraudio11AudioBufferD2Ev(ptr noundef nonnull align 8 dereferenceable(68) %13) #4
  br label %68

68:                                               ; preds = %67
  %69 = load ptr, ptr %6, align 8
  %70 = load i32, ptr %7, align 4
  %71 = insertvalue { ptr, i32 } poison, ptr %69, 0
  %72 = insertvalue { ptr, i32 } %71, i32 %70, 1
  resume { ptr, i32 } %72
}

declare void @_ZN7vraudio11AudioBufferC1Emm(ptr noundef nonnull align 8 dereferenceable(68), i64 noundef, i64 noundef) unnamed_addr #1

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

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

declare i32 @__gxx_personality_v0(...)

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

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN7vraudio11AudioBufferD2Ev(ptr noundef nonnull align 8 dereferenceable(68)) unnamed_addr #3 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 = { "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 = { inlinehint 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 #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 = !{!"float", !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"

%class.NullLogger = type { i8 }

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7vraudio16BufferCrossfaderC2Em(ptr noundef nonnull align 8 dereferenceable(72) %0, i64 noundef %1) unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca %class.NullLogger, align 1
  tail call void @_ZN7vraudio11AudioBufferC1Emm(ptr noundef nonnull align 8 dereferenceable(68) %0, i64 noundef 2, i64 noundef %1)
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %3) #4
  %4 = invoke noundef nonnull align 8 dereferenceable(8) ptr @_ZN10NullLogger9GetStreamEv(ptr noundef nonnull align 1 dereferenceable(1) %3)
          to label %5 unwind label %10

5:                                                ; preds = %2
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %3) #4
  %6 = invoke noundef nonnull align 8 dereferenceable(17) ptr @_ZN7vraudio11AudioBufferixEm(ptr noundef nonnull align 8 dereferenceable(68) %0, i64 noundef 0)
          to label %7 unwind label %12

7:                                                ; preds = %5
  %8 = invoke noundef nonnull align 8 dereferenceable(17) ptr @_ZN7vraudio11AudioBufferixEm(ptr noundef nonnull align 8 dereferenceable(68) %0, i64 noundef 1)
          to label %.preheader unwind label %14

.preheader:                                       ; preds = %7
  %.not = icmp eq i64 %1, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %9 = uitofp i64 %1 to float
  br label %16

._crit_edge:                                      ; preds = %22, %.preheader
  ret void

10:                                               ; preds = %2
  %11 = landingpad { ptr, i32 }
          cleanup
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %3) #4
  br label %27

12:                                               ; preds = %5
  %13 = landingpad { ptr, i32 }
          cleanup
  br label %27

14:                                               ; preds = %7
  %15 = landingpad { ptr, i32 }
          cleanup
  br label %27

16:                                               ; preds = %.lr.ph, %22
  %.01422 = phi i64 [ 0, %.lr.ph ], [ %24, %22 ]
  %17 = invoke noundef nonnull align 4 dereferenceable(4) ptr @_ZN7vraudio11ChannelViewixEm(ptr noundef nonnull align 8 dereferenceable(17) %6, i64 noundef %.01422)
          to label %18 unwind label %25

18:                                               ; preds = %16
  %19 = uitofp i64 %.01422 to float
  %20 = fdiv float %19, %9
  store float %20, ptr %17, align 4, !tbaa !5
  %21 = invoke noundef nonnull align 4 dereferenceable(4) ptr @_ZN7vraudio11ChannelViewixEm(ptr noundef nonnull align 8 dereferenceable(17) %8, i64 noundef %.01422)
          to label %22 unwind label %25

22:                                               ; preds = %18
  %23 = fsub float 1.000000e+00, %20
  store float %23, ptr %21, align 4, !tbaa !5
  %24 = add nuw i64 %.01422, 1
  %exitcond.not = icmp eq i64 %24, %1
  br i1 %exitcond.not, label %._crit_edge, label %16, !llvm.loop !9

25:                                               ; preds = %18, %16
  %26 = landingpad { ptr, i32 }
          cleanup
  br label %27

27:                                               ; preds = %12, %25, %14, %10
  %.pn.pn.pn = phi { ptr, i32 } [ %11, %10 ], [ %13, %12 ], [ %26, %25 ], [ %15, %14 ]
  call void @_ZN7vraudio11AudioBufferD2Ev(ptr noundef nonnull align 8 dereferenceable(68) %0) #4
  resume { ptr, i32 } %.pn.pn.pn
}

declare void @_ZN7vraudio11AudioBufferC1Emm(ptr noundef nonnull align 8 dereferenceable(68), i64 noundef, i64 noundef) unnamed_addr #1

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

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

declare i32 @__gxx_personality_v0(...)

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

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN7vraudio11AudioBufferD2Ev(ptr noundef nonnull align 8 dereferenceable(68)) unnamed_addr #3 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 = { "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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { inlinehint 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 #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 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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