; LLVM IR from cpuimage/cpuimagelib :: cpuimage (CPUImageLuminanceThresholdFilter)

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i8 @step(i8 noundef zeroext, i8 noundef zeroext) #1

; Function Attrs: nounwind uwtable
define dso_local void @CPUImageLuminanceThresholdFilter(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i8 noundef zeroext %5) #2 {
  %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 i8, align 1
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca ptr, align 8
  %17 = alloca ptr, align 8
  %18 = alloca i32, align 4
  %19 = alloca i32, align 4
  %20 = alloca ptr, align 8
  %21 = alloca ptr, align 8
  %22 = alloca i32, align 4
  %23 = 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
  store i8 %5, ptr %12, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %24 = load i32, ptr %11, align 4, !tbaa !9
  %25 = load i32, ptr %9, align 4, !tbaa !9
  %26 = sdiv i32 %24, %25
  store i32 %26, ptr %13, align 4, !tbaa !9
  %27 = load i32, ptr %13, align 4, !tbaa !9
  %28 = icmp eq i32 %27, 1
  br i1 %28, label %29, label %73

29:                                               ; preds = %6
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  store i32 0, ptr %14, align 4, !tbaa !9
  br label %30

30:                                               ; preds = %69, %29
  %31 = load i32, ptr %14, align 4, !tbaa !9
  %32 = load i32, ptr %10, align 4, !tbaa !9
  %33 = icmp slt i32 %31, %32
  br i1 %33, label %35, label %34

34:                                               ; preds = %30
  store i32 2, ptr %15, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  br label %72

35:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  %37 = load i32, ptr %14, align 4, !tbaa !9
  %38 = load i32, ptr %11, align 4, !tbaa !9
  %39 = mul nsw i32 %37, %38
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds i8, ptr %36, i64 %40
  store ptr %41, ptr %16, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #3
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = load i32, ptr %14, align 4, !tbaa !9
  %44 = load i32, ptr %11, align 4, !tbaa !9
  %45 = mul nsw i32 %43, %44
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds i8, ptr %42, i64 %46
  store ptr %47, ptr %17, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #3
  store i32 0, ptr %18, align 4, !tbaa !9
  br label %48

48:                                               ; preds = %65, %35
  %49 = load i32, ptr %18, align 4, !tbaa !9
  %50 = load i32, ptr %9, align 4, !tbaa !9
  %51 = icmp slt i32 %49, %50
  br i1 %51, label %53, label %52

52:                                               ; preds = %48
  store i32 5, ptr %15, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #3
  br label %68

53:                                               ; preds = %48
  %54 = load i8, ptr %12, align 1, !tbaa !11
  %55 = load ptr, ptr %17, align 8, !tbaa !5
  %56 = getelementptr inbounds i8, ptr %55, i64 0
  %57 = load i8, ptr %56, align 1, !tbaa !11
  %58 = call zeroext i8 @step(i8 noundef zeroext %54, i8 noundef zeroext %57)
  %59 = load ptr, ptr %16, align 8, !tbaa !5
  %60 = getelementptr inbounds i8, ptr %59, i64 0
  store i8 %58, ptr %60, align 1, !tbaa !11
  %61 = load ptr, ptr %17, align 8, !tbaa !5
  %62 = getelementptr inbounds i8, ptr %61, i32 1
  store ptr %62, ptr %17, align 8, !tbaa !5
  %63 = load ptr, ptr %16, align 8, !tbaa !5
  %64 = getelementptr inbounds i8, ptr %63, i32 1
  store ptr %64, ptr %16, align 8, !tbaa !5
  br label %65

65:                                               ; preds = %53
  %66 = load i32, ptr %18, align 4, !tbaa !9
  %67 = add nsw i32 %66, 1
  store i32 %67, ptr %18, align 4, !tbaa !9
  br label %48, !llvm.loop !12

68:                                               ; preds = %52
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  br label %69

69:                                               ; preds = %68
  %70 = load i32, ptr %14, align 4, !tbaa !9
  %71 = add nsw i32 %70, 1
  store i32 %71, ptr %14, align 4, !tbaa !9
  br label %30, !llvm.loop !14

72:                                               ; preds = %34
  store i32 1, ptr %15, align 4
  br label %142

73:                                               ; preds = %6
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #3
  store i32 0, ptr %19, align 4, !tbaa !9
  br label %74

74:                                               ; preds = %138, %73
  %75 = load i32, ptr %19, align 4, !tbaa !9
  %76 = load i32, ptr %10, align 4, !tbaa !9
  %77 = icmp slt i32 %75, %76
  br i1 %77, label %79, label %78

78:                                               ; preds = %74
  store i32 8, ptr %15, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #3
  br label %141

79:                                               ; preds = %74
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #3
  %80 = load ptr, ptr %8, align 8, !tbaa !5
  %81 = load i32, ptr %19, align 4, !tbaa !9
  %82 = load i32, ptr %11, align 4, !tbaa !9
  %83 = mul nsw i32 %81, %82
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds i8, ptr %80, i64 %84
  store ptr %85, ptr %20, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %21) #3
  %86 = load ptr, ptr %7, align 8, !tbaa !5
  %87 = load i32, ptr %19, align 4, !tbaa !9
  %88 = load i32, ptr %11, align 4, !tbaa !9
  %89 = mul nsw i32 %87, %88
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds i8, ptr %86, i64 %90
  store ptr %91, ptr %21, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %22) #3
  store i32 0, ptr %22, align 4, !tbaa !9
  br label %92

92:                                               ; preds = %134, %79
  %93 = load i32, ptr %22, align 4, !tbaa !9
  %94 = load i32, ptr %9, align 4, !tbaa !9
  %95 = icmp slt i32 %93, %94
  br i1 %95, label %97, label %96

96:                                               ; preds = %92
  store i32 11, ptr %15, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %22) #3
  br label %137

97:                                               ; preds = %92
  call void @llvm.lifetime.start.p0(i64 1, ptr %23) #3
  %98 = load ptr, ptr %21, align 8, !tbaa !5
  %99 = getelementptr inbounds i8, ptr %98, i64 0
  %100 = load i8, ptr %99, align 1, !tbaa !11
  %101 = zext i8 %100 to i32
  %102 = mul nsw i32 13926, %101
  %103 = load ptr, ptr %21, align 8, !tbaa !5
  %104 = getelementptr inbounds i8, ptr %103, i64 1
  %105 = load i8, ptr %104, align 1, !tbaa !11
  %106 = zext i8 %105 to i32
  %107 = mul nsw i32 46884, %106
  %108 = add nsw i32 %102, %107
  %109 = load ptr, ptr %21, align 8, !tbaa !5
  %110 = getelementptr inbounds i8, ptr %109, i64 2
  %111 = load i8, ptr %110, align 1, !tbaa !11
  %112 = zext i8 %111 to i32
  %113 = mul nsw i32 4725, %112
  %114 = add nsw i32 %108, %113
  %115 = ashr i32 %114, 16
  %116 = trunc i32 %115 to i8
  store i8 %116, ptr %23, align 1, !tbaa !11
  %117 = load i8, ptr %12, align 1, !tbaa !11
  %118 = load i8, ptr %23, align 1, !tbaa !11
  %119 = call zeroext i8 @step(i8 noundef zeroext %117, i8 noundef zeroext %118)
  %120 = load ptr, ptr %20, align 8, !tbaa !5
  %121 = getelementptr inbounds i8, ptr %120, i64 0
  store i8 %119, ptr %121, align 1, !tbaa !11
  %122 = load ptr, ptr %20, align 8, !tbaa !5
  %123 = getelementptr inbounds i8, ptr %122, i64 1
  store i8 %119, ptr %123, align 1, !tbaa !11
  %124 = load ptr, ptr %20, align 8, !tbaa !5
  %125 = getelementptr inbounds i8, ptr %124, i64 2
  store i8 %119, ptr %125, align 1, !tbaa !11
  %126 = load i32, ptr %13, align 4, !tbaa !9
  %127 = load ptr, ptr %21, align 8, !tbaa !5
  %128 = sext i32 %126 to i64
  %129 = getelementptr inbounds i8, ptr %127, i64 %128
  store ptr %129, ptr %21, align 8, !tbaa !5
  %130 = load i32, ptr %13, align 4, !tbaa !9
  %131 = load ptr, ptr %20, align 8, !tbaa !5
  %132 = sext i32 %130 to i64
  %133 = getelementptr inbounds i8, ptr %131, i64 %132
  store ptr %133, ptr %20, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 1, ptr %23) #3
  br label %134

134:                                              ; preds = %97
  %135 = load i32, ptr %22, align 4, !tbaa !9
  %136 = add nsw i32 %135, 1
  store i32 %136, ptr %22, align 4, !tbaa !9
  br label %92, !llvm.loop !15

137:                                              ; preds = %96
  call void @llvm.lifetime.end.p0(i64 8, ptr %21) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #3
  br label %138

138:                                              ; preds = %137
  %139 = load i32, ptr %19, align 4, !tbaa !9
  %140 = add nsw i32 %139, 1
  store i32 %140, ptr %19, align 4, !tbaa !9
  br label %74, !llvm.loop !16

141:                                              ; preds = %78
  store i32 0, ptr %15, align 4
  br label %142

142:                                              ; preds = %141, %72
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  %143 = load i32, ptr %15, align 4
  switch i32 %143, label %145 [
    i32 0, label %144
    i32 1, label %144
  ]

144:                                              ; preds = %142, %142
  ret void

145:                                              ; preds = %142
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 #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}
!15 = distinct !{!15, !13}
!16 = distinct !{!16, !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"

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i8 @step(i8 noundef zeroext, i8 noundef zeroext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @CPUImageLuminanceThresholdFilter(ptr nocapture noundef readonly %0, ptr nocapture noundef writeonly %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i8 noundef zeroext %5) local_unnamed_addr #1 {
  %7 = sdiv i32 %4, %2
  %8 = icmp eq i32 %7, 1
  %9 = icmp sgt i32 %3, 0
  br i1 %8, label %.preheader, label %.preheader51

.preheader51:                                     ; preds = %6
  br i1 %9, label %.lr.ph57, label %.loopexit

.lr.ph57:                                         ; preds = %.preheader51
  %10 = icmp sgt i32 %2, 0
  %11 = sext i32 %7 to i64
  br i1 %10, label %.lr.ph.us.preheader, label %.loopexit

.lr.ph.us.preheader:                              ; preds = %.lr.ph57
  %12 = sext i32 %4 to i64
  %wide.trip.count = zext nneg i32 %3 to i64
  br label %.lr.ph.us

.lr.ph.us:                                        ; preds = %.lr.ph.us.preheader, %._crit_edge.us
  %indvars.iv = phi i64 [ 0, %.lr.ph.us.preheader ], [ %indvars.iv.next, %._crit_edge.us ]
  %13 = mul nsw i64 %indvars.iv, %12
  %14 = getelementptr inbounds i8, ptr %1, i64 %13
  %15 = getelementptr inbounds i8, ptr %0, i64 %13
  br label %16

16:                                               ; preds = %.lr.ph.us, %16
  %.04355.us = phi i32 [ 0, %.lr.ph.us ], [ %37, %16 ]
  %.04454.us = phi ptr [ %15, %.lr.ph.us ], [ %35, %16 ]
  %.04553.us = phi ptr [ %14, %.lr.ph.us ], [ %36, %16 ]
  %17 = load i8, ptr %.04454.us, align 1, !tbaa !5
  %18 = zext i8 %17 to i32
  %19 = mul nuw nsw i32 %18, 13926
  %20 = getelementptr inbounds i8, ptr %.04454.us, i64 1
  %21 = load i8, ptr %20, align 1, !tbaa !5
  %22 = zext i8 %21 to i32
  %23 = mul nuw nsw i32 %22, 46884
  %24 = add nuw nsw i32 %23, %19
  %25 = getelementptr inbounds i8, ptr %.04454.us, i64 2
  %26 = load i8, ptr %25, align 1, !tbaa !5
  %27 = zext i8 %26 to i32
  %28 = mul nuw nsw i32 %27, 4725
  %29 = add nuw nsw i32 %24, %28
  %30 = lshr i32 %29, 16
  %31 = trunc nuw i32 %30 to i8
  %32 = tail call zeroext i8 @step(i8 noundef zeroext %5, i8 noundef zeroext %31)
  store i8 %32, ptr %.04553.us, align 1, !tbaa !5
  %33 = getelementptr inbounds i8, ptr %.04553.us, i64 1
  store i8 %32, ptr %33, align 1, !tbaa !5
  %34 = getelementptr inbounds i8, ptr %.04553.us, i64 2
  store i8 %32, ptr %34, align 1, !tbaa !5
  %35 = getelementptr inbounds i8, ptr %.04454.us, i64 %11
  %36 = getelementptr inbounds i8, ptr %.04553.us, i64 %11
  %37 = add nuw nsw i32 %.04355.us, 1
  %exitcond.not = icmp eq i32 %37, %2
  br i1 %exitcond.not, label %._crit_edge.us, label %16, !llvm.loop !8

._crit_edge.us:                                   ; preds = %16
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond69.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond69.not, label %.loopexit, label %.lr.ph.us, !llvm.loop !10

.preheader:                                       ; preds = %6
  %38 = icmp sgt i32 %2, 0
  %or.cond = and i1 %9, %38
  br i1 %or.cond, label %.lr.ph.us63.preheader, label %.loopexit

.lr.ph.us63.preheader:                            ; preds = %.preheader
  %39 = sext i32 %4 to i64
  %wide.trip.count74 = zext nneg i32 %3 to i64
  br label %.lr.ph.us63

.lr.ph.us63:                                      ; preds = %.lr.ph.us63.preheader, %._crit_edge.us64
  %indvars.iv71 = phi i64 [ 0, %.lr.ph.us63.preheader ], [ %indvars.iv.next72, %._crit_edge.us64 ]
  %40 = mul nsw i64 %indvars.iv71, %39
  %41 = getelementptr inbounds i8, ptr %1, i64 %40
  %42 = getelementptr inbounds i8, ptr %0, i64 %40
  br label %43

43:                                               ; preds = %.lr.ph.us63, %43
  %.04760.us = phi i32 [ 0, %.lr.ph.us63 ], [ %48, %43 ]
  %.04859.us = phi ptr [ %42, %.lr.ph.us63 ], [ %46, %43 ]
  %.04958.us = phi ptr [ %41, %.lr.ph.us63 ], [ %47, %43 ]
  %44 = load i8, ptr %.04859.us, align 1, !tbaa !5
  %45 = tail call zeroext i8 @step(i8 noundef zeroext %5, i8 noundef zeroext %44)
  store i8 %45, ptr %.04958.us, align 1, !tbaa !5
  %46 = getelementptr inbounds i8, ptr %.04859.us, i64 1
  %47 = getelementptr inbounds i8, ptr %.04958.us, i64 1
  %48 = add nuw nsw i32 %.04760.us, 1
  %exitcond70.not = icmp eq i32 %48, %2
  br i1 %exitcond70.not, label %._crit_edge.us64, label %43, !llvm.loop !11

._crit_edge.us64:                                 ; preds = %43
  %indvars.iv.next72 = add nuw nsw i64 %indvars.iv71, 1
  %exitcond75.not = icmp eq i64 %indvars.iv.next72, %wide.trip.count74
  br i1 %exitcond75.not, label %.loopexit, label %.lr.ph.us63, !llvm.loop !12

.loopexit:                                        ; preds = %._crit_edge.us, %._crit_edge.us64, %.lr.ph57, %.preheader51, %.preheader
  ret void
}

attributes #0 = { inlinehint 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 = { 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" }

!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}
!11 = distinct !{!11, !9}
!12 = distinct !{!12, !9}


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