; LLVM IR from tangjz/acm-icpc :: TDL_training/2016-07-08 (G - Voting - tjz)

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

%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%struct.Status = type { i32, i32, i32 }
%struct.Node = type { i32, i32 }
%"struct.std::pair" = type { i32, i32 }

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@p = external dso_local global i32, align 4
@f = external dso_local global [10010 x [4 x i32]], align 16
@e = external dso_local global [10010 x %"class.std::vector"], align 16
@idx = external dso_local global [21 x [21 x [21 x i32]]], align 16
@status = external dso_local global [1771 x %struct.Status], align 16
@tot = external dso_local global i32, align 4
@h = external dso_local global [10010 x [1771 x %struct.Node]], align 16
@out = external dso_local global [10010 x %"struct.std::pair"], align 16
@.str = external hidden unnamed_addr constant [10 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@stdin = external global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1
@stdout = external global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [7 x i8], align 1

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

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

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

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #2 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca %struct.Status, 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
  store i32 0, ptr %1, align 4
  %14 = load ptr, ptr @stdin, align 8, !tbaa !5
  %15 = call ptr @freopen(ptr noundef @.str, ptr noundef @.str.1, ptr noundef %14)
  %16 = load ptr, ptr @stdout, align 8, !tbaa !5
  %17 = call ptr @freopen(ptr noundef @.str.2, ptr noundef @.str.3, ptr noundef %16)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #6
  store i32 0, ptr %2, align 4, !tbaa !9
  br label %18

18:                                               ; preds = %67, %0
  %19 = load i32, ptr %2, align 4, !tbaa !9
  %20 = icmp slt i32 %19, 21
  br i1 %20, label %22, label %21

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

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

23:                                               ; preds = %63, %22
  %24 = load i32, ptr %2, align 4, !tbaa !9
  %25 = load i32, ptr %4, align 4, !tbaa !9
  %26 = add nsw i32 %24, %25
  %27 = icmp slt i32 %26, 21
  br i1 %27, label %29, label %28

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

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

30:                                               ; preds = %59, %29
  %31 = load i32, ptr %2, align 4, !tbaa !9
  %32 = load i32, ptr %4, align 4, !tbaa !9
  %33 = add nsw i32 %31, %32
  %34 = load i32, ptr %5, align 4, !tbaa !9
  %35 = add nsw i32 %33, %34
  %36 = icmp slt i32 %35, 21
  br i1 %36, label %38, label %37

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

38:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 12, ptr %6) #6
  %39 = getelementptr inbounds %struct.Status, ptr %6, i32 0, i32 0
  %40 = load i32, ptr %2, align 4, !tbaa !9
  store i32 %40, ptr %39, align 4, !tbaa !11
  %41 = getelementptr inbounds %struct.Status, ptr %6, i32 0, i32 1
  %42 = load i32, ptr %4, align 4, !tbaa !9
  store i32 %42, ptr %41, align 4, !tbaa !13
  %43 = getelementptr inbounds %struct.Status, ptr %6, i32 0, i32 2
  %44 = load i32, ptr %5, align 4, !tbaa !9
  store i32 %44, ptr %43, align 4, !tbaa !14
  %45 = load i32, ptr @tot, align 4, !tbaa !9
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [1771 x %struct.Status], ptr @status, i64 0, i64 %46
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %47, ptr align 4 %6, i64 12, i1 false), !tbaa.struct !15
  call void @llvm.lifetime.end.p0(i64 12, ptr %6) #6
  %48 = load i32, ptr @tot, align 4, !tbaa !9
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr @tot, align 4, !tbaa !9
  %50 = load i32, ptr %2, align 4, !tbaa !9
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [21 x [21 x [21 x i32]]], ptr @idx, i64 0, i64 %51
  %53 = load i32, ptr %4, align 4, !tbaa !9
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [21 x [21 x i32]], ptr %52, i64 0, i64 %54
  %56 = load i32, ptr %5, align 4, !tbaa !9
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [21 x i32], ptr %55, i64 0, i64 %57
  store i32 %48, ptr %58, align 4, !tbaa !9
  br label %59

59:                                               ; preds = %38
  %60 = load i32, ptr %5, align 4, !tbaa !9
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %5, align 4, !tbaa !9
  br label %30, !llvm.loop !16

62:                                               ; preds = %37
  br label %63

63:                                               ; preds = %62
  %64 = load i32, ptr %4, align 4, !tbaa !9
  %65 = add nsw i32 %64, 1
  store i32 %65, ptr %4, align 4, !tbaa !9
  br label %23, !llvm.loop !18

66:                                               ; preds = %28
  br label %67

67:                                               ; preds = %66
  %68 = load i32, ptr %2, align 4, !tbaa !9
  %69 = add nsw i32 %68, 1
  store i32 %69, ptr %2, align 4, !tbaa !9
  br label %18, !llvm.loop !19

70:                                               ; preds = %21
  %71 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.4, ptr noundef @n, ptr noundef @m, ptr noundef @p)
  call void @llvm.memset.p0.i64(ptr align 16 @f, i8 -1, i64 160160, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #6
  store i32 1, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  br label %72

72:                                               ; preds = %100, %70
  %73 = load i32, ptr %7, align 4, !tbaa !9
  %74 = load i32, ptr @n, align 4, !tbaa !9
  %75 = icmp sle i32 %73, %74
  br i1 %75, label %77, label %76

76:                                               ; preds = %72
  store i32 11, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #6
  br label %103

77:                                               ; preds = %72
  %78 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.5, ptr noundef %8)
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #6
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %79

79:                                               ; preds = %96, %77
  %80 = load i32, ptr %9, align 4, !tbaa !9
  %81 = load i32, ptr @p, align 4, !tbaa !9
  %82 = icmp sle i32 %80, %81
  br i1 %82, label %84, label %83

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

84:                                               ; preds = %79
  %85 = load i32, ptr %9, align 4, !tbaa !9
  %86 = load i32, ptr %8, align 4, !tbaa !9
  %87 = icmp eq i32 %85, %86
  %88 = zext i1 %87 to i64
  %89 = select i1 %87, i32 0, i32 1
  %90 = load i32, ptr %7, align 4, !tbaa !9
  %91 = sext i32 %90 to i64
  %92 = getelementptr inbounds [10010 x [4 x i32]], ptr @f, i64 0, i64 %91
  %93 = load i32, ptr %9, align 4, !tbaa !9
  %94 = sext i32 %93 to i64
  %95 = getelementptr inbounds [4 x i32], ptr %92, i64 0, i64 %94
  store i32 %89, ptr %95, align 4, !tbaa !9
  br label %96

96:                                               ; preds = %84
  %97 = load i32, ptr %9, align 4, !tbaa !9
  %98 = add nsw i32 %97, 1
  store i32 %98, ptr %9, align 4, !tbaa !9
  br label %79, !llvm.loop !20

99:                                               ; preds = %83
  br label %100

100:                                              ; preds = %99
  %101 = load i32, ptr %7, align 4, !tbaa !9
  %102 = add nsw i32 %101, 1
  store i32 %102, ptr %7, align 4, !tbaa !9
  br label %72, !llvm.loop !21

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

104:                                              ; preds = %133, %103
  %105 = load i32, ptr %10, align 4, !tbaa !9
  %106 = load i32, ptr @m, align 4, !tbaa !9
  %107 = icmp sle i32 %105, %106
  br i1 %107, label %109, label %108

108:                                              ; preds = %104
  store i32 17, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #6
  br label %136

109:                                              ; preds = %104
  %110 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.5, ptr noundef %11)
  br label %111

111:                                              ; preds = %125, %109
  %112 = load i32, ptr %11, align 4, !tbaa !9
  %113 = add nsw i32 %112, -1
  store i32 %113, ptr %11, align 4, !tbaa !9
  %114 = icmp ne i32 %112, 0
  br i1 %114, label %115, label %132

115:                                              ; preds = %111
  %116 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.5, ptr noundef %12)
  %117 = load i32, ptr %12, align 4, !tbaa !9
  %118 = icmp slt i32 %117, 0
  br i1 %118, label %119, label %123

119:                                              ; preds = %115
  %120 = load i32, ptr @n, align 4, !tbaa !9
  %121 = load i32, ptr %12, align 4, !tbaa !9
  %122 = sub nsw i32 %120, %121
  br label %125

123:                                              ; preds = %115
  %124 = load i32, ptr %12, align 4, !tbaa !9
  br label %125

125:                                              ; preds = %123, %119
  %126 = phi i32 [ %122, %119 ], [ %124, %123 ]
  store i32 %126, ptr %12, align 4, !tbaa !9
  %127 = load i32, ptr @n, align 4, !tbaa !9
  %128 = load i32, ptr %10, align 4, !tbaa !9
  %129 = add nsw i32 %127, %128
  %130 = sext i32 %129 to i64
  %131 = getelementptr inbounds [10010 x %"class.std::vector"], ptr @e, i64 0, i64 %130
  call void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24) %131, ptr noundef nonnull align 4 dereferenceable(4) %12)
  br label %111, !llvm.loop !22

132:                                              ; preds = %111
  br label %133

133:                                              ; preds = %132
  %134 = load i32, ptr %10, align 4, !tbaa !9
  %135 = add nsw i32 %134, 1
  store i32 %135, ptr %10, align 4, !tbaa !9
  br label %104, !llvm.loop !23

136:                                              ; preds = %108
  store i32 1, ptr @tot, align 4, !tbaa !9
  call void @llvm.memset.p0.i64(ptr align 16 @h, i8 -1, i64 141821680, i1 false)
  store i32 0, ptr getelementptr inbounds (%struct.Node, ptr @h, i32 0, i32 1), align 4, !tbaa !24
  %137 = load i32, ptr @n, align 4, !tbaa !9
  %138 = add nsw i32 %137, 1
  call void @_Z3dfsi(i32 noundef %138)
  store i32 0, ptr @tot, align 4, !tbaa !9
  %139 = load i32, ptr @n, align 4, !tbaa !9
  %140 = add nsw i32 %139, 1
  call void @_Z3pfsii(i32 noundef %140, i32 noundef 1)
  %141 = load i32, ptr @n, align 4, !tbaa !9
  %142 = add nsw i32 %141, 1
  %143 = sext i32 %142 to i64
  %144 = getelementptr inbounds [10010 x [4 x i32]], ptr @f, i64 0, i64 %143
  %145 = getelementptr inbounds [4 x i32], ptr %144, i64 0, i64 1
  %146 = load i32, ptr %145, align 4, !tbaa !9
  %147 = call i32 (ptr, ...) @printf(ptr noundef @.str.6, i32 noundef %146)
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #6
  store i32 0, ptr %13, align 4, !tbaa !9
  br label %148

148:                                              ; preds = %165, %136
  %149 = load i32, ptr %13, align 4, !tbaa !9
  %150 = load i32, ptr @tot, align 4, !tbaa !9
  %151 = icmp slt i32 %149, %150
  br i1 %151, label %153, label %152

152:                                              ; preds = %148
  store i32 22, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #6
  br label %168

153:                                              ; preds = %148
  %154 = load i32, ptr %13, align 4, !tbaa !9
  %155 = sext i32 %154 to i64
  %156 = getelementptr inbounds [10010 x %"struct.std::pair"], ptr @out, i64 0, i64 %155
  %157 = getelementptr inbounds %"struct.std::pair", ptr %156, i32 0, i32 0
  %158 = load i32, ptr %157, align 8, !tbaa !26
  %159 = load i32, ptr %13, align 4, !tbaa !9
  %160 = sext i32 %159 to i64
  %161 = getelementptr inbounds [10010 x %"struct.std::pair"], ptr @out, i64 0, i64 %160
  %162 = getelementptr inbounds %"struct.std::pair", ptr %161, i32 0, i32 1
  %163 = load i32, ptr %162, align 4, !tbaa !28
  %164 = call i32 (ptr, ...) @printf(ptr noundef @.str.7, i32 noundef %158, i32 noundef %163)
  br label %165

165:                                              ; preds = %153
  %166 = load i32, ptr %13, align 4, !tbaa !9
  %167 = add nsw i32 %166, 1
  store i32 %167, ptr %13, align 4, !tbaa !9
  br label %148, !llvm.loop !29

168:                                              ; preds = %152
  ret i32 0
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #4

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 4 dereferenceable(4)) #0 align 2

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

attributes #0 = { mustprogress uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress norecurse uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #4 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #6 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"_ZTS6Status", !10, i64 0, !10, i64 4, !10, i64 8}
!13 = !{!12, !10, i64 4}
!14 = !{!12, !10, i64 8}
!15 = !{i64 0, i64 4, !9, i64 4, i64 4, !9, i64 8, i64 4, !9}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}
!19 = distinct !{!19, !17}
!20 = distinct !{!20, !17}
!21 = distinct !{!21, !17}
!22 = distinct !{!22, !17}
!23 = distinct !{!23, !17}
!24 = !{!25, !10, i64 4}
!25 = !{!"_ZTS4Node", !10, i64 0, !10, i64 4}
!26 = !{!27, !10, i64 0}
!27 = !{!"_ZTSSt4pairIiiE", !10, i64 0, !10, i64 4}
!28 = !{!27, !10, i64 4}
!29 = distinct !{!29, !17}


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

%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%struct.Status = type { i32, i32, i32 }
%struct.Node = type { i32, i32 }
%"struct.std::pair" = type { i32, i32 }

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@p = external dso_local global i32, align 4
@f = external dso_local local_unnamed_addr global [10010 x [4 x i32]], align 16
@e = external dso_local global [10010 x %"class.std::vector"], align 16
@idx = external dso_local local_unnamed_addr global [21 x [21 x [21 x i32]]], align 16
@status = external dso_local local_unnamed_addr global [1771 x %struct.Status], align 16
@tot = external dso_local local_unnamed_addr global i32, align 4
@h = external dso_local local_unnamed_addr global [10010 x [1771 x %struct.Node]], align 16
@out = external dso_local local_unnamed_addr global [10010 x %"struct.std::pair"], align 16
@.str = external hidden unnamed_addr constant [10 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@stdin = external local_unnamed_addr global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1
@stdout = external local_unnamed_addr global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [7 x i8], align 1

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

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

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

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #2 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = load ptr, ptr @stdin, align 8, !tbaa !5
  %5 = tail call ptr @freopen(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, ptr noundef %4)
  %6 = load ptr, ptr @stdout, align 8, !tbaa !5
  %7 = tail call ptr @freopen(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.3, ptr noundef %6)
  %tot.promoted = load i32, ptr @tot, align 4, !tbaa !9
  br label %.preheader39

.preheader39:                                     ; preds = %0, %15
  %indvars.iv80 = phi i64 [ 0, %0 ], [ %indvars.iv.next81, %15 ]
  %indvars.iv78 = phi i64 [ 21, %0 ], [ %indvars.iv.next79, %15 ]
  %.lcssa.lcssa4546 = phi i32 [ %tot.promoted, %0 ], [ %17, %15 ]
  %8 = trunc nuw nsw i64 %indvars.iv80 to i32
  br label %.preheader

9:                                                ; preds = %15
  store i32 %17, ptr @tot, align 4, !tbaa !9
  %10 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.4, ptr noundef nonnull @n, ptr noundef nonnull @m, ptr noundef nonnull @p)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(160160) @f, i8 -1, i64 160160, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #6
  %11 = load i32, ptr @n, align 4, !tbaa !9
  %.not50 = icmp slt i32 %11, 1
  br i1 %.not50, label %._crit_edge54, label %.lr.ph53

.preheader:                                       ; preds = %.preheader39, %16
  %indvars.iv73 = phi i64 [ 0, %.preheader39 ], [ %indvars.iv.next74, %16 ]
  %.lcssa4243 = phi i32 [ %.lcssa.lcssa4546, %.preheader39 ], [ %17, %16 ]
  %12 = add nuw nsw i64 %indvars.iv73, %indvars.iv80
  %13 = sext i32 %.lcssa4243 to i64
  %14 = trunc nuw nsw i64 %indvars.iv73 to i32
  br label %18

15:                                               ; preds = %16
  %indvars.iv.next81 = add nuw nsw i64 %indvars.iv80, 1
  %indvars.iv.next79 = add nsw i64 %indvars.iv78, -1
  %exitcond85.not = icmp eq i64 %indvars.iv.next81, 21
  br i1 %exitcond85.not, label %9, label %.preheader39, !llvm.loop !11

16:                                               ; preds = %18
  %17 = trunc nsw i64 %indvars.iv.next69 to i32
  %indvars.iv.next74 = add nuw nsw i64 %indvars.iv73, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next74, %indvars.iv78
  br i1 %exitcond.not, label %15, label %.preheader, !llvm.loop !13

18:                                               ; preds = %.preheader, %18
  %indvars.iv68 = phi i64 [ %13, %.preheader ], [ %indvars.iv.next69, %18 ]
  %indvars.iv = phi i64 [ 0, %.preheader ], [ %indvars.iv.next, %18 ]
  %19 = getelementptr inbounds [1771 x %struct.Status], ptr @status, i64 0, i64 %indvars.iv68
  store i32 %8, ptr %19, align 4, !tbaa !9
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %19, i64 4
  store i32 %14, ptr %.sroa.4.0..sroa_idx, align 4, !tbaa !9
  %.sroa.5.0..sroa_idx = getelementptr inbounds i8, ptr %19, i64 8
  %20 = trunc nuw nsw i64 %indvars.iv to i32
  store i32 %20, ptr %.sroa.5.0..sroa_idx, align 4, !tbaa !9
  %indvars.iv.next69 = add nsw i64 %indvars.iv68, 1
  %21 = getelementptr inbounds [21 x [21 x [21 x i32]]], ptr @idx, i64 0, i64 %indvars.iv80, i64 %indvars.iv73, i64 %indvars.iv
  %22 = trunc nsw i64 %indvars.iv68 to i32
  store i32 %22, ptr %21, align 4, !tbaa !9
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %23 = add nuw nsw i64 %indvars.iv.next, %12
  %24 = icmp ult i64 %23, 21
  br i1 %24, label %18, label %16, !llvm.loop !14

._crit_edge54:                                    ; preds = %._crit_edge, %9
  %25 = phi i32 [ %11, %9 ], [ %39, %._crit_edge ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #6
  %26 = load i32, ptr @m, align 4, !tbaa !9
  %.not3659 = icmp slt i32 %26, 1
  br i1 %.not3659, label %._crit_edge63, label %.lr.ph62

.lr.ph53:                                         ; preds = %9, %._crit_edge
  %indvars.iv90 = phi i64 [ %indvars.iv.next91, %._crit_edge ], [ 1, %9 ]
  %27 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.5, ptr noundef nonnull %1)
  %28 = load i32, ptr @p, align 4, !tbaa !9
  %.not3848 = icmp slt i32 %28, 0
  br i1 %.not3848, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph53
  %29 = load i32, ptr %1, align 4, !tbaa !9
  %30 = zext i32 %29 to i64
  %31 = add nuw i32 %28, 1
  %wide.trip.count = zext i32 %31 to i64
  %min.iters.check = icmp ult i32 %28, 7
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

scalar.ph.preheader:                              ; preds = %middle.block, %.lr.ph
  %indvars.iv86.ph = phi i64 [ 0, %.lr.ph ], [ %n.vec, %middle.block ]
  br label %scalar.ph

vector.ph:                                        ; preds = %.lr.ph
  %n.vec = and i64 %wide.trip.count, 4294967288
  %broadcast.splatinsert = insertelement <4 x i64> poison, i64 %30, i64 0
  %broadcast.splat = shufflevector <4 x i64> %broadcast.splatinsert, <4 x i64> poison, <4 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.ind = phi <4 x i64> [ <i64 0, i64 1, i64 2, i64 3>, %vector.ph ], [ %vec.ind.next, %vector.body ]
  %step.add = add <4 x i64> %vec.ind, <i64 4, i64 4, i64 4, i64 4>
  %32 = icmp ne <4 x i64> %vec.ind, %broadcast.splat
  %33 = icmp ne <4 x i64> %step.add, %broadcast.splat
  %34 = zext <4 x i1> %32 to <4 x i32>
  %35 = zext <4 x i1> %33 to <4 x i32>
  %36 = getelementptr inbounds [10010 x [4 x i32]], ptr @f, i64 0, i64 %indvars.iv90, i64 %index
  %37 = getelementptr inbounds i8, ptr %36, i64 16
  store <4 x i32> %34, ptr %36, align 16, !tbaa !9
  store <4 x i32> %35, ptr %37, align 16, !tbaa !9
  %index.next = add nuw i64 %index, 8
  %vec.ind.next = add <4 x i64> %vec.ind, <i64 8, i64 8, i64 8, i64 8>
  %38 = icmp eq i64 %index.next, %n.vec
  br i1 %38, label %middle.block, label %vector.body, !llvm.loop !15

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  br i1 %cmp.n, label %._crit_edge, label %scalar.ph.preheader

._crit_edge:                                      ; preds = %scalar.ph, %middle.block, %.lr.ph53
  %indvars.iv.next91 = add nuw nsw i64 %indvars.iv90, 1
  %39 = load i32, ptr @n, align 4, !tbaa !9
  %40 = sext i32 %39 to i64
  %.not.not = icmp slt i64 %indvars.iv90, %40
  br i1 %.not.not, label %.lr.ph53, label %._crit_edge54, !llvm.loop !18

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %indvars.iv86 = phi i64 [ %indvars.iv.next87, %scalar.ph ], [ %indvars.iv86.ph, %scalar.ph.preheader ]
  %41 = icmp ne i64 %indvars.iv86, %30
  %42 = zext i1 %41 to i32
  %43 = getelementptr inbounds [10010 x [4 x i32]], ptr @f, i64 0, i64 %indvars.iv90, i64 %indvars.iv86
  store i32 %42, ptr %43, align 4, !tbaa !9
  %indvars.iv.next87 = add nuw nsw i64 %indvars.iv86, 1
  %exitcond89.not = icmp eq i64 %indvars.iv.next87, %wide.trip.count
  br i1 %exitcond89.not, label %._crit_edge, label %scalar.ph, !llvm.loop !19

._crit_edge63.loopexit:                           ; preds = %._crit_edge58
  %.pre = load i32, ptr @n, align 4, !tbaa !9
  br label %._crit_edge63

._crit_edge63:                                    ; preds = %._crit_edge63.loopexit, %._crit_edge54
  %44 = phi i32 [ %.pre, %._crit_edge63.loopexit ], [ %25, %._crit_edge54 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #6
  store i32 1, ptr @tot, align 4, !tbaa !9
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(141821680) @h, i8 -1, i64 141821680, i1 false)
  store i32 0, ptr getelementptr inbounds (i8, ptr @h, i64 4), align 4, !tbaa !20
  %45 = add nsw i32 %44, 1
  call void @_Z3dfsi(i32 noundef %45)
  store i32 0, ptr @tot, align 4, !tbaa !9
  %46 = load i32, ptr @n, align 4, !tbaa !9
  %47 = add nsw i32 %46, 1
  call void @_Z3pfsii(i32 noundef %47, i32 noundef 1)
  %48 = load i32, ptr @n, align 4, !tbaa !9
  %49 = add nsw i32 %48, 1
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [10010 x [4 x i32]], ptr @f, i64 0, i64 %50, i64 1
  %52 = load i32, ptr %51, align 4, !tbaa !9
  %53 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6, i32 noundef %52)
  %54 = load i32, ptr @tot, align 4, !tbaa !9
  %55 = icmp sgt i32 %54, 0
  br i1 %55, label %.lr.ph66, label %._crit_edge67

