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

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

@N = external dso_local global i32, align 4
@M = external dso_local global i32, align 4
@S = external dso_local global i32, align 4
@T = external dso_local global i32, align 4
@lnk = external dso_local global [61 x i32], align 16
@cur = external dso_local global [61 x i32], align 16
@n = external dso_local global i32, align 4
@a = external dso_local global [61 x i32], align 16
@fa = external dso_local global [2 x [61 x i32]], align 16
@idx = external dso_local global i32, align 4
@ans = external dso_local global i32, align 4
@g = external dso_local global [2 x [61 x %"class.std::vector"]], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z7addEdgeiii(i32 noundef, i32 noundef, 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z3bfsv() #0

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z3dfsii(i32 noundef, i32 noundef) #4

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

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

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

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

21:                                               ; preds = %16
  %22 = load i32, ptr %2, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds i32, ptr @a, i64 %23
  %25 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %24)
  br label %26

26:                                               ; preds = %21
  %27 = load i32, ptr %2, align 4, !tbaa !5
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr %2, align 4, !tbaa !5
  br label %16, !llvm.loop !9

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

30:                                               ; preds = %58, %29
  %31 = load i32, ptr %3, align 4, !tbaa !5
  %32 = icmp slt i32 %31, 2
  br i1 %32, label %34, label %33

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

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

35:                                               ; preds = %54, %34
  %36 = load i32, ptr %5, align 4, !tbaa !5
  %37 = load i32, ptr @n, align 4, !tbaa !5
  %38 = icmp slt i32 %36, %37
  br i1 %38, label %40, label %39

39:                                               ; preds = %35
  store i32 8, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #7
  br label %57

40:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #7
  %41 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %6, ptr noundef %7)
  %42 = load i32, ptr %3, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [2 x [61 x %"class.std::vector"]], ptr @g, i64 0, i64 %43
  %45 = load i32, ptr %6, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [61 x %"class.std::vector"], ptr %44, i64 0, i64 %46
  call void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24) %47, ptr noundef nonnull align 4 dereferenceable(4) %7)
  %48 = load i32, ptr %3, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [2 x [61 x %"class.std::vector"]], ptr @g, i64 0, i64 %49
  %51 = load i32, ptr %7, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [61 x %"class.std::vector"], ptr %50, i64 0, i64 %52
  call void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24) %53, ptr noundef nonnull align 4 dereferenceable(4) %6)
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #7
  br label %54

54:                                               ; preds = %40
  %55 = load i32, ptr %5, align 4, !tbaa !5
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr %5, align 4, !tbaa !5
  br label %35, !llvm.loop !11

57:                                               ; preds = %39
  br label %58

58:                                               ; preds = %57
  %59 = load i32, ptr %3, align 4, !tbaa !5
  %60 = add nsw i32 %59, 1
  store i32 %60, ptr %3, align 4, !tbaa !5
  br label %30, !llvm.loop !12

61:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #7
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %62

62:                                               ; preds = %194, %61
  %63 = load i32, ptr %8, align 4, !tbaa !5
  %64 = load i32, ptr @n, align 4, !tbaa !5
  %65 = icmp slt i32 %63, %64
  br i1 %65, label %67, label %66

66:                                               ; preds = %62
  store i32 11, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #7
  br label %197

67:                                               ; preds = %62
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #7
  store i32 0, ptr %9, align 4, !tbaa !5
  br label %68

68:                                               ; preds = %82, %67
  %69 = load i32, ptr %9, align 4, !tbaa !5
  %70 = icmp slt i32 %69, 2
  br i1 %70, label %72, label %71

71:                                               ; preds = %68
  store i32 14, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #7
  br label %85

72:                                               ; preds = %68
  %73 = load i32, ptr %8, align 4, !tbaa !5
  %74 = load i32, ptr @idx, align 4, !tbaa !5
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds [2 x [61 x i32]], ptr @fa, i64 0, i64 %75
  %77 = load i32, ptr %8, align 4, !tbaa !5
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds [61 x i32], ptr %76, i64 0, i64 %78
  store i32 -1, ptr %79, align 4, !tbaa !5
  call void @_Z3pfsii(i32 noundef %73, i32 noundef -1)
  %80 = load i32, ptr @idx, align 4, !tbaa !5
  %81 = xor i32 %80, 1
  store i32 %81, ptr @idx, align 4, !tbaa !5
  br label %82

82:                                               ; preds = %72
  %83 = load i32, ptr %9, align 4, !tbaa !5
  %84 = add nsw i32 %83, 1
  store i32 %84, ptr %9, align 4, !tbaa !5
  br label %68, !llvm.loop !13

85:                                               ; preds = %71
  %86 = load i32, ptr @n, align 4, !tbaa !5
  %87 = add nsw i32 %86, 2
  store i32 %87, ptr @N, align 4, !tbaa !5
  store i32 0, ptr @M, align 4, !tbaa !5
  %88 = load i32, ptr @N, align 4, !tbaa !5
  %89 = sub nsw i32 %88, 2
  store i32 %89, ptr @S, align 4, !tbaa !5
  %90 = load i32, ptr @N, align 4, !tbaa !5
  %91 = sub nsw i32 %90, 1
  store i32 %91, ptr @T, align 4, !tbaa !5
  %92 = load i32, ptr @N, align 4, !tbaa !5
  %93 = sext i32 %92 to i64
  %94 = mul i64 %93, 4
  call void @llvm.memset.p0.i64(ptr align 16 @lnk, i8 -1, i64 %94, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #7
  store i32 0, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #7
  store i32 0, ptr %11, align 4, !tbaa !5
  br label %95

95:                                               ; preds = %162, %85
  %96 = load i32, ptr %11, align 4, !tbaa !5
  %97 = load i32, ptr @n, align 4, !tbaa !5
  %98 = icmp slt i32 %96, %97
  br i1 %98, label %100, label %99

99:                                               ; preds = %95
  store i32 17, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #7
  br label %165

100:                                              ; preds = %95
  %101 = load i32, ptr %11, align 4, !tbaa !5
  %102 = sext i32 %101 to i64
  %103 = getelementptr inbounds [61 x i32], ptr @a, i64 0, i64 %102
  %104 = load i32, ptr %103, align 4, !tbaa !5
  %105 = icmp sgt i32 %104, 0
  br i1 %105, label %106, label %119

106:                                              ; preds = %100
  %107 = load i32, ptr %11, align 4, !tbaa !5
  %108 = sext i32 %107 to i64
  %109 = getelementptr inbounds [61 x i32], ptr @a, i64 0, i64 %108
  %110 = load i32, ptr %109, align 4, !tbaa !5
  %111 = load i32, ptr %10, align 4, !tbaa !5
  %112 = add nsw i32 %111, %110
  store i32 %112, ptr %10, align 4, !tbaa !5
  %113 = load i32, ptr @S, align 4, !tbaa !5
  %114 = load i32, ptr %11, align 4, !tbaa !5
  %115 = load i32, ptr %11, align 4, !tbaa !5
  %116 = sext i32 %115 to i64
  %117 = getelementptr inbounds [61 x i32], ptr @a, i64 0, i64 %116
  %118 = load i32, ptr %117, align 4, !tbaa !5
  call void @_Z7addEdgeiii(i32 noundef %113, i32 noundef %114, i32 noundef %118)
  br label %134

119:                                              ; preds = %100
  %120 = load i32, ptr %11, align 4, !tbaa !5
  %121 = sext i32 %120 to i64
  %122 = getelementptr inbounds [61 x i32], ptr @a, i64 0, i64 %121
  %123 = load i32, ptr %122, align 4, !tbaa !5
  %124 = icmp slt i32 %123, 0
  br i1 %124, label %125, label %133

125:                                              ; preds = %119
  %126 = load i32, ptr %11, align 4, !tbaa !5
  %127 = load i32, ptr @T, align 4, !tbaa !5
  %128 = load i32, ptr %11, align 4, !tbaa !5
  %129 = sext i32 %128 to i64
  %130 = getelementptr inbounds [61 x i32], ptr @a, i64 0, i64 %129
  %131 = load i32, ptr %130, align 4, !tbaa !5
  %132 = sub nsw i32 0, %131
  call void @_Z7addEdgeiii(i32 noundef %126, i32 noundef %127, i32 noundef %132)
  br label %133

133:                                              ; preds = %125, %119
  br label %134

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

135:                                              ; preds = %158, %134
  %136 = load i32, ptr %12, align 4, !tbaa !5
  %137 = icmp slt i32 %136, 2
  br i1 %137, label %139, label %138

138:                                              ; preds = %135
  store i32 20, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #7
  br label %161

139:                                              ; preds = %135
  %140 = load i32, ptr %12, align 4, !tbaa !5
  %141 = sext i32 %140 to i64
  %142 = getelementptr inbounds [2 x [61 x i32]], ptr @fa, i64 0, i64 %141
  %143 = load i32, ptr %11, align 4, !tbaa !5
  %144 = sext i32 %143 to i64
  %145 = getelementptr inbounds [61 x i32], ptr %142, i64 0, i64 %144
  %146 = load i32, ptr %145, align 4, !tbaa !5
  %147 = icmp ne i32 %146, -1
  br i1 %147, label %148, label %157

148:                                              ; preds = %139
  %149 = load i32, ptr %11, align 4, !tbaa !5
  %150 = load i32, ptr %12, align 4, !tbaa !5
  %151 = sext i32 %150 to i64
  %152 = getelementptr inbounds [2 x [61 x i32]], ptr @fa, i64 0, i64 %151
  %153 = load i32, ptr %11, align 4, !tbaa !5
  %154 = sext i32 %153 to i64
  %155 = getelementptr inbounds [61 x i32], ptr %152, i64 0, i64 %154
  %156 = load i32, ptr %155, align 4, !tbaa !5
  call void @_Z7addEdgeiii(i32 noundef %149, i32 noundef %156, i32 noundef 1061109567)
  br label %157

157:                                              ; preds = %148, %139
  br label %158

158:                                              ; preds = %157
  %159 = load i32, ptr %12, align 4, !tbaa !5
  %160 = add nsw i32 %159, 1
  store i32 %160, ptr %12, align 4, !tbaa !5
  br label %135, !llvm.loop !14

161:                                              ; preds = %138
  br label %162

162:                                              ; preds = %161
  %163 = load i32, ptr %11, align 4, !tbaa !5
  %164 = add nsw i32 %163, 1
  store i32 %164, ptr %11, align 4, !tbaa !5
  br label %95, !llvm.loop !15

165:                                              ; preds = %99
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #7
  store i32 0, ptr %13, align 4, !tbaa !5
  br label %166

166:                                              ; preds = %182, %165
  %167 = call noundef zeroext i1 @_Z3bfsv()
  br i1 %167, label %168, label %183

168:                                              ; preds = %166
  %169 = load i32, ptr @N, align 4, !tbaa !5
  %170 = sext i32 %169 to i64
  %171 = mul i64 %170, 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 @cur, ptr align 16 @lnk, i64 %171, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #7
  br label %172

172:                                              ; preds = %178, %168
  %173 = load i32, ptr @S, align 4, !tbaa !5
  %174 = call noundef i32 @_Z3dfsii(i32 noundef %173, i32 noundef 1061109567)
  store i32 %174, ptr %14, align 4, !tbaa !5
  %175 = icmp ne i32 %174, 0
  br i1 %175, label %177, label %176

176:                                              ; preds = %172
  store i32 25, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #7
  br label %182

177:                                              ; preds = %172
  br label %178

178:                                              ; preds = %177
  %179 = load i32, ptr %14, align 4, !tbaa !5
  %180 = load i32, ptr %13, align 4, !tbaa !5
  %181 = add nsw i32 %180, %179
  store i32 %181, ptr %13, align 4, !tbaa !5
  br label %172, !llvm.loop !16

182:                                              ; preds = %176
  br label %166, !llvm.loop !17

183:                                              ; preds = %166
  %184 = load i32, ptr @ans, align 4, !tbaa !5
  %185 = load i32, ptr %10, align 4, !tbaa !5
  %186 = load i32, ptr %13, align 4, !tbaa !5
  %187 = sub nsw i32 %185, %186
  %188 = icmp slt i32 %184, %187
  br i1 %188, label %189, label %193

189:                                              ; preds = %183
  %190 = load i32, ptr %10, align 4, !tbaa !5
  %191 = load i32, ptr %13, align 4, !tbaa !5
  %192 = sub nsw i32 %190, %191
  store i32 %192, ptr @ans, align 4, !tbaa !5
  br label %193

193:                                              ; preds = %189, %183
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #7
  br label %194

194:                                              ; preds = %193
  %195 = load i32, ptr %8, align 4, !tbaa !5
  %196 = add nsw i32 %195, 1
  store i32 %196, ptr %8, align 4, !tbaa !5
  br label %62, !llvm.loop !18

197:                                              ; preds = %66
  %198 = load i32, ptr @ans, align 4, !tbaa !5
  %199 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %198)
  ret i32 0
}

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

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

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { 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 #5 = { 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 #6 = { "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 #7 = { nounwind }

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

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10}
!15 = distinct !{!15, !10}
!16 = distinct !{!16, !10}
!17 = distinct !{!17, !10}
!18 = distinct !{!18, !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"

%"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 }

@N = external dso_local local_unnamed_addr global i32, align 4
@M = external dso_local local_unnamed_addr global i32, align 4
@S = external dso_local local_unnamed_addr global i32, align 4
@T = external dso_local local_unnamed_addr global i32, align 4
@lnk = external dso_local local_unnamed_addr global [61 x i32], align 16
@cur = external dso_local local_unnamed_addr global [61 x i32], align 16
@n = external dso_local global i32, align 4
@a = external dso_local global [61 x i32], align 16
@fa = external dso_local local_unnamed_addr global [2 x [61 x i32]], align 16
@idx = external dso_local local_unnamed_addr global i32, align 4
@ans = external dso_local local_unnamed_addr global i32, align 4
@g = external dso_local global [2 x [61 x %"class.std::vector"]], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z7addEdgeiii(i32 noundef, i32 noundef, 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; 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 nounwind uwtable
declare dso_local noundef zeroext i1 @_Z3bfsv() local_unnamed_addr #0

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z3dfsii(i32 noundef, i32 noundef) local_unnamed_addr #4

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #5 {
  %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)
  %4 = load i32, ptr @n, align 4, !tbaa !5
  %5 = icmp sgt i32 %4, 0
  br i1 %5, label %.lr.ph, label %.preheader54.._crit_edge72_crit_edge

.preheader56:                                     ; preds = %.lr.ph
  %6 = icmp sgt i32 %9, 1
  br i1 %6, label %.lr.ph59, label %.preheader54

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %0 ]
  %7 = getelementptr inbounds i32, ptr @a, i64 %indvars.iv
  %8 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %7)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %9 = load i32, ptr @n, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = icmp slt i64 %indvars.iv.next, %10
  br i1 %11, label %.lr.ph, label %.preheader56, !llvm.loop !9

