; 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: nounwind uwtable
define dso_local void @apply_kernel_scanline(ptr noundef %0, ptr noundef %1, i64 noundef %2, i64 noundef %3, ptr noundef %4) #0 {
  %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
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  %16 = alloca ptr, align 8
  %17 = alloca ptr, 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
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #3
  store i64 0, ptr %12, align 8, !tbaa !9
  br label %18

18:                                               ; preds = %66, %5
  %19 = load i64, ptr %12, align 8, !tbaa !9
  %20 = load i64, ptr %8, align 8, !tbaa !9
  %21 = icmp ult i64 %19, %20
  br i1 %21, label %22, label %69

22:                                               ; preds = %18
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = load i64, ptr %12, align 8, !tbaa !9
  %25 = getelementptr inbounds ptr, ptr %23, i64 %24
  %26 = load ptr, ptr %25, align 8, !tbaa !5
  store ptr %26, ptr %14, align 8, !tbaa !5
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = load i64, ptr %12, align 8, !tbaa !9
  %29 = getelementptr inbounds ptr, ptr %27, i64 %28
  %30 = load ptr, ptr %29, align 8, !tbaa !5
  store ptr %30, ptr %15, align 8, !tbaa !5
  store i64 0, ptr %11, align 8, !tbaa !9
  br label %31

31:                                               ; preds = %62, %22
  %32 = load i64, ptr %11, align 8, !tbaa !9
  %33 = load i64, ptr %9, align 8, !tbaa !9
  %34 = icmp ult i64 %32, %33
  br i1 %34, label %35, label %65

35:                                               ; preds = %31
  %36 = load ptr, ptr %15, align 8, !tbaa !5
  %37 = load i64, ptr %11, align 8, !tbaa !9
  %38 = getelementptr inbounds float, ptr %36, i64 %37
  store ptr %38, ptr %16, align 8, !tbaa !5
  %39 = load ptr, ptr %10, align 8, !tbaa !5
  %40 = load i64, ptr %11, align 8, !tbaa !9
  %41 = getelementptr inbounds float, ptr %39, i64 %40
  store ptr %41, ptr %17, align 8, !tbaa !5
  store i64 0, ptr %13, align 8, !tbaa !9
  br label %42

42:                                               ; preds = %58, %35
  %43 = load i64, ptr %13, align 8, !tbaa !9
  %44 = load i64, ptr %8, align 8, !tbaa !9
  %45 = icmp ult i64 %43, %44
  br i1 %45, label %46, label %61

46:                                               ; preds = %42
  %47 = load ptr, ptr %16, align 8, !tbaa !5
  %48 = load i64, ptr %13, align 8, !tbaa !9
  %49 = getelementptr inbounds float, ptr %47, i64 %48
  %50 = load float, ptr %49, align 4, !tbaa !11
  %51 = load ptr, ptr %14, align 8, !tbaa !5
  %52 = load i64, ptr %13, align 8, !tbaa !9
  %53 = getelementptr inbounds float, ptr %51, i64 %52
  %54 = load float, ptr %53, align 4, !tbaa !11
  %55 = load ptr, ptr %17, align 8, !tbaa !5
  %56 = load float, ptr %55, align 4, !tbaa !11
  %57 = call float @llvm.fmuladd.f32(float %50, float %54, float %56)
  store float %57, ptr %55, align 4, !tbaa !11
  br label %58

58:                                               ; preds = %46
  %59 = load i64, ptr %13, align 8, !tbaa !9
  %60 = add i64 %59, 1
  store i64 %60, ptr %13, align 8, !tbaa !9
  br label %42, !llvm.loop !13

61:                                               ; preds = %42
  br label %62

62:                                               ; preds = %61
  %63 = load i64, ptr %11, align 8, !tbaa !9
  %64 = add i64 %63, 1
  store i64 %64, ptr %11, align 8, !tbaa !9
  br label %31, !llvm.loop !15

65:                                               ; preds = %31
  br label %66

66:                                               ; preds = %65
  %67 = load i64, ptr %12, align 8, !tbaa !9
  %68 = add i64 %67, 1
  store i64 %68, ptr %12, align 8, !tbaa !9
  br label %18, !llvm.loop !16

69:                                               ; preds = %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  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
  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 = !{!"long", !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(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local void @apply_kernel_scanline(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, i64 noundef %2, i64 noundef %3, ptr nocapture noundef %4) local_unnamed_addr #0 {
  %.not = icmp eq i64 %2, 0
  %.not30 = icmp eq i64 %3, 0
  %or.cond = or i1 %.not, %.not30
  br i1 %or.cond, label %._crit_edge29, label %.lr.ph.us.preheader

.lr.ph.us.preheader:                              ; preds = %5
  %xtraiter = and i64 %2, 1
  %6 = icmp eq i64 %2, 1
  %unroll_iter = and i64 %2, -2
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.lr.ph.us

.lr.ph.us:                                        ; preds = %.lr.ph.us.preheader, %._crit_edge.us
  %.02126.us = phi i64 [ %34, %._crit_edge.us ], [ 0, %.lr.ph.us.preheader ]
  %7 = getelementptr inbounds ptr, ptr %0, i64 %.02126.us
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  %9 = getelementptr inbounds ptr, ptr %1, i64 %.02126.us
  %10 = load ptr, ptr %9, align 8, !tbaa !5
  br label %11

11:                                               ; preds = %.lr.ph.us, %19
  %.025.us = phi i64 [ 0, %.lr.ph.us ], [ %20, %19 ]
  %12 = getelementptr inbounds float, ptr %10, i64 %.025.us
  %13 = getelementptr inbounds float, ptr %4, i64 %.025.us
  %.promoted.us = load float, ptr %13, align 4, !tbaa !9
  br i1 %6, label %.unr-lcssa, label %.new

.unr-lcssa:                                       ; preds = %.new, %11
  %.02224.us.unr = phi i64 [ 0, %11 ], [ %33, %.new ]
  %.unr = phi float [ %.promoted.us, %11 ], [ %32, %.new ]
  br i1 %lcmp.mod.not, label %19, label %.epilog-lcssa

.epilog-lcssa:                                    ; preds = %.unr-lcssa
  %14 = getelementptr inbounds float, ptr %12, i64 %.02224.us.unr
  %15 = load float, ptr %14, align 4, !tbaa !9
  %16 = getelementptr inbounds float, ptr %8, i64 %.02224.us.unr
  %17 = load float, ptr %16, align 4, !tbaa !9
  %18 = tail call float @llvm.fmuladd.f32(float %15, float %17, float %.unr)
  store float %18, ptr %13, align 4, !tbaa !9
  br label %19

19:                                               ; preds = %.unr-lcssa, %.epilog-lcssa
  %20 = add nuw i64 %.025.us, 1
  %exitcond32.not = icmp eq i64 %20, %3
  br i1 %exitcond32.not, label %._crit_edge.us, label %11, !llvm.loop !11

.new:                                             ; preds = %11, %.new
  %.02224.us = phi i64 [ %33, %.new ], [ 0, %11 ]
  %21 = phi float [ %32, %.new ], [ %.promoted.us, %11 ]
  %niter = phi i64 [ %niter.next.1, %.new ], [ 0, %11 ]
  %22 = getelementptr inbounds float, ptr %12, i64 %.02224.us
  %23 = load float, ptr %22, align 4, !tbaa !9
  %24 = getelementptr inbounds float, ptr %8, i64 %.02224.us
  %25 = load float, ptr %24, align 4, !tbaa !9
  %26 = tail call float @llvm.fmuladd.f32(float %23, float %25, float %21)
  store float %26, ptr %13, align 4, !tbaa !9
  %27 = or disjoint i64 %.02224.us, 1
  %28 = getelementptr inbounds float, ptr %12, i64 %27
  %29 = load float, ptr %28, align 4, !tbaa !9
  %30 = getelementptr inbounds float, ptr %8, i64 %27
  %31 = load float, ptr %30, align 4, !tbaa !9
  %32 = tail call float @llvm.fmuladd.f32(float %29, float %31, float %26)
  store float %32, ptr %13, align 4, !tbaa !9
  %33 = add nuw i64 %.02224.us, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %.unr-lcssa, label %.new, !llvm.loop !13

._crit_edge.us:                                   ; preds = %19
  %34 = add nuw i64 %.02126.us, 1
  %exitcond33.not = icmp eq i64 %34, %2
  br i1 %exitcond33.not, label %._crit_edge29, label %.lr.ph.us, !llvm.loop !14

._crit_edge29:                                    ; preds = %._crit_edge.us, %5
  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(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 #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 = !{!"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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}


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