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

; 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.oboe::flowgraph::MonoToMultiConverter" = type { %"class.oboe::flowgraph::FlowGraphNode", %"class.oboe::flowgraph::FlowGraphPortFloatInput", %"class.oboe::flowgraph::FlowGraphPortFloatOutput" }
%"class.oboe::flowgraph::FlowGraphNode" = type { ptr, i64, %"class.std::vector", i8, i8, i32 }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<std::reference_wrapper<oboe::flowgraph::FlowGraphPort>, std::allocator<std::reference_wrapper<oboe::flowgraph::FlowGraphPort>>>::_Vector_impl" }
%"struct.std::_Vector_base<std::reference_wrapper<oboe::flowgraph::FlowGraphPort>, std::allocator<std::reference_wrapper<oboe::flowgraph::FlowGraphPort>>>::_Vector_impl" = type { %"struct.std::_Vector_base<std::reference_wrapper<oboe::flowgraph::FlowGraphPort>, std::allocator<std::reference_wrapper<oboe::flowgraph::FlowGraphPort>>>::_Vector_impl_data" }
%"struct.std::_Vector_base<std::reference_wrapper<oboe::flowgraph::FlowGraphPort>, std::allocator<std::reference_wrapper<oboe::flowgraph::FlowGraphPort>>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.oboe::flowgraph::FlowGraphPortFloatInput" = type { %"class.oboe::flowgraph::FlowGraphPortFloat", ptr }
%"class.oboe::flowgraph::FlowGraphPortFloat" = type { %"class.oboe::flowgraph::FlowGraphPort.base", i32, %"class.std::unique_ptr" }
%"class.oboe::flowgraph::FlowGraphPort.base" = type <{ ptr, ptr, i32 }>
%"class.std::unique_ptr" = type { %"struct.std::__uniq_ptr_data" }
%"struct.std::__uniq_ptr_data" = type { %"class.std::__uniq_ptr_impl" }
%"class.std::__uniq_ptr_impl" = type { %"class.std::tuple" }
%"class.std::tuple" = type { %"struct.std::_Tuple_impl" }
%"struct.std::_Tuple_impl" = type { %"struct.std::_Head_base.1" }
%"struct.std::_Head_base.1" = type { ptr }
%"class.oboe::flowgraph::FlowGraphPortFloatOutput" = type { %"class.oboe::flowgraph::FlowGraphPortFloat" }

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN4oboe9flowgraph20MonoToMultiConverter9onProcessEi(ptr noundef nonnull align 8 dereferenceable(120) %0, i32 noundef %1) unnamed_addr #0 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca float, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %12 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %13 = getelementptr inbounds %"class.oboe::flowgraph::MonoToMultiConverter", ptr %12, i32 0, i32 1
  %14 = call noundef ptr @_ZN4oboe9flowgraph23FlowGraphPortFloatInput9getBufferEv(ptr noundef nonnull align 8 dereferenceable(40) %13)
  store ptr %14, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %15 = getelementptr inbounds %"class.oboe::flowgraph::MonoToMultiConverter", ptr %12, i32 0, i32 2
  %16 = call noundef ptr @_ZN4oboe9flowgraph18FlowGraphPortFloat9getBufferEv(ptr noundef nonnull align 8 dereferenceable(32) %15)
  store ptr %16, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %17 = getelementptr inbounds %"class.oboe::flowgraph::MonoToMultiConverter", ptr %12, i32 0, i32 2
  %18 = call noundef i32 @_ZNK4oboe9flowgraph13FlowGraphPort18getSamplesPerFrameEv(ptr noundef nonnull align 8 dereferenceable(20) %17)
  store i32 %18, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %19

19:                                               ; preds = %41, %2
  %20 = load i32, ptr %8, align 4, !tbaa !9
  %21 = load i32, ptr %4, align 4, !tbaa !9
  %22 = icmp slt i32 %20, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %19
  store i32 2, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %44

24:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds float, ptr %25, i32 1
  store ptr %26, ptr %5, align 8, !tbaa !5
  %27 = load float, ptr %25, align 4, !tbaa !11
  store float %27, ptr %10, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %28

28:                                               ; preds = %37, %24
  %29 = load i32, ptr %11, align 4, !tbaa !9
  %30 = load i32, ptr %7, align 4, !tbaa !9
  %31 = icmp slt i32 %29, %30
  br i1 %31, label %33, label %32

32:                                               ; preds = %28
  store i32 5, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  br label %40

33:                                               ; preds = %28
  %34 = load float, ptr %10, align 4, !tbaa !11
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = getelementptr inbounds float, ptr %35, i32 1
  store ptr %36, ptr %6, align 8, !tbaa !5
  store float %34, ptr %35, align 4, !tbaa !11
  br label %37

37:                                               ; preds = %33
  %38 = load i32, ptr %11, align 4, !tbaa !9
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr %11, align 4, !tbaa !9
  br label %28, !llvm.loop !13

40:                                               ; preds = %32
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  br label %41

41:                                               ; preds = %40
  %42 = load i32, ptr %8, align 4, !tbaa !9
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr %8, align 4, !tbaa !9
  br label %19, !llvm.loop !15

44:                                               ; preds = %23
  %45 = load i32, ptr %4, align 4, !tbaa !9
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret i32 %45
}

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