.lr.ph62:                                         ; preds = %._crit_edge54, %._crit_edge58
  %.02960 = phi i32 [ %70, %._crit_edge58 ], [ 1, %._crit_edge54 ]
  %56 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.5, ptr noundef nonnull %2)
  %57 = load i32, ptr %2, align 4, !tbaa !9
  %58 = add nsw i32 %57, -1
  store i32 %58, ptr %2, align 4, !tbaa !9
  %.not3755 = icmp eq i32 %57, 0
  br i1 %.not3755, label %._crit_edge58, label %.lr.ph57

.lr.ph57:                                         ; preds = %.lr.ph62, %.lr.ph57
  %59 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.5, ptr noundef nonnull %3)
  %60 = load i32, ptr %3, align 4
  %61 = icmp slt i32 %60, 0
  %62 = load i32, ptr @n, align 4
  %63 = sub nsw i32 %62, %60
  %64 = select i1 %61, i32 %63, i32 %60
  store i32 %64, ptr %3, align 4, !tbaa !9
  %65 = add nsw i32 %62, %.02960
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [10010 x %"class.std::vector"], ptr @e, i64 0, i64 %66
  call void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24) %67, ptr noundef nonnull align 4 dereferenceable(4) %3)
  %68 = load i32, ptr %2, align 4, !tbaa !9
  %69 = add nsw i32 %68, -1
  store i32 %69, ptr %2, align 4, !tbaa !9
  %.not37 = icmp eq i32 %68, 0
  br i1 %.not37, label %._crit_edge58, label %.lr.ph57, !llvm.loop !22

._crit_edge58:                                    ; preds = %.lr.ph57, %.lr.ph62
  %70 = add nuw nsw i32 %.02960, 1
  %71 = load i32, ptr @m, align 4, !tbaa !9
  %.not36.not = icmp slt i32 %.02960, %71
  br i1 %.not36.not, label %.lr.ph62, label %._crit_edge63.loopexit, !llvm.loop !23

._crit_edge67:                                    ; preds = %.lr.ph66, %._crit_edge63
  ret i32 0

.lr.ph66:                                         ; preds = %._crit_edge63, %.lr.ph66
  %indvars.iv93 = phi i64 [ %indvars.iv.next94, %.lr.ph66 ], [ 0, %._crit_edge63 ]
  %72 = getelementptr inbounds [10010 x %"struct.std::pair"], ptr @out, i64 0, i64 %indvars.iv93
  %73 = load i32, ptr %72, align 8, !tbaa !24
  %74 = getelementptr inbounds i8, ptr %72, i64 4
  %75 = load i32, ptr %74, align 4, !tbaa !26
  %76 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7, i32 noundef %73, i32 noundef %75)
  %indvars.iv.next94 = add nuw nsw i64 %indvars.iv93, 1
  %77 = load i32, ptr @tot, align 4, !tbaa !9
  %78 = sext i32 %77 to i64
  %79 = icmp slt i64 %indvars.iv.next94, %78
  br i1 %79, label %.lr.ph66, label %._crit_edge67, !llvm.loop !27
}

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

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #0 align 2

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

attributes #0 = { mustprogress uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress norecurse uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #4 = { 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 #5 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #6 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}
!15 = distinct !{!15, !12, !16, !17}
!16 = !{!"llvm.loop.isvectorized", i32 1}
!17 = !{!"llvm.loop.unroll.runtime.disable"}
!18 = distinct !{!18, !12}
!19 = distinct !{!19, !12, !17, !16}
!20 = !{!21, !10, i64 4}
!21 = !{!"_ZTS4Node", !10, i64 0, !10, i64 4}
!22 = distinct !{!22, !12}
!23 = distinct !{!23, !12}
!24 = !{!25, !10, i64 0}
!25 = !{!"_ZTSSt4pairIiiE", !10, i64 0, !10, i64 4}
!26 = !{!25, !10, i64 4}
!27 = distinct !{!27, !12}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass