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

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

%struct.Edge = type { i32, i32 }
%struct.Query = type { i32, i32, i32, i32 }

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@tot = external dso_local global i32, align 4
@lnk = external dso_local global [50001 x i32], align 16
@fa = external dso_local global [50001 x i32], align 16
@son = external dso_local global [50001 x i32], align 16
@top = external dso_local global [50001 x i32], align 16
@e = external dso_local global [50001 x %struct.Edge], align 16
@ans = external dso_local global [50001 x i32], align 16
@que = external dso_local global [100002 x %struct.Query], 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
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z3pfsi(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 @_Z3dfsi(i32 noundef) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z6updatei(i32 noundef) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z5queryi(i32 noundef) #2

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #3 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca %struct.Edge, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca %struct.Query, align 4
  %10 = alloca %struct.Query, 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 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @m)
  %15 = load i32, ptr @n, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = mul i64 %16, 4
  call void @llvm.memset.p0.i64(ptr align 16 @lnk, i8 -1, i64 %17, i1 false)
  %18 = load i32, ptr @n, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = mul i64 %19, 4
  call void @llvm.memset.p0.i64(ptr align 16 @son, i8 -1, i64 %20, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #8
  store i32 1, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #8
  br label %21

21:                                               ; preds = %43, %0
  %22 = load i32, ptr %2, align 4, !tbaa !5
  %23 = load i32, ptr @n, align 4, !tbaa !5
  %24 = icmp slt i32 %22, %23
  br i1 %24, label %26, label %25

25:                                               ; preds = %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #8
  br label %46

26:                                               ; preds = %21
  %27 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %3)
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #8
  %28 = getelementptr inbounds %struct.Edge, ptr %4, i32 0, i32 0
  %29 = load i32, ptr %3, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [50001 x i32], ptr @lnk, i64 0, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !5
  store i32 %32, ptr %28, align 4, !tbaa !9
  %33 = getelementptr inbounds %struct.Edge, ptr %4, i32 0, i32 1
  %34 = load i32, ptr %2, align 4, !tbaa !5
  store i32 %34, ptr %33, align 4, !tbaa !11
  %35 = load i32, ptr @tot, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [50001 x %struct.Edge], ptr @e, i64 0, i64 %36
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %37, ptr align 4 %4, i64 8, i1 false), !tbaa.struct !12
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #8
  %38 = load i32, ptr @tot, align 4, !tbaa !5
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr @tot, align 4, !tbaa !5
  %40 = load i32, ptr %3, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [50001 x i32], ptr @lnk, i64 0, i64 %41
  store i32 %38, ptr %42, align 4, !tbaa !5
  br label %43

43:                                               ; preds = %26
  %44 = load i32, ptr %2, align 4, !tbaa !5
  %45 = add nsw i32 %44, 1
  store i32 %45, ptr %2, align 4, !tbaa !5
  br label %21, !llvm.loop !13

46:                                               ; preds = %25
  store i32 -1, ptr @fa, align 16, !tbaa !5
  call void @_Z3pfsi(i32 noundef 0)
  store i32 0, ptr @tot, align 4, !tbaa !5
  store i32 0, ptr @top, align 16, !tbaa !5
  call void @_Z3dfsi(i32 noundef 0)
  store i32 0, ptr @tot, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #8
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %47

47:                                               ; preds = %81, %46
  %48 = load i32, ptr %5, align 4, !tbaa !5
  %49 = load i32, ptr @m, align 4, !tbaa !5
  %50 = icmp slt i32 %48, %49
  br i1 %50, label %52, label %51

51:                                               ; preds = %47
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #8
  br label %84

52:                                               ; preds = %47
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #8
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #8
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #8
  %53 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.2, ptr noundef %6, ptr noundef %7, ptr noundef %8)
  %54 = load i32, ptr %6, align 4, !tbaa !5
  %55 = icmp ne i32 %54, 0
  br i1 %55, label %56, label %69

56:                                               ; preds = %52
  call void @llvm.lifetime.start.p0(i64 16, ptr %9) #8
  %57 = getelementptr inbounds %struct.Query, ptr %9, i32 0, i32 0
  %58 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %58, ptr %57, align 4, !tbaa !15
  %59 = getelementptr inbounds %struct.Query, ptr %9, i32 0, i32 1
  %60 = load i32, ptr %6, align 4, !tbaa !5
  %61 = sub nsw i32 %60, 1
  store i32 %61, ptr %59, align 4, !tbaa !17
  %62 = getelementptr inbounds %struct.Query, ptr %9, i32 0, i32 2
  %63 = load i32, ptr %8, align 4, !tbaa !5
  store i32 %63, ptr %62, align 4, !tbaa !18
  %64 = getelementptr inbounds %struct.Query, ptr %9, i32 0, i32 3
  store i32 -1, ptr %64, align 4, !tbaa !19
  %65 = load i32, ptr @tot, align 4, !tbaa !5
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr @tot, align 4, !tbaa !5
  %67 = sext i32 %65 to i64
  %68 = getelementptr inbounds [100002 x %struct.Query], ptr @que, i64 0, i64 %67
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %68, ptr align 4 %9, i64 16, i1 false), !tbaa.struct !20
  call void @llvm.lifetime.end.p0(i64 16, ptr %9) #8
  br label %69

69:                                               ; preds = %56, %52
  call void @llvm.lifetime.start.p0(i64 16, ptr %10) #8
  %70 = getelementptr inbounds %struct.Query, ptr %10, i32 0, i32 0
  %71 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %71, ptr %70, align 4, !tbaa !15
  %72 = getelementptr inbounds %struct.Query, ptr %10, i32 0, i32 1
  %73 = load i32, ptr %7, align 4, !tbaa !5
  store i32 %73, ptr %72, align 4, !tbaa !17
  %74 = getelementptr inbounds %struct.Query, ptr %10, i32 0, i32 2
  %75 = load i32, ptr %8, align 4, !tbaa !5
  store i32 %75, ptr %74, align 4, !tbaa !18
  %76 = getelementptr inbounds %struct.Query, ptr %10, i32 0, i32 3
  store i32 1, ptr %76, align 4, !tbaa !19
  %77 = load i32, ptr @tot, align 4, !tbaa !5
  %78 = add nsw i32 %77, 1
  store i32 %78, ptr @tot, align 4, !tbaa !5
  %79 = sext i32 %77 to i64
  %80 = getelementptr inbounds [100002 x %struct.Query], ptr @que, i64 0, i64 %79
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %80, ptr align 4 %10, i64 16, i1 false), !tbaa.struct !20
  call void @llvm.lifetime.end.p0(i64 16, ptr %10) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #8
  br label %81

81:                                               ; preds = %69
  %82 = load i32, ptr %5, align 4, !tbaa !5
  %83 = add nsw i32 %82, 1
  store i32 %83, ptr %5, align 4, !tbaa !5
  br label %47, !llvm.loop !21

84:                                               ; preds = %51
  %85 = load i32, ptr @tot, align 4, !tbaa !5
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds %struct.Query, ptr @que, i64 %86
  call void @_ZSt4sortIP5QueryEvT_S2_(ptr noundef @que, ptr noundef %87)
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #8
  store i32 0, ptr %11, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #8
  store i32 0, ptr %12, align 4, !tbaa !5
  br label %88

88:                                               ; preds = %135, %84
  %89 = load i32, ptr %11, align 4, !tbaa !5
  %90 = load i32, ptr @n, align 4, !tbaa !5
  %91 = icmp slt i32 %89, %90
  br i1 %91, label %93, label %92

92:                                               ; preds = %88
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #8
  br label %138

93:                                               ; preds = %88
  %94 = load i32, ptr %11, align 4, !tbaa !5
  call void @_Z6updatei(i32 noundef %94)
  br label %95

95:                                               ; preds = %131, %93
  %96 = load i32, ptr %12, align 4, !tbaa !5
  %97 = load i32, ptr @tot, align 4, !tbaa !5
  %98 = icmp slt i32 %96, %97
  br i1 %98, label %99, label %107

99:                                               ; preds = %95
  %100 = load i32, ptr %12, align 4, !tbaa !5
  %101 = sext i32 %100 to i64
  %102 = getelementptr inbounds [100002 x %struct.Query], ptr @que, i64 0, i64 %101
  %103 = getelementptr inbounds %struct.Query, ptr %102, i32 0, i32 1
  %104 = load i32, ptr %103, align 4, !tbaa !17
  %105 = load i32, ptr %11, align 4, !tbaa !5
  %106 = icmp eq i32 %104, %105
  br label %107