declare noundef ptr @_ZN4oboe9flowgraph23FlowGraphPortFloatInput9getBufferEv(ptr noundef nonnull align 8 dereferenceable(40)) unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN4oboe9flowgraph18FlowGraphPortFloat9getBufferEv(ptr noundef nonnull align 8 dereferenceable(32)) unnamed_addr #3 align 2

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

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #3 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


; 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
define dso_local noundef i32 @_ZN4oboe9flowgraph20MonoToMultiConverter9onProcessEi(ptr noundef nonnull align 8 dereferenceable(120) %0, i32 noundef returned %1) unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 48
  %4 = tail call noundef ptr @_ZN4oboe9flowgraph23FlowGraphPortFloatInput9getBufferEv(ptr noundef nonnull align 8 dereferenceable(40) %3)
  %5 = getelementptr inbounds i8, ptr %0, i64 88
  %6 = tail call noundef ptr @_ZN4oboe9flowgraph18FlowGraphPortFloat9getBufferEv(ptr noundef nonnull align 8 dereferenceable(32) %5)
  %7 = tail call noundef i32 @_ZNK4oboe9flowgraph13FlowGraphPort18getSamplesPerFrameEv(ptr noundef nonnull align 8 dereferenceable(20) %5)
  %8 = icmp sgt i32 %1, 0
  %9 = icmp sgt i32 %7, 0
  %or.cond = and i1 %8, %9
  br i1 %or.cond, label %.lr.ph.us.preheader, label %._crit_edge21

.lr.ph.us.preheader:                              ; preds = %2
  %10 = zext nneg i32 %7 to i64
  %min.iters.check = icmp ult i32 %7, 8
  %n.vec = and i64 %10, 2147483640
  %ind.end = trunc nuw nsw i64 %n.vec to i32
  %11 = shl nuw nsw i64 %n.vec, 2
  %cmp.n = icmp eq i64 %n.vec, %10
  br label %.lr.ph.us

.lr.ph.us:                                        ; preds = %.lr.ph.us.preheader, %._crit_edge.us
  %.01018.us = phi ptr [ %17, %._crit_edge.us ], [ %4, %.lr.ph.us.preheader ]
  %.01117.us = phi i32 [ %18, %._crit_edge.us ], [ 0, %.lr.ph.us.preheader ]
  %.01216.us = phi ptr [ %.lcssa, %._crit_edge.us ], [ %6, %.lr.ph.us.preheader ]
  %12 = load float, ptr %.01018.us, align 4, !tbaa !5
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph.us
  %ind.end24 = getelementptr i8, ptr %.01216.us, i64 %11
  %broadcast.splatinsert = insertelement <4 x float> poison, float %12, i64 0
  %broadcast.splat = shufflevector <4 x float> %broadcast.splatinsert, <4 x float> poison, <4 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %offset.idx = shl i64 %index, 2
  %next.gep = getelementptr i8, ptr %.01216.us, i64 %offset.idx
  %13 = getelementptr i8, ptr %next.gep, i64 16
  store <4 x float> %broadcast.splat, ptr %next.gep, align 4, !tbaa !5
  store <4 x float> %broadcast.splat, ptr %13, align 4, !tbaa !5
  %index.next = add nuw i64 %index, 8
  %14 = icmp eq i64 %index.next, %n.vec
  br i1 %14, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  br i1 %cmp.n, label %._crit_edge.us, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %middle.block, %.lr.ph.us
  %.015.us.ph = phi i32 [ 0, %.lr.ph.us ], [ %ind.end, %middle.block ]
  %.114.us.ph = phi ptr [ %.01216.us, %.lr.ph.us ], [ %ind.end24, %middle.block ]
  br label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %.015.us = phi i32 [ %16, %scalar.ph ], [ %.015.us.ph, %scalar.ph.preheader ]
  %.114.us = phi ptr [ %15, %scalar.ph ], [ %.114.us.ph, %scalar.ph.preheader ]
  %15 = getelementptr inbounds i8, ptr %.114.us, i64 4
  store float %12, ptr %.114.us, align 4, !tbaa !5
  %16 = add nuw nsw i32 %.015.us, 1
  %exitcond.not = icmp eq i32 %16, %7
  br i1 %exitcond.not, label %._crit_edge.us, label %scalar.ph, !llvm.loop !13

._crit_edge.us:                                   ; preds = %scalar.ph, %middle.block
  %.lcssa = phi ptr [ %ind.end24, %middle.block ], [ %15, %scalar.ph ]
  %17 = getelementptr inbounds i8, ptr %.01018.us, i64 4
  %18 = add nuw nsw i32 %.01117.us, 1
  %exitcond23.not = icmp eq i32 %18, %1
  br i1 %exitcond23.not, label %._crit_edge21, label %.lr.ph.us, !llvm.loop !14

._crit_edge21:                                    ; preds = %._crit_edge.us, %2
  ret i32 %1
}

declare noundef ptr @_ZN4oboe9flowgraph23FlowGraphPortFloatInput9getBufferEv(ptr noundef nonnull align 8 dereferenceable(40)) unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN4oboe9flowgraph18FlowGraphPortFloat9getBufferEv(ptr noundef nonnull align 8 dereferenceable(32)) unnamed_addr #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK4oboe9flowgraph13FlowGraphPort18getSamplesPerFrameEv(ptr noundef nonnull align 8 dereferenceable(20)) local_unnamed_addr #2 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 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" }

!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, !11, !12}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = distinct !{!13, !10, !12, !11}
!14 = distinct !{!14, !10}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass