; LLVM IR from clunietp/libgmsd :: src (convolve)

; 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: nounwind uwtable
define dso_local void @apply_kernel_scanline_2x2(ptr noundef %0, ptr noundef %1, i64 noundef %2, i64 noundef %3, ptr noundef %4) #2 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i64 %2, ptr %8, align 8, !tbaa !9
  store i64 %3, ptr %9, align 8, !tbaa !9
  store ptr %4, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  store i64 0, ptr %11, align 8, !tbaa !9
  br label %12

12:                                               ; preds = %70, %5
  %13 = load i64, ptr %11, align 8, !tbaa !9
  %14 = load i64, ptr %9, align 8, !tbaa !9
  %15 = icmp ult i64 %13, %14
  br i1 %15, label %16, label %73

16:                                               ; preds = %12
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = getelementptr inbounds ptr, ptr %17, i64 0
  %19 = load ptr, ptr %18, align 8, !tbaa !5
  %20 = getelementptr inbounds float, ptr %19, i64 0
  %21 = load float, ptr %20, align 4, !tbaa !11
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = getelementptr inbounds ptr, ptr %22, i64 0
  %24 = load ptr, ptr %23, align 8, !tbaa !5
  %25 = load i64, ptr %11, align 8, !tbaa !9
  %26 = getelementptr inbounds float, ptr %24, i64 %25
  %27 = load float, ptr %26, align 4, !tbaa !11
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = getelementptr inbounds ptr, ptr %28, i64 0
  %30 = load ptr, ptr %29, align 8, !tbaa !5
  %31 = getelementptr inbounds float, ptr %30, i64 1
  %32 = load float, ptr %31, align 4, !tbaa !11
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = getelementptr inbounds ptr, ptr %33, i64 0
  %35 = load ptr, ptr %34, align 8, !tbaa !5
  %36 = load i64, ptr %11, align 8, !tbaa !9
  %37 = add i64 %36, 1
  %38 = getelementptr inbounds float, ptr %35, i64 %37
  %39 = load float, ptr %38, align 4, !tbaa !11
  %40 = fmul float %32, %39
  %41 = call float @llvm.fmuladd.f32(float %21, float %27, float %40)
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = getelementptr inbounds ptr, ptr %42, i64 1
  %44 = load ptr, ptr %43, align 8, !tbaa !5
  %45 = getelementptr inbounds float, ptr %44, i64 0
  %46 = load float, ptr %45, align 4, !tbaa !11
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = getelementptr inbounds ptr, ptr %47, i64 1
  %49 = load ptr, ptr %48, align 8, !tbaa !5
  %50 = load i64, ptr %11, align 8, !tbaa !9
  %51 = getelementptr inbounds float, ptr %49, i64 %50
  %52 = load float, ptr %51, align 4, !tbaa !11
  %53 = call float @llvm.fmuladd.f32(float %46, float %52, float %41)
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = getelementptr inbounds ptr, ptr %54, i64 1
  %56 = load ptr, ptr %55, align 8, !tbaa !5
  %57 = getelementptr inbounds float, ptr %56, i64 1
  %58 = load float, ptr %57, align 4, !tbaa !11
  %59 = load ptr, ptr %7, align 8, !tbaa !5
  %60 = getelementptr inbounds ptr, ptr %59, i64 1
  %61 = load ptr, ptr %60, align 8, !tbaa !5
  %62 = load i64, ptr %11, align 8, !tbaa !9
  %63 = add i64 %62, 1
  %64 = getelementptr inbounds float, ptr %61, i64 %63
  %65 = load float, ptr %64, align 4, !tbaa !11
  %66 = call float @llvm.fmuladd.f32(float %58, float %65, float %53)
  %67 = load ptr, ptr %10, align 8, !tbaa !5
  %68 = load i64, ptr %11, align 8, !tbaa !9
  %69 = getelementptr inbounds float, ptr %67, i64 %68
  store float %66, ptr %69, align 4, !tbaa !11
  br label %70

70:                                               ; preds = %16
  %71 = load i64, ptr %11, align 8, !tbaa !9
  %72 = add i64 %71, 1
  store i64 %72, ptr %11, align 8, !tbaa !9
  br label %12, !llvm.loop !13

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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/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"

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

; Function Attrs: nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local void @apply_kernel_scanline_2x2(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, i64 noundef %2, i64 noundef %3, ptr nocapture noundef writeonly %4) local_unnamed_addr #1 {
  %.not = icmp eq i64 %3, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %5
  %6 = load ptr, ptr %1, align 8, !tbaa !5
  %7 = load <2 x ptr>, ptr %0, align 8, !tbaa !5
  %8 = extractelement <2 x ptr> %7, i64 0
  %9 = getelementptr inbounds i8, ptr %8, i64 4
  %10 = getelementptr inbounds i8, ptr %1, i64 8
  %11 = load ptr, ptr %10, align 8, !tbaa !5
  %12 = extractelement <2 x ptr> %7, i64 1
  %13 = getelementptr inbounds i8, ptr %12, i64 4
  %min.iters.check = icmp ult i64 %3, 8
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.memcheck

vector.memcheck:                                  ; preds = %.lr.ph
  %14 = shl i64 %3, 2
  %scevgep = getelementptr i8, ptr %4, i64 %14
  %15 = getelementptr i8, <2 x ptr> %7, <2 x i64> <i64 8, i64 8>
  %16 = add i64 %14, 4
  %scevgep18 = getelementptr i8, ptr %6, i64 %16
  %scevgep20 = getelementptr i8, ptr %11, i64 %16
  %17 = shufflevector <2 x ptr> %15, <2 x ptr> poison, <4 x i32> <i32 0, i32 1, i32 poison, i32 poison>
  %18 = insertelement <4 x ptr> %17, ptr %scevgep18, i64 2
  %19 = insertelement <4 x ptr> %18, ptr %scevgep20, i64 3
  %20 = insertelement <4 x ptr> poison, ptr %4, i64 0
  %21 = shufflevector <4 x ptr> %20, <4 x ptr> poison, <4 x i32> zeroinitializer
  %22 = icmp ugt <4 x ptr> %19, %21
  %23 = shufflevector <2 x ptr> %7, <2 x ptr> poison, <4 x i32> <i32 0, i32 1, i32 poison, i32 poison>
  %24 = insertelement <4 x ptr> %23, ptr %6, i64 2
  %25 = insertelement <4 x ptr> %24, ptr %11, i64 3
  %26 = insertelement <4 x ptr> poison, ptr %scevgep, i64 0
  %27 = shufflevector <4 x ptr> %26, <4 x ptr> poison, <4 x i32> zeroinitializer
  %28 = icmp ult <4 x ptr> %25, %27
  %29 = and <4 x i1> %22, %28
  %30 = bitcast <4 x i1> %29 to i4
  %.not41 = icmp eq i4 %30, 0
  br i1 %.not41, label %vector.ph, label %scalar.ph.preheader

vector.ph:                                        ; preds = %vector.memcheck
  %n.vec = and i64 %3, -4
  %31 = load float, ptr %8, align 4, !tbaa !9, !alias.scope !11
  %broadcast.splatinsert33 = insertelement <4 x float> poison, float %31, i64 0
  %broadcast.splat34 = shufflevector <4 x float> %broadcast.splatinsert33, <4 x float> poison, <4 x i32> zeroinitializer
  %32 = load float, ptr %9, align 4, !tbaa !9, !alias.scope !11
  %broadcast.splatinsert = insertelement <4 x float> poison, float %32, i64 0
  %broadcast.splat = shufflevector <4 x float> %broadcast.splatinsert, <4 x float> poison, <4 x i32> zeroinitializer
  %33 = load float, ptr %12, align 4, !tbaa !9, !alias.scope !14
  %broadcast.splatinsert36 = insertelement <4 x float> poison, float %33, i64 0
  %broadcast.splat37 = shufflevector <4 x float> %broadcast.splatinsert36, <4 x float> poison, <4 x i32> zeroinitializer
  %34 = load float, ptr %13, align 4, !tbaa !9, !alias.scope !14
  %broadcast.splatinsert39 = insertelement <4 x float> poison, float %34, i64 0
  %broadcast.splat40 = shufflevector <4 x float> %broadcast.splatinsert39, <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 ]
  %35 = getelementptr inbounds float, ptr %6, i64 %index
  %wide.load = load <4 x float>, ptr %35, align 4, !tbaa !9, !alias.scope !16
  %36 = or disjoint i64 %index, 1
  %37 = getelementptr inbounds float, ptr %6, i64 %36
  %wide.load32 = load <4 x float>, ptr %37, align 4, !tbaa !9, !alias.scope !16
  %38 = fmul <4 x float> %broadcast.splat, %wide.load32
  %39 = tail call <4 x float> @llvm.fmuladd.v4f32(<4 x float> %broadcast.splat34, <4 x float> %wide.load, <4 x float> %38)
  %40 = getelementptr inbounds float, ptr %11, i64 %index
  %wide.load35 = load <4 x float>, ptr %40, align 4, !tbaa !9, !alias.scope !18
  %41 = tail call <4 x float> @llvm.fmuladd.v4f32(<4 x float> %broadcast.splat37, <4 x float> %wide.load35, <4 x float> %39)
  %42 = getelementptr inbounds float, ptr %11, i64 %36
  %wide.load38 = load <4 x float>, ptr %42, align 4, !tbaa !9, !alias.scope !18
  %43 = tail call <4 x float> @llvm.fmuladd.v4f32(<4 x float> %broadcast.splat40, <4 x float> %wide.load38, <4 x float> %41)
  %44 = getelementptr inbounds float, ptr %4, i64 %index
  store <4 x float> %43, ptr %44, align 4, !tbaa !9, !alias.scope !20, !noalias !22
  %index.next = add nuw i64 %index, 4
  %45 = icmp eq i64 %index.next, %n.vec
  br i1 %45, label %middle.block, label %vector.body, !llvm.loop !23

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %3
  br i1 %cmp.n, label %._crit_edge, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %middle.block, %vector.memcheck, %.lr.ph
  %.016.ph = phi i64 [ 0, %vector.memcheck ], [ 0, %.lr.ph ], [ %n.vec, %middle.block ]
  br label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %.016 = phi i64 [ %50, %scalar.ph ], [ %.016.ph, %scalar.ph.preheader ]
  %46 = load float, ptr %8, align 4, !tbaa !9
  %47 = getelementptr inbounds float, ptr %6, i64 %.016
  %48 = load float, ptr %47, align 4, !tbaa !9
  %49 = load float, ptr %9, align 4, !tbaa !9
  %50 = add nuw i64 %.016, 1
  %51 = getelementptr inbounds float, ptr %6, i64 %50
  %52 = load float, ptr %51, align 4, !tbaa !9
  %53 = fmul float %49, %52
  %54 = tail call float @llvm.fmuladd.f32(float %46, float %48, float %53)
  %55 = load float, ptr %12, align 4, !tbaa !9
  %56 = getelementptr inbounds float, ptr %11, i64 %.016
  %57 = load float, ptr %56, align 4, !tbaa !9
  %58 = tail call float @llvm.fmuladd.f32(float %55, float %57, float %54)
  %59 = load float, ptr %13, align 4, !tbaa !9
  %60 = getelementptr inbounds float, ptr %11, i64 %50
  %61 = load float, ptr %60, align 4, !tbaa !9
  %62 = tail call float @llvm.fmuladd.f32(float %59, float %61, float %58)
  %63 = getelementptr inbounds float, ptr %4, i64 %.016
  store float %62, ptr %63, align 4, !tbaa !9
  %exitcond.not = icmp eq i64 %50, %3
  br i1 %exitcond.not, label %._crit_edge, label %scalar.ph, !llvm.loop !27

._crit_edge:                                      ; preds = %scalar.ph, %middle.block, %5
  ret void
}

; 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>) #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { 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 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"float", !7, i64 0}
!11 = !{!12}
!12 = distinct !{!12, !13}
!13 = distinct !{!13, !"LVerDomain"}
!14 = !{!15}
!15 = distinct !{!15, !13}
!16 = !{!17}
!17 = distinct !{!17, !13}
!18 = !{!19}
!19 = distinct !{!19, !13}
!20 = !{!21}
!21 = distinct !{!21, !13}
!22 = !{!12, !17, !15, !19}
!23 = distinct !{!23, !24, !25, !26}
!24 = !{!"llvm.loop.mustprogress"}
!25 = !{!"llvm.loop.isvectorized", i32 1}
!26 = !{!"llvm.loop.unroll.runtime.disable"}
!27 = distinct !{!27, !24, !25}


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