; LLVM IR from VastoLorde95/Competitive-Programming :: Codeforces/305 Division 2/Problem B (B)

; 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
@q = external dso_local global i32, align 4
@grid = external dso_local global [501 x [501 x i32]], align 16
@row = external dso_local global [501 x i32], align 16
@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %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
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %16 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @m, ptr noundef @q)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %17

17:                                               ; preds = %41, %0
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = load i32, ptr @n, align 4, !tbaa !5
  %20 = icmp sle i32 %18, %19
  br i1 %20, label %22, label %21

21:                                               ; preds = %17
  store i32 2, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %44

22:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 1, ptr %4, align 4, !tbaa !5
  br label %23

23:                                               ; preds = %37, %22
  %24 = load i32, ptr %4, align 4, !tbaa !5
  %25 = load i32, ptr @m, align 4, !tbaa !5
  %26 = icmp sle i32 %24, %25
  br i1 %26, label %28, label %27

27:                                               ; preds = %23
  store i32 5, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %40

28:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %29 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %5)
  %30 = load i32, ptr %5, align 4, !tbaa !5
  %31 = load i32, ptr %2, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [501 x [501 x i32]], ptr @grid, i64 0, i64 %32
  %34 = load i32, ptr %4, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [501 x i32], ptr %33, i64 0, i64 %35
  store i32 %30, ptr %36, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %37

37:                                               ; preds = %28
  %38 = load i32, ptr %4, align 4, !tbaa !5
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr %4, align 4, !tbaa !5
  br label %23, !llvm.loop !9

40:                                               ; preds = %27
  br label %41

41:                                               ; preds = %40
  %42 = load i32, ptr %2, align 4, !tbaa !5
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr %2, align 4, !tbaa !5
  br label %17, !llvm.loop !11

44:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 1, ptr %6, align 4, !tbaa !5
  br label %45

45:                                               ; preds = %80, %44
  %46 = load i32, ptr %6, align 4, !tbaa !5
  %47 = load i32, ptr @n, align 4, !tbaa !5
  %48 = icmp sle i32 %46, %47
  br i1 %48, label %50, label %49

49:                                               ; preds = %45
  store i32 8, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %83

50:                                               ; preds = %45
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 1, ptr %9, align 4, !tbaa !5
  br label %51

51:                                               ; preds = %72, %50
  %52 = load i32, ptr %9, align 4, !tbaa !5
  %53 = load i32, ptr @m, align 4, !tbaa !5
  %54 = icmp sle i32 %52, %53
  br i1 %54, label %56, label %55

55:                                               ; preds = %51
  store i32 11, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  br label %75

56:                                               ; preds = %51
  %57 = load i32, ptr %6, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [501 x [501 x i32]], ptr @grid, i64 0, i64 %58
  %60 = load i32, ptr %9, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [501 x i32], ptr %59, i64 0, i64 %61
  %63 = load i32, ptr %62, align 4, !tbaa !5
  %64 = icmp eq i32 %63, 1
  br i1 %64, label %65, label %70

65:                                               ; preds = %56
  %66 = load i32, ptr %8, align 4, !tbaa !5
  %67 = add nsw i32 %66, 1
  store i32 %67, ptr %8, align 4, !tbaa !5
  %68 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %7, ptr noundef nonnull align 4 dereferenceable(4) %8)
  %69 = load i32, ptr %68, align 4, !tbaa !5
  store i32 %69, ptr %7, align 4, !tbaa !5
  br label %71

70:                                               ; preds = %56
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %71

71:                                               ; preds = %70, %65
  br label %72

72:                                               ; preds = %71
  %73 = load i32, ptr %9, align 4, !tbaa !5
  %74 = add nsw i32 %73, 1
  store i32 %74, ptr %9, align 4, !tbaa !5
  br label %51, !llvm.loop !12

75:                                               ; preds = %55
  %76 = load i32, ptr %7, align 4, !tbaa !5
  %77 = load i32, ptr %6, align 4, !tbaa !5
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds [501 x i32], ptr @row, i64 0, i64 %78
  store i32 %76, ptr %79, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %80

80:                                               ; preds = %75
  %81 = load i32, ptr %6, align 4, !tbaa !5
  %82 = add nsw i32 %81, 1
  store i32 %82, ptr %6, align 4, !tbaa !5
  br label %45, !llvm.loop !13

83:                                               ; preds = %49
  br label %84

