; LLVM IR from tangjz/acm-icpc :: lydsy (2530)

; 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
@e = external dso_local global [3001 x [3001 x i8]], align 16
@ban = external dso_local global [3001 x i8], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 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 i8, align 1
  %8 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @m)
  br label %10

10:                                               ; preds = %14, %0
  %11 = load i32, ptr @m, align 4, !tbaa !5
  %12 = add nsw i32 %11, -1
  store i32 %12, ptr @m, align 4, !tbaa !5
  %13 = icmp ne i32 %11, 0
  br i1 %13, label %14, label %28

14:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  %15 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2, ptr noundef %3)
  %16 = load i32, ptr %3, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [3001 x [3001 x i8]], ptr @e, i64 0, i64 %17
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [3001 x i8], ptr %18, i64 0, i64 %20
  store i8 1, ptr %21, align 1, !tbaa !9
  %22 = load i32, ptr %2, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [3001 x [3001 x i8]], ptr @e, i64 0, i64 %23
  %25 = load i32, ptr %3, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [3001 x i8], ptr %24, i64 0, i64 %26
  store i8 1, ptr %27, align 1, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %10, !llvm.loop !11

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

29:                                               ; preds = %77, %28
  %30 = load i32, ptr %4, align 4, !tbaa !5
  %31 = load i32, ptr @n, align 4, !tbaa !5
  %32 = icmp sle i32 %30, %31
  br i1 %32, label %34, label %33

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

34:                                               ; preds = %29
  %35 = load i32, ptr %4, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [3001 x i8], ptr @ban, i64 0, i64 %36
  %38 = load i8, ptr %37, align 1, !tbaa !9, !range !13, !noundef !14
  %39 = trunc i8 %38 to i1
  br i1 %39, label %40, label %41

40:                                               ; preds = %34
  br label %77

41:                                               ; preds = %34
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %42 = load i32, ptr %4, align 4, !tbaa !5
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr %6, align 4, !tbaa !5
  br label %44

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

48:                                               ; preds = %44
  store i32 7, ptr %5, align 4
  br label %75

49:                                               ; preds = %44
  %50 = load i32, ptr %6, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [3001 x i8], ptr @ban, i64 0, i64 %51
  %53 = load i8, ptr %52, align 1, !tbaa !9, !range !13, !noundef !14
  %54 = trunc i8 %53 to i1
  br i1 %54, label %71, label %55

55:                                               ; preds = %49
  %56 = load i32, ptr %4, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [3001 x [3001 x i8]], ptr @e, i64 0, i64 %57
  %59 = load i32, ptr %6, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [3001 x i8], ptr %58, i64 0, i64 %60
  %62 = load i8, ptr %61, align 1, !tbaa !9, !range !13, !noundef !14
  %63 = trunc i8 %62 to i1
  br i1 %63, label %71, label %64

64:                                               ; preds = %55
  %65 = load i32, ptr %6, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [3001 x i8], ptr @ban, i64 0, i64 %66
  store i8 1, ptr %67, align 1, !tbaa !9
  %68 = load i32, ptr %4, align 4, !tbaa !5
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [3001 x i8], ptr @ban, i64 0, i64 %69
  store i8 1, ptr %70, align 1, !tbaa !9
  store i32 7, ptr %5, align 4
  br label %75

71:                                               ; preds = %55, %49
  br label %72

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

75:                                               ; preds = %64, %48
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %76

76:                                               ; preds = %75
  br label %77

77:                                               ; preds = %76, %40
  %78 = load i32, ptr %4, align 4, !tbaa !5
  %79 = add nsw i32 %78, 1
  store i32 %79, ptr %4, align 4, !tbaa !5
  br label %29, !llvm.loop !16

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

81:                                               ; preds = %102, %80
  %82 = load i32, ptr %8, align 4, !tbaa !5
  %83 = load i32, ptr @n, align 4, !tbaa !5
  %84 = icmp sle i32 %82, %83
  br i1 %84, label %86, label %85

85:                                               ; preds = %81
  store i32 10, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %105

86:                                               ; preds = %81
  %87 = load i32, ptr %8, align 4, !tbaa !5
  %88 = sext i32 %87 to i64
  %89 = getelementptr inbounds [3001 x i8], ptr @ban, i64 0, i64 %88
  %90 = load i8, ptr %89, align 1, !tbaa !9, !range !13, !noundef !14
  %91 = trunc i8 %90 to i1
  br i1 %91, label %92, label %93

92:                                               ; preds = %86
  br label %102

93:                                               ; preds = %86
  %94 = load i8, ptr %7, align 1, !tbaa !9, !range !13, !noundef !14
  %95 = trunc i8 %94 to i1
  br i1 %95, label %98, label %96

96:                                               ; preds = %93
  %97 = call i32 @putchar(i32 noundef 32)
  br label %99

98:                                               ; preds = %93
  store i8 0, ptr %7, align 1, !tbaa !9
  br label %99

99:                                               ; preds = %98, %96
  %100 = load i32, ptr %8, align 4, !tbaa !5
  %101 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %100)
  br label %102

102:                                              ; preds = %99, %92
  %103 = load i32, ptr %8, align 4, !tbaa !5
  %104 = add nsw i32 %103, 1
  store i32 %104, ptr %8, align 4, !tbaa !5
  br label %81, !llvm.loop !17

105:                                              ; preds = %85
  %106 = call i32 @putchar(i32 noundef 10)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #4
  %107 = load i32, ptr %1, align 4
  ret i32 %107
}

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 uwtable
declare i32 @putchar(i32 noundef) #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 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 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = distinct !{!15, !12}
!16 = distinct !{!16, !12}
!17 = distinct !{!17, !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
@e = external dso_local local_unnamed_addr global [3001 x [3001 x i8]], align 16
@ban = external dso_local local_unnamed_addr global [3001 x i8], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress nofree 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 @m, align 4, !tbaa !5
  %5 = add nsw i32 %4, -1
  store i32 %5, ptr @m, align 4, !tbaa !5
  %.not25 = icmp eq i32 %4, 0
  br i1 %.not25, label %.preheader24, label %.lr.ph

.preheader24:                                     ; preds = %.lr.ph, %0
  %6 = load i32, ptr @n, align 4, !tbaa !5
  %.not2031 = icmp slt i32 %6, 1
  br i1 %.not2031, label %._crit_edge, label %.lr.ph33.preheader

.lr.ph33.preheader:                               ; preds = %.preheader24
  %7 = zext nneg i32 %6 to i64
  %8 = add nuw i32 %6, 1
  %wide.trip.count44 = zext i32 %8 to i64
  %wide.trip.count = zext nneg i32 %6 to i64
  br label %.lr.ph33

.lr.ph:                                           ; preds = %0, %.lr.ph
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #4
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1, ptr noundef nonnull %2)
  %10 = load i32, ptr %2, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = load i32, ptr %1, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [3001 x [3001 x i8]], ptr @e, i64 0, i64 %11, i64 %13
  store i8 1, ptr %14, align 1, !tbaa !9
  %15 = getelementptr inbounds [3001 x [3001 x i8]], ptr @e, i64 0, i64 %13, i64 %11
  store i8 1, ptr %15, align 1, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #4
  %16 = load i32, ptr @m, align 4, !tbaa !5
  %17 = add nsw i32 %16, -1
  store i32 %17, ptr @m, align 4, !tbaa !5
  %.not = icmp eq i32 %16, 0
  br i1 %.not, label %.preheader24, label %.lr.ph, !llvm.loop !11

.preheader:                                       ; preds = %.loopexit
  br i1 %.not2031, label %._crit_edge, label %.lr.ph37

.lr.ph33:                                         ; preds = %.lr.ph33.preheader, %.loopexit
  %indvars.iv = phi i64 [ 1, %.lr.ph33.preheader ], [ %indvars.iv.next, %.loopexit ]
  %18 = getelementptr inbounds [3001 x i8], ptr @ban, i64 0, i64 %indvars.iv
  %19 = load i8, ptr %18, align 1, !tbaa !9, !range !13, !noundef !14
  %20 = trunc nuw i8 %19 to i1
  %.not22.not28 = icmp uge i64 %indvars.iv, %7
  %or.cond.not = or i1 %.not22.not28, %20
  br i1 %or.cond.not, label %.loopexit, label %.lr.ph30

.lr.ph30:                                         ; preds = %.lr.ph33, %30
  %indvars.iv40 = phi i64 [ %indvars.iv.next41, %30 ], [ %indvars.iv, %.lr.ph33 ]
  %indvars.iv.next41 = add nuw nsw i64 %indvars.iv40, 1
  %21 = getelementptr inbounds [3001 x i8], ptr @ban, i64 0, i64 %indvars.iv.next41
  %22 = load i8, ptr %21, align 1, !tbaa !9, !range !13, !noundef !14
  %23 = trunc nuw i8 %22 to i1
  br i1 %23, label %30, label %24

24:                                               ; preds = %.lr.ph30
  %25 = getelementptr inbounds [3001 x [3001 x i8]], ptr @e, i64 0, i64 %indvars.iv, i64 %indvars.iv.next41
  %26 = load i8, ptr %25, align 1, !tbaa !9, !range !13, !noundef !14
  %27 = trunc nuw i8 %26 to i1
  br i1 %27, label %30, label %28

28:                                               ; preds = %24
  %29 = getelementptr inbounds [3001 x i8], ptr @ban, i64 0, i64 %indvars.iv.next41
  store i8 1, ptr %29, align 1, !tbaa !9
  store i8 1, ptr %18, align 1, !tbaa !9
  br label %.loopexit

30:                                               ; preds = %.lr.ph30, %24
  %exitcond.not = icmp eq i64 %indvars.iv.next41, %wide.trip.count
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph30, !llvm.loop !15

.loopexit:                                        ; preds = %30, %28, %.lr.ph33
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond45.not = icmp eq i64 %indvars.iv.next, %wide.trip.count44
  br i1 %exitcond45.not, label %.preheader, label %.lr.ph33, !llvm.loop !16

._crit_edge:                                      ; preds = %42, %.preheader24, %.preheader
  %31 = call i32 @putchar(i32 noundef 10)
  ret i32 0

.lr.ph37:                                         ; preds = %.preheader, %42
  %32 = phi i32 [ %43, %42 ], [ %6, %.preheader ]
  %indvars.iv46 = phi i64 [ %indvars.iv.next47, %42 ], [ 1, %.preheader ]
  %.01735 = phi i1 [ %.2, %42 ], [ true, %.preheader ]
  %33 = getelementptr inbounds [3001 x i8], ptr @ban, i64 0, i64 %indvars.iv46
  %34 = load i8, ptr %33, align 1, !tbaa !9, !range !13, !noundef !14
  %35 = trunc nuw i8 %34 to i1
  br i1 %35, label %42, label %36

36:                                               ; preds = %.lr.ph37
  br i1 %.01735, label %39, label %37

37:                                               ; preds = %36
  %38 = call i32 @putchar(i32 noundef 32)
  br label %39

39:                                               ; preds = %36, %37
  %40 = trunc nuw nsw i64 %indvars.iv46 to i32
  %41 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %40)
  %.pre = load i32, ptr @n, align 4, !tbaa !5
  br label %42

42:                                               ; preds = %.lr.ph37, %39
  %43 = phi i32 [ %32, %.lr.ph37 ], [ %.pre, %39 ]
  %.2 = phi i1 [ %.01735, %.lr.ph37 ], [ false, %39 ]
  %indvars.iv.next47 = add nuw nsw i64 %indvars.iv46, 1
  %44 = sext i32 %43 to i64
  %.not21.not = icmp slt i64 %indvars.iv46, %44
  br i1 %.not21.not, label %.lr.ph37, label %._crit_edge, !llvm.loop !17
}

; 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 nofree nounwind uwtable
declare noundef i32 @putchar(i32 noundef) local_unnamed_addr #3

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

attributes #0 = { mustprogress nofree 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 nofree 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 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = distinct !{!15, !12}
!16 = distinct !{!16, !12}
!17 = distinct !{!17, !12}


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