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

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

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@tot = external dso_local global i32, align 4
@pre = external dso_local global [100001 x i32], align 16
@que = external dso_local global [100001 x i32], align 16
@L = external dso_local global i32, align 4
@R = external dso_local global i32, align 4
@dis = external dso_local global [100001 x i32], align 16
@sum = external dso_local global i32, align 4
@ans = external dso_local global i32, align 4
@vis = external dso_local global [100001 x i8], align 16
@e = external dso_local global [2000002 x %struct.Edge], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [7 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 %struct.Edge, align 4
  %5 = alloca %struct.Edge, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %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)
  br label %16

16:                                               ; preds = %20, %0
  %17 = load i32, ptr @m, align 4, !tbaa !5
  %18 = add nsw i32 %17, -1
  store i32 %18, ptr @m, align 4, !tbaa !5
  %19 = icmp ne i32 %17, 0
  br i1 %19, label %20, label %54

20:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #6
  %21 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2, ptr noundef %3)
  call void @llvm.lifetime.start.p0(i64 12, ptr %4) #6
  %22 = getelementptr inbounds %struct.Edge, ptr %4, i32 0, i32 0
  %23 = load i32, ptr %2, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [100001 x i32], ptr @pre, i64 0, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !5
  store i32 %26, ptr %22, align 4, !tbaa !9
  %27 = getelementptr inbounds %struct.Edge, ptr %4, i32 0, i32 1
  %28 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %28, ptr %27, align 4, !tbaa !11
  %29 = getelementptr inbounds %struct.Edge, ptr %4, i32 0, i32 2
  store i32 1, ptr %29, align 4, !tbaa !12
  %30 = load i32, ptr @tot, align 4, !tbaa !5
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr @tot, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [2000002 x %struct.Edge], ptr @e, i64 0, i64 %32
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %33, ptr align 4 %4, i64 12, i1 false), !tbaa.struct !13
  call void @llvm.lifetime.end.p0(i64 12, ptr %4) #6
  %34 = load i32, ptr @tot, align 4, !tbaa !5
  %35 = load i32, ptr %2, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [100001 x i32], ptr @pre, i64 0, i64 %36
  store i32 %34, ptr %37, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 12, ptr %5) #6
  %38 = getelementptr inbounds %struct.Edge, ptr %5, i32 0, i32 0
  %39 = load i32, ptr %3, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [100001 x i32], ptr @pre, i64 0, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !5
  store i32 %42, ptr %38, align 4, !tbaa !9
  %43 = getelementptr inbounds %struct.Edge, ptr %5, i32 0, i32 1
  %44 = load i32, ptr %2, align 4, !tbaa !5
  store i32 %44, ptr %43, align 4, !tbaa !11
  %45 = getelementptr inbounds %struct.Edge, ptr %5, i32 0, i32 2
  store i32 -1, ptr %45, align 4, !tbaa !12
  %46 = load i32, ptr @tot, align 4, !tbaa !5
  %47 = add nsw i32 %46, 1
  store i32 %47, ptr @tot, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [2000002 x %struct.Edge], ptr @e, i64 0, i64 %48
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %49, ptr align 4 %5, i64 12, i1 false), !tbaa.struct !13
  call void @llvm.lifetime.end.p0(i64 12, ptr %5) #6
  %50 = load i32, ptr @tot, align 4, !tbaa !5
  %51 = load i32, ptr %3, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [100001 x i32], ptr @pre, i64 0, i64 %52
  store i32 %50, ptr %53, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #6
  br label %16, !llvm.loop !14

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

55:                                               ; preds = %193, %54
  %56 = load i32, ptr %6, align 4, !tbaa !5
  %57 = load i32, ptr @n, align 4, !tbaa !5
  %58 = icmp sle i32 %56, %57
  br i1 %58, label %60, label %59

59:                                               ; preds = %55
  store i32 4, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  br label %196

60:                                               ; preds = %55
  %61 = load i32, ptr %6, align 4, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [100001 x i8], ptr @vis, i64 0, i64 %62
  %64 = load i8, ptr %63, align 1, !tbaa !16, !range !18, !noundef !19
  %65 = trunc i8 %64 to i1
  br i1 %65, label %192, label %66

66:                                               ; preds = %60
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  store i32 0, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #6
  store i32 0, ptr %9, align 4, !tbaa !5
  %67 = load i32, ptr %6, align 4, !tbaa !5
  %68 = load i32, ptr @R, align 4, !tbaa !5
  %69 = add nsw i32 %68, 1
  store i32 %69, ptr @R, align 4, !tbaa !5
  %70 = sext i32 %68 to i64
  %71 = getelementptr inbounds [100001 x i32], ptr @que, i64 0, i64 %70
  store i32 %67, ptr %71, align 4, !tbaa !5
  %72 = load i32, ptr %6, align 4, !tbaa !5
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [100001 x i8], ptr @vis, i64 0, i64 %73
  store i8 1, ptr %74, align 1, !tbaa !16
  br label %75

75:                                               ; preds = %184, %66
  %76 = load i32, ptr @L, align 4, !tbaa !5
  %77 = load i32, ptr @R, align 4, !tbaa !5
  %78 = icmp slt i32 %76, %77
  br i1 %78, label %79, label %185

79:                                               ; preds = %75
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #6
  %80 = load i32, ptr @L, align 4, !tbaa !5
  %81 = add nsw i32 %80, 1
  store i32 %81, ptr @L, align 4, !tbaa !5
  %82 = sext i32 %80 to i64
  %83 = getelementptr inbounds [100001 x i32], ptr @que, i64 0, i64 %82
  store ptr %83, ptr %10, align 8, !tbaa !20
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #6
  %84 = load ptr, ptr %10, align 8, !tbaa !20
  %85 = load i32, ptr %84, align 4, !tbaa !5
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds [100001 x i32], ptr @pre, i64 0, i64 %86
  %88 = load i32, ptr %87, align 4, !tbaa !5
  store i32 %88, ptr %11, align 4, !tbaa !5
  br label %89

89:                                               ; preds = %178, %79
  %90 = load i32, ptr %11, align 4, !tbaa !5
  %91 = icmp ne i32 %90, 0
  br i1 %91, label %93, label %92

92:                                               ; preds = %89
  store i32 9, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #6
  br label %184

93:                                               ; preds = %89
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #6
  %94 = load i32, ptr %11, align 4, !tbaa !5
  %95 = sext i32 %94 to i64
  %96 = getelementptr inbounds [2000002 x %struct.Edge], ptr @e, i64 0, i64 %95
  %97 = getelementptr inbounds %struct.Edge, ptr %96, i32 0, i32 1
  store ptr %97, ptr %12, align 8, !tbaa !20
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #6
  %98 = load i32, ptr %11, align 4, !tbaa !5
  %99 = sext i32 %98 to i64
  %100 = getelementptr inbounds [2000002 x %struct.Edge], ptr @e, i64 0, i64 %99
  %101 = getelementptr inbounds %struct.Edge, ptr %100, i32 0, i32 2
  store ptr %101, ptr %13, align 8, !tbaa !20
  %102 = load ptr, ptr %12, align 8, !tbaa !20
  %103 = load i32, ptr %102, align 4, !tbaa !5
  %104 = sext i32 %103 to i64
  %105 = getelementptr inbounds [100001 x i8], ptr @vis, i64 0, i64 %104
  %106 = load i8, ptr %105, align 1, !tbaa !16, !range !18, !noundef !19
  %107 = trunc i8 %106 to i1
  br i1 %107, label %108, label %126

108:                                              ; preds = %93
  %109 = load i32, ptr @ans, align 4, !tbaa !5
  %110 = load ptr, ptr %10, align 8, !tbaa !20
  %111 = load i32, ptr %110, align 4, !tbaa !5
  %112 = sext i32 %111 to i64
  %113 = getelementptr inbounds [100001 x i32], ptr @dis, i64 0, i64 %112
  %114 = load i32, ptr %113, align 4, !tbaa !5
  %115 = load ptr, ptr %13, align 8, !tbaa !20
  %116 = load i32, ptr %115, align 4, !tbaa !5
  %117 = add nsw i32 %114, %116
  %118 = load ptr, ptr %12, align 8, !tbaa !20
  %119 = load i32, ptr %118, align 4, !tbaa !5
  %120 = sext i32 %119 to i64
  %121 = getelementptr inbounds [100001 x i32], ptr @dis, i64 0, i64 %120
  %122 = load i32, ptr %121, align 4, !tbaa !5
  %123 = sub nsw i32 %117, %122
  %124 = call i32 @llvm.abs.i32(i32 %123, i1 true)
  %125 = call noundef i32 @_ZSt5__gcdIiET_S0_S0_(i32 noundef %109, i32 noundef %124)
  store i32 %125, ptr @ans, align 4, !tbaa !5
  br label %177

126:                                              ; preds = %93
  %127 = load ptr, ptr %12, align 8, !tbaa !20
  %128 = load i32, ptr %127, align 4, !tbaa !5
  %129 = load i32, ptr @R, align 4, !tbaa !5
  %130 = add nsw i32 %129, 1
  store i32 %130, ptr @R, align 4, !tbaa !5
  %131 = sext i32 %129 to i64
  %132 = getelementptr inbounds [100001 x i32], ptr @que, i64 0, i64 %131
  store i32 %128, ptr %132, align 4, !tbaa !5
  %133 = load ptr, ptr %12, align 8, !tbaa !20
  %134 = load i32, ptr %133, align 4, !tbaa !5
  %135 = sext i32 %134 to i64
  %136 = getelementptr inbounds [100001 x i8], ptr @vis, i64 0, i64 %135
  store i8 1, ptr %136, align 1, !tbaa !16
  %137 = load ptr, ptr %10, align 8, !tbaa !20
  %138 = load i32, ptr %137, align 4, !tbaa !5
  %139 = sext i32 %138 to i64
  %140 = getelementptr inbounds [100001 x i32], ptr @dis, i64 0, i64 %139
  %141 = load i32, ptr %140, align 4, !tbaa !5
  %142 = load ptr, ptr %13, align 8, !tbaa !20
  %143 = load i32, ptr %142, align 4, !tbaa !5
  %144 = add nsw i32 %141, %143
  %145 = load ptr, ptr %12, align 8, !tbaa !20
  %146 = load i32, ptr %145, align 4, !tbaa !5
  %147 = sext i32 %146 to i64
  %148 = getelementptr inbounds [100001 x i32], ptr @dis, i64 0, i64 %147
  store i32 %144, ptr %148, align 4, !tbaa !5
  %149 = load i32, ptr %8, align 4, !tbaa !5
  %150 = load ptr, ptr %12, align 8, !tbaa !20
  %151 = load i32, ptr %150, align 4, !tbaa !5
  %152 = sext i32 %151 to i64
  %153 = getelementptr inbounds [100001 x i32], ptr @dis, i64 0, i64 %152
  %154 = load i32, ptr %153, align 4, !tbaa !5
  %155 = icmp slt i32 %149, %154
  br i1 %155, label %156, label %162

156:                                              ; preds = %126
  %157 = load ptr, ptr %12, align 8, !tbaa !20
  %158 = load i32, ptr %157, align 4, !tbaa !5
  %159 = sext i32 %158 to i64
  %160 = getelementptr inbounds [100001 x i32], ptr @dis, i64 0, i64 %159
  %161 = load i32, ptr %160, align 4, !tbaa !5
  store i32 %161, ptr %8, align 4, !tbaa !5
  br label %162

162:                                              ; preds = %156, %126
  %163 = load i32, ptr %9, align 4, !tbaa !5
  %164 = load ptr, ptr %12, align 8, !tbaa !20
  %165 = load i32, ptr %164, align 4, !tbaa !5
  %166 = sext i32 %165 to i64
  %167 = getelementptr inbounds [100001 x i32], ptr @dis, i64 0, i64 %166
  %168 = load i32, ptr %167, align 4, !tbaa !5
  %169 = icmp sgt i32 %163, %168
  br i1 %169, label %170, label %176

170:                                              ; preds = %162
  %171 = load ptr, ptr %12, align 8, !tbaa !20
  %172 = load i32, ptr %171, align 4, !tbaa !5
  %173 = sext i32 %172 to i64
  %174 = getelementptr inbounds [100001 x i32], ptr @dis, i64 0, i64 %173
  %175 = load i32, ptr %174, align 4, !tbaa !5
  store i32 %175, ptr %9, align 4, !tbaa !5
  br label %176

176:                                              ; preds = %170, %162
  br label %177

177:                                              ; preds = %176, %108
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #6
  br label %178

178:                                              ; preds = %177
  %179 = load i32, ptr %11, align 4, !tbaa !5
  %180 = sext i32 %179 to i64
  %181 = getelementptr inbounds [2000002 x %struct.Edge], ptr @e, i64 0, i64 %180
  %182 = getelementptr inbounds %struct.Edge, ptr %181, i32 0, i32 0
  %183 = load i32, ptr %182, align 4, !tbaa !9
  store i32 %183, ptr %11, align 4, !tbaa !5
  br label %89, !llvm.loop !22

184:                                              ; preds = %92
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #6
  br label %75, !llvm.loop !23

185:                                              ; preds = %75
  %186 = load i32, ptr %8, align 4, !tbaa !5
  %187 = load i32, ptr %9, align 4, !tbaa !5
  %188 = sub nsw i32 %186, %187
  %189 = add nsw i32 %188, 1
  %190 = load i32, ptr @sum, align 4, !tbaa !5
  %191 = add nsw i32 %190, %189
  store i32 %191, ptr @sum, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  br label %192

192:                                              ; preds = %185, %60
  br label %193

193:                                              ; preds = %192
  %194 = load i32, ptr %6, align 4, !tbaa !5
  %195 = add nsw i32 %194, 1
  store i32 %195, ptr %6, align 4, !tbaa !5
  br label %55, !llvm.loop !24

196:                                              ; preds = %59
  %197 = load i32, ptr @ans, align 4, !tbaa !5
  %198 = icmp ne i32 %197, 0
  br i1 %198, label %199, label %204

199:                                              ; preds = %196
  %200 = load i32, ptr @ans, align 4, !tbaa !5
  %201 = icmp slt i32 %200, 3
  br i1 %201, label %202, label %204

202:                                              ; preds = %199
  %203 = call i32 @puts(ptr noundef @.str.1)
  br label %232

204:                                              ; preds = %199, %196
  %205 = load i32, ptr @ans, align 4, !tbaa !5
  %206 = icmp ne i32 %205, 0
  br i1 %206, label %207, label %222

207:                                              ; preds = %204
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #6
  store i32 3, ptr %14, align 4, !tbaa !5
  br label %208

208:                                              ; preds = %218, %207
  %209 = load i32, ptr @ans, align 4, !tbaa !5
  %210 = load i32, ptr %14, align 4, !tbaa !5
  %211 = srem i32 %209, %210
  %212 = icmp eq i32 %211, 0
  br i1 %212, label %213, label %217

213:                                              ; preds = %208
  %214 = load i32, ptr @ans, align 4, !tbaa !5
  %215 = load i32, ptr %14, align 4, !tbaa !5
  %216 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %214, i32 noundef %215)
  store i32 12, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #6
  br label %221

217:                                              ; preds = %208
  br label %218

218:                                              ; preds = %217
  %219 = load i32, ptr %14, align 4, !tbaa !5
  %220 = add nsw i32 %219, 1
  store i32 %220, ptr %14, align 4, !tbaa !5
  br label %208, !llvm.loop !25

221:                                              ; preds = %213
  br label %231

222:                                              ; preds = %204
  %223 = load i32, ptr @sum, align 4, !tbaa !5
  %224 = icmp slt i32 %223, 3
  br i1 %224, label %225, label %227

225:                                              ; preds = %222
  %226 = call i32 @puts(ptr noundef @.str.1)
  br label %230

227:                                              ; preds = %222
  %228 = load i32, ptr @sum, align 4, !tbaa !5
  %229 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %228, i32 noundef 3)
  br label %230

230:                                              ; preds = %227, %225
  br label %231

231:                                              ; preds = %230, %221
  br label %232

232:                                              ; preds = %231, %202
  ret i32 0
}

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #5

declare i32 @puts(ptr noundef) #1

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

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 nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 #5 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{i64 0, i64 4, !5, i64 4, i64 4, !5, i64 8, i64 4, !5}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!17, !17, i64 0}
!17 = !{!"bool", !7, i64 0}
!18 = !{i8 0, i8 2}
!19 = !{}
!20 = !{!21, !21, i64 0}
!21 = !{!"any pointer", !7, i64 0}
!22 = distinct !{!22, !15}
!23 = distinct !{!23, !15}
!24 = distinct !{!24, !15}
!25 = distinct !{!25, !15}


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

@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
@pre = external dso_local local_unnamed_addr global [100001 x i32], align 16
@que = external dso_local local_unnamed_addr global [100001 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
@dis = external dso_local local_unnamed_addr global [100001 x i32], align 16
@sum = external dso_local local_unnamed_addr global i32, align 4
@ans = external dso_local local_unnamed_addr global i32, align 4
@vis = external dso_local local_unnamed_addr global [100001 x i8], align 16
@e = external dso_local local_unnamed_addr global [2000002 x %struct.Edge], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1

; Function Attrs: mustprogress norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @m)
  %4 = load i32, ptr @m, align 4, !tbaa !5
  %5 = add nsw i32 %4, -1
  store i32 %5, ptr @m, align 4, !tbaa !5
  %.not47 = icmp eq i32 %4, 0
  br i1 %.not47, label %.preheader46, label %.lr.ph

.preheader46:                                     ; preds = %.lr.ph, %0
  %6 = load i32, ptr @n, align 4, !tbaa !5
  %.not4360 = icmp slt i32 %6, 1
  br i1 %.not4360, label %._crit_edge63, label %.lr.ph62

.lr.ph:                                           ; preds = %0, %.lr.ph
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #6
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1, ptr noundef nonnull %2)
  %8 = load i32, ptr %1, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [100001 x i32], ptr @pre, i64 0, i64 %9
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = load i32, ptr %2, align 4, !tbaa !5
  %13 = load i32, ptr @tot, align 4, !tbaa !5
  %14 = add nsw i32 %13, 1
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [2000002 x %struct.Edge], ptr @e, i64 0, i64 %15
  store i32 %11, ptr %16, align 4, !tbaa !5
  %.sroa.431.0..sroa_idx = getelementptr inbounds i8, ptr %16, i64 4
  store i32 %12, ptr %.sroa.431.0..sroa_idx, align 4, !tbaa !5
  %.sroa.532.0..sroa_idx = getelementptr inbounds i8, ptr %16, i64 8
  store i32 1, ptr %.sroa.532.0..sroa_idx, align 4, !tbaa !5
  store i32 %14, ptr %10, align 4, !tbaa !5
  %17 = sext i32 %12 to i64
  %18 = getelementptr inbounds [100001 x i32], ptr @pre, i64 0, i64 %17
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = add nsw i32 %13, 2
  store i32 %20, ptr @tot, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [2000002 x %struct.Edge], ptr @e, i64 0, i64 %21
  store i32 %19, ptr %22, align 4, !tbaa !5
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %22, i64 4
  store i32 %8, ptr %.sroa.4.0..sroa_idx, align 4, !tbaa !5
  %.sroa.5.0..sroa_idx = getelementptr inbounds i8, ptr %22, i64 8
  store i32 -1, ptr %.sroa.5.0..sroa_idx, align 4, !tbaa !5
  store i32 %20, ptr %18, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #6
  %23 = load i32, ptr @m, align 4, !tbaa !5
  %24 = add nsw i32 %23, -1
  store i32 %24, ptr @m, align 4, !tbaa !5
  %.not = icmp eq i32 %23, 0
  br i1 %.not, label %.preheader46, label %.lr.ph, !llvm.loop !9

._crit_edge63:                                    ; preds = %89, %.preheader46
  %25 = load i32, ptr @ans, align 4
  %26 = icmp ne i32 %25, 0
  %27 = icmp slt i32 %25, 3
  %or.cond = and i1 %26, %27
  br i1 %or.cond, label %92, label %94

.lr.ph62:                                         ; preds = %.preheader46, %89
  %.pre6768 = phi i32 [ %.pre6769, %89 ], [ %6, %.preheader46 ]
  %28 = phi i32 [ %90, %89 ], [ %6, %.preheader46 ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %89 ], [ 1, %.preheader46 ]
  %29 = getelementptr inbounds [100001 x i8], ptr @vis, i64 0, i64 %indvars.iv
  %30 = load i8, ptr %29, align 1, !tbaa !11, !range !13, !noundef !14
  %31 = trunc nuw i8 %30 to i1
  br i1 %31, label %89, label %32

32:                                               ; preds = %.lr.ph62
  %33 = load i32, ptr @R, align 4, !tbaa !5
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr @R, align 4, !tbaa !5
  %35 = sext i32 %33 to i64
  %36 = getelementptr inbounds [100001 x i32], ptr @que, i64 0, i64 %35
  %37 = trunc nuw nsw i64 %indvars.iv to i32
  store i32 %37, ptr %36, align 4, !tbaa !5
  store i8 1, ptr %29, align 1, !tbaa !11
  %38 = load i32, ptr @L, align 4, !tbaa !5
  %.not64 = icmp sgt i32 %38, %33
  br i1 %.not64, label %._crit_edge, label %.lr.ph57

.loopexit.loopexit:                               ; preds = %84
  %.pre = load i32, ptr @L, align 4, !tbaa !5
  %.pre66 = load i32, ptr @R, align 4, !tbaa !5
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit, %.lr.ph57
  %39 = phi i32 [ %42, %.lr.ph57 ], [ %.pre66, %.loopexit.loopexit ]
  %40 = phi i32 [ %44, %.lr.ph57 ], [ %.pre, %.loopexit.loopexit ]
  %.137.lcssa = phi i32 [ %.03655, %.lr.ph57 ], [ %.238, %.loopexit.loopexit ]
  %.1.lcssa = phi i32 [ %.03556, %.lr.ph57 ], [ %.3, %.loopexit.loopexit ]
  %41 = icmp slt i32 %40, %39
  br i1 %41, label %.lr.ph57, label %._crit_edge.loopexit, !llvm.loop !15

.lr.ph57:                                         ; preds = %32, %.loopexit
  %42 = phi i32 [ %39, %.loopexit ], [ %34, %32 ]
  %43 = phi i32 [ %40, %.loopexit ], [ %38, %32 ]
  %.03556 = phi i32 [ %.1.lcssa, %.loopexit ], [ 0, %32 ]
  %.03655 = phi i32 [ %.137.lcssa, %.loopexit ], [ 0, %32 ]
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr @L, align 4, !tbaa !5
  %45 = sext i32 %43 to i64
  %46 = getelementptr inbounds [100001 x i32], ptr @que, i64 0, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [100001 x i32], ptr @pre, i64 0, i64 %48
  %.03448 = load i32, ptr %49, align 4, !tbaa !5
  %.not4449 = icmp eq i32 %.03448, 0
  br i1 %.not4449, label %.loopexit, label %.lr.ph53

.lr.ph53:                                         ; preds = %.lr.ph57, %84
  %.03452 = phi i32 [ %.034, %84 ], [ %.03448, %.lr.ph57 ]
  %.151 = phi i32 [ %.3, %84 ], [ %.03556, %.lr.ph57 ]
  %.13750 = phi i32 [ %.238, %84 ], [ %.03655, %.lr.ph57 ]
  %50 = sext i32 %.03452 to i64
  %51 = getelementptr inbounds [2000002 x %struct.Edge], ptr @e, i64 0, i64 %50
  %52 = getelementptr inbounds i8, ptr %51, i64 4
  %53 = getelementptr inbounds i8, ptr %51, i64 8
  %54 = load i32, ptr %52, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [100001 x i8], ptr @vis, i64 0, i64 %55
  %57 = load i8, ptr %56, align 1, !tbaa !11, !range !13, !noundef !14
  %58 = trunc nuw i8 %57 to i1
  br i1 %58, label %59, label %72

59:                                               ; preds = %.lr.ph53
  %60 = load i32, ptr @ans, align 4, !tbaa !5
  %61 = load i32, ptr %46, align 4, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [100001 x i32], ptr @dis, i64 0, i64 %62
  %64 = load i32, ptr %63, align 4, !tbaa !5
  %65 = load i32, ptr %53, align 4, !tbaa !5
  %66 = add nsw i32 %65, %64
  %67 = getelementptr inbounds [100001 x i32], ptr @dis, i64 0, i64 %55
  %68 = load i32, ptr %67, align 4, !tbaa !5
  %69 = sub i32 %66, %68
  %70 = call i32 @llvm.abs.i32(i32 %69, i1 true)
  %71 = call noundef i32 @_ZSt5__gcdIiET_S0_S0_(i32 noundef %60, i32 noundef %70)
  store i32 %71, ptr @ans, align 4, !tbaa !5
  br label %84

72:                                               ; preds = %.lr.ph53
  %73 = load i32, ptr @R, align 4, !tbaa !5
  %74 = add nsw i32 %73, 1
  store i32 %74, ptr @R, align 4, !tbaa !5
  %75 = sext i32 %73 to i64
  %76 = getelementptr inbounds [100001 x i32], ptr @que, i64 0, i64 %75
  store i32 %54, ptr %76, align 4, !tbaa !5
  store i8 1, ptr %56, align 1, !tbaa !11
  %77 = load i32, ptr %46, align 4, !tbaa !5
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds [100001 x i32], ptr @dis, i64 0, i64 %78
  %80 = load i32, ptr %79, align 4, !tbaa !5
  %81 = load i32, ptr %53, align 4, !tbaa !5
  %82 = add nsw i32 %81, %80
  %83 = getelementptr inbounds [100001 x i32], ptr @dis, i64 0, i64 %55
  store i32 %82, ptr %83, align 4, !tbaa !5
  %spec.select = call i32 @llvm.smax.i32(i32 %.151, i32 %82)
  %spec.select45 = call i32 @llvm.smin.i32(i32 %.13750, i32 %82)
  br label %84

84:                                               ; preds = %72, %59
  %.238 = phi i32 [ %.13750, %59 ], [ %spec.select45, %72 ]
  %.3 = phi i32 [ %.151, %59 ], [ %spec.select, %72 ]
  %.034 = load i32, ptr %51, align 4, !tbaa !5
  %.not44 = icmp eq i32 %.034, 0
  br i1 %.not44, label %.loopexit.loopexit, label %.lr.ph53, !llvm.loop !16

._crit_edge.loopexit:                             ; preds = %.loopexit
  %.pre67.pre = load i32, ptr @n, align 4, !tbaa !5
  %85 = sub i32 %.1.lcssa, %.137.lcssa
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %32
  %.pre67 = phi i32 [ %.pre6768, %32 ], [ %.pre67.pre, %._crit_edge.loopexit ]
  %reass.sub = phi i32 [ 0, %32 ], [ %85, %._crit_edge.loopexit ]
  %86 = load i32, ptr @sum, align 4, !tbaa !5
  %87 = add i32 %reass.sub, 1
  %88 = add nsw i32 %87, %86
  store i32 %88, ptr @sum, align 4, !tbaa !5
  br label %89

89:                                               ; preds = %.lr.ph62, %._crit_edge
  %.pre6769 = phi i32 [ %.pre6768, %.lr.ph62 ], [ %.pre67, %._crit_edge ]
  %90 = phi i32 [ %28, %.lr.ph62 ], [ %.pre67, %._crit_edge ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %91 = sext i32 %90 to i64
  %.not43.not = icmp slt i64 %indvars.iv, %91
  br i1 %.not43.not, label %.lr.ph62, label %._crit_edge63, !llvm.loop !17

92:                                               ; preds = %._crit_edge63
  %93 = call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.1)
  br label %107

94:                                               ; preds = %._crit_edge63
  br i1 %26, label %.preheader, label %100

.preheader:                                       ; preds = %94, %.preheader
  %.0 = phi i32 [ %97, %.preheader ], [ 3, %94 ]
  %95 = urem i32 %25, %.0
  %96 = icmp eq i32 %95, 0
  %97 = add nuw nsw i32 %.0, 1
  br i1 %96, label %98, label %.preheader, !llvm.loop !18

98:                                               ; preds = %.preheader
  %99 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %25, i32 noundef %.0)
  br label %107

100:                                              ; preds = %94
  %101 = load i32, ptr @sum, align 4, !tbaa !5
  %102 = icmp slt i32 %101, 3
  br i1 %102, label %103, label %105

103:                                              ; preds = %100
  %104 = call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.1)
  br label %107

105:                                              ; preds = %100
  %106 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %101, i32 noundef 3)
  br label %107

107:                                              ; preds = %98, %105, %103, %92
  ret i32 0
}

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

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZSt5__gcdIiET_S0_S0_(i32 noundef, i32 noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #4

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #5

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, i32) #5

attributes #0 = { mustprogress 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 nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = distinct !{!15, !10}
!16 = distinct !{!16, !10}
!17 = distinct !{!17, !10}
!18 = distinct !{!18, !10}


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