; LLVM IR from casensiom/fast-image-processing :: src (convolution)

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

@__const.applyGaussianBlur.Gaus3x3 = external hidden unnamed_addr constant [9 x i8], align 1
@__const.applyGaussianBlur.Gaus5x5 = external hidden unnamed_addr constant [25 x i8], align 16

; 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 willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @applyGaussianBlur(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) #2 {
  %6 = alloca i8, align 1
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca [9 x i8], align 1
  %14 = alloca i32, align 4
  %15 = alloca [25 x i8], align 16
  %16 = alloca ptr, align 8
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  %19 = alloca ptr, align 8
  %20 = alloca i32, align 4
  %21 = alloca i32, align 4
  %22 = alloca i32, align 4
  %23 = alloca i32, align 4
  %24 = alloca i8, align 1
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store i32 %2, ptr %9, align 4, !tbaa !9
  store i32 %3, ptr %10, align 4, !tbaa !9
  store i32 %4, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  store i32 16, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 9, ptr %13) #3
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %13, ptr align 1 @__const.applyGaussianBlur.Gaus3x3, i64 9, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  store i32 159, ptr %14, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 25, ptr %15) #3
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %15, ptr align 16 @__const.applyGaussianBlur.Gaus5x5, i64 25, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  %25 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %25, ptr %16, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %20) #3
  %26 = load i32, ptr %11, align 4, !tbaa !9
  %27 = icmp eq i32 %26, 5
  br i1 %27, label %28, label %30

28:                                               ; preds = %5
  %29 = getelementptr inbounds [25 x i8], ptr %15, i64 0, i64 0
  store ptr %29, ptr %19, align 8, !tbaa !5
  store i32 159, ptr %20, align 4, !tbaa !9
  br label %32

30:                                               ; preds = %5
  store i32 3, ptr %11, align 4, !tbaa !9
  %31 = getelementptr inbounds [9 x i8], ptr %13, i64 0, i64 0
  store ptr %31, ptr %19, align 8, !tbaa !5
  store i32 16, ptr %20, align 4, !tbaa !9
  br label %32

32:                                               ; preds = %30, %28
  %33 = load i32, ptr %11, align 4, !tbaa !9
  store i32 %33, ptr %17, align 4, !tbaa !9
  %34 = load i32, ptr %11, align 4, !tbaa !9
  store i32 %34, ptr %18, align 4, !tbaa !9
  %35 = load i32, ptr %11, align 4, !tbaa !9
  %36 = load i32, ptr %9, align 4, !tbaa !9
  %37 = icmp ugt i32 %35, %36
  br i1 %37, label %42, label %38

38:                                               ; preds = %32
  %39 = load i32, ptr %11, align 4, !tbaa !9
  %40 = load i32, ptr %10, align 4, !tbaa !9
  %41 = icmp ugt i32 %39, %40
  br i1 %41, label %42, label %43

42:                                               ; preds = %38, %32
  store i8 0, ptr %6, align 1
  store i32 1, ptr %21, align 4
  br label %97

43:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 4, ptr %22) #3
  %44 = load i32, ptr %9, align 4, !tbaa !9
  %45 = load i32, ptr %11, align 4, !tbaa !9
  %46 = sub i32 %44, %45
  store i32 %46, ptr %22, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %23) #3
  %47 = load i32, ptr %10, align 4, !tbaa !9
  %48 = load i32, ptr %11, align 4, !tbaa !9
  %49 = sub i32 %47, %48
  store i32 %49, ptr %23, align 4, !tbaa !9
  %50 = load ptr, ptr %8, align 8, !tbaa !5
  %51 = load i32, ptr %11, align 4, !tbaa !9
  %52 = load i32, ptr %11, align 4, !tbaa !9
  %53 = load i32, ptr %9, align 4, !tbaa !9
  %54 = mul i32 %52, %53
  %55 = add i32 %51, %54
  %56 = zext i32 %55 to i64
  %57 = getelementptr inbounds i8, ptr %50, i64 %56
  store ptr %57, ptr %16, align 8, !tbaa !5
  %58 = load i32, ptr %11, align 4, !tbaa !9
  store i32 %58, ptr %18, align 4, !tbaa !9
  br label %59

59:                                               ; preds = %93, %43
  %60 = load i32, ptr %18, align 4, !tbaa !9
  %61 = load i32, ptr %23, align 4, !tbaa !9
  %62 = icmp ult i32 %60, %61
  br i1 %62, label %63, label %96

63:                                               ; preds = %59
  %64 = load i32, ptr %11, align 4, !tbaa !9
  store i32 %64, ptr %17, align 4, !tbaa !9
  br label %65

65:                                               ; preds = %84, %63
  %66 = load i32, ptr %17, align 4, !tbaa !9
  %67 = load i32, ptr %22, align 4, !tbaa !9
  %68 = icmp ult i32 %66, %67
  br i1 %68, label %69, label %87

69:                                               ; preds = %65
  call void @llvm.lifetime.start.p0(i64 1, ptr %24) #3
  %70 = load ptr, ptr %7, align 8, !tbaa !5
  %71 = load i32, ptr %9, align 4, !tbaa !9
  %72 = load i32, ptr %10, align 4, !tbaa !9
  %73 = load i32, ptr %17, align 4, !tbaa !9
  %74 = load i32, ptr %18, align 4, !tbaa !9
  %75 = load ptr, ptr %19, align 8, !tbaa !5
  %76 = load i32, ptr %11, align 4, !tbaa !9
  %77 = trunc i32 %76 to i8
  %78 = load i32, ptr %20, align 4, !tbaa !9
  %79 = call zeroext i8 @applyConvolution(ptr noundef %70, i32 noundef %71, i32 noundef %72, i32 noundef %73, i32 noundef %74, ptr noundef %75, i8 noundef zeroext %77, i32 noundef %78)
  store i8 %79, ptr %24, align 1, !tbaa !11
  %80 = load i8, ptr %24, align 1, !tbaa !11
  %81 = load ptr, ptr %16, align 8, !tbaa !5
  store i8 %80, ptr %81, align 1, !tbaa !11
  %82 = load ptr, ptr %16, align 8, !tbaa !5
  %83 = getelementptr inbounds i8, ptr %82, i32 1
  store ptr %83, ptr %16, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 1, ptr %24) #3
  br label %84

84:                                               ; preds = %69
  %85 = load i32, ptr %17, align 4, !tbaa !9
  %86 = add i32 %85, 1
  store i32 %86, ptr %17, align 4, !tbaa !9
  br label %65, !llvm.loop !12

87:                                               ; preds = %65
  %88 = load i32, ptr %11, align 4, !tbaa !9
  %89 = sub i32 %88, 1
  %90 = load ptr, ptr %16, align 8, !tbaa !5
  %91 = zext i32 %89 to i64
  %92 = getelementptr inbounds i8, ptr %90, i64 %91
  store ptr %92, ptr %16, align 8, !tbaa !5
  br label %93

93:                                               ; preds = %87
  %94 = load i32, ptr %18, align 4, !tbaa !9
  %95 = add i32 %94, 1
  store i32 %95, ptr %18, align 4, !tbaa !9
  br label %59, !llvm.loop !14

96:                                               ; preds = %59
  store i8 1, ptr %6, align 1
  store i32 1, ptr %21, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %23) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %22) #3
  br label %97

97:                                               ; preds = %96, %42
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 25, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 9, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  %98 = load i8, ptr %6, align 1
  ret i8 %98
}

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @applyConvolution(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef, i8 noundef zeroext, i32 noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


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

@__const.applyGaussianBlur.Gaus3x3 = external hidden unnamed_addr constant [9 x i8], align 1
@__const.applyGaussianBlur.Gaus5x5 = external hidden unnamed_addr constant [25 x i8], align 16

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

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: nounwind uwtable
define dso_local zeroext range(i8 0, 2) i8 @applyGaussianBlur(ptr noundef %0, ptr nocapture noundef writeonly %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #2 {
  %6 = alloca [9 x i8], align 1
  %7 = alloca [25 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 9, ptr nonnull %6) #3
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(9) %6, ptr noundef nonnull align 1 dereferenceable(9) @__const.applyGaussianBlur.Gaus3x3, i64 9, i1 false)
  call void @llvm.lifetime.start.p0(i64 25, ptr nonnull %7) #3
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(25) %7, ptr noundef nonnull align 16 dereferenceable(25) @__const.applyGaussianBlur.Gaus5x5, i64 25, i1 false)
  %8 = icmp eq i32 %4, 5
  %. = select i1 %8, ptr %7, ptr %6
  %.46 = select i1 %8, i32 159, i32 16
  %.47 = select i1 %8, i32 5, i32 3
  %9 = icmp ugt i32 %.47, %2
  %10 = icmp ugt i32 %.47, %3
  %or.cond = or i1 %9, %10
  br i1 %or.cond, label %.loopexit, label %11

11:                                               ; preds = %5
  %12 = sub i32 %2, %.47
  %13 = sub i32 %3, %.47
  %14 = icmp ult i32 %.47, %13
  br i1 %14, label %.preheader.lr.ph, label %.loopexit

.preheader.lr.ph:                                 ; preds = %11
  %15 = icmp ult i32 %.47, %12
  %16 = trunc nuw nsw i32 %.47 to i8
  br i1 %15, label %.preheader.us.preheader, label %.loopexit

.preheader.us.preheader:                          ; preds = %.preheader.lr.ph
  %17 = add i32 %2, 1
  %18 = mul i32 %.47, %17
  %19 = zext i32 %18 to i64
  %20 = getelementptr inbounds i8, ptr %1, i64 %19
  %21 = zext nneg i32 %.47 to i64
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge.us
  %.03851.us = phi ptr [ %27, %._crit_edge.us ], [ %20, %.preheader.us.preheader ]
  %.04150.us = phi i32 [ %28, %._crit_edge.us ], [ %.47, %.preheader.us.preheader ]
  br label %22

22:                                               ; preds = %.preheader.us, %22
  %.149.us = phi ptr [ %.03851.us, %.preheader.us ], [ %24, %22 ]
  %.04248.us = phi i32 [ %.47, %.preheader.us ], [ %25, %22 ]
  %23 = call zeroext i8 @applyConvolution(ptr noundef %0, i32 noundef %2, i32 noundef %3, i32 noundef %.04248.us, i32 noundef %.04150.us, ptr noundef nonnull %., i8 noundef zeroext %16, i32 noundef %.46)
  store i8 %23, ptr %.149.us, align 1, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %.149.us, i64 1
  %25 = add i32 %.04248.us, 1
  %exitcond.not = icmp eq i32 %25, %12
  br i1 %exitcond.not, label %._crit_edge.us, label %22, !llvm.loop !8

._crit_edge.us:                                   ; preds = %22
  %26 = getelementptr i8, ptr %24, i64 %21
  %27 = getelementptr i8, ptr %26, i64 -1
  %28 = add i32 %.04150.us, 1
  %exitcond53.not = icmp eq i32 %28, %13
  br i1 %exitcond53.not, label %.loopexit, label %.preheader.us, !llvm.loop !10

.loopexit:                                        ; preds = %._crit_edge.us, %.preheader.lr.ph, %11, %5
  %.0 = phi i8 [ 0, %5 ], [ 1, %11 ], [ 1, %.preheader.lr.ph ], [ 1, %._crit_edge.us ]
  call void @llvm.lifetime.end.p0(i64 25, ptr nonnull %7) #3
  call void @llvm.lifetime.end.p0(i64 9, ptr nonnull %6) #3
  ret i8 %.0
}

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @applyConvolution(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef, i8 noundef zeroext, i32 noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = distinct !{!10, !9}


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