; LLVM IR from yanglr/leetcode-ac :: algo-basic (acwing1097-lake-counting_flood_fill_readFile)

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

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@g = external dso_local global [1010 x [1010 x i8]], align 16
@st = external dso_local global [1010 x [1010 x i8]], align 16
@.str = external hidden unnamed_addr constant [11 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@stdin = external global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z3bfsii(i32 noundef, i32 noundef) #0

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #2 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %7 = load ptr, ptr @stdin, align 8, !tbaa !5
  %8 = call ptr @freopen(ptr noundef @.str, ptr noundef @.str.1, ptr noundef %7)
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.2, ptr noundef @n, ptr noundef @m)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 0, ptr %2, align 4, !tbaa !9
  br label %10

10:                                               ; preds = %21, %0
  %11 = load i32, ptr %2, align 4, !tbaa !9
  %12 = load i32, ptr @n, align 4, !tbaa !9
  %13 = icmp slt i32 %11, %12
  br i1 %13, label %15, label %14

14:                                               ; preds = %10
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %24

15:                                               ; preds = %10
  %16 = load i32, ptr %2, align 4, !tbaa !9
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [1010 x [1010 x i8]], ptr @g, i64 0, i64 %17
  %19 = getelementptr inbounds [1010 x i8], ptr %18, i64 0, i64 0
  %20 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.3, ptr noundef %19)
  br label %21

21:                                               ; preds = %15
  %22 = load i32, ptr %2, align 4, !tbaa !9
  %23 = add nsw i32 %22, 1
  store i32 %23, ptr %2, align 4, !tbaa !9
  br label %10, !llvm.loop !11

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

25:                                               ; preds = %65, %24
  %26 = load i32, ptr %4, align 4, !tbaa !9
  %27 = load i32, ptr @n, align 4, !tbaa !9
  %28 = icmp slt i32 %26, %27
  br i1 %28, label %30, label %29

29:                                               ; preds = %25
  store i32 5, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %68

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

31:                                               ; preds = %61, %30
  %32 = load i32, ptr %6, align 4, !tbaa !9
  %33 = load i32, ptr @m, align 4, !tbaa !9
  %34 = icmp slt i32 %32, %33
  br i1 %34, label %36, label %35

35:                                               ; preds = %31
  store i32 8, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %64

36:                                               ; preds = %31
  %37 = load i32, ptr %4, align 4, !tbaa !9
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [1010 x [1010 x i8]], ptr @g, i64 0, i64 %38
  %40 = load i32, ptr %6, align 4, !tbaa !9
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [1010 x i8], ptr %39, i64 0, i64 %41
  %43 = load i8, ptr %42, align 1, !tbaa !13
  %44 = sext i8 %43 to i32
  %45 = icmp eq i32 %44, 87
  br i1 %45, label %46, label %60

46:                                               ; preds = %36
  %47 = load i32, ptr %4, align 4, !tbaa !9
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [1010 x [1010 x i8]], ptr @st, i64 0, i64 %48
  %50 = load i32, ptr %6, align 4, !tbaa !9
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [1010 x i8], ptr %49, i64 0, i64 %51
  %53 = load i8, ptr %52, align 1, !tbaa !14, !range !16, !noundef !17
  %54 = trunc i8 %53 to i1
  br i1 %54, label %60, label %55

55:                                               ; preds = %46
  %56 = load i32, ptr %4, align 4, !tbaa !9
  %57 = load i32, ptr %6, align 4, !tbaa !9
  call void @_Z3bfsii(i32 noundef %56, i32 noundef %57)
  %58 = load i32, ptr %3, align 4, !tbaa !9
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %3, align 4, !tbaa !9
  br label %60

60:                                               ; preds = %55, %46, %36
  br label %61

61:                                               ; preds = %60
  %62 = load i32, ptr %6, align 4, !tbaa !9
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr %6, align 4, !tbaa !9
  br label %31, !llvm.loop !18

64:                                               ; preds = %35
  br label %65

65:                                               ; preds = %64
  %66 = load i32, ptr %4, align 4, !tbaa !9
  %67 = add nsw i32 %66, 1
  store i32 %67, ptr %4, align 4, !tbaa !9
  br label %25, !llvm.loop !19

68:                                               ; preds = %29
  %69 = load i32, ptr %3, align 4, !tbaa !9
  %70 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, i32 noundef %69)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  %71 = load i32, ptr %1, align 4
  ret i32 %71
}

declare ptr @freopen(ptr noundef, ptr noundef, ptr noundef) #3

declare i32 @__isoc99_scanf(ptr noundef, ...) #3

