; LLVM IR from tangjz/acm-icpc :: codeforces/complete (796D)

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

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@d = external dso_local global i32, align 4
@lnk = external dso_local global [300001 x i32], align 16
@dis = external dso_local global [300001 x i32], align 16
@pre = external dso_local global [300001 x i32], align 16
@que = external dso_local global [300001 x i32], align 16
@L = external dso_local global i32, align 4
@R = external dso_local global i32, align 4
@ans = external dso_local global i32, align 4
@e = external dso_local global [600003 x %struct.Edge], align 16
@vis = external dso_local global [300001 x i8], align 16
@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca %struct.Edge, align 4
  %8 = alloca %struct.Edge, align 4
  %9 = alloca i32, align 4
  %10 = alloca i8, align 1
  %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, ptr noundef @m, ptr noundef @d)
  %16 = load i32, ptr @n, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = mul i64 %17, 4
  call void @llvm.memset.p0.i64(ptr align 4 getelementptr inbounds (i32, ptr @dis, i64 1), i8 63, i64 %18, i1 false)
  br label %19

19:                                               ; preds = %45, %43, %0
  %20 = load i32, ptr @m, align 4, !tbaa !5
  %21 = add nsw i32 %20, -1
  store i32 %21, ptr @m, align 4, !tbaa !5
  %22 = icmp ne i32 %20, 0
  br i1 %22, label %23, label %46

23:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #6
  %24 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %2)
  %25 = load i32, ptr %2, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [300001 x i32], ptr @dis, i64 0, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = icmp ne i32 %28, 0
  br i1 %29, label %31, label %30

30:                                               ; preds = %23
  store i32 2, ptr %3, align 4
  br label %43, !llvm.loop !9

31:                                               ; preds = %23
  %32 = load i32, ptr %2, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [300001 x i32], ptr @dis, i64 0, i64 %33
  store i32 0, ptr %34, align 4, !tbaa !5
  %35 = load i32, ptr %2, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [300001 x i32], ptr @pre, i64 0, i64 %36
  store i32 -1, ptr %37, align 4, !tbaa !5
  %38 = load i32, ptr %2, align 4, !tbaa !5
  %39 = load i32, ptr @R, align 4, !tbaa !5
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr @R, align 4, !tbaa !5
  %41 = sext i32 %39 to i64
  %42 = getelementptr inbounds [300001 x i32], ptr @que, i64 0, i64 %41
  store i32 %38, ptr %42, align 4, !tbaa !5
  store i32 0, ptr %3, align 4
  br label %43

43:                                               ; preds = %31, %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #6
  %44 = load i32, ptr %3, align 4
  switch i32 %44, label %204 [
    i32 0, label %45
    i32 2, label %19
  ]

45:                                               ; preds = %43
  br label %19, !llvm.loop !9

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

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

51:                                               ; preds = %47
  store i32 4, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #6
  br label %91

52:                                               ; preds = %47
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  %53 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.2, ptr noundef %5, ptr noundef %6)
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #6
  %54 = getelementptr inbounds %struct.Edge, ptr %7, i32 0, i32 0
  %55 = load i32, ptr %5, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [300001 x i32], ptr @lnk, i64 0, i64 %56
  %58 = load i32, ptr %57, align 4, !tbaa !5
  store i32 %58, ptr %54, align 4, !tbaa !11
  %59 = getelementptr inbounds %struct.Edge, ptr %7, i32 0, i32 1
  %60 = load i32, ptr %6, align 4, !tbaa !5
  store i32 %60, ptr %59, align 4, !tbaa !13
  %61 = load i32, ptr %4, align 4, !tbaa !5
  %62 = shl i32 %61, 1
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [600003 x %struct.Edge], ptr @e, i64 0, i64 %63
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %64, ptr align 4 %7, i64 8, i1 false), !tbaa.struct !14
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #6
  %65 = load i32, ptr %4, align 4, !tbaa !5
  %66 = shl i32 %65, 1
  %67 = load i32, ptr %5, align 4, !tbaa !5
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds [300001 x i32], ptr @lnk, i64 0, i64 %68
  store i32 %66, ptr %69, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #6
  %70 = getelementptr inbounds %struct.Edge, ptr %8, i32 0, i32 0
  %71 = load i32, ptr %6, align 4, !tbaa !5
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds [300001 x i32], ptr @lnk, i64 0, i64 %72
  %74 = load i32, ptr %73, align 4, !tbaa !5
  store i32 %74, ptr %70, align 4, !tbaa !11
  %75 = getelementptr inbounds %struct.Edge, ptr %8, i32 0, i32 1
  %76 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %76, ptr %75, align 4, !tbaa !13
  %77 = load i32, ptr %4, align 4, !tbaa !5
  %78 = shl i32 %77, 1
  %79 = or i32 %78, 1
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [600003 x %struct.Edge], ptr @e, i64 0, i64 %80
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %81, ptr align 4 %8, i64 8, i1 false), !tbaa.struct !14
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  %82 = load i32, ptr %4, align 4, !tbaa !5
  %83 = shl i32 %82, 1
  %84 = or i32 %83, 1
  %85 = load i32, ptr %6, align 4, !tbaa !5
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds [300001 x i32], ptr @lnk, i64 0, i64 %86
  store i32 %84, ptr %87, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  br label %88

88:                                               ; preds = %52
  %89 = load i32, ptr %4, align 4, !tbaa !5
  %90 = add nsw i32 %89, 1
  store i32 %90, ptr %4, align 4, !tbaa !5
  br label %47, !llvm.loop !15

91:                                               ; preds = %51
  br label %92

92:                                               ; preds = %173, %91
  %93 = load i32, ptr @L, align 4, !tbaa !5
  %94 = load i32, ptr @R, align 4, !tbaa !5
  %95 = icmp slt i32 %93, %94
  br i1 %95, label %96, label %174

96:                                               ; preds = %92
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #6
  %97 = load i32, ptr @L, align 4, !tbaa !5
  %98 = add nsw i32 %97, 1
  store i32 %98, ptr @L, align 4, !tbaa !5
  %99 = sext i32 %97 to i64
  %100 = getelementptr inbounds [300001 x i32], ptr @que, i64 0, i64 %99
  %101 = load i32, ptr %100, align 4, !tbaa !5
  store i32 %101, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %10) #6
  store i8 0, ptr %10, align 1, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #6
  %102 = load i32, ptr %9, align 4, !tbaa !5
  %103 = sext i32 %102 to i64
  %104 = getelementptr inbounds [300001 x i32], ptr @lnk, i64 0, i64 %103
  %105 = load i32, ptr %104, align 4, !tbaa !5
  store i32 %105, ptr %11, align 4, !tbaa !5
  br label %106

106:                                              ; preds = %167, %96
  %107 = load i32, ptr %11, align 4, !tbaa !5
  %108 = icmp ne i32 %107, 0
  br i1 %108, label %110, label %109

109:                                              ; preds = %106
  store i32 9, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #6
  br label %173

110:                                              ; preds = %106
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #6
  %111 = load i32, ptr %11, align 4, !tbaa !5
  %112 = sext i32 %111 to i64
  %113 = getelementptr inbounds [600003 x %struct.Edge], ptr @e, i64 0, i64 %112
  %114 = getelementptr inbounds %struct.Edge, ptr %113, i32 0, i32 1
  %115 = load i32, ptr %114, align 4, !tbaa !13
  store i32 %115, ptr %12, align 4, !tbaa !5
  %116 = load i8, ptr %10, align 1, !tbaa !16, !range !18, !noundef !19
  %117 = trunc i8 %116 to i1
  br i1 %117, label %126, label %118

118:                                              ; preds = %110
  %119 = load i32, ptr %9, align 4, !tbaa !5
  %120 = sext i32 %119 to i64
  %121 = getelementptr inbounds [300001 x i32], ptr @pre, i64 0, i64 %120
  %122 = load i32, ptr %121, align 4, !tbaa !5
  %123 = load i32, ptr %12, align 4, !tbaa !5
  %124 = icmp eq i32 %122, %123
  br i1 %124, label %125, label %126

125:                                              ; preds = %118
  store i8 1, ptr %10, align 1, !tbaa !16
  br label %166

126:                                              ; preds = %118, %110
  %127 = load i32, ptr %12, align 4, !tbaa !5
  %128 = sext i32 %127 to i64
  %129 = getelementptr inbounds [300001 x i32], ptr @dis, i64 0, i64 %128
  %130 = load i32, ptr %129, align 4, !tbaa !5
  %131 = icmp eq i32 %130, 1061109567
  br i1 %131, label %132, label %150

132:                                              ; preds = %126
  %133 = load i32, ptr %9, align 4, !tbaa !5
  %134 = sext i32 %133 to i64
  %135 = getelementptr inbounds [300001 x i32], ptr @dis, i64 0, i64 %134
  %136 = load i32, ptr %135, align 4, !tbaa !5
  %137 = add nsw i32 %136, 1
  %138 = load i32, ptr %12, align 4, !tbaa !5
  %139 = sext i32 %138 to i64
  %140 = getelementptr inbounds [300001 x i32], ptr @dis, i64 0, i64 %139
  store i32 %137, ptr %140, align 4, !tbaa !5
  %141 = load i32, ptr %9, align 4, !tbaa !5
  %142 = load i32, ptr %12, align 4, !tbaa !5
  %143 = sext i32 %142 to i64
  %144 = getelementptr inbounds [300001 x i32], ptr @pre, i64 0, i64 %143
  store i32 %141, ptr %144, align 4, !tbaa !5
  %145 = load i32, ptr %12, align 4, !tbaa !5
  %146 = load i32, ptr @R, align 4, !tbaa !5
  %147 = add nsw i32 %146, 1
  store i32 %147, ptr @R, align 4, !tbaa !5
  %148 = sext i32 %146 to i64
  %149 = getelementptr inbounds [300001 x i32], ptr @que, i64 0, i64 %148
  store i32 %145, ptr %149, align 4, !tbaa !5
  br label %165

150:                                              ; preds = %126
  %151 = load i32, ptr %11, align 4, !tbaa !5
  %152 = ashr i32 %151, 1
  %153 = sext i32 %152 to i64
  %154 = getelementptr inbounds [300001 x i8], ptr @vis, i64 0, i64 %153
  %155 = load i8, ptr %154, align 1, !tbaa !16, !range !18, !noundef !19
  %156 = trunc i8 %155 to i1
  br i1 %156, label %164, label %157

157:                                              ; preds = %150
  %158 = load i32, ptr %11, align 4, !tbaa !5
  %159 = ashr i32 %158, 1
  %160 = sext i32 %159 to i64
  %161 = getelementptr inbounds [300001 x i8], ptr @vis, i64 0, i64 %160
  store i8 1, ptr %161, align 1, !tbaa !16
  %162 = load i32, ptr @ans, align 4, !tbaa !5
  %163 = add nsw i32 %162, 1
  store i32 %163, ptr @ans, align 4, !tbaa !5
  br label %164

164:                                              ; preds = %157, %150
  br label %165

165:                                              ; preds = %164, %132
  br label %166

166:                                              ; preds = %165, %125
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #6
  br label %167

167:                                              ; preds = %166
  %168 = load i32, ptr %11, align 4, !tbaa !5
  %169 = sext i32 %168 to i64
  %170 = getelementptr inbounds [600003 x %struct.Edge], ptr @e, i64 0, i64 %169
  %171 = getelementptr inbounds %struct.Edge, ptr %170, i32 0, i32 0
  %172 = load i32, ptr %171, align 8, !tbaa !11
  store i32 %172, ptr %11, align 4, !tbaa !5
  br label %106, !llvm.loop !20

173:                                              ; preds = %109
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #6
  br label %92, !llvm.loop !21

174:                                              ; preds = %92
  %175 = load i32, ptr @ans, align 4, !tbaa !5
  %176 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i32 noundef %175)
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #6
  store i32 1, ptr %13, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #6
  store i32 0, ptr %14, align 4, !tbaa !5
  br label %177

177:                                              ; preds = %199, %174
  %178 = load i32, ptr %13, align 4, !tbaa !5
  %179 = load i32, ptr @n, align 4, !tbaa !5
  %180 = icmp slt i32 %178, %179
  br i1 %180, label %182, label %181

181:                                              ; preds = %177
  store i32 12, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #6
  br label %202

182:                                              ; preds = %177
  %183 = load i32, ptr %13, align 4, !tbaa !5
  %184 = sext i32 %183 to i64
  %185 = getelementptr inbounds [300001 x i8], ptr @vis, i64 0, i64 %184
  %186 = load i8, ptr %185, align 1, !tbaa !16, !range !18, !noundef !19
  %187 = trunc i8 %186 to i1
  br i1 %187, label %189, label %188

188:                                              ; preds = %182
  br label %199

189:                                              ; preds = %182
  %190 = load i32, ptr %14, align 4, !tbaa !5
  %191 = icmp ne i32 %190, 0
  br i1 %191, label %192, label %194

192:                                              ; preds = %189
  %193 = call i32 @putchar(i32 noundef 32)
  br label %195

194:                                              ; preds = %189
  store i32 1, ptr %14, align 4, !tbaa !5
  br label %195

195:                                              ; preds = %194, %192
  %196 = phi i32 [ %193, %192 ], [ 1, %194 ]
  %197 = load i32, ptr %13, align 4, !tbaa !5
  %198 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %197)
  br label %199

199:                                              ; preds = %195, %188
  %200 = load i32, ptr %13, align 4, !tbaa !5
  %201 = add nsw i32 %200, 1
  store i32 %201, ptr %13, align 4, !tbaa !5
  br label %177, !llvm.loop !22

202:                                              ; preds = %181
  %203 = call i32 @putchar(i32 noundef 10)
  ret i32 0

204:                                              ; preds = %43
  unreachable
}

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

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

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

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

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare i32 @putchar(i32 noundef) #5

attributes #0 = { mustprogress norecurse uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { 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 #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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !6, i64 0}
!12 = !{!"_ZTS4Edge", !6, i64 0, !6, i64 4}
!13 = !{!12, !6, i64 4}
!14 = !{i64 0, i64 4, !5, i64 4, i64 4, !5}
!15 = distinct !{!15, !10}
!16 = !{!17, !17, i64 0}
!17 = !{!"bool", !7, i64 0}
!18 = !{i8 0, i8 2}
!19 = !{}
!20 = distinct !{!20, !10}
!21 = distinct !{!21, !10}
!22 = distinct !{!22, !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"

%struct.Edge = type { i32, i32 }

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@d = external dso_local global i32, align 4
@lnk = external dso_local local_unnamed_addr global [300001 x i32], align 16
@dis = external dso_local local_unnamed_addr global [300001 x i32], align 16
@pre = external dso_local local_unnamed_addr global [300001 x i32], align 16
@que = external dso_local local_unnamed_addr global [300001 x i32], align 16
@L = external dso_local local_unnamed_addr global i32, align 4
@R = external dso_local local_unnamed_addr global i32, align 4
@ans = external dso_local local_unnamed_addr global i32, align 4
@e = external dso_local local_unnamed_addr global [600003 x %struct.Edge], align 16
@vis = external dso_local local_unnamed_addr global [300001 x i8], align 16
@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @m, ptr noundef nonnull @d)
  %5 = load i32, ptr @n, align 4, !tbaa !5
  %6 = sext i32 %5 to i64
  %7 = shl nsw i64 %6, 2
  tail call void @llvm.memset.p0.i64(ptr nonnull align 4 getelementptr inbounds (i8, ptr @dis, i64 4), i8 63, i64 %7, i1 false)
  %8 = load i32, ptr @m, align 4, !tbaa !5
  %9 = add nsw i32 %8, -1
  store i32 %9, ptr @m, align 4, !tbaa !5
  %.not38 = icmp eq i32 %8, 0
  br i1 %.not38, label %.preheader37, label %.lr.ph

.preheader37.loopexit:                            ; preds = %23
  %.pre = load i32, ptr @n, align 4, !tbaa !5
  br label %.preheader37

.preheader37:                                     ; preds = %.preheader37.loopexit, %0
  %10 = phi i32 [ %.pre, %.preheader37.loopexit ], [ %5, %0 ]
  %11 = icmp sgt i32 %10, 1
  br i1 %11, label %.lr.ph40, label %.preheader

.lr.ph:                                           ; preds = %0, %23
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #5
  %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 [300001 x i32], ptr @dis, i64 0, i64 %14
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %.not36 = icmp eq i32 %16, 0
  br i1 %.not36, label %23, label %17, !llvm.loop !9

17:                                               ; preds = %.lr.ph
  store i32 0, ptr %15, align 4, !tbaa !5
  %18 = getelementptr inbounds [300001 x i32], ptr @pre, i64 0, i64 %14
  store i32 -1, ptr %18, align 4, !tbaa !5
  %19 = load i32, ptr @R, align 4, !tbaa !5
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr @R, align 4, !tbaa !5
  %21 = sext i32 %19 to i64
  %22 = getelementptr inbounds [300001 x i32], ptr @que, i64 0, i64 %21
  store i32 %13, ptr %22, align 4, !tbaa !5
  br label %23

23:                                               ; preds = %.lr.ph, %17
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #5
  %24 = load i32, ptr @m, align 4, !tbaa !5
  %25 = add nsw i32 %24, -1
  store i32 %25, ptr @m, align 4, !tbaa !5
  %.not = icmp eq i32 %24, 0
  br i1 %.not, label %.preheader37.loopexit, label %.lr.ph

.preheader:                                       ; preds = %.lr.ph40, %.preheader37
  %L.promoted = load i32, ptr @L, align 4, !tbaa !5
  %R.promoted46 = load i32, ptr @R, align 4, !tbaa !5
  %ans.promoted51 = load i32, ptr @ans, align 4, !tbaa !5
  %26 = icmp slt i32 %L.promoted, %R.promoted46
  br i1 %26, label %.lr.ph58.preheader, label %90

.lr.ph58.preheader:                               ; preds = %.preheader
  %27 = sext i32 %L.promoted to i64
  br label %.lr.ph58

.lr.ph40:                                         ; preds = %.preheader37, %.lr.ph40
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph40 ], [ 1, %.preheader37 ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #5
  %28 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.2, ptr noundef nonnull %2, ptr noundef nonnull %3)
  %29 = load i32, ptr %2, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [300001 x i32], ptr @lnk, i64 0, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = load i32, ptr %3, align 4, !tbaa !5
  %34 = shl nuw i64 %indvars.iv, 1
  %35 = trunc nuw i64 %34 to i32
  %sext = shl i64 %indvars.iv, 33
  %36 = ashr exact i64 %sext, 32
  %37 = getelementptr inbounds [600003 x %struct.Edge], ptr @e, i64 0, i64 %36
  store i32 %32, ptr %37, align 16, !tbaa !5
  %.sroa.421.0..sroa_idx = getelementptr inbounds i8, ptr %37, i64 4
  store i32 %33, ptr %.sroa.421.0..sroa_idx, align 4, !tbaa !5
  store i32 %35, ptr %31, align 4, !tbaa !5
  %38 = sext i32 %33 to i64
  %39 = getelementptr inbounds [300001 x i32], ptr @lnk, i64 0, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %41 = trunc i64 %34 to i32
  %42 = or disjoint i32 %41, 1
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [600003 x %struct.Edge], ptr @e, i64 0, i64 %43
  store i32 %40, ptr %44, align 8, !tbaa !5
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %44, i64 4
  store i32 %29, ptr %.sroa.4.0..sroa_idx, align 4, !tbaa !5
  store i32 %42, ptr %39, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %45 = load i32, ptr @n, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = icmp slt i64 %indvars.iv.next, %46
  br i1 %47, label %.lr.ph40, label %.preheader, !llvm.loop !11

.loopexit:                                        ; preds = %86, %.lr.ph58
  %ans.promoted54 = phi i32 [ %ans.promoted5556, %.lr.ph58 ], [ %ans.promoted52, %86 ]
  %R.promoted49 = phi i32 [ %R.promoted5057, %.lr.ph58 ], [ %R.promoted47, %86 ]
  %48 = sext i32 %R.promoted49 to i64
  %49 = icmp slt i64 %indvars.iv.next66, %48
  br i1 %49, label %.lr.ph58, label %._crit_edge, !llvm.loop !12

.lr.ph58:                                         ; preds = %.lr.ph58.preheader, %.loopexit
  %indvars.iv65 = phi i64 [ %27, %.lr.ph58.preheader ], [ %indvars.iv.next66, %.loopexit ]
  %R.promoted5057 = phi i32 [ %R.promoted46, %.lr.ph58.preheader ], [ %R.promoted49, %.loopexit ]
  %ans.promoted5556 = phi i32 [ %ans.promoted51, %.lr.ph58.preheader ], [ %ans.promoted54, %.loopexit ]
  %indvars.iv.next66 = add nsw i64 %indvars.iv65, 1
  %50 = getelementptr inbounds [300001 x i32], ptr @que, i64 0, i64 %indvars.iv65
  %51 = load i32, ptr %50, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [300001 x i32], ptr @lnk, i64 0, i64 %52
  %.02941 = load i32, ptr %53, align 4, !tbaa !5
  %.not3542 = icmp eq i32 %.02941, 0
  br i1 %.not3542, label %.loopexit, label %.lr.ph45

.lr.ph45:                                         ; preds = %.lr.ph58
  %54 = getelementptr inbounds [300001 x i32], ptr @pre, i64 0, i64 %52
  %55 = getelementptr inbounds [300001 x i32], ptr @dis, i64 0, i64 %52
  br label %56

56:                                               ; preds = %.lr.ph45, %86
  %ans.promoted53 = phi i32 [ %ans.promoted5556, %.lr.ph45 ], [ %ans.promoted52, %86 ]
  %R.promoted48 = phi i32 [ %R.promoted5057, %.lr.ph45 ], [ %R.promoted47, %86 ]
  %.02944 = phi i32 [ %.02941, %.lr.ph45 ], [ %.029, %86 ]
  %.03043 = phi i1 [ false, %.lr.ph45 ], [ %.131, %86 ]
  %57 = phi i32 [ %ans.promoted5556, %.lr.ph45 ], [ %88, %86 ]
  %58 = phi i32 [ %R.promoted5057, %.lr.ph45 ], [ %87, %86 ]
  %59 = sext i32 %.02944 to i64
  %60 = getelementptr inbounds [600003 x %struct.Edge], ptr @e, i64 0, i64 %59
  %61 = getelementptr inbounds i8, ptr %60, i64 4
  %62 = load i32, ptr %61, align 4, !tbaa !13
  br i1 %.03043, label %66, label %63

63:                                               ; preds = %56
  %64 = load i32, ptr %54, align 4, !tbaa !5
  %65 = icmp eq i32 %64, %62
  br i1 %65, label %86, label %66

66:                                               ; preds = %63, %56
  %67 = sext i32 %62 to i64
  %68 = getelementptr inbounds [300001 x i32], ptr @dis, i64 0, i64 %67
  %69 = load i32, ptr %68, align 4, !tbaa !5
  %70 = icmp eq i32 %69, 1061109567
  br i1 %70, label %71, label %78

71:                                               ; preds = %66
  %72 = load i32, ptr %55, align 4, !tbaa !5
  %73 = add nsw i32 %72, 1
  store i32 %73, ptr %68, align 4, !tbaa !5
  %74 = getelementptr inbounds [300001 x i32], ptr @pre, i64 0, i64 %67
  store i32 %51, ptr %74, align 4, !tbaa !5
  %75 = add nsw i32 %58, 1
  store i32 %75, ptr @R, align 4, !tbaa !5
  %76 = sext i32 %58 to i64
  %77 = getelementptr inbounds [300001 x i32], ptr @que, i64 0, i64 %76
  store i32 %62, ptr %77, align 4, !tbaa !5
  br label %86

78:                                               ; preds = %66
  %79 = ashr i32 %.02944, 1
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [300001 x i8], ptr @vis, i64 0, i64 %80
  %82 = load i8, ptr %81, align 1, !tbaa !15, !range !17, !noundef !18
  %83 = trunc nuw i8 %82 to i1
  br i1 %83, label %86, label %84

84:                                               ; preds = %78
  store i8 1, ptr %81, align 1, !tbaa !15
  %85 = add nsw i32 %57, 1
  store i32 %85, ptr @ans, align 4, !tbaa !5
  br label %86

86:                                               ; preds = %63, %71, %84, %78
  %ans.promoted52 = phi i32 [ %ans.promoted53, %71 ], [ %ans.promoted53, %78 ], [ %85, %84 ], [ %ans.promoted53, %63 ]
  %R.promoted47 = phi i32 [ %75, %71 ], [ %R.promoted48, %78 ], [ %R.promoted48, %84 ], [ %R.promoted48, %63 ]
  %87 = phi i32 [ %75, %71 ], [ %58, %78 ], [ %58, %84 ], [ %58, %63 ]
  %88 = phi i32 [ %57, %71 ], [ %57, %78 ], [ %85, %84 ], [ %57, %63 ]
  %.131 = phi i1 [ %.03043, %71 ], [ %.03043, %78 ], [ %.03043, %84 ], [ true, %63 ]
  %.029 = load i32, ptr %60, align 8, !tbaa !5
  %.not35 = icmp eq i32 %.029, 0
  br i1 %.not35, label %.loopexit, label %56, !llvm.loop !19

._crit_edge:                                      ; preds = %.loopexit
  %89 = trunc nsw i64 %indvars.iv.next66 to i32
  store i32 %89, ptr @L, align 4, !tbaa !5
  br label %90

90:                                               ; preds = %._crit_edge, %.preheader
  %91 = phi i32 [ %ans.promoted54, %._crit_edge ], [ %ans.promoted51, %.preheader ]
  %92 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %91)
  %93 = load i32, ptr @n, align 4, !tbaa !5
  %94 = icmp sgt i32 %93, 1
  br i1 %94, label %.lr.ph62, label %._crit_edge63

._crit_edge63:                                    ; preds = %106, %90
  %95 = call i32 @putchar(i32 noundef 10)
  ret i32 0

.lr.ph62:                                         ; preds = %90, %106
  %96 = phi i32 [ %107, %106 ], [ %93, %90 ]
  %indvars.iv68 = phi i64 [ %indvars.iv.next69, %106 ], [ 1, %90 ]
  %.060 = phi i32 [ %.2, %106 ], [ 0, %90 ]
  %97 = getelementptr inbounds [300001 x i8], ptr @vis, i64 0, i64 %indvars.iv68
  %98 = load i8, ptr %97, align 1, !tbaa !15, !range !17, !noundef !18
  %99 = trunc nuw i8 %98 to i1
  br i1 %99, label %100, label %106

100:                                              ; preds = %.lr.ph62
  %.not34 = icmp eq i32 %.060, 0
  br i1 %.not34, label %103, label %101

101:                                              ; preds = %100
  %102 = call i32 @putchar(i32 noundef 32)
  br label %103

103:                                              ; preds = %100, %101
  %104 = trunc nuw nsw i64 %indvars.iv68 to i32
  %105 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %104)
  %.pre71 = load i32, ptr @n, align 4, !tbaa !5
  br label %106

106:                                              ; preds = %.lr.ph62, %103
  %107 = phi i32 [ %.pre71, %103 ], [ %96, %.lr.ph62 ]
  %.2 = phi i32 [ 1, %103 ], [ %.060, %.lr.ph62 ]
  %indvars.iv.next69 = add nuw nsw i64 %indvars.iv68, 1
  %108 = sext i32 %107 to i64
  %109 = icmp slt i64 %indvars.iv.next69, %108
  br i1 %109, label %.lr.ph62, label %._crit_edge63, !llvm.loop !20
}

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

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

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

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

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

; Function Attrs: inlinehint mustprogress nofree nounwind uwtable
declare noundef i32 @putchar(i32 noundef) local_unnamed_addr #4

attributes #0 = { mustprogress nofree norecurse 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 = { 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 #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { inlinehint mustprogress nofree 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 #5 = { 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 = !{!14, !6, i64 4}
!14 = !{!"_ZTS4Edge", !6, i64 0, !6, i64 4}
!15 = !{!16, !16, i64 0}
!16 = !{!"bool", !7, i64 0}
!17 = !{i8 0, i8 2}
!18 = !{}
!19 = distinct !{!19, !10}
!20 = distinct !{!20, !10}


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