; LLVM IR from tangjz/acm-icpc :: 51nod/Contest/Baishan_Geek_Challenge (D)

; 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, i32 }
%"struct.std::pair" = type { i32, i32 }

@tot = external dso_local global i32, align 4
@lnk = external dso_local global [100010 x i32], align 16
@e = external dso_local global [200020 x %struct.Edge], align 16
@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@Log = external dso_local global [200020 x i32], align 16
@st = external dso_local global [18 x [200020 x i32]], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local i64 @_Z5mergeSt4pairIiiES0_i(i64, i64, i32 noundef) #2

; 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) #3

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #4 {
  %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
  %15 = alloca %"struct.std::pair", align 4
  %16 = alloca %"struct.std::pair", align 4
  %17 = alloca %"struct.std::pair", align 4
  %18 = alloca %"struct.std::pair", align 4
  %19 = alloca %"struct.std::pair", align 4
  store i32 0, ptr %1, align 4
  %20 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #7
  store i32 1, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #7
  br label %21

21:                                               ; preds = %74, %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 %5) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #7
  br label %77

26:                                               ; preds = %21
  %27 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %3, ptr noundef %4, ptr noundef %5)
  %28 = load i32, ptr %3, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [100010 x i32], ptr @lnk, i64 0, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = load i32, ptr @tot, align 4, !tbaa !5
  %33 = add nsw i32 %32, 1
  store i32 %33, ptr @tot, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [200020 x %struct.Edge], ptr @e, i64 0, i64 %34
  %36 = getelementptr inbounds %struct.Edge, ptr %35, i32 0, i32 0
  store i32 %31, ptr %36, align 4, !tbaa !9
  %37 = load i32, ptr %4, align 4, !tbaa !5
  %38 = load i32, ptr @tot, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [200020 x %struct.Edge], ptr @e, i64 0, i64 %39
  %41 = getelementptr inbounds %struct.Edge, ptr %40, i32 0, i32 1
  store i32 %37, ptr %41, align 4, !tbaa !11
  %42 = load i32, ptr %5, align 4, !tbaa !5
  %43 = load i32, ptr @tot, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [200020 x %struct.Edge], ptr @e, i64 0, i64 %44
  %46 = getelementptr inbounds %struct.Edge, ptr %45, i32 0, i32 2
  store i32 %42, ptr %46, align 4, !tbaa !12
  %47 = load i32, ptr @tot, align 4, !tbaa !5
  %48 = load i32, ptr %3, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [100010 x i32], ptr @lnk, i64 0, i64 %49
  store i32 %47, ptr %50, align 4, !tbaa !5
  %51 = load i32, ptr %4, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [100010 x i32], ptr @lnk, i64 0, i64 %52
  %54 = load i32, ptr %53, align 4, !tbaa !5
  %55 = load i32, ptr @tot, align 4, !tbaa !5
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr @tot, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [200020 x %struct.Edge], ptr @e, i64 0, i64 %57
  %59 = getelementptr inbounds %struct.Edge, ptr %58, i32 0, i32 0
  store i32 %54, ptr %59, align 4, !tbaa !9
  %60 = load i32, ptr %3, align 4, !tbaa !5
  %61 = load i32, ptr @tot, align 4, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [200020 x %struct.Edge], ptr @e, i64 0, i64 %62
  %64 = getelementptr inbounds %struct.Edge, ptr %63, i32 0, i32 1
  store i32 %60, ptr %64, align 4, !tbaa !11
  %65 = load i32, ptr %5, align 4, !tbaa !5
  %66 = load i32, ptr @tot, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [200020 x %struct.Edge], ptr @e, i64 0, i64 %67
  %69 = getelementptr inbounds %struct.Edge, ptr %68, i32 0, i32 2
  store i32 %65, ptr %69, align 4, !tbaa !12
  %70 = load i32, ptr @tot, align 4, !tbaa !5
  %71 = load i32, ptr %4, align 4, !tbaa !5
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds [100010 x i32], ptr @lnk, i64 0, i64 %72
  store i32 %70, ptr %73, align 4, !tbaa !5
  br label %74

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

77:                                               ; preds = %25
  store i32 0, ptr @tot, align 4, !tbaa !5
  call void @_Z3dfsii(i32 noundef 1, i32 noundef -1)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #7
  store i32 2, ptr %6, align 4, !tbaa !5
  br label %78

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

82:                                               ; preds = %78
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #7
  br label %96

83:                                               ; preds = %78
  %84 = load i32, ptr %6, align 4, !tbaa !5
  %85 = ashr i32 %84, 1
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds [200020 x i32], ptr @Log, i64 0, i64 %86
  %88 = load i32, ptr %87, align 4, !tbaa !5
  %89 = add nsw i32 %88, 1
  %90 = load i32, ptr %6, align 4, !tbaa !5
  %91 = sext i32 %90 to i64
  %92 = getelementptr inbounds [200020 x i32], ptr @Log, i64 0, i64 %91
  store i32 %89, ptr %92, align 4, !tbaa !5
  br label %93

93:                                               ; preds = %83
  %94 = load i32, ptr %6, align 4, !tbaa !5
  %95 = add nsw i32 %94, 1
  store i32 %95, ptr %6, align 4, !tbaa !5
  br label %78, !llvm.loop !15

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

97:                                               ; preds = %107, %96
  %98 = load i32, ptr %7, align 4, !tbaa !5
  %99 = load i32, ptr @tot, align 4, !tbaa !5
  %100 = icmp sle i32 %98, %99
  br i1 %100, label %102, label %101

101:                                              ; preds = %97
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #7
  br label %110

102:                                              ; preds = %97
  %103 = load i32, ptr %7, align 4, !tbaa !5
  %104 = load i32, ptr %7, align 4, !tbaa !5
  %105 = sext i32 %104 to i64
  %106 = getelementptr inbounds [200020 x i32], ptr @st, i64 0, i64 %105
  store i32 %103, ptr %106, align 4, !tbaa !5
  br label %107

107:                                              ; preds = %102
  %108 = load i32, ptr %7, align 4, !tbaa !5
  %109 = add nsw i32 %108, 1
  store i32 %109, ptr %7, align 4, !tbaa !5
  br label %97, !llvm.loop !16

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

111:                                              ; preds = %161, %110
  %112 = load i32, ptr %8, align 4, !tbaa !5
  %113 = load i32, ptr @tot, align 4, !tbaa !5
  %114 = sext i32 %113 to i64
  %115 = getelementptr inbounds [200020 x i32], ptr @Log, i64 0, i64 %114
  %116 = load i32, ptr %115, align 4, !tbaa !5
  %117 = icmp sle i32 %112, %116
  br i1 %117, label %119, label %118

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

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

120:                                              ; preds = %157, %119
  %121 = load i32, ptr %10, align 4, !tbaa !5
  %122 = load i32, ptr %8, align 4, !tbaa !5
  %123 = sub nsw i32 %122, 1
  %124 = shl i32 1, %123
  %125 = add nsw i32 %121, %124
  %126 = load i32, ptr @tot, align 4, !tbaa !5
  %127 = icmp sle i32 %125, %126
  br i1 %127, label %129, label %128

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

129:                                              ; preds = %120
  %130 = load i32, ptr %8, align 4, !tbaa !5
  %131 = sub nsw i32 %130, 1
  %132 = sext i32 %131 to i64
  %133 = getelementptr inbounds [18 x [200020 x i32]], ptr @st, i64 0, i64 %132
  %134 = load i32, ptr %10, align 4, !tbaa !5
  %135 = sext i32 %134 to i64
  %136 = getelementptr inbounds [200020 x i32], ptr %133, i64 0, i64 %135
  %137 = load i32, ptr %136, align 4, !tbaa !5
  %138 = load i32, ptr %8, align 4, !tbaa !5
  %139 = sub nsw i32 %138, 1
  %140 = sext i32 %139 to i64
  %141 = getelementptr inbounds [18 x [200020 x i32]], ptr @st, i64 0, i64 %140
  %142 = load i32, ptr %10, align 4, !tbaa !5
  %143 = load i32, ptr %8, align 4, !tbaa !5
  %144 = sub nsw i32 %143, 1
  %145 = shl i32 1, %144
  %146 = add nsw i32 %142, %145
  %147 = sext i32 %146 to i64
  %148 = getelementptr inbounds [200020 x i32], ptr %141, i64 0, i64 %147
  %149 = load i32, ptr %148, align 4, !tbaa !5
  %150 = call noundef i32 @_Z8deeplessii(i32 noundef %137, i32 noundef %149)
  %151 = load i32, ptr %8, align 4, !tbaa !5
  %152 = sext i32 %151 to i64
  %153 = getelementptr inbounds [18 x [200020 x i32]], ptr @st, i64 0, i64 %152
  %154 = load i32, ptr %10, align 4, !tbaa !5
  %155 = sext i32 %154 to i64
  %156 = getelementptr inbounds [200020 x i32], ptr %153, i64 0, i64 %155
  store i32 %150, ptr %156, align 4, !tbaa !5
  br label %157

157:                                              ; preds = %129
  %158 = load i32, ptr %10, align 4, !tbaa !5
  %159 = add nsw i32 %158, 1
  store i32 %159, ptr %10, align 4, !tbaa !5
  br label %120, !llvm.loop !17

160:                                              ; preds = %128
  br label %161

161:                                              ; preds = %160
  %162 = load i32, ptr %8, align 4, !tbaa !5
  %163 = add nsw i32 %162, 1
  store i32 %163, ptr %8, align 4, !tbaa !5
  br label %111, !llvm.loop !18

164:                                              ; preds = %118
  %165 = load i32, ptr @n, align 4, !tbaa !5
  call void @_Z5buildii(i32 noundef 1, i32 noundef %165)
  %166 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @m)
  br label %167

167:                                              ; preds = %171, %164
  %168 = load i32, ptr @m, align 4, !tbaa !5
  %169 = add nsw i32 %168, -1
  store i32 %169, ptr @m, align 4, !tbaa !5
  %170 = icmp ne i32 %168, 0
  br i1 %170, label %171, label %190

171:                                              ; preds = %167
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #7
  %172 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.2, ptr noundef %11, ptr noundef %12, ptr noundef %13, ptr noundef %14)
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #7
  %173 = load i32, ptr @n, align 4, !tbaa !5
  %174 = load i32, ptr %11, align 4, !tbaa !5
  %175 = load i32, ptr %12, align 4, !tbaa !5
  %176 = call i64 @_Z5queryiiii(i32 noundef 1, i32 noundef %173, i32 noundef %174, i32 noundef %175)
  store i64 %176, ptr %15, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #7
  %177 = load i32, ptr @n, align 4, !tbaa !5
  %178 = load i32, ptr %13, align 4, !tbaa !5
  %179 = load i32, ptr %14, align 4, !tbaa !5
  %180 = call i64 @_Z5queryiiii(i32 noundef 1, i32 noundef %177, i32 noundef %178, i32 noundef %179)
  store i64 %180, ptr %16, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #7
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %18, ptr align 4 %15, i64 8, i1 false)
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %19, ptr align 4 %16, i64 8, i1 false)
  %181 = load i64, ptr %18, align 4
  %182 = load i64, ptr %19, align 4
  %183 = call i64 @_Z5mergeSt4pairIiiES0_i(i64 %181, i64 %182, i32 noundef 0)
  store i64 %183, ptr %17, align 4
  %184 = getelementptr inbounds %"struct.std::pair", ptr %17, i32 0, i32 0
  %185 = load i32, ptr %184, align 4, !tbaa !19
  %186 = getelementptr inbounds %"struct.std::pair", ptr %17, i32 0, i32 1
  %187 = load i32, ptr %186, align 4, !tbaa !21
  %188 = call noundef i32 @_Z4distii(i32 noundef %185, i32 noundef %187)
  %189 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i32 noundef %188)
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #7
  br label %167, !llvm.loop !22

190:                                              ; preds = %167
  ret i32 0
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z8deeplessii(i32 noundef, i32 noundef) #6

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_Z4distii(i32 noundef, i32 noundef) #2

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

@tot = external dso_local local_unnamed_addr global i32, align 4
@lnk = external dso_local local_unnamed_addr global [100010 x i32], align 16
@e = external dso_local local_unnamed_addr global [200020 x %struct.Edge], align 16
@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@Log = external dso_local local_unnamed_addr global [200020 x i32], align 16
@st = external dso_local local_unnamed_addr global [18 x [200020 x i32]], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local i64 @_Z5mergeSt4pairIiiES0_i(i64, i64, i32 noundef) local_unnamed_addr #2

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

; 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 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  call void @llvm.lifetime.start.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
  %9 = load i32, ptr @n, align 4, !tbaa !5
  %10 = icmp sgt i32 %9, 1
  br i1 %10, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %0
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #6
  store i32 0, ptr @tot, align 4, !tbaa !5
  call void @_Z3dfsii(i32 noundef 1, i32 noundef -1)
  %11 = load i32, ptr @tot, align 4, !tbaa !5
  %.not38 = icmp slt i32 %11, 2
  br i1 %.not38, label %.preheader36, label %.lr.ph41.preheader

.lr.ph41.preheader:                               ; preds = %._crit_edge
  %12 = add nuw i32 %11, 1
  %wide.trip.count = zext i32 %12 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %13 = icmp eq i32 %12, 3
  br i1 %13, label %.preheader36.loopexit.unr-lcssa, label %.lr.ph41.preheader.new

.lr.ph41.preheader.new:                           ; preds = %.lr.ph41.preheader
  %14 = and i64 %wide.trip.count, 4294967294
  %15 = add nsw i64 %14, -4
  br label %.lr.ph41

.lr.ph:                                           ; preds = %0, %.lr.ph
  %.037 = phi i32 [ %37, %.lr.ph ], [ 1, %0 ]
  %16 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %1, ptr noundef nonnull %2, ptr noundef nonnull %3)
  %17 = load i32, ptr %1, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [100010 x i32], ptr @lnk, i64 0, i64 %18
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %21 = load i32, ptr @tot, align 4, !tbaa !5
  %22 = add nsw i32 %21, 1
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [200020 x %struct.Edge], ptr @e, i64 0, i64 %23
  store i32 %20, ptr %24, align 4, !tbaa !9
  %25 = load i32, ptr %2, align 4, !tbaa !5
  %26 = getelementptr inbounds [200020 x %struct.Edge], ptr @e, i64 0, i64 %23, i32 1
  store i32 %25, ptr %26, align 4, !tbaa !11
  %27 = load i32, ptr %3, align 4, !tbaa !5
  %28 = getelementptr inbounds [200020 x %struct.Edge], ptr @e, i64 0, i64 %23, i32 2
  store i32 %27, ptr %28, align 4, !tbaa !12
  store i32 %22, ptr %19, align 4, !tbaa !5
  %29 = sext i32 %25 to i64
  %30 = getelementptr inbounds [100010 x i32], ptr @lnk, i64 0, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = add nsw i32 %21, 2
  store i32 %32, ptr @tot, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [200020 x %struct.Edge], ptr @e, i64 0, i64 %33
  store i32 %31, ptr %34, align 4, !tbaa !9
  %35 = getelementptr inbounds [200020 x %struct.Edge], ptr @e, i64 0, i64 %33, i32 1
  store i32 %17, ptr %35, align 4, !tbaa !11
  %36 = getelementptr inbounds [200020 x %struct.Edge], ptr @e, i64 0, i64 %33, i32 2
  store i32 %27, ptr %36, align 4, !tbaa !12
  store i32 %32, ptr %30, align 4, !tbaa !5
  %37 = add nuw nsw i32 %.037, 1
  %38 = load i32, ptr @n, align 4, !tbaa !5
  %39 = icmp slt i32 %37, %38
  br i1 %39, label %.lr.ph, label %._crit_edge, !llvm.loop !13

