; LLVM IR from parallella/pal :: src/dsp (p_conv)

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

; Function Attrs: nounwind uwtable
define dso_local void @p_conv_f32(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, i32 noundef %4) #0 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca float, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store i32 %3, ptr %9, align 4, !tbaa !9
  store i32 %4, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %15 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %15, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  store i32 0, ptr %12, align 4, !tbaa !9
  br label %16

16:                                               ; preds = %26, %5
  %17 = load i32, ptr %12, align 4, !tbaa !9
  %18 = load i32, ptr %9, align 4, !tbaa !9
  %19 = load i32, ptr %10, align 4, !tbaa !9
  %20 = add nsw i32 %18, %19
  %21 = sub nsw i32 %20, 1
  %22 = icmp slt i32 %17, %21
  br i1 %22, label %23, label %29

23:                                               ; preds = %16
  %24 = load ptr, ptr %11, align 8, !tbaa !5
  %25 = getelementptr inbounds float, ptr %24, i32 1
  store ptr %25, ptr %11, align 8, !tbaa !5
  store float 0.000000e+00, ptr %24, align 4, !tbaa !11
  br label %26

26:                                               ; preds = %23
  %27 = load i32, ptr %12, align 4, !tbaa !9
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr %12, align 4, !tbaa !9
  br label %16, !llvm.loop !13

29:                                               ; preds = %16
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %30, ptr %11, align 8, !tbaa !5
  store i32 0, ptr %12, align 4, !tbaa !9
  br label %31

31:                                               ; preds = %62, %29
  %32 = load i32, ptr %12, align 4, !tbaa !9
  %33 = load i32, ptr %9, align 4, !tbaa !9
  %34 = icmp slt i32 %32, %33
  br i1 %34, label %35, label %65

35:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = getelementptr inbounds float, ptr %36, i32 1
  store ptr %37, ptr %6, align 8, !tbaa !5
  %38 = load float, ptr %36, align 4, !tbaa !11
  store float %38, ptr %14, align 4, !tbaa !11
  store i32 0, ptr %13, align 4, !tbaa !9
  br label %39

39:                                               ; preds = %56, %35
  %40 = load i32, ptr %13, align 4, !tbaa !9
  %41 = load i32, ptr %10, align 4, !tbaa !9
  %42 = icmp slt i32 %40, %41
  br i1 %42, label %43, label %59

43:                                               ; preds = %39
  %44 = load float, ptr %14, align 4, !tbaa !11
  %45 = load ptr, ptr %7, align 8, !tbaa !5
  %46 = load i32, ptr %13, align 4, !tbaa !9
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds float, ptr %45, i64 %47
  %49 = load float, ptr %48, align 4, !tbaa !11
  %50 = load ptr, ptr %11, align 8, !tbaa !5
  %51 = load i32, ptr %13, align 4, !tbaa !9
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds float, ptr %50, i64 %52
  %54 = load float, ptr %53, align 4, !tbaa !11
  %55 = call float @llvm.fmuladd.f32(float %44, float %49, float %54)
  store float %55, ptr %53, align 4, !tbaa !11
  br label %56

56:                                               ; preds = %43
  %57 = load i32, ptr %13, align 4, !tbaa !9
  %58 = add nsw i32 %57, 1
  store i32 %58, ptr %13, align 4, !tbaa !9
  br label %39, !llvm.loop !15

59:                                               ; preds = %39
  %60 = load ptr, ptr %11, align 8, !tbaa !5
  %61 = getelementptr inbounds float, ptr %60, i32 1
  store ptr %61, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  br label %62

62:                                               ; preds = %59
  %63 = load i32, ptr %12, align 4, !tbaa !9
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr %12, align 4, !tbaa !9
  br label %31, !llvm.loop !16

65:                                               ; preds = %31
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  ret void
}

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #2

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

attributes #0 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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/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}
!16 = distinct !{!16, !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: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @p_conv_f32(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, ptr nocapture noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #0 {
  %6 = add i32 %3, -1
  %7 = add i32 %6, %4
  %8 = icmp sgt i32 %7, 0
  br i1 %8, label %.lr.ph.preheader, label %.preheader

.lr.ph.preheader:                                 ; preds = %5
  %9 = add i32 %4, %3
  %10 = add i32 %9, -2
  %11 = zext i32 %10 to i64
  %12 = shl nuw nsw i64 %11, 2
  %13 = add nuw nsw i64 %12, 4
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(1) %2, i8 0, i64 %13, i1 false), !tbaa !5
  br label %.preheader

.preheader:                                       ; preds = %.lr.ph.preheader, %5
  %14 = icmp sgt i32 %3, 0
  %15 = icmp sgt i32 %4, 0
  %or.cond = and i1 %14, %15
  br i1 %or.cond, label %.lr.ph26.us.preheader, label %._crit_edge31

.lr.ph26.us.preheader:                            ; preds = %.preheader
  %wide.trip.count = zext nneg i32 %4 to i64
  %16 = shl nuw nsw i64 %wide.trip.count, 2
  %17 = add nsw i32 %3, -1
  %18 = zext i32 %17 to i64
  %19 = add nuw nsw i64 %wide.trip.count, %18
  %20 = shl nuw nsw i64 %19, 2
  %scevgep = getelementptr i8, ptr %2, i64 %20
  %scevgep35 = getelementptr i8, ptr %1, i64 %16
  %min.iters.check = icmp ult i32 %4, 8
  %bound0 = icmp ugt ptr %scevgep35, %2
  %bound1 = icmp ugt ptr %scevgep, %1
  %found.conflict = and i1 %bound0, %bound1
  %n.vec = and i64 %wide.trip.count, 2147483640
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  %xtraiter = and i64 %wide.trip.count, 1
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  %21 = add nsw i64 %wide.trip.count, -1
  br label %.lr.ph26.us

.lr.ph26.us:                                      ; preds = %.lr.ph26.us.preheader, %._crit_edge.us
  %.029.us = phi ptr [ %46, %._crit_edge.us ], [ %0, %.lr.ph26.us.preheader ]
  %.128.us = phi i32 [ %48, %._crit_edge.us ], [ 0, %.lr.ph26.us.preheader ]
  %.12227.us = phi ptr [ %47, %._crit_edge.us ], [ %2, %.lr.ph26.us.preheader ]
  %22 = load float, ptr %.029.us, align 4, !tbaa !5
  %brmerge = select i1 %min.iters.check, i1 true, i1 %found.conflict
  br i1 %brmerge, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph26.us
  %broadcast.splatinsert = insertelement <4 x float> poison, float %22, 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 ]
  %23 = getelementptr inbounds float, ptr %1, i64 %index
  %24 = getelementptr inbounds i8, ptr %23, i64 16
  %wide.load = load <4 x float>, ptr %23, align 4, !tbaa !5, !alias.scope !9
  %wide.load36 = load <4 x float>, ptr %24, align 4, !tbaa !5, !alias.scope !9
  %25 = getelementptr inbounds float, ptr %.12227.us, i64 %index
  %26 = getelementptr inbounds i8, ptr %25, i64 16
  %wide.load37 = load <4 x float>, ptr %25, align 4, !tbaa !5, !alias.scope !12, !noalias !9
  %wide.load38 = load <4 x float>, ptr %26, align 4, !tbaa !5, !alias.scope !12, !noalias !9
  %27 = tail call <4 x float> @llvm.fmuladd.v4f32(<4 x float> %broadcast.splat, <4 x float> %wide.load, <4 x float> %wide.load37)
  %28 = tail call <4 x float> @llvm.fmuladd.v4f32(<4 x float> %broadcast.splat, <4 x float> %wide.load36, <4 x float> %wide.load38)
  store <4 x float> %27, ptr %25, align 4, !tbaa !5, !alias.scope !12, !noalias !9
  store <4 x float> %28, ptr %26, align 4, !tbaa !5, !alias.scope !12, !noalias !9
  %index.next = add nuw i64 %index, 8
  %29 = icmp eq i64 %index.next, %n.vec
  br i1 %29, label %middle.block, label %vector.body, !llvm.loop !14

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

scalar.ph.preheader:                              ; preds = %.lr.ph26.us, %middle.block
  %indvars.iv.ph = phi i64 [ 0, %.lr.ph26.us ], [ %n.vec, %middle.block ]
  br i1 %lcmp.mod.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol

scalar.ph.prol:                                   ; preds = %scalar.ph.preheader
  %30 = getelementptr inbounds float, ptr %1, i64 %indvars.iv.ph
  %31 = load float, ptr %30, align 4, !tbaa !5
  %32 = getelementptr inbounds float, ptr %.12227.us, i64 %indvars.iv.ph
  %33 = load float, ptr %32, align 4, !tbaa !5
  %34 = tail call float @llvm.fmuladd.f32(float %22, float %31, float %33)
  store float %34, ptr %32, align 4, !tbaa !5
  %indvars.iv.next.prol = or disjoint i64 %indvars.iv.ph, 1
  br label %scalar.ph.prol.loopexit

scalar.ph.prol.loopexit:                          ; preds = %scalar.ph.prol, %scalar.ph.preheader
  %indvars.iv.unr = phi i64 [ %indvars.iv.ph, %scalar.ph.preheader ], [ %indvars.iv.next.prol, %scalar.ph.prol ]
  %35 = icmp eq i64 %indvars.iv.ph, %21
  br i1 %35, label %._crit_edge.us, label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next.1, %scalar.ph ], [ %indvars.iv.unr, %scalar.ph.prol.loopexit ]
  %36 = getelementptr inbounds float, ptr %1, i64 %indvars.iv
  %37 = load float, ptr %36, align 4, !tbaa !5
  %38 = getelementptr inbounds float, ptr %.12227.us, i64 %indvars.iv
  %39 = load float, ptr %38, align 4, !tbaa !5
  %40 = tail call float @llvm.fmuladd.f32(float %22, float %37, float %39)
  store float %40, ptr %38, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %41 = getelementptr inbounds float, ptr %1, i64 %indvars.iv.next
  %42 = load float, ptr %41, align 4, !tbaa !5
  %43 = getelementptr inbounds float, ptr %.12227.us, i64 %indvars.iv.next
  %44 = load float, ptr %43, align 4, !tbaa !5
  %45 = tail call float @llvm.fmuladd.f32(float %22, float %42, float %44)
  store float %45, ptr %43, align 4, !tbaa !5
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %exitcond.not.1 = icmp eq i64 %indvars.iv.next.1, %wide.trip.count
  br i1 %exitcond.not.1, label %._crit_edge.us, label %scalar.ph, !llvm.loop !18

._crit_edge.us:                                   ; preds = %scalar.ph.prol.loopexit, %scalar.ph, %middle.block
  %46 = getelementptr inbounds i8, ptr %.029.us, i64 4
  %47 = getelementptr inbounds i8, ptr %.12227.us, i64 4
  %48 = add nuw nsw i32 %.128.us, 1
  %exitcond34.not = icmp eq i32 %48, %3
  br i1 %exitcond34.not, label %._crit_edge31, label %.lr.ph26.us, !llvm.loop !19

._crit_edge31:                                    ; preds = %._crit_edge.us, %.preheader
  ret void
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <4 x float> @llvm.fmuladd.v4f32(<4 x float>, <4 x float>, <4 x float>) #3

attributes #0 = { nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) 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 nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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/C++ TBAA"}
!9 = !{!10}
!10 = distinct !{!10, !11}
!11 = distinct !{!11, !"LVerDomain"}
!12 = !{!13}
!13 = distinct !{!13, !11}
!14 = distinct !{!14, !15, !16, !17}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!"llvm.loop.isvectorized", i32 1}
!17 = !{!"llvm.loop.unroll.runtime.disable"}
!18 = distinct !{!18, !15, !16}
!19 = distinct !{!19, !15}


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