; LLVM IR from tangjz/acm-icpc :: 51nod (1250)

; 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
@mx = external dso_local global i32, align 4
@f = external dso_local global [2 x [3001 x i32]], align 16
@g = external dso_local global [2 x [3001 x i32]], align 16
@cur = external dso_local global i32, align 4
@pre = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 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
  store i32 0, ptr %1, align 4
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @m)
  %9 = load i32, ptr @n, align 4, !tbaa !5
  %10 = load i32, ptr @m, align 4, !tbaa !5
  %11 = icmp slt i32 %9, %10
  br i1 %11, label %12, label %14

12:                                               ; preds = %0
  %13 = load i32, ptr @m, align 4, !tbaa !5
  br label %16

14:                                               ; preds = %0
  %15 = load i32, ptr @n, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %14, %12
  %17 = phi i32 [ %13, %12 ], [ %15, %14 ]
  store i32 %17, ptr @mx, align 4, !tbaa !5
  %18 = load i32, ptr @cur, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [2 x [3001 x i32]], ptr @g, i64 0, i64 %19
  %21 = getelementptr inbounds [3001 x i32], ptr %20, i64 0, i64 0
  store i32 1, ptr %21, align 4, !tbaa !5
  %22 = load i32, ptr @cur, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [2 x [3001 x i32]], ptr @f, i64 0, i64 %23
  %25 = getelementptr inbounds [3001 x i32], ptr %24, i64 0, i64 0
  store i32 1, ptr %25, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %26

26:                                               ; preds = %131, %16
  %27 = load i32, ptr %2, align 4, !tbaa !5
  %28 = load i32, ptr @n, align 4, !tbaa !5
  %29 = icmp sle i32 %27, %28
  br i1 %29, label %31, label %30

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

31:                                               ; preds = %26
  %32 = load i32, ptr @pre, align 4, !tbaa !5
  %33 = xor i32 %32, 1
  store i32 %33, ptr @pre, align 4, !tbaa !5
  %34 = load i32, ptr @cur, align 4, !tbaa !5
  %35 = xor i32 %34, 1
  store i32 %35, ptr @cur, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %36

36:                                               ; preds = %127, %31
  %37 = load i32, ptr %4, align 4, !tbaa !5
  %38 = load i32, ptr @mx, align 4, !tbaa !5
  %39 = icmp sle i32 %37, %38
  br i1 %39, label %41, label %40

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

41:                                               ; preds = %36
  %42 = load i32, ptr @pre, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [2 x [3001 x i32]], ptr @f, i64 0, i64 %43
  %45 = load i32, ptr %4, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [3001 x i32], ptr %44, i64 0, i64 %46
  %48 = load i32, ptr %47, align 4, !tbaa !5
  %49 = load i32, ptr @cur, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [2 x [3001 x i32]], ptr @f, i64 0, i64 %50
  %52 = load i32, ptr %4, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [3001 x i32], ptr %51, i64 0, i64 %53
  store i32 %48, ptr %54, align 4, !tbaa !5
  %55 = load i32, ptr %2, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = sub nsw i64 %56, 1
  %58 = load i32, ptr @pre, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [2 x [3001 x i32]], ptr @g, i64 0, i64 %59
  %61 = load i32, ptr %4, align 4, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [3001 x i32], ptr %60, i64 0, i64 %62
  %64 = load i32, ptr %63, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = mul nsw i64 %57, %65
  %67 = srem i64 %66, 1000000007
  %68 = trunc i64 %67 to i32
  %69 = load i32, ptr @cur, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [2 x [3001 x i32]], ptr @g, i64 0, i64 %70
  %72 = load i32, ptr %4, align 4, !tbaa !5
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [3001 x i32], ptr %71, i64 0, i64 %73
  store i32 %68, ptr %74, align 4, !tbaa !5
  %75 = load i32, ptr %4, align 4, !tbaa !5
  %76 = icmp sgt i32 %75, 0
  br i1 %76, label %77, label %106

77:                                               ; preds = %41
  %78 = load i32, ptr @cur, align 4, !tbaa !5
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds [2 x [3001 x i32]], ptr @f, i64 0, i64 %79
  %81 = load i32, ptr %4, align 4, !tbaa !5
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds [3001 x i32], ptr %80, i64 0, i64 %82
  %84 = load i32, ptr @cur, align 4, !tbaa !5
  %85 = sext i32 %84 to i64
  %86 = getelementptr inbounds [2 x [3001 x i32]], ptr @f, i64 0, i64 %85
  %87 = load i32, ptr %4, align 4, !tbaa !5
  %88 = sub nsw i32 %87, 1
  %89 = sext i32 %88 to i64
  %90 = getelementptr inbounds [3001 x i32], ptr %86, i64 0, i64 %89
  %91 = load i32, ptr %90, align 4, !tbaa !5
  call void @_Z7mod_incRii(ptr noundef nonnull align 4 dereferenceable(4) %83, i32 noundef %91)
  %92 = load i32, ptr @cur, align 4, !tbaa !5
  %93 = sext i32 %92 to i64
  %94 = getelementptr inbounds [2 x [3001 x i32]], ptr @g, i64 0, i64 %93
  %95 = load i32, ptr %4, align 4, !tbaa !5
  %96 = sext i32 %95 to i64
  %97 = getelementptr inbounds [3001 x i32], ptr %94, i64 0, i64 %96
  %98 = load i32, ptr @pre, align 4, !tbaa !5
  %99 = sext i32 %98 to i64
  %100 = getelementptr inbounds [2 x [3001 x i32]], ptr @g, i64 0, i64 %99
  %101 = load i32, ptr %4, align 4, !tbaa !5
  %102 = sub nsw i32 %101, 1
  %103 = sext i32 %102 to i64
  %104 = getelementptr inbounds [3001 x i32], ptr %100, i64 0, i64 %103
  %105 = load i32, ptr %104, align 4, !tbaa !5
  call void @_Z7mod_incRii(ptr noundef nonnull align 4 dereferenceable(4) %97, i32 noundef %105)
  br label %106

106:                                              ; preds = %77, %41
  %107 = load i32, ptr %4, align 4, !tbaa !5
  %108 = load i32, ptr %2, align 4, !tbaa !5
  %109 = icmp sge i32 %107, %108
  br i1 %109, label %110, label %126

110:                                              ; preds = %106
  %111 = load i32, ptr @cur, align 4, !tbaa !5
  %112 = sext i32 %111 to i64
  %113 = getelementptr inbounds [2 x [3001 x i32]], ptr @f, i64 0, i64 %112
  %114 = load i32, ptr %4, align 4, !tbaa !5
  %115 = sext i32 %114 to i64
  %116 = getelementptr inbounds [3001 x i32], ptr %113, i64 0, i64 %115
  %117 = load i32, ptr @pre, align 4, !tbaa !5
  %118 = sext i32 %117 to i64
  %119 = getelementptr inbounds [2 x [3001 x i32]], ptr @f, i64 0, i64 %118
  %120 = load i32, ptr %4, align 4, !tbaa !5
  %121 = load i32, ptr %2, align 4, !tbaa !5
  %122 = sub nsw i32 %120, %121
  %123 = sext i32 %122 to i64
  %124 = getelementptr inbounds [3001 x i32], ptr %119, i64 0, i64 %123
  %125 = load i32, ptr %124, align 4, !tbaa !5
  call void @_Z7mod_decRii(ptr noundef nonnull align 4 dereferenceable(4) %116, i32 noundef %125)
  br label %126

126:                                              ; preds = %110, %106
  br label %127

127:                                              ; preds = %126
  %128 = load i32, ptr %4, align 4, !tbaa !5
  %129 = add nsw i32 %128, 1
  store i32 %129, ptr %4, align 4, !tbaa !5
  br label %36, !llvm.loop !9

130:                                              ; preds = %40
  br label %131

131:                                              ; preds = %130
  %132 = load i32, ptr %2, align 4, !tbaa !5
  %133 = add nsw i32 %132, 1
  store i32 %133, ptr %2, align 4, !tbaa !5
  br label %26, !llvm.loop !11

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

135:                                              ; preds = %173, %134
  %136 = load i32, ptr %7, align 4, !tbaa !5
  %137 = load i32, ptr @mx, align 4, !tbaa !5
  %138 = icmp sle i32 %136, %137
  br i1 %138, label %140, label %139

139:                                              ; preds = %135
  store i32 8, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %176

140:                                              ; preds = %135
  %141 = load i32, ptr %7, align 4, !tbaa !5
  %142 = load i32, ptr @m, align 4, !tbaa !5
  %143 = icmp sle i32 %141, %142
  br i1 %143, label %144, label %158

144:                                              ; preds = %140
  %145 = load i32, ptr %7, align 4, !tbaa !5
  %146 = and i32 %145, 1
  %147 = load i32, ptr @m, align 4, !tbaa !5
  %148 = and i32 %147, 1
  %149 = icmp eq i32 %146, %148
  br i1 %149, label %150, label %158

150:                                              ; preds = %144
  %151 = load i32, ptr @cur, align 4, !tbaa !5
  %152 = sext i32 %151 to i64
  %153 = getelementptr inbounds [2 x [3001 x i32]], ptr @f, i64 0, i64 %152
  %154 = load i32, ptr %7, align 4, !tbaa !5
  %155 = sext i32 %154 to i64
  %156 = getelementptr inbounds [3001 x i32], ptr %153, i64 0, i64 %155
  %157 = load i32, ptr %156, align 4, !tbaa !5
  call void @_Z7mod_incRii(ptr noundef nonnull align 4 dereferenceable(4) %5, i32 noundef %157)
  br label %158

158:                                              ; preds = %150, %144, %140
  %159 = load i32, ptr %7, align 4, !tbaa !5
  %160 = load i32, ptr @m, align 4, !tbaa !5
  %161 = add nsw i32 %159, %160
  %162 = load i32, ptr @n, align 4, !tbaa !5
  %163 = icmp sge i32 %161, %162
  br i1 %163, label %164, label %172

164:                                              ; preds = %158
  %165 = load i32, ptr @cur, align 4, !tbaa !5
  %166 = sext i32 %165 to i64
  %167 = getelementptr inbounds [2 x [3001 x i32]], ptr @g, i64 0, i64 %166
  %168 = load i32, ptr %7, align 4, !tbaa !5
  %169 = sext i32 %168 to i64
  %170 = getelementptr inbounds [3001 x i32], ptr %167, i64 0, i64 %169
  %171 = load i32, ptr %170, align 4, !tbaa !5
  call void @_Z7mod_incRii(ptr noundef nonnull align 4 dereferenceable(4) %6, i32 noundef %171)
  br label %172

172:                                              ; preds = %164, %158
  br label %173

173:                                              ; preds = %172
  %174 = load i32, ptr %7, align 4, !tbaa !5
  %175 = add nsw i32 %174, 1
  store i32 %175, ptr %7, align 4, !tbaa !5
  br label %135, !llvm.loop !12

176:                                              ; preds = %139
  %177 = load i32, ptr %5, align 4, !tbaa !5
  %178 = load i32, ptr %6, align 4, !tbaa !5
  %179 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %177, i32 noundef %178)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  %180 = load i32, ptr %1, align 4
  ret i32 %180
}

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: inlinehint mustprogress nounwind uwtable
declare dso_local void @_Z7mod_incRii(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef) #3

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

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

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}


; 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
@mx = external dso_local local_unnamed_addr global i32, align 4
@f = external dso_local global [2 x [3001 x i32]], align 16
@g = external dso_local global [2 x [3001 x i32]], align 16
@cur = external dso_local local_unnamed_addr global i32, align 4
@pre = external dso_local local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 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 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @m)
  %4 = load i32, ptr @n, align 4
  %5 = load i32, ptr @m, align 4
  %6 = tail call i32 @llvm.smax.i32(i32 %4, i32 %5)
  store i32 %6, ptr @mx, align 4, !tbaa !5
  %7 = load i32, ptr @cur, align 4, !tbaa !5
  %8 = sext i32 %7 to i64
  %9 = getelementptr inbounds [2 x [3001 x i32]], ptr @g, i64 0, i64 %8
  store i32 1, ptr %9, align 4, !tbaa !5
  %10 = getelementptr inbounds [2 x [3001 x i32]], ptr @f, i64 0, i64 %8
  store i32 1, ptr %10, align 4, !tbaa !5
  %.not38 = icmp slt i32 %4, 1
  br i1 %.not38, label %._crit_edge42, label %.lr.ph41.split

._crit_edge42:                                    ; preds = %._crit_edge, %0
  %11 = phi i32 [ %6, %0 ], [ %34, %._crit_edge ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #5
  store i32 0, ptr %1, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #5
  store i32 0, ptr %2, align 4, !tbaa !5
  %.not3044 = icmp slt i32 %11, 0
  br i1 %.not3044, label %._crit_edge48, label %.lr.ph47.preheader

.lr.ph47.preheader:                               ; preds = %._crit_edge42
  %.pre60 = load i32, ptr @m, align 4, !tbaa !5
  br label %.lr.ph47

.lr.ph41.split:                                   ; preds = %0, %._crit_edge
  %.pre64 = phi i32 [ %.pre65, %._crit_edge ], [ %4, %0 ]
  %12 = phi i32 [ %33, %._crit_edge ], [ %4, %0 ]
  %13 = phi i32 [ %34, %._crit_edge ], [ %6, %0 ]
  %14 = phi i32 [ %35, %._crit_edge ], [ %6, %0 ]
  %indvars.iv52 = phi i64 [ %indvars.iv.next53, %._crit_edge ], [ 1, %0 ]
  %15 = load i32, ptr @pre, align 4, !tbaa !5
  %16 = xor i32 %15, 1
  store i32 %16, ptr @pre, align 4, !tbaa !5
  %17 = load i32, ptr @cur, align 4, !tbaa !5
  %18 = xor i32 %17, 1
  store i32 %18, ptr @cur, align 4, !tbaa !5
  %.not3336 = icmp slt i32 %14, 0
  br i1 %.not3336, label %._crit_edge, label %19

19:                                               ; preds = %.lr.ph41.split
  %20 = add nsw i64 %indvars.iv52, -1
  %21 = sext i32 %16 to i64
  %22 = getelementptr inbounds [2 x [3001 x i32]], ptr @f, i64 0, i64 %21, i64 0
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = sext i32 %18 to i64
  %25 = getelementptr inbounds [2 x [3001 x i32]], ptr @f, i64 0, i64 %24, i64 0
  store i32 %23, ptr %25, align 4, !tbaa !5
  %26 = getelementptr inbounds [2 x [3001 x i32]], ptr @g, i64 0, i64 %21, i64 0
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = mul nsw i64 %20, %28
  %30 = srem i64 %29, 1000000007
  %31 = trunc nsw i64 %30 to i32
  %32 = getelementptr inbounds [2 x [3001 x i32]], ptr @g, i64 0, i64 %24, i64 0
  store i32 %31, ptr %32, align 4, !tbaa !5
  %.not33.not.peel = icmp sgt i32 %13, 0
  br i1 %.not33.not.peel, label %.peel.next, label %._crit_edge

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

._crit_edge:                                      ; preds = %19, %._crit_edge.loopexit.loopexit, %.lr.ph41.split
  %.pre65 = phi i32 [ %.pre64, %.lr.ph41.split ], [ %.pre.pre, %._crit_edge.loopexit.loopexit ], [ %.pre64, %19 ]
  %33 = phi i32 [ %12, %.lr.ph41.split ], [ %.pre.pre, %._crit_edge.loopexit.loopexit ], [ %.pre64, %19 ]
  %34 = phi i32 [ %13, %.lr.ph41.split ], [ %71, %._crit_edge.loopexit.loopexit ], [ %13, %19 ]
  %35 = phi i32 [ %14, %.lr.ph41.split ], [ %71, %._crit_edge.loopexit.loopexit ], [ %13, %19 ]
  %indvars.iv.next53 = add nuw nsw i64 %indvars.iv52, 1
  %36 = sext i32 %33 to i64
  %.not.not = icmp slt i64 %indvars.iv52, %36
  br i1 %.not.not, label %.lr.ph41.split, label %._crit_edge42, !llvm.loop !9

.peel.next:                                       ; preds = %19, %70
  %indvars.iv = phi i64 [ %indvars.iv.next, %70 ], [ 1, %19 ]
  %37 = load i32, ptr @pre, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [2 x [3001 x i32]], ptr @f, i64 0, i64 %38, i64 %indvars.iv
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %41 = load i32, ptr @cur, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [2 x [3001 x i32]], ptr @f, i64 0, i64 %42, i64 %indvars.iv
  store i32 %40, ptr %43, align 4, !tbaa !5
  %44 = getelementptr inbounds [2 x [3001 x i32]], ptr @g, i64 0, i64 %38, i64 %indvars.iv
  %45 = load i32, ptr %44, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = mul nsw i64 %20, %46
  %48 = srem i64 %47, 1000000007
  %49 = trunc nsw i64 %48 to i32
  %50 = getelementptr inbounds [2 x [3001 x i32]], ptr @g, i64 0, i64 %42, i64 %indvars.iv
  store i32 %49, ptr %50, align 4, !tbaa !5
  %51 = add nsw i64 %indvars.iv, -1
  %52 = getelementptr inbounds [2 x [3001 x i32]], ptr @f, i64 0, i64 %42, i64 %51
  %53 = load i32, ptr %52, align 4, !tbaa !5
  tail call void @_Z7mod_incRii(ptr noundef nonnull align 4 dereferenceable(4) %43, i32 noundef %53)
  %54 = load i32, ptr @cur, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [2 x [3001 x i32]], ptr @g, i64 0, i64 %55, i64 %indvars.iv
  %57 = load i32, ptr @pre, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [2 x [3001 x i32]], ptr @g, i64 0, i64 %58, i64 %51
  %60 = load i32, ptr %59, align 4, !tbaa !5
  tail call void @_Z7mod_incRii(ptr noundef nonnull align 4 dereferenceable(4) %56, i32 noundef %60)
  %.not35 = icmp ult i64 %indvars.iv, %indvars.iv52
  br i1 %.not35, label %70, label %61

61:                                               ; preds = %.peel.next
  %62 = load i32, ptr @cur, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [2 x [3001 x i32]], ptr @f, i64 0, i64 %63, i64 %indvars.iv
  %65 = load i32, ptr @pre, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = sub nsw i64 %indvars.iv, %indvars.iv52
  %68 = getelementptr inbounds [2 x [3001 x i32]], ptr @f, i64 0, i64 %66, i64 %67
  %69 = load i32, ptr %68, align 4, !tbaa !5
  tail call void @_Z7mod_decRii(ptr noundef nonnull align 4 dereferenceable(4) %64, i32 noundef %69)
  br label %70

70:                                               ; preds = %.peel.next, %61
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %71 = load i32, ptr @mx, align 4, !tbaa !5
  %72 = sext i32 %71 to i64
  %.not33.not = icmp slt i64 %indvars.iv, %72
  br i1 %.not33.not, label %.peel.next, label %._crit_edge.loopexit.loopexit, !llvm.loop !12

._crit_edge48.loopexit:                           ; preds = %95
  %.pre62 = load i32, ptr %1, align 4, !tbaa !5
  %.pre63 = load i32, ptr %2, align 4, !tbaa !5
  br label %._crit_edge48

._crit_edge48:                                    ; preds = %._crit_edge48.loopexit, %._crit_edge42
  %73 = phi i32 [ %.pre63, %._crit_edge48.loopexit ], [ 0, %._crit_edge42 ]
  %74 = phi i32 [ %.pre62, %._crit_edge48.loopexit ], [ 0, %._crit_edge42 ]
  %75 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %74, i32 noundef %73)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #5
  ret i32 0

.lr.ph47:                                         ; preds = %.lr.ph47.preheader, %95
  %76 = phi i32 [ %.pre60, %.lr.ph47.preheader ], [ %96, %95 ]
  %indvars.iv55 = phi i64 [ 0, %.lr.ph47.preheader ], [ %indvars.iv.next56, %95 ]
  %77 = sext i32 %76 to i64
  %.not31 = icmp sgt i64 %indvars.iv55, %77
  %.pre67 = trunc nuw nsw i64 %indvars.iv55 to i32
  br i1 %.not31, label %.lr.ph47._crit_edge, label %78

78:                                               ; preds = %.lr.ph47
  %79 = xor i32 %76, %.pre67
  %80 = and i32 %79, 1
  %81 = icmp eq i32 %80, 0
  br i1 %81, label %82, label %.lr.ph47._crit_edge

82:                                               ; preds = %78
  %83 = load i32, ptr @cur, align 4, !tbaa !5
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds [2 x [3001 x i32]], ptr @f, i64 0, i64 %84, i64 %indvars.iv55
  %86 = load i32, ptr %85, align 4, !tbaa !5
  call void @_Z7mod_incRii(ptr noundef nonnull align 4 dereferenceable(4) %1, i32 noundef %86)
  %.pre61 = load i32, ptr @m, align 4, !tbaa !5
  br label %.lr.ph47._crit_edge

.lr.ph47._crit_edge:                              ; preds = %.lr.ph47, %82, %78
  %87 = phi i32 [ %.pre61, %82 ], [ %76, %78 ], [ %76, %.lr.ph47 ]
  %88 = add nsw i32 %87, %.pre67
  %89 = load i32, ptr @n, align 4, !tbaa !5
  %.not32 = icmp slt i32 %88, %89
  br i1 %.not32, label %95, label %90

90:                                               ; preds = %.lr.ph47._crit_edge
  %91 = load i32, ptr @cur, align 4, !tbaa !5
  %92 = sext i32 %91 to i64
  %93 = getelementptr inbounds [2 x [3001 x i32]], ptr @g, i64 0, i64 %92, i64 %indvars.iv55
  %94 = load i32, ptr %93, align 4, !tbaa !5
  call void @_Z7mod_incRii(ptr noundef nonnull align 4 dereferenceable(4) %2, i32 noundef %94)
  %.pre59 = load i32, ptr @m, align 4, !tbaa !5
  br label %95

95:                                               ; preds = %.lr.ph47._crit_edge, %90
  %96 = phi i32 [ %87, %.lr.ph47._crit_edge ], [ %.pre59, %90 ]
  %indvars.iv.next56 = add nuw nsw i64 %indvars.iv55, 1
  %97 = load i32, ptr @mx, align 4, !tbaa !5
  %98 = sext i32 %97 to i64
  %.not30.not = icmp slt i64 %indvars.iv55, %98
  br i1 %.not30.not, label %.lr.ph47, label %._crit_edge48.loopexit, !llvm.loop !14
}

; 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: inlinehint mustprogress nounwind uwtable
declare dso_local void @_Z7mod_incRii(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef) local_unnamed_addr #3

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

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #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 nosync nounwind speculatable willreturn memory(none) }
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}
!13 = !{!"llvm.loop.peeled.count", i32 1}
!14 = distinct !{!14, !10}


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