.preheader54:                                     ; preds = %.lr.ph59.1, %._crit_edge, %.preheader56
  %12 = phi i32 [ %9, %.preheader56 ], [ %33, %._crit_edge ], [ %23, %.lr.ph59.1 ]
  %13 = icmp sgt i32 %12, 0
  br i1 %13, label %.preheader53, label %.preheader54.._crit_edge72_crit_edge

.preheader54.._crit_edge72_crit_edge:             ; preds = %0, %.preheader54
  %.pre = load i32, ptr @ans, align 4, !tbaa !5
  br label %._crit_edge72

._crit_edge:                                      ; preds = %.lr.ph59
  %14 = icmp sgt i32 %33, 1
  br i1 %14, label %.lr.ph59.1, label %.preheader54

.lr.ph59.1:                                       ; preds = %._crit_edge, %.lr.ph59.1
  %.04558.1 = phi i32 [ %22, %.lr.ph59.1 ], [ 1, %._crit_edge ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #7
  %15 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %1, ptr noundef nonnull %2)
  %16 = load i32, ptr %1, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [2 x [61 x %"class.std::vector"]], ptr @g, i64 0, i64 1, i64 %17
  call void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24) %18, ptr noundef nonnull align 4 dereferenceable(4) %2)
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [2 x [61 x %"class.std::vector"]], ptr @g, i64 0, i64 1, i64 %20
  call void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24) %21, ptr noundef nonnull align 4 dereferenceable(4) %1)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #7
  %22 = add nuw nsw i32 %.04558.1, 1
  %23 = load i32, ptr @n, align 4, !tbaa !5
  %24 = icmp slt i32 %22, %23
  br i1 %24, label %.lr.ph59.1, label %.preheader54, !llvm.loop !11