declare i32 @printf(ptr noundef, ...) #3

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress norecurse 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 = { "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 #4 = { 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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!7, !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"bool", !7, i64 0}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = distinct !{!18, !12}
!19 = distinct !{!19, !12}


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

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@g = external dso_local global [1010 x [1010 x i8]], align 16
@st = external dso_local local_unnamed_addr global [1010 x [1010 x i8]], align 16
@.str = external hidden unnamed_addr constant [11 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@stdin = external local_unnamed_addr global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z3bfsii(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = load ptr, ptr @stdin, align 8, !tbaa !5
  %2 = tail call ptr @freopen(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, ptr noundef %1)
  %3 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.2, ptr noundef nonnull @n, ptr noundef nonnull @m)
  %4 = load i32, ptr @n, align 4, !tbaa !9
  %5 = icmp sgt i32 %4, 0
  br i1 %5, label %.lr.ph, label %._crit_edge26

.preheader19:                                     ; preds = %.lr.ph
  %6 = icmp sgt i32 %11, 0
  %7 = load i32, ptr @m, align 4
  %8 = icmp sgt i32 %7, 0
  %or.cond = select i1 %6, i1 %8, i1 false
  br i1 %or.cond, label %.preheader, label %._crit_edge26

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %0 ]
  %9 = getelementptr inbounds [1010 x [1010 x i8]], ptr @g, i64 0, i64 %indvars.iv
  %10 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.3, ptr noundef nonnull %9)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %11 = load i32, ptr @n, align 4, !tbaa !9
  %12 = sext i32 %11 to i64
  %13 = icmp slt i64 %indvars.iv.next, %12
  br i1 %13, label %.lr.ph, label %.preheader19, !llvm.loop !11

.preheader:                                       ; preds = %.preheader19, %._crit_edge
  %14 = phi i32 [ %20, %._crit_edge ], [ %11, %.preheader19 ]
  %15 = phi i32 [ %21, %._crit_edge ], [ %7, %.preheader19 ]
  %16 = phi i32 [ %22, %._crit_edge ], [ %7, %.preheader19 ]
  %indvars.iv33 = phi i64 [ %indvars.iv.next34, %._crit_edge ], [ 0, %.preheader19 ]
  %.01724 = phi i32 [ %.1.lcssa, %._crit_edge ], [ 0, %.preheader19 ]
  %17 = icmp sgt i32 %16, 0
  br i1 %17, label %.lr.ph23, label %._crit_edge

.lr.ph23:                                         ; preds = %.preheader
  %18 = trunc nuw nsw i64 %indvars.iv33 to i32
  br label %25

._crit_edge26:                                    ; preds = %._crit_edge, %0, %.preheader19
  %.017.lcssa = phi i32 [ 0, %.preheader19 ], [ 0, %0 ], [ %.1.lcssa, %._crit_edge ]
  %19 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, i32 noundef %.017.lcssa)
  ret i32 0

._crit_edge.loopexit:                             ; preds = %37
  %.pre36 = load i32, ptr @n, align 4, !tbaa !9
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader
  %20 = phi i32 [ %14, %.preheader ], [ %.pre36, %._crit_edge.loopexit ]
  %21 = phi i32 [ %15, %.preheader ], [ %38, %._crit_edge.loopexit ]
  %22 = phi i32 [ %16, %.preheader ], [ %38, %._crit_edge.loopexit ]
  %.1.lcssa = phi i32 [ %.01724, %.preheader ], [ %.2, %._crit_edge.loopexit ]
  %indvars.iv.next34 = add nuw nsw i64 %indvars.iv33, 1
  %23 = sext i32 %20 to i64
  %24 = icmp slt i64 %indvars.iv.next34, %23
  br i1 %24, label %.preheader, label %._crit_edge26, !llvm.loop !13

25:                                               ; preds = %.lr.ph23, %37
  %26 = phi i32 [ %15, %.lr.ph23 ], [ %38, %37 ]
  %indvars.iv30 = phi i64 [ 0, %.lr.ph23 ], [ %indvars.iv.next31, %37 ]
  %.121 = phi i32 [ %.01724, %.lr.ph23 ], [ %.2, %37 ]
  %27 = getelementptr inbounds [1010 x [1010 x i8]], ptr @g, i64 0, i64 %indvars.iv33, i64 %indvars.iv30
  %28 = load i8, ptr %27, align 1, !tbaa !15
  %29 = icmp eq i8 %28, 87
  br i1 %29, label %30, label %37

30:                                               ; preds = %25
  %31 = getelementptr inbounds [1010 x [1010 x i8]], ptr @st, i64 0, i64 %indvars.iv33, i64 %indvars.iv30
  %32 = load i8, ptr %31, align 1, !tbaa !16, !range !18, !noundef !19
  %33 = trunc nuw i8 %32 to i1
  br i1 %33, label %37, label %34

34:                                               ; preds = %30
  %35 = trunc nuw nsw i64 %indvars.iv30 to i32
  tail call void @_Z3bfsii(i32 noundef %18, i32 noundef %35)
  %36 = add nsw i32 %.121, 1
  %.pre = load i32, ptr @m, align 4, !tbaa !9
  br label %37

37:                                               ; preds = %25, %30, %34
  %38 = phi i32 [ %26, %30 ], [ %.pre, %34 ], [ %26, %25 ]
  %.2 = phi i32 [ %.121, %30 ], [ %36, %34 ], [ %.121, %25 ]
  %indvars.iv.next31 = add nuw nsw i64 %indvars.iv30, 1
  %39 = sext i32 %38 to i64
  %40 = icmp slt i64 %indvars.iv.next31, %39
  br i1 %40, label %25, label %._crit_edge.loopexit, !llvm.loop !20
}

declare ptr @freopen(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #3

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #3

attributes #0 = { 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 #1 = { mustprogress norecurse 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 = { "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 = { nofree nounwind "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 = !{!"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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12, !14}
!14 = !{!"llvm.loop.unswitch.partial.disable"}
!15 = !{!7, !7, i64 0}
!16 = !{!17, !17, i64 0}
!17 = !{!"bool", !7, i64 0}
!18 = !{i8 0, i8 2}
!19 = !{}
!20 = distinct !{!20, !12}


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