; LLVM IR from Wilson-ZheLin/Introduction-to-Digital-Image-Processing :: 8. Erosion, Dilation, Opening and Closing Operations, Boundary Extraction and Connect_4cba0230 (MarkPixelsP5ImagePiiii)

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

%struct.Image = type { i32, i32, i32, ptr, [15 x [100 x i8]], i32 }

; 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: mustprogress uwtable
define dso_local void @_Z14DFS_MarkPixelsP5ImagePiiii(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) #1 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !9
  store i32 %4, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.Image, ptr %16, i32 0, i32 3
  %18 = load ptr, ptr %17, align 8, !tbaa !11
  store ptr %18, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.Image, ptr %19, i32 0, i32 0
  %21 = load i32, ptr %20, align 8, !tbaa !13
  %22 = load i32, ptr %9, align 4, !tbaa !9
  %23 = mul nsw i32 %21, %22
  %24 = load i32, ptr %8, align 4, !tbaa !9
  %25 = add nsw i32 %23, %24
  store i32 %25, ptr %12, align 4, !tbaa !9
  %26 = load i32, ptr %8, align 4, !tbaa !9
  %27 = icmp slt i32 %26, 0
  br i1 %27, label %58, label %28

28:                                               ; preds = %5
  %29 = load i32, ptr %9, align 4, !tbaa !9
  %30 = icmp slt i32 %29, 0
  br i1 %30, label %58, label %31

31:                                               ; preds = %28
  %32 = load i32, ptr %8, align 4, !tbaa !9
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.Image, ptr %33, i32 0, i32 0
  %35 = load i32, ptr %34, align 8, !tbaa !13
  %36 = icmp sge i32 %32, %35
  br i1 %36, label %58, label %37

37:                                               ; preds = %31
  %38 = load i32, ptr %9, align 4, !tbaa !9
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.Image, ptr %39, i32 0, i32 1
  %41 = load i32, ptr %40, align 4, !tbaa !14
  %42 = icmp sge i32 %38, %41
  br i1 %42, label %58, label %43

43:                                               ; preds = %37
  %44 = load ptr, ptr %7, align 8, !tbaa !5
  %45 = load i32, ptr %12, align 4, !tbaa !9
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds i32, ptr %44, i64 %46
  %48 = load i32, ptr %47, align 4, !tbaa !9
  %49 = icmp ne i32 %48, 0
  br i1 %49, label %58, label %50

50:                                               ; preds = %43
  %51 = load ptr, ptr %11, align 8, !tbaa !5
  %52 = load i32, ptr %12, align 4, !tbaa !9
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds i8, ptr %51, i64 %53
  %55 = load i8, ptr %54, align 1, !tbaa !15
  %56 = zext i8 %55 to i32
  %57 = icmp eq i32 %56, 0
  br i1 %57, label %58, label %59

58:                                               ; preds = %50, %43, %37, %31, %28, %5
  store i32 1, ptr %13, align 4
  br label %92

59:                                               ; preds = %50
  %60 = load i32, ptr %10, align 4, !tbaa !9
  %61 = load ptr, ptr %7, align 8, !tbaa !5
  %62 = load i32, ptr %12, align 4, !tbaa !9
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds i32, ptr %61, i64 %63
  store i32 %60, ptr %64, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #2
  store i32 -1, ptr %14, align 4, !tbaa !9
  br label %65

65:                                               ; preds = %88, %59
  %66 = load i32, ptr %14, align 4, !tbaa !9
  %67 = icmp sle i32 %66, 1
  br i1 %67, label %69, label %68

68:                                               ; preds = %65
  store i32 2, ptr %13, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #2
  br label %91

69:                                               ; preds = %65
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #2
  store i32 -1, ptr %15, align 4, !tbaa !9
  br label %70

70:                                               ; preds = %84, %69
  %71 = load i32, ptr %15, align 4, !tbaa !9
  %72 = icmp sle i32 %71, 1
  br i1 %72, label %74, label %73

73:                                               ; preds = %70
  store i32 5, ptr %13, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #2
  br label %87

74:                                               ; preds = %70
  %75 = load ptr, ptr %6, align 8, !tbaa !5
  %76 = load ptr, ptr %7, align 8, !tbaa !5
  %77 = load i32, ptr %8, align 4, !tbaa !9
  %78 = load i32, ptr %14, align 4, !tbaa !9
  %79 = add nsw i32 %77, %78
  %80 = load i32, ptr %9, align 4, !tbaa !9
  %81 = load i32, ptr %15, align 4, !tbaa !9
  %82 = add nsw i32 %80, %81
  %83 = load i32, ptr %10, align 4, !tbaa !9
  call void @_Z14DFS_MarkPixelsP5ImagePiiii(ptr noundef %75, ptr noundef %76, i32 noundef %79, i32 noundef %82, i32 noundef %83)
  br label %84

84:                                               ; preds = %74
  %85 = load i32, ptr %15, align 4, !tbaa !9
  %86 = add nsw i32 %85, 1
  store i32 %86, ptr %15, align 4, !tbaa !9
  br label %70, !llvm.loop !16

87:                                               ; preds = %73
  br label %88

88:                                               ; preds = %87
  %89 = load i32, ptr %14, align 4, !tbaa !9
  %90 = add nsw i32 %89, 1
  store i32 %90, ptr %14, align 4, !tbaa !9
  br label %65, !llvm.loop !18

91:                                               ; preds = %68
  store i32 0, ptr %13, align 4
  br label %92

92:                                               ; preds = %91, %58
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  %93 = load i32, ptr %13, align 4
  switch i32 %93, label %95 [
    i32 0, label %94
    i32 1, label %94
  ]

94:                                               ; preds = %92, %92
  ret void

95:                                               ; preds = %92
  unreachable
}

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

!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, !6, i64 16}
!12 = !{!"_ZTS5Image", !10, i64 0, !10, i64 4, !10, i64 8, !6, i64 16, !7, i64 24, !10, i64 1524}
!13 = !{!12, !10, i64 0}
!14 = !{!12, !10, i64 4}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}


; 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 nofree nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local void @_Z14DFS_MarkPixelsP5ImagePiiii(ptr nocapture noundef readonly %0, ptr nocapture noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #0 {
  br label %tailrecurse

tailrecurse:                                      ; preds = %.preheader, %5
  %.tr36 = phi i32 [ %2, %5 ], [ %26, %.preheader ]
  %.tr37 = phi i32 [ %3, %5 ], [ %25, %.preheader ]
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %8 = load i32, ptr %0, align 8, !tbaa !11
  %9 = mul nsw i32 %8, %.tr37
  %10 = add nsw i32 %9, %.tr36
  %11 = or i32 %.tr37, %.tr36
  %or.cond.not = icmp sgt i32 %11, -1
  %.not = icmp sgt i32 %8, %.tr36
  %or.cond = select i1 %or.cond.not, i1 %.not, i1 false
  br i1 %or.cond, label %12, label %.loopexit

12:                                               ; preds = %tailrecurse
  %13 = getelementptr inbounds i8, ptr %0, i64 4
  %14 = load i32, ptr %13, align 4, !tbaa !12
  %.not31 = icmp sgt i32 %14, %.tr37
  br i1 %.not31, label %15, label %.loopexit

15:                                               ; preds = %12
  %16 = sext i32 %10 to i64
  %17 = getelementptr inbounds i32, ptr %1, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !13
  %.not32 = icmp eq i32 %18, 0
  br i1 %.not32, label %19, label %.loopexit

19:                                               ; preds = %15
  %20 = getelementptr inbounds i8, ptr %7, i64 %16
  %21 = load i8, ptr %20, align 1, !tbaa !14
  %22 = icmp eq i8 %21, 0
  br i1 %22, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %19
  store i32 %4, ptr %17, align 4, !tbaa !13
  %23 = add nsw i32 %.tr37, -1
  %24 = add nsw i32 %.tr36, -1
  tail call void @_Z14DFS_MarkPixelsP5ImagePiiii(ptr noundef nonnull %0, ptr noundef nonnull %1, i32 noundef %24, i32 noundef %23, i32 noundef %4)
  tail call void @_Z14DFS_MarkPixelsP5ImagePiiii(ptr noundef nonnull %0, ptr noundef nonnull %1, i32 noundef %24, i32 noundef %.tr37, i32 noundef %4)
  %25 = add nsw i32 %.tr37, 1
  tail call void @_Z14DFS_MarkPixelsP5ImagePiiii(ptr noundef nonnull %0, ptr noundef nonnull %1, i32 noundef %24, i32 noundef %25, i32 noundef %4)
  tail call void @_Z14DFS_MarkPixelsP5ImagePiiii(ptr noundef nonnull %0, ptr noundef nonnull %1, i32 noundef %.tr36, i32 noundef %23, i32 noundef %4)
  tail call void @_Z14DFS_MarkPixelsP5ImagePiiii(ptr noundef nonnull %0, ptr noundef nonnull %1, i32 noundef %.tr36, i32 noundef %.tr37, i32 noundef %4)
  tail call void @_Z14DFS_MarkPixelsP5ImagePiiii(ptr noundef nonnull %0, ptr noundef nonnull %1, i32 noundef %.tr36, i32 noundef %25, i32 noundef %4)
  %26 = add nsw i32 %.tr36, 1
  tail call void @_Z14DFS_MarkPixelsP5ImagePiiii(ptr noundef nonnull %0, ptr noundef nonnull %1, i32 noundef %26, i32 noundef %23, i32 noundef %4)
  tail call void @_Z14DFS_MarkPixelsP5ImagePiiii(ptr noundef nonnull %0, ptr noundef nonnull %1, i32 noundef %26, i32 noundef %.tr37, i32 noundef %4)
  br label %tailrecurse

.loopexit:                                        ; preds = %tailrecurse, %12, %15, %19
  ret void
}

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

!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, !10, i64 16}
!6 = !{!"_ZTS5Image", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 16, !8, i64 24, !7, i64 1524}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!6, !7, i64 4}
!13 = !{!7, !7, i64 0}
!14 = !{!8, !8, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass