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

; 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_acorr_f32(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) #0 {
  %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 i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  store i32 %3, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %14, ptr %11, align 8, !tbaa !5
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %15

15:                                               ; preds = %48, %4
  %16 = load i32, ptr %9, align 4, !tbaa !9
  %17 = load i32, ptr %8, align 4, !tbaa !9
  %18 = icmp slt i32 %16, %17
  br i1 %18, label %19, label %51

19:                                               ; preds = %15
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  store float 0.000000e+00, ptr %20, align 4, !tbaa !11
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %21, ptr %12, align 8, !tbaa !5
  %22 = load ptr, ptr %11, align 8, !tbaa !5
  store ptr %22, ptr %13, align 8, !tbaa !5
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %23

23:                                               ; preds = %40, %19
  %24 = load i32, ptr %10, align 4, !tbaa !9
  %25 = load i32, ptr %7, align 4, !tbaa !9
  %26 = load i32, ptr %9, align 4, !tbaa !9
  %27 = sub nsw i32 %25, %26
  %28 = icmp slt i32 %24, %27
  br i1 %28, label %29, label %43

29:                                               ; preds = %23
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = load float, ptr %30, align 4, !tbaa !11
  %32 = load ptr, ptr %12, align 8, !tbaa !5
  %33 = getelementptr inbounds float, ptr %32, i32 1
  store ptr %33, ptr %12, align 8, !tbaa !5
  %34 = load float, ptr %32, align 4, !tbaa !11
  %35 = load ptr, ptr %13, align 8, !tbaa !5
  %36 = getelementptr inbounds float, ptr %35, i32 1
  store ptr %36, ptr %13, align 8, !tbaa !5
  %37 = load float, ptr %35, align 4, !tbaa !11
  %38 = call float @llvm.fmuladd.f32(float %34, float %37, float %31)
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  store float %38, ptr %39, align 4, !tbaa !11
  br label %40

40:                                               ; preds = %29
  %41 = load i32, ptr %10, align 4, !tbaa !9
  %42 = add nsw i32 %41, 1
  store i32 %42, ptr %10, align 4, !tbaa !9
  br label %23, !llvm.loop !13

43:                                               ; preds = %23
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = getelementptr inbounds float, ptr %44, i32 1
  store ptr %45, ptr %6, align 8, !tbaa !5
  %46 = load ptr, ptr %11, align 8, !tbaa !5
  %47 = getelementptr inbounds float, ptr %46, i32 1
  store ptr %47, ptr %11, align 8, !tbaa !5
  br label %48

48:                                               ; preds = %43
  %49 = load i32, ptr %9, align 4, !tbaa !9
  %50 = add nsw i32 %49, 1
  store i32 %50, ptr %9, align 4, !tbaa !9
  br label %15, !llvm.loop !15

51:                                               ; preds = %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #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}


; 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_acorr_f32(ptr nocapture noundef readonly %0, ptr nocapture noundef writeonly %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = icmp sgt i32 %3, 0
  br i1 %5, label %.lr.ph28, label %._crit_edge29

.lr.ph28:                                         ; preds = %4, %._crit_edge
  %indvars.iv = phi i32 [ %indvars.iv.next, %._crit_edge ], [ %2, %4 ]
  %.01726 = phi ptr [ %37, %._crit_edge ], [ %0, %4 ]
  %.01925 = phi i32 [ %38, %._crit_edge ], [ 0, %4 ]
  %.02024 = phi ptr [ %36, %._crit_edge ], [ %1, %4 ]
  store float 0.000000e+00, ptr %.02024, align 4, !tbaa !5
  %6 = icmp slt i32 %.01925, %2
  br i1 %6, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %.lr.ph28
  %xtraiter = and i32 %indvars.iv, 3
  %7 = sub i32 %.01925, %2
  %8 = icmp ugt i32 %7, -4
  br i1 %8, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i32 %indvars.iv, -4
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %9 = phi float [ 0.000000e+00, %.lr.ph.preheader.new ], [ %29, %.lr.ph ]
  %.023 = phi ptr [ %.01726, %.lr.ph.preheader.new ], [ %27, %.lr.ph ]
  %.01622 = phi ptr [ %0, %.lr.ph.preheader.new ], [ %25, %.lr.ph ]
  %niter = phi i32 [ 0, %.lr.ph.preheader.new ], [ %niter.next.3, %.lr.ph ]
  %10 = getelementptr inbounds i8, ptr %.01622, i64 4
  %11 = load float, ptr %.01622, align 4, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %.023, i64 4
  %13 = load float, ptr %.023, align 4, !tbaa !5
  %14 = tail call float @llvm.fmuladd.f32(float %11, float %13, float %9)
  store float %14, ptr %.02024, align 4, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %.01622, i64 8
  %16 = load float, ptr %10, align 4, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %.023, i64 8
  %18 = load float, ptr %12, align 4, !tbaa !5
  %19 = tail call float @llvm.fmuladd.f32(float %16, float %18, float %14)
  store float %19, ptr %.02024, align 4, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %.01622, i64 12
  %21 = load float, ptr %15, align 4, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %.023, i64 12
  %23 = load float, ptr %17, align 4, !tbaa !5
  %24 = tail call float @llvm.fmuladd.f32(float %21, float %23, float %19)
  store float %24, ptr %.02024, align 4, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %.01622, i64 16
  %26 = load float, ptr %20, align 4, !tbaa !5
  %27 = getelementptr inbounds i8, ptr %.023, i64 16
  %28 = load float, ptr %22, align 4, !tbaa !5
  %29 = tail call float @llvm.fmuladd.f32(float %26, float %28, float %24)
  store float %29, ptr %.02024, align 4, !tbaa !5
  %niter.next.3 = add i32 %niter, 4
  %niter.ncmp.3 = icmp eq i32 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !9

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.lr.ph, %.lr.ph.preheader
  %.unr = phi float [ 0.000000e+00, %.lr.ph.preheader ], [ %29, %.lr.ph ]
  %.023.unr = phi ptr [ %.01726, %.lr.ph.preheader ], [ %27, %.lr.ph ]
  %.01622.unr = phi ptr [ %0, %.lr.ph.preheader ], [ %25, %.lr.ph ]
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.epil
  %30 = phi float [ %35, %.lr.ph.epil ], [ %.unr, %._crit_edge.loopexit.unr-lcssa ]
  %.023.epil = phi ptr [ %33, %.lr.ph.epil ], [ %.023.unr, %._crit_edge.loopexit.unr-lcssa ]
  %.01622.epil = phi ptr [ %31, %.lr.ph.epil ], [ %.01622.unr, %._crit_edge.loopexit.unr-lcssa ]
  %epil.iter = phi i32 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %31 = getelementptr inbounds i8, ptr %.01622.epil, i64 4
  %32 = load float, ptr %.01622.epil, align 4, !tbaa !5
  %33 = getelementptr inbounds i8, ptr %.023.epil, i64 4
  %34 = load float, ptr %.023.epil, align 4, !tbaa !5
  %35 = tail call float @llvm.fmuladd.f32(float %32, float %34, float %30)
  store float %35, ptr %.02024, align 4, !tbaa !5
  %epil.iter.next = add i32 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i32 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge, label %.lr.ph.epil, !llvm.loop !11

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.epil, %.lr.ph28
  %36 = getelementptr inbounds i8, ptr %.02024, i64 4
  %37 = getelementptr inbounds i8, ptr %.01726, i64 4
  %38 = add nuw nsw i32 %.01925, 1
  %indvars.iv.next = add i32 %indvars.iv, -1
  %exitcond30.not = icmp eq i32 %38, %3
  br i1 %exitcond30.not, label %._crit_edge29, label %.lr.ph28, !llvm.loop !13

._crit_edge29:                                    ; preds = %._crit_edge, %4
  ret void
}

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

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) }

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


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