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

; 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
@ans = external dso_local global [21 x [2 x [2 x i32]]], align 16
@.str = external hidden unnamed_addr constant [11 x i8], align 1
@.str.1 = 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
  store i32 0, ptr %1, align 4
  call void @_Z4scanIiEvRT_(ptr noundef nonnull align 4 dereferenceable(4) @n)
  call void @_Z4scanIiEvRT_(ptr noundef nonnull align 4 dereferenceable(4) @m)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %7

7:                                                ; preds = %73, %0
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %9 = load i32, ptr @n, align 4, !tbaa !5
  %10 = icmp sle i32 %8, %9
  br i1 %10, label %12, label %11

11:                                               ; preds = %7
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %76

12:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  call void @_Z4scanIiEvRT_(ptr noundef nonnull align 4 dereferenceable(4) %3)
  call void @_Z4scanIiEvRT_(ptr noundef nonnull align 4 dereferenceable(4) %4)
  call void @_Z4scanIiEvRT_(ptr noundef nonnull align 4 dereferenceable(4) %5)
  %13 = load i32, ptr %5, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [21 x [2 x [2 x i32]]], ptr @ans, i64 0, i64 %14
  %16 = getelementptr inbounds [2 x [2 x i32]], ptr %15, i64 0, i64 0
  %17 = getelementptr inbounds [2 x i32], ptr %16, i64 0, i64 1
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %19 = icmp ne i32 %18, 0
  br i1 %19, label %20, label %29

20:                                               ; preds = %12
  %21 = load i32, ptr %5, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [21 x [2 x [2 x i32]]], ptr @ans, i64 0, i64 %22
  %24 = getelementptr inbounds [2 x [2 x i32]], ptr %23, i64 0, i64 0
  %25 = getelementptr inbounds [2 x i32], ptr %24, i64 0, i64 0
  %26 = load i32, ptr %25, align 16, !tbaa !5
  %27 = load i32, ptr %4, align 4, !tbaa !5
  %28 = icmp sgt i32 %26, %27
  br i1 %28, label %29, label %42

29:                                               ; preds = %20, %12
  %30 = load i32, ptr %4, align 4, !tbaa !5
  %31 = load i32, ptr %5, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [21 x [2 x [2 x i32]]], ptr @ans, i64 0, i64 %32
  %34 = getelementptr inbounds [2 x [2 x i32]], ptr %33, i64 0, i64 0
  %35 = getelementptr inbounds [2 x i32], ptr %34, i64 0, i64 0
  store i32 %30, ptr %35, align 16, !tbaa !5
  %36 = load i32, ptr %2, align 4, !tbaa !5
  %37 = load i32, ptr %5, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [21 x [2 x [2 x i32]]], ptr @ans, i64 0, i64 %38
  %40 = getelementptr inbounds [2 x [2 x i32]], ptr %39, i64 0, i64 0
  %41 = getelementptr inbounds [2 x i32], ptr %40, i64 0, i64 1
  store i32 %36, ptr %41, align 4, !tbaa !5
  br label %42

42:                                               ; preds = %29, %20
  %43 = load i32, ptr %5, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [21 x [2 x [2 x i32]]], ptr @ans, i64 0, i64 %44
  %46 = getelementptr inbounds [2 x [2 x i32]], ptr %45, i64 0, i64 1
  %47 = getelementptr inbounds [2 x i32], ptr %46, i64 0, i64 1
  %48 = load i32, ptr %47, align 4, !tbaa !5
  %49 = icmp ne i32 %48, 0
  br i1 %49, label %50, label %59

50:                                               ; preds = %42
  %51 = load i32, ptr %5, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [21 x [2 x [2 x i32]]], ptr @ans, i64 0, i64 %52
  %54 = getelementptr inbounds [2 x [2 x i32]], ptr %53, i64 0, i64 1
  %55 = getelementptr inbounds [2 x i32], ptr %54, i64 0, i64 0
  %56 = load i32, ptr %55, align 8, !tbaa !5
  %57 = load i32, ptr %3, align 4, !tbaa !5
  %58 = icmp slt i32 %56, %57
  br i1 %58, label %59, label %72

