; LLVM IR from rdguez-mariano/fast_imas_IPOL :: libSimuTilts/filter.ll (Z18buffer_convolutionPfS_ii)

; 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: 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 speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #1

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z18buffer_convolutionPfS_ii(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) #2 {
  %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 float, align 4
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  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
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %15

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

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

20:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store float 0.000000e+00, ptr %11, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = load i32, ptr %9, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds float, ptr %21, i64 %23
  store ptr %24, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = getelementptr inbounds float, ptr %25, i64 0
  store ptr %26, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  store i32 0, ptr %14, align 4, !tbaa !9
  br label %27

27:                                               ; preds = %41, %20
  %28 = load i32, ptr %14, align 4, !tbaa !9
  %29 = load i32, ptr %8, align 4, !tbaa !9
  %30 = icmp slt i32 %28, %29
  br i1 %30, label %32, label %31

31:                                               ; preds = %27
  store i32 5, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  br label %44

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

41:                                               ; preds = %32
  %42 = load i32, ptr %14, align 4, !tbaa !9
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr %14, align 4, !tbaa !9
  br label %27, !llvm.loop !13

44:                                               ; preds = %31
  %45 = load float, ptr %11, align 4, !tbaa !11
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = load i32, ptr %9, align 4, !tbaa !9
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds float, ptr %46, i64 %48
  store float %45, ptr %49, align 4, !tbaa !11
  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 4, ptr %11) #3
  br label %50

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

53:                                               ; preds = %19
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !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 nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #0

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local void @_Z18buffer_convolutionPfS_ii(ptr nocapture noundef %0, ptr nocapture noundef readonly %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #1 {
  %5 = icmp sgt i32 %2, 0
  br i1 %5, label %.lr.ph24, label %._crit_edge25

.lr.ph24:                                         ; preds = %4
  %6 = icmp sgt i32 %3, 0
  %wide.trip.count = zext nneg i32 %2 to i64
  br i1 %6, label %.lr.ph.us.preheader, label %.lr.ph24.split.preheader

.lr.ph.us.preheader:                              ; preds = %.lr.ph24
  %xtraiter = and i32 %3, 3
  %7 = icmp ult i32 %3, 4
  %unroll_iter = and i32 %3, 2147483644
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br label %.lr.ph.us

.lr.ph24.split.preheader:                         ; preds = %.lr.ph24
  %8 = shl nuw nsw i64 %wide.trip.count, 2
  tail call void @llvm.memset.p0.i64(ptr align 4 %0, i8 0, i64 %8, i1 false), !tbaa !5
  br label %._crit_edge25

.lr.ph.us:                                        ; preds = %.lr.ph.us.preheader, %._crit_edge.us
  %indvars.iv = phi i64 [ %indvars.iv.next, %._crit_edge.us ], [ 0, %.lr.ph.us.preheader ]
  %9 = getelementptr inbounds float, ptr %0, i64 %indvars.iv
  br i1 %7, label %._crit_edge.us.unr-lcssa, label %.lr.ph.us.new

.lr.ph.us.new:                                    ; preds = %.lr.ph.us, %.lr.ph.us.new
  %.01420.us = phi ptr [ %27, %.lr.ph.us.new ], [ %1, %.lr.ph.us ]
  %.01519.us = phi ptr [ %25, %.lr.ph.us.new ], [ %9, %.lr.ph.us ]
  %.01618.us = phi float [ %29, %.lr.ph.us.new ], [ 0.000000e+00, %.lr.ph.us ]
  %niter = phi i32 [ %niter.next.3, %.lr.ph.us.new ], [ 0, %.lr.ph.us ]
  %10 = getelementptr inbounds i8, ptr %.01519.us, i64 4
  %11 = load float, ptr %.01519.us, align 4, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %.01420.us, i64 4
  %13 = load float, ptr %.01420.us, align 4, !tbaa !5
  %14 = tail call float @llvm.fmuladd.f32(float %11, float %13, float %.01618.us)
  %15 = getelementptr inbounds i8, ptr %.01519.us, i64 8
  %16 = load float, ptr %10, align 4, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %.01420.us, i64 8
  %18 = load float, ptr %12, align 4, !tbaa !5
  %19 = tail call float @llvm.fmuladd.f32(float %16, float %18, float %14)
  %20 = getelementptr inbounds i8, ptr %.01519.us, i64 12
  %21 = load float, ptr %15, align 4, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %.01420.us, i64 12
  %23 = load float, ptr %17, align 4, !tbaa !5
  %24 = tail call float @llvm.fmuladd.f32(float %21, float %23, float %19)
  %25 = getelementptr inbounds i8, ptr %.01519.us, i64 16
  %26 = load float, ptr %20, align 4, !tbaa !5
  %27 = getelementptr inbounds i8, ptr %.01420.us, i64 16
  %28 = load float, ptr %22, align 4, !tbaa !5
  %29 = tail call float @llvm.fmuladd.f32(float %26, float %28, float %24)
  %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.us.unr-lcssa, label %.lr.ph.us.new, !llvm.loop !9

._crit_edge.us.unr-lcssa:                         ; preds = %.lr.ph.us.new, %.lr.ph.us
  %.lcssa.ph = phi float [ poison, %.lr.ph.us ], [ %29, %.lr.ph.us.new ]
  %.01420.us.unr = phi ptr [ %1, %.lr.ph.us ], [ %27, %.lr.ph.us.new ]
  %.01519.us.unr = phi ptr [ %9, %.lr.ph.us ], [ %25, %.lr.ph.us.new ]
  %.01618.us.unr = phi float [ 0.000000e+00, %.lr.ph.us ], [ %29, %.lr.ph.us.new ]
  br i1 %lcmp.mod.not, label %._crit_edge.us, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge.us.unr-lcssa, %.epil.preheader
  %.01420.us.epil = phi ptr [ %32, %.epil.preheader ], [ %.01420.us.unr, %._crit_edge.us.unr-lcssa ]
  %.01519.us.epil = phi ptr [ %30, %.epil.preheader ], [ %.01519.us.unr, %._crit_edge.us.unr-lcssa ]
  %.01618.us.epil = phi float [ %34, %.epil.preheader ], [ %.01618.us.unr, %._crit_edge.us.unr-lcssa ]
  %epil.iter = phi i32 [ %epil.iter.next, %.epil.preheader ], [ 0, %._crit_edge.us.unr-lcssa ]
  %30 = getelementptr inbounds i8, ptr %.01519.us.epil, i64 4
  %31 = load float, ptr %.01519.us.epil, align 4, !tbaa !5
  %32 = getelementptr inbounds i8, ptr %.01420.us.epil, i64 4
  %33 = load float, ptr %.01420.us.epil, align 4, !tbaa !5
  %34 = tail call float @llvm.fmuladd.f32(float %31, float %33, float %.01618.us.epil)
  %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.us, label %.epil.preheader, !llvm.loop !11

._crit_edge.us:                                   ; preds = %.epil.preheader, %._crit_edge.us.unr-lcssa
  %.lcssa = phi float [ %.lcssa.ph, %._crit_edge.us.unr-lcssa ], [ %34, %.epil.preheader ]
  store float %.lcssa, ptr %9, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond29.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond29.not, label %._crit_edge25, label %.lr.ph.us, !llvm.loop !13

._crit_edge25:                                    ; preds = %._crit_edge.us, %.lr.ph24.split.preheader, %4
  ret void
}

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

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

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


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