.lr.ph59:                                         ; preds = %.preheader56, %.lr.ph59
  %.04558 = phi i32 [ %32, %.lr.ph59 ], [ 1, %.preheader56 ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #7
  %25 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %1, ptr noundef nonnull %2)
  %26 = load i32, ptr %1, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [2 x [61 x %"class.std::vector"]], ptr @g, i64 0, i64 0, i64 %27
  call void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24) %28, ptr noundef nonnull align 4 dereferenceable(4) %2)
  %29 = load i32, ptr %2, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [2 x [61 x %"class.std::vector"]], ptr @g, i64 0, i64 0, i64 %30
  call void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24) %31, ptr noundef nonnull align 4 dereferenceable(4) %1)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #7
  %32 = add nuw nsw i32 %.04558, 1
  %33 = load i32, ptr @n, align 4, !tbaa !5
  %34 = icmp slt i32 %32, %33
  br i1 %34, label %.lr.ph59, label %._crit_edge, !llvm.loop !11

.preheader53:                                     ; preds = %.preheader54, %93
  %indvars.iv84 = phi i64 [ %indvars.iv.next85, %93 ], [ 0, %.preheader54 ]
  %35 = load i32, ptr @idx, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [2 x [61 x i32]], ptr @fa, i64 0, i64 %36, i64 %indvars.iv84
  store i32 -1, ptr %37, align 4, !tbaa !5
  %38 = trunc nuw nsw i64 %indvars.iv84 to i32
  call void @_Z3pfsii(i32 noundef %38, i32 noundef -1)
  %39 = load i32, ptr @idx, align 4, !tbaa !5
  %40 = xor i32 %39, 1
  store i32 %40, ptr @idx, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [2 x [61 x i32]], ptr @fa, i64 0, i64 %41, i64 %indvars.iv84
  store i32 -1, ptr %42, align 4, !tbaa !5
  call void @_Z3pfsii(i32 noundef %38, i32 noundef -1)
  %43 = load i32, ptr @idx, align 4, !tbaa !5
  %44 = xor i32 %43, 1
  store i32 %44, ptr @idx, align 4, !tbaa !5
  %45 = load i32, ptr @n, align 4, !tbaa !5
  %46 = add nsw i32 %45, 2
  store i32 %46, ptr @N, align 4, !tbaa !5
  store i32 0, ptr @M, align 4, !tbaa !5
  store i32 %45, ptr @S, align 4, !tbaa !5
  %47 = add nsw i32 %45, 1
  store i32 %47, ptr @T, align 4, !tbaa !5
  %48 = sext i32 %46 to i64
  %49 = shl nsw i64 %48, 2
  call void @llvm.memset.p0.i64(ptr nonnull align 16 @lnk, i8 -1, i64 %49, i1 false)
  %50 = icmp sgt i32 %45, 0
  br i1 %50, label %.lr.ph66, label %.preheader

._crit_edge72:                                    ; preds = %93, %.preheader54.._crit_edge72_crit_edge
  %51 = phi i32 [ %.pre, %.preheader54.._crit_edge72_crit_edge ], [ %94, %93 ]
  %52 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %51)
  ret i32 0

.preheader:                                       ; preds = %77, %.preheader53
  %.041.lcssa = phi i32 [ 0, %.preheader53 ], [ %.142, %77 ]
  %53 = call noundef zeroext i1 @_Z3bfsv()
  br i1 %53, label %.lr.ph68, label %._crit_edge69

.lr.ph66:                                         ; preds = %.preheader53, %77
  %indvars.iv81 = phi i64 [ %indvars.iv.next82, %77 ], [ 0, %.preheader53 ]
  %.04163 = phi i32 [ %.142, %77 ], [ 0, %.preheader53 ]
  %54 = getelementptr inbounds [61 x i32], ptr @a, i64 0, i64 %indvars.iv81
  %55 = load i32, ptr %54, align 4, !tbaa !5
  %56 = icmp sgt i32 %55, 0
  br i1 %56, label %57, label %61

57:                                               ; preds = %.lr.ph66
  %58 = add nuw nsw i32 %55, %.04163
  %59 = load i32, ptr @S, align 4, !tbaa !5
  %60 = trunc nuw nsw i64 %indvars.iv81 to i32
  call void @_Z7addEdgeiii(i32 noundef %59, i32 noundef %60, i32 noundef %55)
  br label %67

61:                                               ; preds = %.lr.ph66
  %62 = icmp slt i32 %55, 0
  br i1 %62, label %63, label %67

63:                                               ; preds = %61
  %64 = load i32, ptr @T, align 4, !tbaa !5
  %65 = sub nsw i32 0, %55
  %66 = trunc nuw nsw i64 %indvars.iv81 to i32
  call void @_Z7addEdgeiii(i32 noundef %66, i32 noundef %64, i32 noundef %65)
  br label %67

67:                                               ; preds = %61, %63, %57
  %.142 = phi i32 [ %58, %57 ], [ %.04163, %63 ], [ %.04163, %61 ]
  %68 = getelementptr inbounds [2 x [61 x i32]], ptr @fa, i64 0, i64 0, i64 %indvars.iv81
  %69 = load i32, ptr %68, align 4, !tbaa !5
  %.not52 = icmp eq i32 %69, -1
  br i1 %.not52, label %72, label %70

70:                                               ; preds = %67
  %71 = trunc nuw nsw i64 %indvars.iv81 to i32
  call void @_Z7addEdgeiii(i32 noundef %71, i32 noundef %69, i32 noundef 1061109567)
  br label %72

72:                                               ; preds = %67, %70
  %73 = getelementptr inbounds [2 x [61 x i32]], ptr @fa, i64 0, i64 1, i64 %indvars.iv81
  %74 = load i32, ptr %73, align 4, !tbaa !5
  %.not52.1 = icmp eq i32 %74, -1
  br i1 %.not52.1, label %77, label %75

75:                                               ; preds = %72
  %76 = trunc nuw nsw i64 %indvars.iv81 to i32
  call void @_Z7addEdgeiii(i32 noundef %76, i32 noundef %74, i32 noundef 1061109567)
  br label %77

77:                                               ; preds = %75, %72
  %indvars.iv.next82 = add nuw nsw i64 %indvars.iv81, 1
  %78 = load i32, ptr @n, align 4, !tbaa !5
  %79 = sext i32 %78 to i64
  %80 = icmp slt i64 %indvars.iv.next82, %79
  br i1 %80, label %.lr.ph66, label %.preheader, !llvm.loop !12

.loopexit:                                        ; preds = %85
  %81 = call noundef zeroext i1 @_Z3bfsv()
  br i1 %81, label %.lr.ph68, label %._crit_edge69, !llvm.loop !13

.lr.ph68:                                         ; preds = %.preheader, %.loopexit
  %.03867 = phi i32 [ %.1, %.loopexit ], [ 0, %.preheader ]
  %82 = load i32, ptr @N, align 4, !tbaa !5
  %83 = sext i32 %82 to i64
  %84 = shl nsw i64 %83, 2
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 16 @cur, ptr nonnull align 16 @lnk, i64 %84, i1 false)
  br label %85

85:                                               ; preds = %85, %.lr.ph68
  %.1 = phi i32 [ %.03867, %.lr.ph68 ], [ %88, %85 ]
  %86 = load i32, ptr @S, align 4, !tbaa !5
  %87 = call noundef i32 @_Z3dfsii(i32 noundef %86, i32 noundef 1061109567)
  %.not = icmp eq i32 %87, 0
  %88 = add nsw i32 %87, %.1
  br i1 %.not, label %.loopexit, label %85, !llvm.loop !14

._crit_edge69:                                    ; preds = %.loopexit, %.preheader
  %.038.lcssa = phi i32 [ 0, %.preheader ], [ %.1, %.loopexit ]
  %89 = load i32, ptr @ans, align 4, !tbaa !5
  %90 = sub nsw i32 %.041.lcssa, %.038.lcssa
  %91 = icmp slt i32 %89, %90
  br i1 %91, label %92, label %93

92:                                               ; preds = %._crit_edge69
  store i32 %90, ptr @ans, align 4, !tbaa !5
  br label %93

93:                                               ; preds = %92, %._crit_edge69
  %94 = phi i32 [ %90, %92 ], [ %89, %._crit_edge69 ]
  %indvars.iv.next85 = add nuw nsw i64 %indvars.iv84, 1
  %95 = load i32, ptr @n, align 4, !tbaa !5
  %96 = sext i32 %95 to i64
  %97 = icmp slt i64 %indvars.iv.next85, %96
  br i1 %97, label %.preheader53, label %._crit_edge72, !llvm.loop !15
}

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

; 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 #4 align 2

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

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { 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 #5 = { 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 #6 = { 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 #7 = { nounwind }

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

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10}
!15 = distinct !{!15, !10}


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