59:                                               ; preds = %50, %42
  %60 = load i32, ptr %3, align 4, !tbaa !5
  %61 = load i32, ptr %5, align 4, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [21 x [2 x [2 x i32]]], ptr @ans, i64 0, i64 %62
  %64 = getelementptr inbounds [2 x [2 x i32]], ptr %63, i64 0, i64 1
  %65 = getelementptr inbounds [2 x i32], ptr %64, i64 0, i64 0
  store i32 %60, ptr %65, align 8, !tbaa !5
  %66 = load i32, ptr %2, align 4, !tbaa !5
  %67 = load i32, ptr %5, align 4, !tbaa !5
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds [21 x [2 x [2 x i32]]], ptr @ans, i64 0, i64 %68
  %70 = getelementptr inbounds [2 x [2 x i32]], ptr %69, i64 0, i64 1
  %71 = getelementptr inbounds [2 x i32], ptr %70, i64 0, i64 1
  store i32 %66, ptr %71, align 4, !tbaa !5
  br label %72

72:                                               ; preds = %59, %50
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %73

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

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

77:                                               ; preds = %113, %76
  %78 = load i32, ptr %6, align 4, !tbaa !5
  %79 = load i32, ptr @m, align 4, !tbaa !5
  %80 = icmp sle i32 %78, %79
  br i1 %80, label %82, label %81

81:                                               ; preds = %77
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %116

82:                                               ; preds = %77
  %83 = load i32, ptr %6, align 4, !tbaa !5
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds [21 x [2 x [2 x i32]]], ptr @ans, i64 0, i64 %84
  %86 = getelementptr inbounds [2 x [2 x i32]], ptr %85, i64 0, i64 0
  %87 = getelementptr inbounds [2 x i32], ptr %86, i64 0, i64 0
  %88 = load i32, ptr %87, align 16, !tbaa !5
  %89 = load i32, ptr %6, align 4, !tbaa !5
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds [21 x [2 x [2 x i32]]], ptr @ans, i64 0, i64 %90
  %92 = getelementptr inbounds [2 x [2 x i32]], ptr %91, i64 0, i64 1
  %93 = getelementptr inbounds [2 x i32], ptr %92, i64 0, i64 0
  %94 = load i32, ptr %93, align 8, !tbaa !5
  %95 = icmp slt i32 %88, %94
  br i1 %95, label %96, label %110

96:                                               ; preds = %82
  %97 = load i32, ptr %6, align 4, !tbaa !5
  %98 = sext i32 %97 to i64
  %99 = getelementptr inbounds [21 x [2 x [2 x i32]]], ptr @ans, i64 0, i64 %98
  %100 = getelementptr inbounds [2 x [2 x i32]], ptr %99, i64 0, i64 0
  %101 = getelementptr inbounds [2 x i32], ptr %100, i64 0, i64 1
  %102 = load i32, ptr %101, align 4, !tbaa !5
  %103 = load i32, ptr %6, align 4, !tbaa !5
  %104 = sext i32 %103 to i64
  %105 = getelementptr inbounds [21 x [2 x [2 x i32]]], ptr @ans, i64 0, i64 %104
  %106 = getelementptr inbounds [2 x [2 x i32]], ptr %105, i64 0, i64 1
  %107 = getelementptr inbounds [2 x i32], ptr %106, i64 0, i64 1
  %108 = load i32, ptr %107, align 4, !tbaa !5
  %109 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %102, i32 noundef %108)
  br label %112

110:                                              ; preds = %82
  %111 = call i32 @puts(ptr noundef @.str.1)
  br label %112

112:                                              ; preds = %110, %96
  br label %113

113:                                              ; preds = %112
  %114 = load i32, ptr %6, align 4, !tbaa !5
  %115 = add nsw i32 %114, 1
  store i32 %115, ptr %6, align 4, !tbaa !5
  br label %77, !llvm.loop !11

116:                                              ; preds = %81
  ret i32 0
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z4scanIiEvRT_(ptr noundef nonnull align 4 dereferenceable(4)) #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

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

declare i32 @puts(ptr noundef) #3

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 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"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}


; 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
@ans = external dso_local local_unnamed_addr global [21 x [2 x [2 x i32]]], align 16
@.str = external hidden unnamed_addr constant [11 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress norecurse 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
  tail call void @_Z4scanIiEvRT_(ptr noundef nonnull align 4 dereferenceable(4) @n)
  tail call void @_Z4scanIiEvRT_(ptr noundef nonnull align 4 dereferenceable(4) @m)
  %4 = load i32, ptr @n, align 4, !tbaa !5
  %.not14 = icmp slt i32 %4, 1
  br i1 %.not14, label %.preheader, label %.lr.ph

.preheader:                                       ; preds = %25, %0
  %5 = load i32, ptr @m, align 4, !tbaa !5
  %.not1116 = icmp slt i32 %5, 1
  br i1 %.not1116, label %._crit_edge, label %.lr.ph18

.lr.ph:                                           ; preds = %0, %25
  %.01015 = phi i32 [ %26, %25 ], [ 1, %0 ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #4
  call void @_Z4scanIiEvRT_(ptr noundef nonnull align 4 dereferenceable(4) %1)
  call void @_Z4scanIiEvRT_(ptr noundef nonnull align 4 dereferenceable(4) %2)
  call void @_Z4scanIiEvRT_(ptr noundef nonnull align 4 dereferenceable(4) %3)
  %6 = load i32, ptr %3, align 4, !tbaa !5
  %7 = sext i32 %6 to i64
  %8 = getelementptr inbounds [21 x [2 x [2 x i32]]], ptr @ans, i64 0, i64 %7
  %9 = getelementptr inbounds i8, ptr %8, i64 4
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %.not12 = icmp eq i32 %10, 0
  %.pre = load i32, ptr %2, align 4, !tbaa !5
  br i1 %.not12, label %14, label %11

11:                                               ; preds = %.lr.ph
  %12 = load i32, ptr %8, align 16, !tbaa !5
  %13 = icmp sgt i32 %12, %.pre
  br i1 %13, label %14, label %16

14:                                               ; preds = %11, %.lr.ph
  store i32 %.pre, ptr %8, align 16, !tbaa !5
  %15 = getelementptr inbounds [21 x [2 x [2 x i32]]], ptr @ans, i64 0, i64 %7, i64 0, i64 1
  store i32 %.01015, ptr %15, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %14, %11
  %17 = getelementptr inbounds [21 x [2 x [2 x i32]]], ptr @ans, i64 0, i64 %7, i64 1
  %18 = getelementptr inbounds i8, ptr %17, i64 4
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %.not13 = icmp eq i32 %19, 0
  %.pre20 = load i32, ptr %1, align 4, !tbaa !5
  br i1 %.not13, label %23, label %20

20:                                               ; preds = %16
  %21 = load i32, ptr %17, align 8, !tbaa !5
  %22 = icmp slt i32 %21, %.pre20
  br i1 %22, label %23, label %25

23:                                               ; preds = %20, %16
  store i32 %.pre20, ptr %17, align 8, !tbaa !5
  %24 = getelementptr inbounds [21 x [2 x [2 x i32]]], ptr @ans, i64 0, i64 %7, i64 1, i64 1
  store i32 %.01015, ptr %24, align 4, !tbaa !5
  br label %25

25:                                               ; preds = %23, %20
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #4
  %26 = add nuw nsw i32 %.01015, 1
  %27 = load i32, ptr @n, align 4, !tbaa !5
  %.not.not = icmp slt i32 %.01015, %27
  br i1 %.not.not, label %.lr.ph, label %.preheader, !llvm.loop !9

._crit_edge:                                      ; preds = %41, %.preheader
  ret i32 0

.lr.ph18:                                         ; preds = %.preheader, %41
  %indvars.iv = phi i64 [ %indvars.iv.next, %41 ], [ 1, %.preheader ]
  %28 = getelementptr inbounds [21 x [2 x [2 x i32]]], ptr @ans, i64 0, i64 %indvars.iv
  %29 = load i32, ptr %28, align 16, !tbaa !5
  %30 = getelementptr inbounds i8, ptr %28, i64 8
  %31 = load i32, ptr %30, align 8, !tbaa !5
  %32 = icmp slt i32 %29, %31
  br i1 %32, label %33, label %39

33:                                               ; preds = %.lr.ph18
  %34 = getelementptr inbounds i8, ptr %28, i64 4
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %36 = getelementptr inbounds i8, ptr %28, i64 12
  %37 = load i32, ptr %36, align 4, !tbaa !5
  %38 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %35, i32 noundef %37)
  br label %41

39:                                               ; preds = %.lr.ph18
  %40 = call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.1)
  br label %41

41:                                               ; preds = %33, %39
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %42 = load i32, ptr @m, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %.not11.not = icmp slt i64 %indvars.iv, %43
  br i1 %.not11.not, label %.lr.ph18, label %._crit_edge, !llvm.loop !11
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z4scanIiEvRT_(ptr noundef nonnull align 4 dereferenceable(4)) 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: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #3

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

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


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass