; LLVM IR from tangjz/acm-icpc :: uoj (200)

; 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
@q = external dso_local global i32, align 4
@mod = external dso_local global i32, align 4
@ans = external dso_local global [100001 x i32], align 16
@e = external dso_local global [150001 x %struct.Edge], align 16
@que = external dso_local global [100001 x %struct.Edge], align 16
@.str.1 = external hidden unnamed_addr constant [61 x i8], align 1
@stderr = external global ptr, align 8
@_ZZ4mainE3buf = external hidden global [1025 x i8], align 16
@.str.29 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.30 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.31 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.32 = external hidden unnamed_addr constant [139 x i8], align 1
@__PRETTY_FUNCTION__.main = external hidden unnamed_addr constant [11 x i8], align 1
@_ZL5maxew = external hidden constant i32, align 4
@_ZL5maxqw = external hidden constant i32, align 4
@.str.33 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.34 = external hidden unnamed_addr constant [137 x i8], align 1
@_ZZ4mainE5solve = external hidden global [11 x ptr], align 16
@.str.35 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.36 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.37 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.38 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.39 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.40 = external hidden unnamed_addr constant [21 x i8], align 1

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

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

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #2

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

; Function Attrs: mustprogress 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 ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i8, align 1
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #6
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %214, %0
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = icmp sle i32 %14, 10
  br i1 %15, label %17, label %16

16:                                               ; preds = %13
  store i32 2, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #6
  br label %217

17:                                               ; preds = %13
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef @_ZZ4mainE3buf, ptr noundef @.str.29, i32 noundef %18) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #6
  %20 = call noalias ptr @fopen(ptr noundef @_ZZ4mainE3buf, ptr noundef @.str.30)
  store ptr %20, ptr %4, align 8, !tbaa !9
  %21 = load ptr, ptr %4, align 8, !tbaa !9
  %22 = call i32 (ptr, ptr, ...) @__isoc99_fscanf(ptr noundef %21, ptr noundef @.str.31, ptr noundef @n, ptr noundef @m, ptr noundef @q, ptr noundef @mod)
  %23 = icmp eq i32 %22, 4
  br i1 %23, label %24, label %48

24:                                               ; preds = %17
  %25 = load i32, ptr @n, align 4, !tbaa !5
  %26 = icmp sle i32 1, %25
  br i1 %26, label %27, label %48

27:                                               ; preds = %24
  %28 = load i32, ptr @n, align 4, !tbaa !5
  %29 = icmp slt i32 %28, 100001
  br i1 %29, label %30, label %48

30:                                               ; preds = %27
  %31 = load i32, ptr @m, align 4, !tbaa !5
  %32 = icmp sle i32 1, %31
  br i1 %32, label %33, label %48

33:                                               ; preds = %30
  %34 = load i32, ptr @m, align 4, !tbaa !5
  %35 = icmp slt i32 %34, 150001
  br i1 %35, label %36, label %48

36:                                               ; preds = %33
  %37 = load i32, ptr @q, align 4, !tbaa !5
  %38 = icmp sle i32 1, %37
  br i1 %38, label %39, label %48

39:                                               ; preds = %36
  %40 = load i32, ptr @q, align 4, !tbaa !5
  %41 = icmp slt i32 %40, 100001
  br i1 %41, label %42, label %48

42:                                               ; preds = %39
  %43 = load i32, ptr @mod, align 4, !tbaa !5
  %44 = icmp sle i32 1, %43
  br i1 %44, label %45, label %48

45:                                               ; preds = %42
  %46 = load i32, ptr @mod, align 4, !tbaa !5
  %47 = icmp slt i32 %46, 2147483647
  br label %48

48:                                               ; preds = %45, %42, %39, %36, %33, %30, %27, %24, %17
  %49 = phi i1 [ false, %42 ], [ false, %39 ], [ false, %36 ], [ false, %33 ], [ false, %30 ], [ false, %27 ], [ false, %24 ], [ false, %17 ], [ %47, %45 ]
  br i1 %49, label %50, label %51

50:                                               ; preds = %48
  br label %53

51:                                               ; preds = %48
  call void @__assert_fail(ptr noundef @.str.32, ptr noundef @.str.1, i32 noundef 910, ptr noundef @__PRETTY_FUNCTION__.main) #7
  unreachable

52:                                               ; No predecessors!
  br label %53

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

54:                                               ; preds = %133, %53
  %55 = load i32, ptr %5, align 4, !tbaa !5
  %56 = load i32, ptr @m, align 4, !tbaa !5
  %57 = load i32, ptr @q, align 4, !tbaa !5
  %58 = add nsw i32 %56, %57
  %59 = icmp slt i32 %55, %58
  br i1 %59, label %61, label %60

60:                                               ; preds = %54
  store i32 5, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  br label %136

61:                                               ; preds = %54
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #6
  %62 = load i32, ptr %5, align 4, !tbaa !5
  %63 = load i32, ptr @m, align 4, !tbaa !5
  %64 = icmp slt i32 %62, %63
  br i1 %64, label %65, label %69

65:                                               ; preds = %61
  %66 = load i32, ptr %5, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [150001 x %struct.Edge], ptr @e, i64 0, i64 %67
  br label %75

69:                                               ; preds = %61
  %70 = load i32, ptr %5, align 4, !tbaa !5
  %71 = load i32, ptr @m, align 4, !tbaa !5
  %72 = sub nsw i32 %70, %71
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [100001 x %struct.Edge], ptr @que, i64 0, i64 %73
  br label %75

75:                                               ; preds = %69, %65
  %76 = phi ptr [ %68, %65 ], [ %74, %69 ]
  store ptr %76, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #6
  %77 = load i32, ptr %5, align 4, !tbaa !5
  %78 = load i32, ptr @m, align 4, !tbaa !5
  %79 = icmp slt i32 %77, %78
  br i1 %79, label %80, label %81

80:                                               ; preds = %75
  br label %82

81:                                               ; preds = %75
  br label %82

82:                                               ; preds = %81, %80
  %83 = phi ptr [ @_ZL5maxew, %80 ], [ @_ZL5maxqw, %81 ]
  store ptr %83, ptr %7, align 8, !tbaa !9
  %84 = load ptr, ptr %4, align 8, !tbaa !9
  %85 = load ptr, ptr %6, align 8, !tbaa !9
  %86 = getelementptr inbounds %struct.Edge, ptr %85, i32 0, i32 0
  %87 = load ptr, ptr %6, align 8, !tbaa !9
  %88 = getelementptr inbounds %struct.Edge, ptr %87, i32 0, i32 1
  %89 = load ptr, ptr %6, align 8, !tbaa !9
  %90 = getelementptr inbounds %struct.Edge, ptr %89, i32 0, i32 2
  %91 = call i32 (ptr, ptr, ...) @__isoc99_fscanf(ptr noundef %84, ptr noundef @.str.33, ptr noundef %86, ptr noundef %88, ptr noundef %90)
  %92 = icmp eq i32 %91, 3
  br i1 %92, label %93, label %127

93:                                               ; preds = %82
  %94 = load ptr, ptr %6, align 8, !tbaa !9
  %95 = getelementptr inbounds %struct.Edge, ptr %94, i32 0, i32 0
  %96 = load i32, ptr %95, align 4, !tbaa !11
  %97 = icmp sle i32 1, %96
  br i1 %97, label %98, label %127

98:                                               ; preds = %93
  %99 = load ptr, ptr %6, align 8, !tbaa !9
  %100 = getelementptr inbounds %struct.Edge, ptr %99, i32 0, i32 0
  %101 = load i32, ptr %100, align 4, !tbaa !11
  %102 = load i32, ptr @n, align 4, !tbaa !5
  %103 = icmp sle i32 %101, %102
  br i1 %103, label %104, label %127

104:                                              ; preds = %98
  %105 = load ptr, ptr %6, align 8, !tbaa !9
  %106 = getelementptr inbounds %struct.Edge, ptr %105, i32 0, i32 1
  %107 = load i32, ptr %106, align 4, !tbaa !13
  %108 = icmp sle i32 1, %107
  br i1 %108, label %109, label %127

109:                                              ; preds = %104
  %110 = load ptr, ptr %6, align 8, !tbaa !9
  %111 = getelementptr inbounds %struct.Edge, ptr %110, i32 0, i32 1
  %112 = load i32, ptr %111, align 4, !tbaa !13
  %113 = load i32, ptr @n, align 4, !tbaa !5
  %114 = icmp sle i32 %112, %113
  br i1 %114, label %115, label %127

115:                                              ; preds = %109
  %116 = load ptr, ptr %6, align 8, !tbaa !9
  %117 = getelementptr inbounds %struct.Edge, ptr %116, i32 0, i32 2
  %118 = load i32, ptr %117, align 4, !tbaa !14
  %119 = icmp sle i32 0, %118
  br i1 %119, label %120, label %127

120:                                              ; preds = %115
  %121 = load ptr, ptr %6, align 8, !tbaa !9
  %122 = getelementptr inbounds %struct.Edge, ptr %121, i32 0, i32 2
  %123 = load i32, ptr %122, align 4, !tbaa !14
  %124 = load ptr, ptr %7, align 8, !tbaa !9
  %125 = load i32, ptr %124, align 4, !tbaa !5
  %126 = icmp slt i32 %123, %125
  br label %127

127:                                              ; preds = %120, %115, %109, %104, %98, %93, %82
  %128 = phi i1 [ false, %115 ], [ false, %109 ], [ false, %104 ], [ false, %98 ], [ false, %93 ], [ false, %82 ], [ %126, %120 ]
  br i1 %128, label %129, label %130

129:                                              ; preds = %127
  br label %132

130:                                              ; preds = %127
  call void @__assert_fail(ptr noundef @.str.34, ptr noundef @.str.1, i32 noundef 916, ptr noundef @__PRETTY_FUNCTION__.main) #7
  unreachable

131:                                              ; No predecessors!
  br label %132

132:                                              ; preds = %131, %129
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  br label %133

133:                                              ; preds = %132
  %134 = load i32, ptr %5, align 4, !tbaa !5
  %135 = add nsw i32 %134, 1
  store i32 %135, ptr %5, align 4, !tbaa !5
  br label %54, !llvm.loop !15

136:                                              ; preds = %60
  %137 = load i32, ptr @q, align 4, !tbaa !5
  %138 = sext i32 %137 to i64
  %139 = mul i64 %138, 4
  call void @llvm.memset.p0.i64(ptr align 16 @ans, i8 -1, i64 %139, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #6
  %140 = call i64 @clock() #6
  store i64 %140, ptr %8, align 8, !tbaa !17
  %141 = load i32, ptr %2, align 4, !tbaa !5
  %142 = sext i32 %141 to i64
  %143 = getelementptr inbounds [11 x ptr], ptr @_ZZ4mainE5solve, i64 0, i64 %142
  %144 = load ptr, ptr %143, align 8, !tbaa !9
  call void %144()
  %145 = load ptr, ptr @stderr, align 8, !tbaa !9
  %146 = call i64 @clock() #6
  %147 = load i64, ptr %8, align 8, !tbaa !17
  %148 = sub nsw i64 %146, %147
  %149 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %145, ptr noundef @.str.35, i64 noundef %148) #6
  %150 = load ptr, ptr %4, align 8, !tbaa !9
  %151 = call i32 @fclose(ptr noundef %150)
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #6
  store i8 0, ptr %9, align 1, !tbaa !19
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #6
  store i32 0, ptr %10, align 4, !tbaa !5
  br label %152

152:                                              ; preds = %176, %136
  %153 = load i32, ptr %10, align 4, !tbaa !5
  %154 = load i32, ptr @q, align 4, !tbaa !5
  %155 = icmp slt i32 %153, %154
  br i1 %155, label %156, label %160

156:                                              ; preds = %152
  %157 = load i8, ptr %9, align 1, !tbaa !19, !range !21, !noundef !22
  %158 = trunc i8 %157 to i1
  %159 = xor i1 %158, true
  br label %160

160:                                              ; preds = %156, %152
  %161 = phi i1 [ false, %152 ], [ %159, %156 ]
  br i1 %161, label %163, label %162

162:                                              ; preds = %160
  store i32 8, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #6
  br label %179

163:                                              ; preds = %160
  %164 = load i32, ptr %10, align 4, !tbaa !5
  %165 = sext i32 %164 to i64
  %166 = getelementptr inbounds [100001 x i32], ptr @ans, i64 0, i64 %165
  %167 = load i32, ptr %166, align 4, !tbaa !5
  %168 = icmp eq i32 %167, -1
  %169 = zext i1 %168 to i32
  %170 = load i8, ptr %9, align 1, !tbaa !19, !range !21, !noundef !22
  %171 = trunc i8 %170 to i1
  %172 = zext i1 %171 to i32
  %173 = or i32 %172, %169
  %174 = icmp ne i32 %173, 0
  %175 = zext i1 %174 to i8
  store i8 %175, ptr %9, align 1, !tbaa !19
  br label %176

176:                                              ; preds = %163
  %177 = load i32, ptr %10, align 4, !tbaa !5
  %178 = add nsw i32 %177, 1
  store i32 %178, ptr %10, align 4, !tbaa !5
  br label %152, !llvm.loop !23

179:                                              ; preds = %162
  %180 = load i8, ptr %9, align 1, !tbaa !19, !range !21, !noundef !22
  %181 = trunc i8 %180 to i1
  br i1 %181, label %182, label %186

182:                                              ; preds = %179
  %183 = load ptr, ptr @stderr, align 8, !tbaa !9
  %184 = load i32, ptr %2, align 4, !tbaa !5
  %185 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %183, ptr noundef @.str.36, i32 noundef %184) #6
  store i32 4, ptr %3, align 4
  br label %211

186:                                              ; preds = %179
  %187 = load i32, ptr %2, align 4, !tbaa !5
  %188 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef @_ZZ4mainE3buf, ptr noundef @.str.37, i32 noundef %187) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #6
  %189 = call noalias ptr @fopen(ptr noundef @_ZZ4mainE3buf, ptr noundef @.str.38)
  store ptr %189, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #6
  store i32 0, ptr %12, align 4, !tbaa !5
  br label %190

190:                                              ; preds = %202, %186
  %191 = load i32, ptr %12, align 4, !tbaa !5
  %192 = load i32, ptr @q, align 4, !tbaa !5
  %193 = icmp slt i32 %191, %192
  br i1 %193, label %195, label %194

194:                                              ; preds = %190
  store i32 11, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #6
  br label %205

195:                                              ; preds = %190
  %196 = load ptr, ptr %11, align 8, !tbaa !9
  %197 = load i32, ptr %12, align 4, !tbaa !5
  %198 = sext i32 %197 to i64
  %199 = getelementptr inbounds [100001 x i32], ptr @ans, i64 0, i64 %198
  %200 = load i32, ptr %199, align 4, !tbaa !5
  %201 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %196, ptr noundef @.str.39, i32 noundef %200) #6
  br label %202

202:                                              ; preds = %195
  %203 = load i32, ptr %12, align 4, !tbaa !5
  %204 = add nsw i32 %203, 1
  store i32 %204, ptr %12, align 4, !tbaa !5
  br label %190, !llvm.loop !24

205:                                              ; preds = %194
  %206 = load ptr, ptr %11, align 8, !tbaa !9
  %207 = call i32 @fclose(ptr noundef %206)
  %208 = load ptr, ptr @stderr, align 8, !tbaa !9
  %209 = load i32, ptr %2, align 4, !tbaa !5
  %210 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %208, ptr noundef @.str.40, i32 noundef %209) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #6
  store i32 0, ptr %3, align 4
  br label %211

211:                                              ; preds = %205, %182
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #6
  %212 = load i32, ptr %3, align 4
  switch i32 %212, label %218 [
    i32 0, label %213
    i32 4, label %214
  ]

213:                                              ; preds = %211
  br label %214

214:                                              ; preds = %213, %211
  %215 = load i32, ptr %2, align 4, !tbaa !5
  %216 = add nsw i32 %215, 1
  store i32 %216, ptr %2, align 4, !tbaa !5
  br label %13, !llvm.loop !25

217:                                              ; preds = %16
  ret i32 0

218:                                              ; preds = %211
  unreachable
}

; Function Attrs: nounwind
declare i32 @sprintf(ptr noundef, ptr noundef, ...) #2

declare noalias ptr @fopen(ptr noundef, ptr noundef) #5

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

; Function Attrs: nounwind
declare i64 @clock() #2

declare i32 @fclose(ptr noundef) #5

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


; 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
@q = external dso_local global i32, align 4
@mod = external dso_local global i32, align 4
@ans = external dso_local local_unnamed_addr global [100001 x i32], align 16
@e = external dso_local global [150001 x %struct.Edge], align 16
@que = external dso_local global [100001 x %struct.Edge], align 16
@.str.1 = external hidden unnamed_addr constant [61 x i8], align 1
@stderr = external local_unnamed_addr global ptr, align 8
@_ZZ4mainE3buf = external hidden global [1025 x i8], align 16
@.str.29 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.30 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.31 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.32 = external hidden unnamed_addr constant [139 x i8], align 1
@__PRETTY_FUNCTION__.main = external hidden unnamed_addr constant [11 x i8], align 1
@_ZL5maxew = external hidden local_unnamed_addr constant i32, align 4
@_ZL5maxqw = external hidden local_unnamed_addr constant i32, align 4
@.str.33 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.34 = external hidden unnamed_addr constant [137 x i8], align 1
@_ZZ4mainE5solve = external hidden local_unnamed_addr global [11 x ptr], align 16
@.str.35 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.36 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.37 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.38 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.39 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.40 = external hidden unnamed_addr constant [21 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, 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 norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #3 {
  %_ZL5maxew.val = load i32, ptr @_ZL5maxew, align 4
  %_ZL5maxqw.val = load i32, ptr @_ZL5maxqw, align 4
  br label %2

1:                                                ; preds = %80
  ret i32 0

2:                                                ; preds = %0, %80
  %indvars.iv87 = phi i64 [ 1, %0 ], [ %indvars.iv.next88, %80 ]
  %3 = trunc nuw nsw i64 %indvars.iv87 to i32
  %4 = tail call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) @_ZZ4mainE3buf, ptr noundef nonnull dereferenceable(1) @.str.29, i32 noundef %3) #6
  %5 = tail call noalias ptr @fopen(ptr noundef nonnull @_ZZ4mainE3buf, ptr noundef nonnull @.str.30)
  %6 = tail call i32 (ptr, ptr, ...) @__isoc99_fscanf(ptr noundef %5, ptr noundef nonnull @.str.31, ptr noundef nonnull @n, ptr noundef nonnull @m, ptr noundef nonnull @q, ptr noundef nonnull @mod)
  %7 = icmp eq i32 %6, 4
  %8 = load i32, ptr @n, align 4
  %9 = add i32 %8, -1
  %10 = icmp ult i32 %9, 100000
  %or.cond3 = select i1 %7, i1 %10, i1 false
  %11 = load i32, ptr @m, align 4
  %12 = add i32 %11, -1
  %13 = icmp ult i32 %12, 150000
  %or.cond7 = select i1 %or.cond3, i1 %13, i1 false
  %14 = load i32, ptr @q, align 4
  %15 = add i32 %14, -1
  %16 = icmp ult i32 %15, 100000
  %or.cond11 = select i1 %or.cond7, i1 %16, i1 false
  %17 = load i32, ptr @mod, align 4
  %18 = add i32 %17, -1
  %19 = icmp ult i32 %18, 2147483646
  %or.cond17 = select i1 %or.cond11, i1 %19, i1 false
  br i1 %or.cond17, label %.lr.ph, label %.critedge

.critedge:                                        ; preds = %2
  tail call void @__assert_fail(ptr noundef nonnull @.str.32, ptr noundef nonnull @.str.1, i32 noundef 910, ptr noundef nonnull @__PRETTY_FUNCTION__.main) #7
  unreachable

20:                                               ; preds = %60
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %21 = load i32, ptr @m, align 4, !tbaa !5
  %22 = load i32, ptr @q, align 4, !tbaa !5
  %23 = add nsw i32 %22, %21
  %24 = sext i32 %23 to i64
  %25 = icmp slt i64 %indvars.iv.next, %24
  br i1 %25, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %20
  %26 = sext i32 %22 to i64
  %27 = shl nsw i64 %26, 2
  tail call void @llvm.memset.p0.i64(ptr nonnull align 16 @ans, i8 -1, i64 %27, i1 false)
  %28 = tail call i64 @clock() #6
  %29 = getelementptr inbounds [11 x ptr], ptr @_ZZ4mainE5solve, i64 0, i64 %indvars.iv87
  %30 = load ptr, ptr %29, align 8, !tbaa !11
  tail call void %30()
  %31 = load ptr, ptr @stderr, align 8, !tbaa !11
  %32 = tail call i64 @clock() #6
  %33 = sub nsw i64 %32, %28
  %34 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %31, ptr noundef nonnull @.str.35, i64 noundef %33) #8
  %35 = tail call i32 @fclose(ptr noundef %5)
  %36 = load i32, ptr @q, align 4, !tbaa !5
  %37 = icmp slt i32 %36, 1
  br i1 %37, label %.critedge78, label %.lr.ph70.preheader

.lr.ph70.preheader:                               ; preds = %._crit_edge
  %38 = zext nneg i32 %36 to i64
  br label %.lr.ph70

.lr.ph:                                           ; preds = %2, %20
  %indvars.iv = phi i64 [ %indvars.iv.next, %20 ], [ 0, %2 ]
  %39 = phi i32 [ %21, %20 ], [ %11, %2 ]
  %40 = sext i32 %39 to i64
  %41 = icmp slt i64 %indvars.iv, %40
  %42 = getelementptr inbounds [150001 x %struct.Edge], ptr @e, i64 0, i64 %indvars.iv
  %43 = trunc nuw nsw i64 %indvars.iv to i32
  %44 = sub nsw i32 %43, %39
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [100001 x %struct.Edge], ptr @que, i64 0, i64 %45
  %47 = select i1 %41, ptr %42, ptr %46
  %48 = getelementptr inbounds i8, ptr %47, i64 4
  %49 = getelementptr inbounds i8, ptr %47, i64 8
  %50 = tail call i32 (ptr, ptr, ...) @__isoc99_fscanf(ptr noundef %5, ptr noundef nonnull @.str.33, ptr noundef nonnull %47, ptr noundef nonnull %48, ptr noundef nonnull %49)
  %51 = icmp eq i32 %50, 3
  br i1 %51, label %52, label %.critedge15

52:                                               ; preds = %.lr.ph
  %53 = load i32, ptr %47, align 4, !tbaa !13
  %54 = icmp sgt i32 %53, 0
  br i1 %54, label %55, label %.critedge15

55:                                               ; preds = %52
  %56 = load i32, ptr @n, align 4, !tbaa !5
  %.not = icmp sgt i32 %53, %56
  br i1 %.not, label %.critedge15, label %57

57:                                               ; preds = %55
  %58 = load i32, ptr %48, align 4, !tbaa !15
  %59 = icmp slt i32 %58, 1
  %.not64 = icmp sgt i32 %58, %56
  %or.cond = or i1 %59, %.not64
  br i1 %or.cond, label %.critedge15, label %60

60:                                               ; preds = %57
  %61 = load i32, ptr %49, align 4, !tbaa !16
  %62 = icmp sgt i32 %61, -1
  %63 = select i1 %41, i32 %_ZL5maxew.val, i32 %_ZL5maxqw.val
  %64 = icmp slt i32 %61, %63
  %or.cond93 = select i1 %62, i1 %64, i1 false
  br i1 %or.cond93, label %20, label %.critedge15

.critedge15:                                      ; preds = %60, %57, %55, %52, %.lr.ph
  tail call void @__assert_fail(ptr noundef nonnull @.str.34, ptr noundef nonnull @.str.1, i32 noundef 916, ptr noundef nonnull @__PRETTY_FUNCTION__.main) #7
  unreachable

._crit_edge71:                                    ; preds = %.lr.ph70
  br i1 %67, label %80, label %.critedge78

.lr.ph70:                                         ; preds = %.lr.ph70.preheader, %.lr.ph70
  %indvars.iv82 = phi i64 [ 0, %.lr.ph70.preheader ], [ %indvars.iv.next83, %.lr.ph70 ]
  %65 = getelementptr inbounds [100001 x i32], ptr @ans, i64 0, i64 %indvars.iv82
  %66 = load i32, ptr %65, align 4, !tbaa !5
  %67 = icmp eq i32 %66, -1
  %indvars.iv.next83 = add nuw nsw i64 %indvars.iv82, 1
  %68 = icmp uge i64 %indvars.iv.next83, %38
  %.not63 = select i1 %68, i1 true, i1 %67
  br i1 %.not63, label %._crit_edge71, label %.lr.ph70, !llvm.loop !17

.critedge78:                                      ; preds = %._crit_edge, %._crit_edge71
  %69 = tail call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) @_ZZ4mainE3buf, ptr noundef nonnull dereferenceable(1) @.str.37, i32 noundef %3) #6
  %70 = tail call noalias ptr @fopen(ptr noundef nonnull @_ZZ4mainE3buf, ptr noundef nonnull @.str.38)
  %71 = load i32, ptr @q, align 4, !tbaa !5
  %72 = icmp sgt i32 %71, 0
  br i1 %72, label %.lr.ph75, label %._crit_edge76

._crit_edge76:                                    ; preds = %.lr.ph75, %.critedge78
  %73 = tail call i32 @fclose(ptr noundef %70)
  br label %80

.lr.ph75:                                         ; preds = %.critedge78, %.lr.ph75
  %indvars.iv84 = phi i64 [ %indvars.iv.next85, %.lr.ph75 ], [ 0, %.critedge78 ]
  %74 = getelementptr inbounds [100001 x i32], ptr @ans, i64 0, i64 %indvars.iv84
  %75 = load i32, ptr %74, align 4, !tbaa !5
  %76 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %70, ptr noundef nonnull @.str.39, i32 noundef %75) #6
  %indvars.iv.next85 = add nuw nsw i64 %indvars.iv84, 1
  %77 = load i32, ptr @q, align 4, !tbaa !5
  %78 = sext i32 %77 to i64
  %79 = icmp slt i64 %indvars.iv.next85, %78
  br i1 %79, label %.lr.ph75, label %._crit_edge76, !llvm.loop !18

80:                                               ; preds = %._crit_edge71, %._crit_edge76
  %.str.40.sink = phi ptr [ @.str.40, %._crit_edge76 ], [ @.str.36, %._crit_edge71 ]
  %81 = load ptr, ptr @stderr, align 8, !tbaa !11
  %82 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %81, ptr noundef nonnull %.str.40.sink, i32 noundef %3) #8
  %indvars.iv.next88 = add nuw nsw i64 %indvars.iv87, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next88, 11
  br i1 %exitcond.not, label %1, label %2, !llvm.loop !19
}

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

; Function Attrs: nofree nounwind
declare noalias noundef ptr @fopen(ptr nocapture noundef readonly, ptr nocapture noundef readonly) local_unnamed_addr #1

declare i32 @__isoc99_fscanf(ptr noundef, ptr noundef, ...) local_unnamed_addr #4

; Function Attrs: nounwind
declare i64 @clock() local_unnamed_addr #5

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

attributes #0 = { noreturn 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 #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 norecurse uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #4 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #5 = { 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 #6 = { nounwind }
attributes #7 = { noreturn nounwind }
attributes #8 = { cold 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 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"_ZTS4Edge", !6, i64 0, !6, i64 4, !6, i64 8}
!15 = !{!14, !6, i64 4}
!16 = !{!14, !6, i64 8}
!17 = distinct !{!17, !10}
!18 = distinct !{!18, !10}
!19 = distinct !{!19, !10}


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