84:                                               ; preds = %147, %83
  %85 = load i32, ptr @q, align 4, !tbaa !5
  %86 = add nsw i32 %85, -1
  store i32 %86, ptr @q, align 4, !tbaa !5
  %87 = icmp ne i32 %85, 0
  br i1 %87, label %88, label %150

88:                                               ; preds = %84
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %89 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.2, ptr noundef %10, ptr noundef %11)
  %90 = load i32, ptr %10, align 4, !tbaa !5
  %91 = sext i32 %90 to i64
  %92 = getelementptr inbounds [501 x [501 x i32]], ptr @grid, i64 0, i64 %91
  %93 = load i32, ptr %11, align 4, !tbaa !5
  %94 = sext i32 %93 to i64
  %95 = getelementptr inbounds [501 x i32], ptr %92, i64 0, i64 %94
  %96 = load i32, ptr %95, align 4, !tbaa !5
  %97 = sub nsw i32 1, %96
  %98 = load i32, ptr %10, align 4, !tbaa !5
  %99 = sext i32 %98 to i64
  %100 = getelementptr inbounds [501 x [501 x i32]], ptr @grid, i64 0, i64 %99
  %101 = load i32, ptr %11, align 4, !tbaa !5
  %102 = sext i32 %101 to i64
  %103 = getelementptr inbounds [501 x i32], ptr %100, i64 0, i64 %102
  store i32 %97, ptr %103, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  store i32 0, ptr %12, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  store i32 0, ptr %13, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  store i32 1, ptr %14, align 4, !tbaa !5
  br label %104

104:                                              ; preds = %125, %88
  %105 = load i32, ptr %14, align 4, !tbaa !5
  %106 = load i32, ptr @m, align 4, !tbaa !5
  %107 = icmp sle i32 %105, %106
  br i1 %107, label %109, label %108

108:                                              ; preds = %104
  store i32 16, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  br label %128

109:                                              ; preds = %104
  %110 = load i32, ptr %10, align 4, !tbaa !5
  %111 = sext i32 %110 to i64
  %112 = getelementptr inbounds [501 x [501 x i32]], ptr @grid, i64 0, i64 %111
  %113 = load i32, ptr %14, align 4, !tbaa !5
  %114 = sext i32 %113 to i64
  %115 = getelementptr inbounds [501 x i32], ptr %112, i64 0, i64 %114
  %116 = load i32, ptr %115, align 4, !tbaa !5
  %117 = icmp eq i32 %116, 1
  br i1 %117, label %118, label %123

118:                                              ; preds = %109
  %119 = load i32, ptr %13, align 4, !tbaa !5
  %120 = add nsw i32 %119, 1
  store i32 %120, ptr %13, align 4, !tbaa !5
  %121 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %12, ptr noundef nonnull align 4 dereferenceable(4) %13)
  %122 = load i32, ptr %121, align 4, !tbaa !5
  store i32 %122, ptr %12, align 4, !tbaa !5
  br label %124

123:                                              ; preds = %109
  store i32 0, ptr %13, align 4, !tbaa !5
  br label %124

124:                                              ; preds = %123, %118
  br label %125

125:                                              ; preds = %124
  %126 = load i32, ptr %14, align 4, !tbaa !5
  %127 = add nsw i32 %126, 1
  store i32 %127, ptr %14, align 4, !tbaa !5
  br label %104, !llvm.loop !14

128:                                              ; preds = %108
  %129 = load i32, ptr %12, align 4, !tbaa !5
  %130 = load i32, ptr %10, align 4, !tbaa !5
  %131 = sext i32 %130 to i64
  %132 = getelementptr inbounds [501 x i32], ptr @row, i64 0, i64 %131
  store i32 %129, ptr %132, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #4
  store i32 1, ptr %15, align 4, !tbaa !5
  br label %133

133:                                              ; preds = %144, %128
  %134 = load i32, ptr %15, align 4, !tbaa !5
  %135 = load i32, ptr @n, align 4, !tbaa !5
  %136 = icmp sle i32 %134, %135
  br i1 %136, label %138, label %137

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

138:                                              ; preds = %133
  %139 = load i32, ptr %15, align 4, !tbaa !5
  %140 = sext i32 %139 to i64
  %141 = getelementptr inbounds [501 x i32], ptr @row, i64 0, i64 %140
  %142 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %12, ptr noundef nonnull align 4 dereferenceable(4) %141)
  %143 = load i32, ptr %142, align 4, !tbaa !5
  store i32 %143, ptr %12, align 4, !tbaa !5
  br label %144