.preheader36.loopexit.unr-lcssa:                  ; preds = %.lr.ph41, %.lr.ph41.preheader
  %indvars.iv.unr = phi i64 [ 2, %.lr.ph41.preheader ], [ %indvars.iv.next.1, %.lr.ph41 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.preheader36, label %.lr.ph41.epil

.lr.ph41.epil:                                    ; preds = %.preheader36.loopexit.unr-lcssa
  %40 = lshr i64 %indvars.iv.unr, 1
  %41 = and i64 %40, 2147483647
  %42 = getelementptr inbounds [200020 x i32], ptr @Log, i64 0, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !5
  %44 = add nsw i32 %43, 1
  %45 = getelementptr inbounds [200020 x i32], ptr @Log, i64 0, i64 %indvars.iv.unr
  store i32 %44, ptr %45, align 4, !tbaa !5
  br label %.preheader36

.preheader36:                                     ; preds = %.lr.ph41.epil, %.preheader36.loopexit.unr-lcssa, %._crit_edge
  %.not3142 = icmp slt i32 %11, 1
  br i1 %.not3142, label %.preheader35, label %.lr.ph44.preheader

.lr.ph44.preheader:                               ; preds = %.preheader36
  %46 = add nuw i32 %11, 1
  %wide.trip.count60 = zext i32 %46 to i64
  %47 = zext nneg i32 %11 to i64
  %min.iters.check = icmp ult i32 %11, 8
  br i1 %min.iters.check, label %.lr.ph44.preheader72, label %vector.ph

.lr.ph44.preheader72:                             ; preds = %middle.block, %.lr.ph44.preheader
  %indvars.iv57.ph = phi i64 [ 1, %.lr.ph44.preheader ], [ %ind.end, %middle.block ]
  br label %.lr.ph44

vector.ph:                                        ; preds = %.lr.ph44.preheader
  %n.vec = and i64 %47, 2147483640
  %ind.end = or disjoint i64 %n.vec, 1
  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 i32> [ <i32 1, i32 2, i32 3, i32 4>, %vector.ph ], [ %vec.ind.next, %vector.body ]
  %step.add = add <4 x i32> %vec.ind, <i32 4, i32 4, i32 4, i32 4>
  %offset.idx = or disjoint i64 %index, 1
  %48 = getelementptr inbounds [200020 x i32], ptr @st, i64 0, i64 %offset.idx
  %49 = getelementptr inbounds i8, ptr %48, i64 16
  store <4 x i32> %vec.ind, ptr %48, align 4, !tbaa !5
  store <4 x i32> %step.add, ptr %49, align 4, !tbaa !5
  %index.next = add nuw i64 %index, 8
  %vec.ind.next = add <4 x i32> %vec.ind, <i32 8, i32 8, i32 8, i32 8>
  %50 = icmp eq i64 %index.next, %n.vec
  br i1 %50, label %middle.block, label %vector.body, !llvm.loop !15

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %47
  br i1 %cmp.n, label %.preheader35, label %.lr.ph44.preheader72

.lr.ph41:                                         ; preds = %.lr.ph41, %.lr.ph41.preheader.new
  %indvars.iv = phi i64 [ 2, %.lr.ph41.preheader.new ], [ %indvars.iv.next.1, %.lr.ph41 ]
  %niter = phi i64 [ 0, %.lr.ph41.preheader.new ], [ %niter.next.1, %.lr.ph41 ]
  %51 = lshr exact i64 %indvars.iv, 1
  %52 = and i64 %51, 2147483647
  %53 = getelementptr inbounds [200020 x i32], ptr @Log, i64 0, i64 %52
  %54 = load i32, ptr %53, align 4, !tbaa !5
  %55 = add nsw i32 %54, 1
  %56 = getelementptr inbounds [200020 x i32], ptr @Log, i64 0, i64 %indvars.iv
  store i32 %55, ptr %56, align 8, !tbaa !5
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %57 = lshr exact i64 %indvars.iv, 1
  %58 = and i64 %57, 2147483647
  %59 = getelementptr inbounds [200020 x i32], ptr @Log, i64 0, i64 %58
  %60 = load i32, ptr %59, align 4, !tbaa !5
  %61 = add nsw i32 %60, 1
  %62 = getelementptr inbounds [200020 x i32], ptr @Log, i64 0, i64 %indvars.iv.next
  store i32 %61, ptr %62, align 4, !tbaa !5
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter, %15
  br i1 %niter.ncmp.1, label %.preheader36.loopexit.unr-lcssa, label %.lr.ph41, !llvm.loop !18

.preheader35:                                     ; preds = %.lr.ph44, %middle.block, %.preheader36
  %63 = sext i32 %11 to i64
  %64 = getelementptr inbounds [200020 x i32], ptr @Log, i64 0, i64 %63
  %65 = load i32, ptr %64, align 4, !tbaa !5
  %.not3249 = icmp slt i32 %65, 1
  br i1 %.not3249, label %._crit_edge51, label %.preheader

.lr.ph44:                                         ; preds = %.lr.ph44.preheader72, %.lr.ph44
  %indvars.iv57 = phi i64 [ %indvars.iv.next58, %.lr.ph44 ], [ %indvars.iv57.ph, %.lr.ph44.preheader72 ]
  %66 = getelementptr inbounds [200020 x i32], ptr @st, i64 0, i64 %indvars.iv57
  %67 = trunc nuw nsw i64 %indvars.iv57 to i32
  store i32 %67, ptr %66, align 4, !tbaa !5
  %indvars.iv.next58 = add nuw nsw i64 %indvars.iv57, 1
  %exitcond61.not = icmp eq i64 %indvars.iv.next58, %wide.trip.count60
  br i1 %exitcond61.not, label %.preheader35, label %.lr.ph44, !llvm.loop !19

.preheader:                                       ; preds = %.preheader35, %._crit_edge48
  %68 = phi i32 [ %78, %._crit_edge48 ], [ %11, %.preheader35 ]
  %indvars.iv65 = phi i64 [ %indvars.iv.next66, %._crit_edge48 ], [ 1, %.preheader35 ]
  %69 = add nsw i64 %indvars.iv65, -1
  %70 = trunc nuw nsw i64 %69 to i32
  %71 = shl nuw i32 1, %70
  %.not3445.not = icmp slt i32 %71, %68
  br i1 %.not3445.not, label %.lr.ph47, label %.preheader.._crit_edge48_crit_edge

.preheader.._crit_edge48_crit_edge:               ; preds = %.preheader
  %.pre = sext i32 %68 to i64
  br label %._crit_edge48

.lr.ph47:                                         ; preds = %.preheader
  %72 = add nuw nsw i32 %71, 1
  %73 = sext i32 %71 to i64
  br label %82

._crit_edge51:                                    ; preds = %._crit_edge48, %.preheader35
  %74 = load i32, ptr @n, align 4, !tbaa !5
  call void @_Z5buildii(i32 noundef 1, i32 noundef %74)
  %75 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @m)
  %76 = load i32, ptr @m, align 4, !tbaa !5
  %77 = add nsw i32 %76, -1
  store i32 %77, ptr @m, align 4, !tbaa !5
  %.not3352 = icmp eq i32 %76, 0
  br i1 %.not3352, label %._crit_edge55, label %.lr.ph54

._crit_edge48:                                    ; preds = %82, %.preheader.._crit_edge48_crit_edge
  %.pre-phi = phi i64 [ %.pre, %.preheader.._crit_edge48_crit_edge ], [ %93, %82 ]
  %78 = phi i32 [ %68, %.preheader.._crit_edge48_crit_edge ], [ %92, %82 ]
  %indvars.iv.next66 = add nuw nsw i64 %indvars.iv65, 1
  %79 = getelementptr inbounds [200020 x i32], ptr @Log, i64 0, i64 %.pre-phi
  %80 = load i32, ptr %79, align 4, !tbaa !5
  %81 = sext i32 %80 to i64
  %.not32.not = icmp slt i64 %indvars.iv65, %81
  br i1 %.not32.not, label %.preheader, label %._crit_edge51, !llvm.loop !20

82:                                               ; preds = %.lr.ph47, %82
  %indvars.iv62 = phi i64 [ 1, %.lr.ph47 ], [ %indvars.iv.next63, %82 ]
  %83 = phi i32 [ %72, %.lr.ph47 ], [ %94, %82 ]
  %84 = getelementptr inbounds [18 x [200020 x i32]], ptr @st, i64 0, i64 %69, i64 %indvars.iv62
  %85 = load i32, ptr %84, align 4, !tbaa !5
  %86 = sext i32 %83 to i64
  %87 = getelementptr inbounds [18 x [200020 x i32]], ptr @st, i64 0, i64 %69, i64 %86
  %88 = load i32, ptr %87, align 4, !tbaa !5
  %89 = call noundef i32 @_Z8deeplessii(i32 noundef %85, i32 noundef %88)
  %90 = getelementptr inbounds [18 x [200020 x i32]], ptr @st, i64 0, i64 %indvars.iv65, i64 %indvars.iv62
  store i32 %89, ptr %90, align 4, !tbaa !5
  %indvars.iv.next63 = add nuw nsw i64 %indvars.iv62, 1
  %91 = add nuw nsw i64 %indvars.iv.next63, %73
  %92 = load i32, ptr @tot, align 4, !tbaa !5
  %93 = sext i32 %92 to i64
  %.not34 = icmp sgt i64 %91, %93
  %94 = trunc nsw i64 %91 to i32
  br i1 %.not34, label %._crit_edge48, label %82, !llvm.loop !21

.lr.ph54:                                         ; preds = %._crit_edge51, %.lr.ph54
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %7) #6
  %95 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.2, ptr noundef nonnull %4, ptr noundef nonnull %5, ptr noundef nonnull %6, ptr noundef nonnull %7)
  %96 = load i32, ptr @n, align 4, !tbaa !5
  %97 = load i32, ptr %4, align 4, !tbaa !5
  %98 = load i32, ptr %5, align 4, !tbaa !5
  %99 = call i64 @_Z5queryiiii(i32 noundef 1, i32 noundef %96, i32 noundef %97, i32 noundef %98)
  %100 = load i32, ptr @n, align 4, !tbaa !5
  %101 = load i32, ptr %6, align 4, !tbaa !5
  %102 = load i32, ptr %7, align 4, !tbaa !5
  %103 = call i64 @_Z5queryiiii(i32 noundef 1, i32 noundef %100, i32 noundef %101, i32 noundef %102)
  %104 = call i64 @_Z5mergeSt4pairIiiES0_i(i64 %99, i64 %103, i32 noundef 0)
  %.sroa.02.0.extract.trunc = trunc i64 %104 to i32
  %.sroa.4.0.extract.shift = lshr i64 %104, 32
  %.sroa.4.0.extract.trunc = trunc nuw i64 %.sroa.4.0.extract.shift to i32
  %105 = call noundef i32 @_Z4distii(i32 noundef %.sroa.02.0.extract.trunc, i32 noundef %.sroa.4.0.extract.trunc)
  %106 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %105)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %7) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #6
  %107 = load i32, ptr @m, align 4, !tbaa !5
  %108 = add nsw i32 %107, -1
  store i32 %108, ptr @m, align 4, !tbaa !5
  %.not33 = icmp eq i32 %107, 0
  br i1 %.not33, label %._crit_edge55, label %.lr.ph54, !llvm.loop !22

._crit_edge55:                                    ; preds = %.lr.ph54, %._crit_edge51
  ret i32 0
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z8deeplessii(i32 noundef, i32 noundef) local_unnamed_addr #5

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_Z4distii(i32 noundef, i32 noundef) local_unnamed_addr #2

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 = { 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 #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 = { inlinehint 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 #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 = !{!"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, !6, i64 8}
!11 = !{!10, !6, i64 4}
!12 = !{!10, !6, i64 8}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14, !16, !17}
!16 = !{!"llvm.loop.isvectorized", i32 1}
!17 = !{!"llvm.loop.unroll.runtime.disable"}
!18 = distinct !{!18, !14}
!19 = distinct !{!19, !14, !17, !16}
!20 = distinct !{!20, !14}
!21 = distinct !{!21, !14}
!22 = distinct !{!22, !14}


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