107:                                              ; preds = %99, %95
  %108 = phi i1 [ false, %95 ], [ %106, %99 ]
  br i1 %108, label %109, label %134

109:                                              ; preds = %107
  %110 = load i32, ptr %12, align 4, !tbaa !5
  %111 = sext i32 %110 to i64
  %112 = getelementptr inbounds [100002 x %struct.Query], ptr @que, i64 0, i64 %111
  %113 = getelementptr inbounds %struct.Query, ptr %112, i32 0, i32 2
  %114 = load i32, ptr %113, align 8, !tbaa !18
  %115 = call noundef i32 @_Z5queryi(i32 noundef %114)
  %116 = load i32, ptr %12, align 4, !tbaa !5
  %117 = sext i32 %116 to i64
  %118 = getelementptr inbounds [100002 x %struct.Query], ptr @que, i64 0, i64 %117
  %119 = getelementptr inbounds %struct.Query, ptr %118, i32 0, i32 3
  %120 = load i32, ptr %119, align 4, !tbaa !19
  %121 = mul nsw i32 %115, %120
  %122 = load i32, ptr %12, align 4, !tbaa !5
  %123 = sext i32 %122 to i64
  %124 = getelementptr inbounds [100002 x %struct.Query], ptr @que, i64 0, i64 %123
  %125 = getelementptr inbounds %struct.Query, ptr %124, i32 0, i32 0
  %126 = load i32, ptr %125, align 16, !tbaa !15
  %127 = sext i32 %126 to i64
  %128 = getelementptr inbounds [50001 x i32], ptr @ans, i64 0, i64 %127
  %129 = load i32, ptr %128, align 4, !tbaa !5
  %130 = add nsw i32 %129, %121
  store i32 %130, ptr %128, align 4, !tbaa !5
  br label %131

131:                                              ; preds = %109
  %132 = load i32, ptr %12, align 4, !tbaa !5
  %133 = add nsw i32 %132, 1
  store i32 %133, ptr %12, align 4, !tbaa !5
  br label %95, !llvm.loop !22

134:                                              ; preds = %107
  br label %135

135:                                              ; preds = %134
  %136 = load i32, ptr %11, align 4, !tbaa !5
  %137 = add nsw i32 %136, 1
  store i32 %137, ptr %11, align 4, !tbaa !5
  br label %88, !llvm.loop !23

138:                                              ; preds = %92
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #8
  store i32 0, ptr %13, align 4, !tbaa !5
  br label %139

139:                                              ; preds = %164, %138
  %140 = load i32, ptr %13, align 4, !tbaa !5
  %141 = load i32, ptr @m, align 4, !tbaa !5
  %142 = icmp slt i32 %140, %141
  br i1 %142, label %144, label %143

143:                                              ; preds = %139
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #8
  br label %167

144:                                              ; preds = %139
  %145 = load i32, ptr %13, align 4, !tbaa !5
  %146 = sext i32 %145 to i64
  %147 = getelementptr inbounds [50001 x i32], ptr @ans, i64 0, i64 %146
  %148 = load i32, ptr %147, align 4, !tbaa !5
  %149 = icmp slt i32 %148, 0
  br i1 %149, label %150, label %156

150:                                              ; preds = %144
  %151 = load i32, ptr %13, align 4, !tbaa !5
  %152 = sext i32 %151 to i64
  %153 = getelementptr inbounds [50001 x i32], ptr @ans, i64 0, i64 %152
  %154 = load i32, ptr %153, align 4, !tbaa !5
  %155 = add nsw i32 %154, 201314
  br label %161

156:                                              ; preds = %144
  %157 = load i32, ptr %13, align 4, !tbaa !5
  %158 = sext i32 %157 to i64
  %159 = getelementptr inbounds [50001 x i32], ptr @ans, i64 0, i64 %158
  %160 = load i32, ptr %159, align 4, !tbaa !5
  br label %161

161:                                              ; preds = %156, %150
  %162 = phi i32 [ %155, %150 ], [ %160, %156 ]
  %163 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i32 noundef %162)
  br label %164