144:                                              ; preds = %138
  %145 = load i32, ptr %15, align 4, !tbaa !5
  %146 = add nsw i32 %145, 1
  store i32 %146, ptr %15, align 4, !tbaa !5
  br label %133, !llvm.loop !15

147:                                              ; preds = %137
  %148 = load i32, ptr %12, align 4, !tbaa !5
  %149 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i32 noundef %148)
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  br label %84, !llvm.loop !16

150:                                              ; preds = %84
  ret i32 0
}

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

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #3

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

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


; 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
@q = external dso_local global i32, align 4
@grid = external dso_local local_unnamed_addr global [501 x [501 x i32]], align 16
@row = external dso_local global [501 x i32], align 16
@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %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
  %7 = alloca i32, align 4
  %8 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @m, ptr noundef nonnull @q)
  %9 = load i32, ptr @n, align 4, !tbaa !5
  %.not34 = icmp slt i32 %9, 1
  br i1 %.not34, label %.preheader, label %.preheader31.lr.ph

.preheader31.lr.ph:                               ; preds = %0
  %10 = load i32, ptr @m, align 4, !tbaa !5
  %11 = icmp slt i32 %10, 1
  br i1 %11, label %.lr.ph43.split.us, label %.preheader31

.preheader31:                                     ; preds = %.preheader31.lr.ph, %._crit_edge
  %12 = phi i32 [ %18, %._crit_edge ], [ %9, %.preheader31.lr.ph ]
  %13 = phi i32 [ %19, %._crit_edge ], [ %10, %.preheader31.lr.ph ]
  %indvars.iv60 = phi i64 [ %indvars.iv.next61, %._crit_edge ], [ 1, %.preheader31.lr.ph ]
  %.not2932 = icmp slt i32 %13, 1
  br i1 %.not2932, label %._crit_edge, label %.lr.ph

.preheader30:                                     ; preds = %._crit_edge
  %.not2441 = icmp slt i32 %18, 1
  br i1 %.not2441, label %.preheader, label %.lr.ph43

.lr.ph43:                                         ; preds = %.preheader30
  %.pr = load i32, ptr @m, align 4, !tbaa !5
  %14 = icmp slt i32 %.pr, 1
  br i1 %14, label %.lr.ph43.split.us, label %.lr.ph43.split

.lr.ph43.split.us:                                ; preds = %.preheader31.lr.ph, %.lr.ph43
  %15 = phi i32 [ %18, %.lr.ph43 ], [ %9, %.preheader31.lr.ph ]
  %16 = zext nneg i32 %15 to i64
  %17 = shl nuw nsw i64 %16, 2
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(1) getelementptr inbounds (i8, ptr @row, i64 4), i8 0, i64 %17, i1 false), !tbaa !5
  br label %.preheader

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %.pre = load i32, ptr @n, align 4, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader31
  %18 = phi i32 [ %.pre, %._crit_edge.loopexit ], [ %12, %.preheader31 ]
  %19 = phi i32 [ %24, %._crit_edge.loopexit ], [ %13, %.preheader31 ]
  %indvars.iv.next61 = add nuw nsw i64 %indvars.iv60, 1
  %20 = sext i32 %18 to i64
  %.not.not = icmp slt i64 %indvars.iv60, %20
  br i1 %.not.not, label %.preheader31, label %.preheader30, !llvm.loop !9

.lr.ph:                                           ; preds = %.preheader31, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 1, %.preheader31 ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #5
  %21 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %1)
  %22 = load i32, ptr %1, align 4, !tbaa !5
  %23 = getelementptr inbounds [501 x [501 x i32]], ptr @grid, i64 0, i64 %indvars.iv60, i64 %indvars.iv
  store i32 %22, ptr %23, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %24 = load i32, ptr @m, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %.not29.not = icmp slt i64 %indvars.iv, %25
  br i1 %.not29.not, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !12

.preheader:                                       ; preds = %._crit_edge40, %.lr.ph43.split.us, %0, %.preheader30
  %26 = load i32, ptr @q, align 4, !tbaa !5
  %27 = add nsw i32 %26, -1
  store i32 %27, ptr @q, align 4, !tbaa !5
  %.not2554 = icmp eq i32 %26, 0
  br i1 %.not2554, label %._crit_edge56, label %.lr.ph55

.lr.ph43.split:                                   ; preds = %.lr.ph43, %._crit_edge40
  %28 = phi i32 [ %31, %._crit_edge40 ], [ %18, %.lr.ph43 ]
  %29 = phi i32 [ %33, %._crit_edge40 ], [ %.pr, %.lr.ph43 ]
  %30 = phi i32 [ %34, %._crit_edge40 ], [ %.pr, %.lr.ph43 ]
  %indvars.iv66 = phi i64 [ %indvars.iv.next67, %._crit_edge40 ], [ 1, %.lr.ph43 ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #5
  store i32 0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #5
  store i32 0, ptr %3, align 4, !tbaa !5
  %.not2836 = icmp slt i32 %30, 1
  br i1 %.not2836, label %._crit_edge40, label %.lr.ph39

._crit_edge40.loopexit:                           ; preds = %48
  %.pre80 = load i32, ptr @n, align 4, !tbaa !5
  br label %._crit_edge40

._crit_edge40:                                    ; preds = %._crit_edge40.loopexit, %.lr.ph43.split
  %31 = phi i32 [ %.pre80, %._crit_edge40.loopexit ], [ %28, %.lr.ph43.split ]
  %32 = phi i32 [ %49, %._crit_edge40.loopexit ], [ 0, %.lr.ph43.split ]
  %33 = phi i32 [ %50, %._crit_edge40.loopexit ], [ %29, %.lr.ph43.split ]
  %34 = phi i32 [ %50, %._crit_edge40.loopexit ], [ %30, %.lr.ph43.split ]
  %35 = getelementptr inbounds [501 x i32], ptr @row, i64 0, i64 %indvars.iv66
  store i32 %32, ptr %35, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #5
  %indvars.iv.next67 = add nuw nsw i64 %indvars.iv66, 1
  %36 = sext i32 %31 to i64
  %.not24.not = icmp slt i64 %indvars.iv66, %36
  br i1 %.not24.not, label %.lr.ph43.split, label %.preheader, !llvm.loop !13

.lr.ph39:                                         ; preds = %.lr.ph43.split, %48
  %37 = phi i32 [ %49, %48 ], [ 0, %.lr.ph43.split ]
  %38 = phi i32 [ %50, %48 ], [ %29, %.lr.ph43.split ]
  %indvars.iv63 = phi i64 [ %indvars.iv.next64, %48 ], [ 1, %.lr.ph43.split ]
  %39 = getelementptr inbounds [501 x [501 x i32]], ptr @grid, i64 0, i64 %indvars.iv66, i64 %indvars.iv63
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %41 = icmp eq i32 %40, 1
  br i1 %41, label %42, label %47

42:                                               ; preds = %.lr.ph39
  %43 = load i32, ptr %3, align 4, !tbaa !5
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr %3, align 4, !tbaa !5
  %45 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %2, ptr noundef nonnull align 4 dereferenceable(4) %3)
  %46 = load i32, ptr %45, align 4, !tbaa !5
  store i32 %46, ptr %2, align 4, !tbaa !5
  %.pre79 = load i32, ptr @m, align 4, !tbaa !5
  br label %48

47:                                               ; preds = %.lr.ph39
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %48

48:                                               ; preds = %42, %47
  %49 = phi i32 [ %46, %42 ], [ %37, %47 ]
  %50 = phi i32 [ %.pre79, %42 ], [ %38, %47 ]
  %indvars.iv.next64 = add nuw nsw i64 %indvars.iv63, 1
  %51 = sext i32 %50 to i64
  %.not28.not = icmp slt i64 %indvars.iv63, %51
  br i1 %.not28.not, label %.lr.ph39, label %._crit_edge40.loopexit, !llvm.loop !14

.lr.ph55:                                         ; preds = %.preheader, %._crit_edge53
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #5
  %52 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.2, ptr noundef nonnull %4, ptr noundef nonnull %5)
  %53 = load i32, ptr %4, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = load i32, ptr %5, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [501 x [501 x i32]], ptr @grid, i64 0, i64 %54, i64 %56
  %58 = load i32, ptr %57, align 4, !tbaa !5
  %59 = sub nsw i32 1, %58
  store i32 %59, ptr %57, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #5
  store i32 0, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %7) #5
  store i32 0, ptr %7, align 4, !tbaa !5
  %60 = load i32, ptr @m, align 4, !tbaa !5
  %.not2644 = icmp slt i32 %60, 1
  br i1 %.not2644, label %._crit_edge48, label %.lr.ph47

._crit_edge48.loopexit:                           ; preds = %77
  %.pre82 = load i32, ptr %4, align 4, !tbaa !5
  %.pre83 = sext i32 %.pre82 to i64
  br label %._crit_edge48

._crit_edge48:                                    ; preds = %._crit_edge48.loopexit, %.lr.ph55
  %.pre-phi = phi i64 [ %.pre83, %._crit_edge48.loopexit ], [ %54, %.lr.ph55 ]
  %61 = phi i32 [ %78, %._crit_edge48.loopexit ], [ 0, %.lr.ph55 ]
  %62 = getelementptr inbounds [501 x i32], ptr @row, i64 0, i64 %.pre-phi
  store i32 %61, ptr %62, align 4, !tbaa !5
  %63 = load i32, ptr @n, align 4, !tbaa !5
  %.not2749 = icmp slt i32 %63, 1
  br i1 %.not2749, label %._crit_edge53, label %.lr.ph52

.lr.ph47:                                         ; preds = %.lr.ph55, %77
  %64 = phi i32 [ %78, %77 ], [ 0, %.lr.ph55 ]
  %65 = phi i32 [ %79, %77 ], [ %60, %.lr.ph55 ]
  %indvars.iv73 = phi i64 [ %indvars.iv.next74, %77 ], [ 1, %.lr.ph55 ]
  %66 = load i32, ptr %4, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [501 x [501 x i32]], ptr @grid, i64 0, i64 %67, i64 %indvars.iv73
  %69 = load i32, ptr %68, align 4, !tbaa !5
  %70 = icmp eq i32 %69, 1
  br i1 %70, label %71, label %76

71:                                               ; preds = %.lr.ph47
  %72 = load i32, ptr %7, align 4, !tbaa !5
  %73 = add nsw i32 %72, 1
  store i32 %73, ptr %7, align 4, !tbaa !5
  %74 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %6, ptr noundef nonnull align 4 dereferenceable(4) %7)
  %75 = load i32, ptr %74, align 4, !tbaa !5
  store i32 %75, ptr %6, align 4, !tbaa !5
  %.pre81 = load i32, ptr @m, align 4, !tbaa !5
  br label %77

76:                                               ; preds = %.lr.ph47
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %77

77:                                               ; preds = %71, %76
  %78 = phi i32 [ %75, %71 ], [ %64, %76 ]
  %79 = phi i32 [ %.pre81, %71 ], [ %65, %76 ]
  %indvars.iv.next74 = add nuw nsw i64 %indvars.iv73, 1
  %80 = sext i32 %79 to i64
  %.not26.not = icmp slt i64 %indvars.iv73, %80
  br i1 %.not26.not, label %.lr.ph47, label %._crit_edge48.loopexit, !llvm.loop !15

._crit_edge53:                                    ; preds = %.lr.ph52, %._crit_edge48
  %81 = phi i32 [ %61, %._crit_edge48 ], [ %87, %.lr.ph52 ]
  %82 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %81)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %7) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #5
  %83 = load i32, ptr @q, align 4, !tbaa !5
  %84 = add nsw i32 %83, -1
  store i32 %84, ptr @q, align 4, !tbaa !5
  %.not25 = icmp eq i32 %83, 0
  br i1 %.not25, label %._crit_edge56, label %.lr.ph55, !llvm.loop !16

.lr.ph52:                                         ; preds = %._crit_edge48, %.lr.ph52
  %indvars.iv76 = phi i64 [ %indvars.iv.next77, %.lr.ph52 ], [ 1, %._crit_edge48 ]
  %85 = getelementptr inbounds [501 x i32], ptr @row, i64 0, i64 %indvars.iv76
  %86 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %6, ptr noundef nonnull align 4 dereferenceable(4) %85)
  %87 = load i32, ptr %86, align 4, !tbaa !5
  store i32 %87, ptr %6, align 4, !tbaa !5
  %indvars.iv.next77 = add nuw nsw i64 %indvars.iv76, 1
  %88 = load i32, ptr @n, align 4, !tbaa !5
  %89 = sext i32 %88 to i64
  %.not27.not = icmp slt i64 %indvars.iv76, %89
  br i1 %.not27.not, label %.lr.ph52, label %._crit_edge53, !llvm.loop !17

._crit_edge56:                                    ; preds = %._crit_edge53, %.preheader
  ret i32 0
}

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

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #3

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

attributes #0 = { mustprogress norecurse 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 = { 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" }
attributes #2 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { inlinehint mustprogress 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 #4 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10, !11}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.unswitch.partial.disable"}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !10, !11}
!14 = distinct !{!14, !10}
!15 = distinct !{!15, !10}
!16 = distinct !{!16, !10}
!17 = distinct !{!17, !10}


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