164:                                              ; preds = %161
  %165 = load i32, ptr %13, align 4, !tbaa !5
  %166 = add nsw i32 %165, 1
  store i32 %166, ptr %13, align 4, !tbaa !5
  br label %139, !llvm.loop !24

167:                                              ; preds = %143
  ret i32 0
}

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

; 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: 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) #6

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIP5QueryEvT_S2_(ptr noundef, ptr noundef) #7

declare i32 @printf(ptr noundef, ...) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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 #4 = { "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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #6 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #7 = { 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 #8 = { 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, !6, i64 0}
!10 = !{!"_ZTS4Edge", !6, i64 0, !6, i64 4}
!11 = !{!10, !6, i64 4}
!12 = !{i64 0, i64 4, !5, i64 4, i64 4, !5}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !6, i64 0}
!16 = !{!"_ZTS5Query", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12}
!17 = !{!16, !6, i64 4}
!18 = !{!16, !6, i64 8}
!19 = !{!16, !6, i64 12}
!20 = !{i64 0, i64 4, !5, i64 4, i64 4, !5, i64 8, i64 4, !5, i64 12, i64 4, !5}
!21 = distinct !{!21, !14}
!22 = distinct !{!22, !14}
!23 = distinct !{!23, !14}
!24 = distinct !{!24, !14}


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

%struct.Edge = type { i32, i32 }
%struct.Query = type { i32, i32, i32, i32 }

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@tot = external dso_local local_unnamed_addr global i32, align 4
@lnk = external dso_local local_unnamed_addr global [50001 x i32], align 16
@fa = external dso_local local_unnamed_addr global [50001 x i32], align 16
@son = external dso_local local_unnamed_addr global [50001 x i32], align 16
@top = external dso_local local_unnamed_addr global [50001 x i32], align 16
@e = external dso_local local_unnamed_addr global [50001 x %struct.Edge], align 16
@ans = external dso_local local_unnamed_addr global [50001 x i32], align 16
@que = external dso_local global [100002 x %struct.Query], 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
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z3pfsi(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 @_Z3dfsi(i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z6updatei(i32 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z5queryi(i32 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #3 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @m)
  %6 = load i32, ptr @n, align 4, !tbaa !5
  %7 = sext i32 %6 to i64
  %8 = shl nsw i64 %7, 2
  tail call void @llvm.memset.p0.i64(ptr nonnull align 16 @lnk, i8 -1, i64 %8, i1 false)
  tail call void @llvm.memset.p0.i64(ptr nonnull align 16 @son, i8 -1, i64 %8, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #7
  %9 = icmp sgt i32 %6, 1
  br i1 %9, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %0
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #7
  store i32 -1, ptr @fa, align 16, !tbaa !5
  call void @_Z3pfsi(i32 noundef 0)
  store i32 0, ptr @tot, align 4, !tbaa !5
  store i32 0, ptr @top, align 16, !tbaa !5
  call void @_Z3dfsi(i32 noundef 0)
  store i32 0, ptr @tot, align 4, !tbaa !5
  %10 = load i32, ptr @m, align 4, !tbaa !5
  %11 = icmp sgt i32 %10, 0
  br i1 %11, label %.lr.ph38, label %._crit_edge39

.lr.ph:                                           ; preds = %0, %.lr.ph
  %.03035 = phi i32 [ %21, %.lr.ph ], [ 1, %0 ]
  %12 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %1)
  %13 = load i32, ptr %1, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [50001 x i32], ptr @lnk, i64 0, i64 %14
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %17 = load i32, ptr @tot, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [50001 x %struct.Edge], ptr @e, i64 0, i64 %18
  store i32 %16, ptr %19, align 8, !tbaa !5
  %.sroa.424.0..sroa_idx = getelementptr inbounds i8, ptr %19, i64 4
  store i32 %.03035, ptr %.sroa.424.0..sroa_idx, align 4, !tbaa !5
  %20 = add nsw i32 %17, 1
  store i32 %20, ptr @tot, align 4, !tbaa !5
  store i32 %17, ptr %15, align 4, !tbaa !5
  %21 = add nuw nsw i32 %.03035, 1
  %22 = load i32, ptr @n, align 4, !tbaa !5
  %23 = icmp slt i32 %21, %22
  br i1 %23, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge39.loopexit:                           ; preds = %36
  %24 = sext i32 %39 to i64
  br label %._crit_edge39

._crit_edge39:                                    ; preds = %._crit_edge39.loopexit, %._crit_edge
  %25 = phi i64 [ %24, %._crit_edge39.loopexit ], [ 0, %._crit_edge ]
  %26 = getelementptr inbounds %struct.Query, ptr @que, i64 %25
  call void @_ZSt4sortIP5QueryEvT_S2_(ptr noundef nonnull @que, ptr noundef nonnull %26)
  %27 = load i32, ptr @n, align 4, !tbaa !5
  %28 = icmp sgt i32 %27, 0
  br i1 %28, label %.lr.ph48, label %.preheader

.lr.ph38:                                         ; preds = %._crit_edge, %36
  %.03136 = phi i32 [ %42, %36 ], [ 0, %._crit_edge ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #7
  %29 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.2, ptr noundef nonnull %2, ptr noundef nonnull %3, ptr noundef nonnull %4)
  %30 = load i32, ptr %2, align 4, !tbaa !5
  %.not = icmp eq i32 %30, 0
  %.pre = load i32, ptr %4, align 4, !tbaa !5
  %.pre57 = load i32, ptr @tot, align 4, !tbaa !5
  br i1 %.not, label %36, label %31

31:                                               ; preds = %.lr.ph38
  %32 = add nsw i32 %30, -1
  %33 = add nsw i32 %.pre57, 1
  %34 = sext i32 %.pre57 to i64
  %35 = getelementptr inbounds [100002 x %struct.Query], ptr @que, i64 0, i64 %34
  store i32 %.03136, ptr %35, align 16, !tbaa !5
  %.sroa.416.0..sroa_idx = getelementptr inbounds i8, ptr %35, i64 4
  store i32 %32, ptr %.sroa.416.0..sroa_idx, align 4, !tbaa !5
  %.sroa.517.0..sroa_idx = getelementptr inbounds i8, ptr %35, i64 8
  store i32 %.pre, ptr %.sroa.517.0..sroa_idx, align 8, !tbaa !5
  %.sroa.618.0..sroa_idx = getelementptr inbounds i8, ptr %35, i64 12
  store i32 -1, ptr %.sroa.618.0..sroa_idx, align 4, !tbaa !5
  br label %36

36:                                               ; preds = %31, %.lr.ph38
  %37 = phi i32 [ %33, %31 ], [ %.pre57, %.lr.ph38 ]
  %38 = load i32, ptr %3, align 4, !tbaa !5
  %39 = add nsw i32 %37, 1
  store i32 %39, ptr @tot, align 4, !tbaa !5
  %40 = sext i32 %37 to i64
  %41 = getelementptr inbounds [100002 x %struct.Query], ptr @que, i64 0, i64 %40
  store i32 %.03136, ptr %41, align 16, !tbaa !5
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %41, i64 4
  store i32 %38, ptr %.sroa.4.0..sroa_idx, align 4, !tbaa !5
  %.sroa.5.0..sroa_idx = getelementptr inbounds i8, ptr %41, i64 8
  store i32 %.pre, ptr %.sroa.5.0..sroa_idx, align 8, !tbaa !5
  %.sroa.6.0..sroa_idx = getelementptr inbounds i8, ptr %41, i64 12
  store i32 1, ptr %.sroa.6.0..sroa_idx, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #7
  %42 = add nuw nsw i32 %.03136, 1
  %43 = load i32, ptr @m, align 4, !tbaa !5
  %44 = icmp slt i32 %42, %43
  br i1 %44, label %.lr.ph38, label %._crit_edge39.loopexit, !llvm.loop !11

.preheader:                                       ; preds = %.critedge, %._crit_edge39
  %45 = load i32, ptr @m, align 4, !tbaa !5
  %46 = icmp sgt i32 %45, 0
  br i1 %46, label %.lr.ph50, label %._crit_edge51

.lr.ph48:                                         ; preds = %._crit_edge39, %.critedge
  %.02846 = phi i32 [ %.1.lcssa, %.critedge ], [ 0, %._crit_edge39 ]
  %.02945 = phi i32 [ %69, %.critedge ], [ 0, %._crit_edge39 ]
  call void @_Z6updatei(i32 noundef %.02945)
  %47 = load i32, ptr @tot, align 4, !tbaa !5
  %48 = icmp slt i32 %.02846, %47
  br i1 %48, label %.lr.ph42.preheader, label %.critedge

.lr.ph42.preheader:                               ; preds = %.lr.ph48
  %49 = sext i32 %.02846 to i64
  br label %.lr.ph42

.lr.ph42:                                         ; preds = %.lr.ph42.preheader, %54
  %indvars.iv = phi i64 [ %49, %.lr.ph42.preheader ], [ %indvars.iv.next, %54 ]
  %50 = getelementptr inbounds [100002 x %struct.Query], ptr @que, i64 0, i64 %indvars.iv
  %51 = getelementptr inbounds i8, ptr %50, i64 4
  %52 = load i32, ptr %51, align 4, !tbaa !12
  %53 = icmp eq i32 %52, %.02945
  br i1 %53, label %54, label %.critedge.loopexit

54:                                               ; preds = %.lr.ph42
  %55 = getelementptr inbounds i8, ptr %50, i64 8
  %56 = load i32, ptr %55, align 8, !tbaa !14
  %57 = call noundef i32 @_Z5queryi(i32 noundef %56)
  %58 = getelementptr inbounds i8, ptr %50, i64 12
  %59 = load i32, ptr %58, align 4, !tbaa !15
  %60 = mul nsw i32 %59, %57
  %61 = load i32, ptr %50, align 16, !tbaa !16
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [50001 x i32], ptr @ans, i64 0, i64 %62
  %64 = load i32, ptr %63, align 4, !tbaa !5
  %65 = add nsw i32 %64, %60
  store i32 %65, ptr %63, align 4, !tbaa !5
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %66 = load i32, ptr @tot, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = icmp slt i64 %indvars.iv.next, %67
  br i1 %68, label %.lr.ph42, label %.critedge.loopexit, !llvm.loop !17

.critedge.loopexit:                               ; preds = %.lr.ph42, %54
  %.1.lcssa.ph.in = phi i64 [ %indvars.iv.next, %54 ], [ %indvars.iv, %.lr.ph42 ]
  %.1.lcssa.ph = trunc i64 %.1.lcssa.ph.in to i32
  br label %.critedge

.critedge:                                        ; preds = %.critedge.loopexit, %.lr.ph48
  %.1.lcssa = phi i32 [ %.02846, %.lr.ph48 ], [ %.1.lcssa.ph, %.critedge.loopexit ]
  %69 = add nuw nsw i32 %.02945, 1
  %70 = load i32, ptr @n, align 4, !tbaa !5
  %71 = icmp slt i32 %69, %70
  br i1 %71, label %.lr.ph48, label %.preheader, !llvm.loop !18

._crit_edge51:                                    ; preds = %.lr.ph50, %.preheader
  ret i32 0

.lr.ph50:                                         ; preds = %.preheader, %.lr.ph50
  %indvars.iv53 = phi i64 [ %indvars.iv.next54, %.lr.ph50 ], [ 0, %.preheader ]
  %72 = getelementptr inbounds [50001 x i32], ptr @ans, i64 0, i64 %indvars.iv53
  %73 = load i32, ptr %72, align 4, !tbaa !5
  %74 = icmp slt i32 %73, 0
  %75 = add nsw i32 %73, 201314
  %76 = select i1 %74, i32 %75, i32 %73
  %77 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %76)
  %indvars.iv.next54 = add nuw nsw i64 %indvars.iv53, 1
  %78 = load i32, ptr @m, align 4, !tbaa !5
  %79 = sext i32 %78 to i64
  %80 = icmp slt i64 %indvars.iv.next54, %79
  br i1 %80, label %.lr.ph50, label %._crit_edge51, !llvm.loop !19
}

; 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: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIP5QueryEvT_S2_(ptr noundef, ptr noundef) local_unnamed_addr #6

; 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 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 #3 = { 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 #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 = { 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 #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 = !{!13, !6, i64 4}
!13 = !{!"_ZTS5Query", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12}
!14 = !{!13, !6, i64 8}
!15 = !{!13, !6, i64 12}
!16 = !{!13, !6, i64 0}
!17 = distinct !{!17, !10}
!18 = distinct !{!18, !10}
!19 = distinct !{!19, !10}


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