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

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%struct.Edge = type { i32, i32 }
%"struct.std::pair" = type { i32, i32 }

@n = external dso_local global i32, align 4
@lnk = external dso_local global [400001 x i32], align 16
@fa = external dso_local global [400001 x i32], align 16
@sz = external dso_local global [400001 x i32], align 16
@seq = external dso_local global [400001 x i32], align 16
@son = external dso_local global [400001 x i32], align 16
@e = external dso_local global [800003 x %struct.Edge], align 16
@a = external dso_local global [400001 x i32], align 16
@b = external dso_local global [400001 x i32], align 16
@mx = external dso_local global %"struct.std::pair", align 4
@ans = external dso_local global [400001 x %"struct.std::pair"], align 16
@.str = external hidden unnamed_addr constant [6 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1

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

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

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z13counter_clearv() #3

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z14counter_updateii(i32 noundef, i32 noundef) #3

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt4pairIiiEaSERKS0_(ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(8)) #0 align 2

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #4 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca %struct.Edge, align 4
  %6 = alloca %struct.Edge, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %14 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  %15 = load i32, ptr @n, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = mul i64 %16, 4
  call void @llvm.memset.p0.i64(ptr align 4 getelementptr inbounds (i32, ptr @lnk, i64 1), i8 -1, i64 %17, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #7
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %18

18:                                               ; preds = %60, %0
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = load i32, ptr @n, align 4, !tbaa !5
  %21 = sub nsw i32 %20, 1
  %22 = icmp slt i32 %19, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #7
  br label %63

24:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #7
  %25 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %3, ptr noundef %4)
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #7
  %26 = getelementptr inbounds %struct.Edge, ptr %5, i32 0, i32 0
  %27 = load i32, ptr %3, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [400001 x i32], ptr @lnk, i64 0, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !5
  store i32 %30, ptr %26, align 4, !tbaa !9
  %31 = getelementptr inbounds %struct.Edge, ptr %5, i32 0, i32 1
  %32 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %32, ptr %31, align 4, !tbaa !11
  %33 = load i32, ptr %2, align 4, !tbaa !5
  %34 = shl i32 %33, 1
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [800003 x %struct.Edge], ptr @e, i64 0, i64 %35
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %36, ptr align 4 %5, i64 8, i1 false), !tbaa.struct !12
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #7
  %37 = load i32, ptr %2, align 4, !tbaa !5
  %38 = shl i32 %37, 1
  %39 = load i32, ptr %3, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [400001 x i32], ptr @lnk, i64 0, i64 %40
  store i32 %38, ptr %41, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #7
  %42 = getelementptr inbounds %struct.Edge, ptr %6, i32 0, i32 0
  %43 = load i32, ptr %4, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [400001 x i32], ptr @lnk, i64 0, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !5
  store i32 %46, ptr %42, align 4, !tbaa !9
  %47 = getelementptr inbounds %struct.Edge, ptr %6, i32 0, i32 1
  %48 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %48, ptr %47, align 4, !tbaa !11
  %49 = load i32, ptr %2, align 4, !tbaa !5
  %50 = shl i32 %49, 1
  %51 = or i32 %50, 1
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [800003 x %struct.Edge], ptr @e, i64 0, i64 %52
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %53, ptr align 4 %6, i64 8, i1 false), !tbaa.struct !12
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #7
  %54 = load i32, ptr %2, align 4, !tbaa !5
  %55 = shl i32 %54, 1
  %56 = or i32 %55, 1
  %57 = load i32, ptr %4, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [400001 x i32], ptr @lnk, i64 0, i64 %58
  store i32 %56, ptr %59, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #7
  br label %60

60:                                               ; preds = %24
  %61 = load i32, ptr %2, align 4, !tbaa !5
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %2, align 4, !tbaa !5
  br label %18, !llvm.loop !13

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

64:                                               ; preds = %77, %63
  %65 = load i32, ptr %7, align 4, !tbaa !5
  %66 = load i32, ptr @n, align 4, !tbaa !5
  %67 = icmp sle i32 %65, %66
  br i1 %67, label %69, label %68

68:                                               ; preds = %64
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #7
  br label %80

69:                                               ; preds = %64
  %70 = load i32, ptr %7, align 4, !tbaa !5
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds i32, ptr @a, i64 %71
  %73 = load i32, ptr %7, align 4, !tbaa !5
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds i32, ptr @b, i64 %74
  %76 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %72, ptr noundef %75)
  br label %77

77:                                               ; preds = %69
  %78 = load i32, ptr %7, align 4, !tbaa !5
  %79 = add nsw i32 %78, 1
  store i32 %79, ptr %7, align 4, !tbaa !5
  br label %64, !llvm.loop !15

80:                                               ; preds = %68
  call void @_Z10tree_buildi(i32 noundef 1)
  call void @_Z13counter_clearv()
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #7
  %81 = load i32, ptr @n, align 4, !tbaa !5
  store i32 %81, ptr %8, align 4, !tbaa !5
  br label %82

82:                                               ; preds = %164, %80
  %83 = load i32, ptr %8, align 4, !tbaa !5
  %84 = icmp sge i32 %83, 1
  br i1 %84, label %86, label %85

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

86:                                               ; preds = %82
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #7
  %87 = load i32, ptr %8, align 4, !tbaa !5
  %88 = sext i32 %87 to i64
  %89 = getelementptr inbounds [400001 x i32], ptr @seq, i64 0, i64 %88
  %90 = load i32, ptr %89, align 4, !tbaa !5
  store i32 %90, ptr %10, align 4, !tbaa !5
  %91 = load i32, ptr %10, align 4, !tbaa !5
  %92 = sext i32 %91 to i64
  %93 = getelementptr inbounds [400001 x i32], ptr @sz, i64 0, i64 %92
  %94 = load i32, ptr %93, align 4, !tbaa !5
  %95 = icmp sgt i32 %94, 1
  br i1 %95, label %96, label %137

96:                                               ; preds = %86
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #7
  %97 = load i32, ptr %8, align 4, !tbaa !5
  %98 = load i32, ptr %10, align 4, !tbaa !5
  %99 = sext i32 %98 to i64
  %100 = getelementptr inbounds [400001 x i32], ptr @son, i64 0, i64 %99
  %101 = load i32, ptr %100, align 4, !tbaa !5
  %102 = sext i32 %101 to i64
  %103 = getelementptr inbounds [400001 x i32], ptr @sz, i64 0, i64 %102
  %104 = load i32, ptr %103, align 4, !tbaa !5
  %105 = add nsw i32 %97, %104
  %106 = add nsw i32 %105, 1
  store i32 %106, ptr %11, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #7
  %107 = load i32, ptr %8, align 4, !tbaa !5
  %108 = load i32, ptr %10, align 4, !tbaa !5
  %109 = sext i32 %108 to i64
  %110 = getelementptr inbounds [400001 x i32], ptr @sz, i64 0, i64 %109
  %111 = load i32, ptr %110, align 4, !tbaa !5
  %112 = add nsw i32 %107, %111
  store i32 %112, ptr %12, align 4, !tbaa !5
  br label %113

113:                                              ; preds = %133, %96
  %114 = load i32, ptr %11, align 4, !tbaa !5
  %115 = load i32, ptr %12, align 4, !tbaa !5
  %116 = icmp slt i32 %114, %115
  br i1 %116, label %118, label %117

117:                                              ; preds = %113
  store i32 11, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #7
  br label %136

118:                                              ; preds = %113
  %119 = load i32, ptr %11, align 4, !tbaa !5
  %120 = sext i32 %119 to i64
  %121 = getelementptr inbounds [400001 x i32], ptr @seq, i64 0, i64 %120
  %122 = load i32, ptr %121, align 4, !tbaa !5
  %123 = sext i32 %122 to i64
  %124 = getelementptr inbounds [400001 x i32], ptr @a, i64 0, i64 %123
  %125 = load i32, ptr %124, align 4, !tbaa !5
  %126 = load i32, ptr %11, align 4, !tbaa !5
  %127 = sext i32 %126 to i64
  %128 = getelementptr inbounds [400001 x i32], ptr @seq, i64 0, i64 %127
  %129 = load i32, ptr %128, align 4, !tbaa !5
  %130 = sext i32 %129 to i64
  %131 = getelementptr inbounds [400001 x i32], ptr @b, i64 0, i64 %130
  %132 = load i32, ptr %131, align 4, !tbaa !5
  call void @_Z14counter_updateii(i32 noundef %125, i32 noundef %132)
  br label %133

133:                                              ; preds = %118
  %134 = load i32, ptr %11, align 4, !tbaa !5
  %135 = add nsw i32 %134, 1
  store i32 %135, ptr %11, align 4, !tbaa !5
  br label %113, !llvm.loop !16

136:                                              ; preds = %117
  br label %137

137:                                              ; preds = %136, %86
  %138 = load i32, ptr %10, align 4, !tbaa !5
  %139 = sext i32 %138 to i64
  %140 = getelementptr inbounds [400001 x i32], ptr @a, i64 0, i64 %139
  %141 = load i32, ptr %140, align 4, !tbaa !5
  %142 = load i32, ptr %10, align 4, !tbaa !5
  %143 = sext i32 %142 to i64
  %144 = getelementptr inbounds [400001 x i32], ptr @b, i64 0, i64 %143
  %145 = load i32, ptr %144, align 4, !tbaa !5
  call void @_Z14counter_updateii(i32 noundef %141, i32 noundef %145)
  %146 = load i32, ptr %10, align 4, !tbaa !5
  %147 = sext i32 %146 to i64
  %148 = getelementptr inbounds [400001 x %"struct.std::pair"], ptr @ans, i64 0, i64 %147
  %149 = call noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt4pairIiiEaSERKS0_(ptr noundef nonnull align 4 dereferenceable(8) %148, ptr noundef nonnull align 4 dereferenceable(8) @mx)
  %150 = load i32, ptr %8, align 4, !tbaa !5
  %151 = icmp sgt i32 %150, 1
  br i1 %151, label %152, label %163

152:                                              ; preds = %137
  %153 = load i32, ptr %10, align 4, !tbaa !5
  %154 = sext i32 %153 to i64
  %155 = getelementptr inbounds [400001 x i32], ptr @fa, i64 0, i64 %154
  %156 = load i32, ptr %155, align 4, !tbaa !5
  %157 = sext i32 %156 to i64
  %158 = getelementptr inbounds [400001 x i32], ptr @son, i64 0, i64 %157
  %159 = load i32, ptr %158, align 4, !tbaa !5
  %160 = load i32, ptr %10, align 4, !tbaa !5
  %161 = icmp ne i32 %159, %160
  br i1 %161, label %162, label %163

162:                                              ; preds = %152
  call void @_Z13counter_clearv()
  br label %163

163:                                              ; preds = %162, %152, %137
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #7
  br label %164

164:                                              ; preds = %163
  %165 = load i32, ptr %8, align 4, !tbaa !5
  %166 = add nsw i32 %165, -1
  store i32 %166, ptr %8, align 4, !tbaa !5
  br label %82, !llvm.loop !17

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

168:                                              ; preds = %186, %167
  %169 = load i32, ptr %13, align 4, !tbaa !5
  %170 = load i32, ptr @n, align 4, !tbaa !5
  %171 = icmp sle i32 %169, %170
  br i1 %171, label %173, label %172

172:                                              ; preds = %168
  store i32 14, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #7
  br label %189

173:                                              ; preds = %168
  %174 = load i32, ptr %13, align 4, !tbaa !5
  %175 = sext i32 %174 to i64
  %176 = getelementptr inbounds [400001 x %"struct.std::pair"], ptr @ans, i64 0, i64 %175
  %177 = getelementptr inbounds %"struct.std::pair", ptr %176, i32 0, i32 1
  %178 = load i32, ptr %177, align 4, !tbaa !18
  %179 = sub nsw i32 0, %178
  %180 = load i32, ptr %13, align 4, !tbaa !5
  %181 = sext i32 %180 to i64
  %182 = getelementptr inbounds [400001 x %"struct.std::pair"], ptr @ans, i64 0, i64 %181
  %183 = getelementptr inbounds %"struct.std::pair", ptr %182, i32 0, i32 0
  %184 = load i32, ptr %183, align 8, !tbaa !20
  %185 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %179, i32 noundef %184)
  br label %186

186:                                              ; preds = %173
  %187 = load i32, ptr %13, align 4, !tbaa !5
  %188 = add nsw i32 %187, 1
  store i32 %188, ptr %13, align 4, !tbaa !5
  br label %168, !llvm.loop !21

189:                                              ; preds = %172
  ret i32 0
}

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

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

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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 #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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #7 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"_ZTS4Edge", !6, i64 0, !6, i64 4}
!11 = !{!10, !6, i64 4}
!12 = !{i64 0, i64 4, !5, i64 4, i64 4, !5}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}
!17 = distinct !{!17, !14}
!18 = !{!19, !6, i64 4}
!19 = !{!"_ZTSSt4pairIiiE", !6, i64 0, !6, i64 4}
!20 = !{!19, !6, i64 0}
!21 = distinct !{!21, !14}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%struct.Edge = type { i32, i32 }
%"struct.std::pair" = type { i32, i32 }

@n = external dso_local global i32, align 4
@lnk = external dso_local local_unnamed_addr global [400001 x i32], align 16
@fa = external dso_local local_unnamed_addr global [400001 x i32], align 16
@sz = external dso_local local_unnamed_addr global [400001 x i32], align 16
@seq = external dso_local local_unnamed_addr global [400001 x i32], align 16
@son = external dso_local local_unnamed_addr global [400001 x i32], align 16
@e = external dso_local local_unnamed_addr global [800003 x %struct.Edge], align 16
@a = external dso_local global [400001 x i32], align 16
@b = external dso_local global [400001 x i32], align 16
@mx = external dso_local global %"struct.std::pair", align 4
@ans = external dso_local global [400001 x %"struct.std::pair"], align 16
@.str = external hidden unnamed_addr constant [6 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1

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

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

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z13counter_clearv() local_unnamed_addr #3

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt4pairIiiEaSERKS0_(ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(8)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #4 {
  %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)
  %4 = load i32, ptr @n, align 4, !tbaa !5
  %5 = sext i32 %4 to i64
  %6 = shl nsw i64 %5, 2
  tail call void @llvm.memset.p0.i64(ptr nonnull align 4 getelementptr inbounds (i8, ptr @lnk, i64 4), i8 -1, i64 %6, i1 false)
  %7 = icmp sgt i32 %4, 1
  br i1 %7, label %.lr.ph, label %.preheader43

.preheader43:                                     ; preds = %.lr.ph, %0
  %8 = phi i32 [ %4, %0 ], [ %26, %.lr.ph ]
  %.not45 = icmp slt i32 %8, 1
  br i1 %.not45, label %._crit_edge, label %.lr.ph47

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %0 ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #6
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %1, ptr noundef nonnull %2)
  %10 = load i32, ptr %1, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [400001 x i32], ptr @lnk, i64 0, i64 %11
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = shl nuw i64 %indvars.iv, 1
  %16 = trunc nuw i64 %15 to i32
  %sext = shl i64 %indvars.iv, 33
  %17 = ashr exact i64 %sext, 32
  %18 = getelementptr inbounds [800003 x %struct.Edge], ptr @e, i64 0, i64 %17
  store i32 %13, ptr %18, align 16, !tbaa !5
  %.sroa.428.0..sroa_idx = getelementptr inbounds i8, ptr %18, i64 4
  store i32 %14, ptr %.sroa.428.0..sroa_idx, align 4, !tbaa !5
  store i32 %16, ptr %12, align 4, !tbaa !5
  %19 = sext i32 %14 to i64
  %20 = getelementptr inbounds [400001 x i32], ptr @lnk, i64 0, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = trunc i64 %15 to i32
  %23 = or disjoint i32 %22, 1
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [800003 x %struct.Edge], ptr @e, i64 0, i64 %24
  store i32 %21, ptr %25, align 8, !tbaa !5
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %25, i64 4
  store i32 %10, ptr %.sroa.4.0..sroa_idx, align 4, !tbaa !5
  store i32 %23, ptr %20, 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
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %26 = load i32, ptr @n, align 4, !tbaa !5
  %27 = add nsw i32 %26, -1
  %28 = sext i32 %27 to i64
  %29 = icmp slt i64 %indvars.iv.next, %28
  br i1 %29, label %.lr.ph, label %.preheader43, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph47, %.preheader43
  call void @_Z10tree_buildi(i32 noundef 1)
  call void @_Z13counter_clearv()
  %30 = load i32, ptr @n, align 4, !tbaa !5
  %31 = icmp sgt i32 %30, 0
  br i1 %31, label %.lr.ph54.preheader, label %._crit_edge58

.lr.ph54.preheader:                               ; preds = %._crit_edge
  %32 = add nuw i32 %30, 1
  %33 = zext nneg i32 %30 to i64
  br label %.lr.ph54

.lr.ph47:                                         ; preds = %.preheader43, %.lr.ph47
  %indvars.iv60 = phi i64 [ %indvars.iv.next61, %.lr.ph47 ], [ 1, %.preheader43 ]
  %34 = getelementptr inbounds i32, ptr @a, i64 %indvars.iv60
  %35 = getelementptr inbounds i32, ptr @b, i64 %indvars.iv60
  %36 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %34, ptr noundef nonnull %35)
  %indvars.iv.next61 = add nuw nsw i64 %indvars.iv60, 1
  %37 = load i32, ptr @n, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %.not.not = icmp slt i64 %indvars.iv60, %38
  br i1 %.not.not, label %.lr.ph47, label %._crit_edge, !llvm.loop !11

.preheader:                                       ; preds = %.loopexit, %77
  %.pre = load i32, ptr @n, align 4, !tbaa !5
  %39 = icmp slt i32 %.pre, 1
  br i1 %39, label %._crit_edge58, label %.lr.ph57

.lr.ph54:                                         ; preds = %.lr.ph54.preheader, %77
  %indvars.iv68 = phi i64 [ %33, %.lr.ph54.preheader ], [ %indvars.iv.next69, %77 ]
  %indvars.iv63 = phi i32 [ %32, %.lr.ph54.preheader ], [ %indvars.iv.next64, %77 ]
  %40 = getelementptr inbounds [400001 x i32], ptr @seq, i64 0, i64 %indvars.iv68
  %41 = load i32, ptr %40, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [400001 x i32], ptr @sz, i64 0, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !5
  %45 = icmp sgt i32 %44, 1
  br i1 %45, label %46, label %.loopexit

46:                                               ; preds = %.lr.ph54
  %indvars70 = trunc i64 %indvars.iv68 to i32
  %47 = getelementptr inbounds [400001 x i32], ptr @son, i64 0, i64 %42
  %48 = load i32, ptr %47, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [400001 x i32], ptr @sz, i64 0, i64 %49
  %51 = load i32, ptr %50, align 4, !tbaa !5
  %52 = add nsw i32 %51, %indvars70
  %53 = add i32 %44, %indvars70
  %.03648 = add nsw i32 %52, 1
  %54 = icmp slt i32 %.03648, %53
  br i1 %54, label %.lr.ph51.preheader, label %.loopexit

.lr.ph51.preheader:                               ; preds = %46
  %55 = add i32 %51, %indvars.iv63
  %56 = sext i32 %55 to i64
  br label %.lr.ph51

.lr.ph51:                                         ; preds = %.lr.ph51.preheader, %.lr.ph51
  %indvars.iv65 = phi i64 [ %56, %.lr.ph51.preheader ], [ %indvars.iv.next66, %.lr.ph51 ]
  %57 = getelementptr inbounds [400001 x i32], ptr @seq, i64 0, i64 %indvars.iv65
  %58 = load i32, ptr %57, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [400001 x i32], ptr @a, i64 0, i64 %59
  %61 = load i32, ptr %60, align 4, !tbaa !5
  %62 = getelementptr inbounds [400001 x i32], ptr @b, i64 0, i64 %59
  %63 = load i32, ptr %62, align 4, !tbaa !5
  call void @_Z14counter_updateii(i32 noundef %61, i32 noundef %63)
  %indvars.iv.next66 = add nsw i64 %indvars.iv65, 1
  %lftr.wideiv = trunc i64 %indvars.iv.next66 to i32
  %exitcond.not = icmp eq i32 %53, %lftr.wideiv
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph51, !llvm.loop !12

.loopexit:                                        ; preds = %.lr.ph51, %46, %.lr.ph54
  %64 = getelementptr inbounds [400001 x i32], ptr @a, i64 0, i64 %42
  %65 = load i32, ptr %64, align 4, !tbaa !5
  %66 = getelementptr inbounds [400001 x i32], ptr @b, i64 0, i64 %42
  %67 = load i32, ptr %66, align 4, !tbaa !5
  call void @_Z14counter_updateii(i32 noundef %65, i32 noundef %67)
  %68 = getelementptr inbounds [400001 x %"struct.std::pair"], ptr @ans, i64 0, i64 %42
  %69 = call noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt4pairIiiEaSERKS0_(ptr noundef nonnull align 4 dereferenceable(8) %68, ptr noundef nonnull align 4 dereferenceable(8) @mx)
  %.not41 = icmp eq i64 %indvars.iv68, 1
  br i1 %.not41, label %.preheader, label %70

70:                                               ; preds = %.loopexit
  %71 = getelementptr inbounds [400001 x i32], ptr @fa, i64 0, i64 %42
  %72 = load i32, ptr %71, align 4, !tbaa !5
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [400001 x i32], ptr @son, i64 0, i64 %73
  %75 = load i32, ptr %74, align 4, !tbaa !5
  %.not42 = icmp eq i32 %75, %41
  br i1 %.not42, label %77, label %76

76:                                               ; preds = %70
  call void @_Z13counter_clearv()
  br label %77

77:                                               ; preds = %76, %70
  %indvars.iv.next69 = add nsw i64 %indvars.iv68, -1
  %78 = icmp sgt i64 %indvars.iv68, 1
  %indvars.iv.next64 = add i32 %indvars.iv63, -1
  br i1 %78, label %.lr.ph54, label %.preheader, !llvm.loop !13

._crit_edge58:                                    ; preds = %.lr.ph57, %._crit_edge, %.preheader
  ret i32 0

.lr.ph57:                                         ; preds = %.preheader, %.lr.ph57
  %indvars.iv71 = phi i64 [ %indvars.iv.next72, %.lr.ph57 ], [ 1, %.preheader ]
  %79 = getelementptr inbounds [400001 x %"struct.std::pair"], ptr @ans, i64 0, i64 %indvars.iv71
  %80 = getelementptr inbounds i8, ptr %79, i64 4
  %81 = load i32, ptr %80, align 4, !tbaa !14
  %82 = sub nsw i32 0, %81
  %83 = load i32, ptr %79, align 8, !tbaa !16
  %84 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %82, i32 noundef %83)
  %indvars.iv.next72 = add nuw nsw i64 %indvars.iv71, 1
  %85 = load i32, ptr @n, align 4, !tbaa !5
  %86 = sext i32 %85 to i64
  %.not40.not = icmp slt i64 %indvars.iv71, %86
  br i1 %.not40.not, label %.lr.ph57, label %._crit_edge58, !llvm.loop !17
}

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

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

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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 #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 = { 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 #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 = distinct !{!11, !10}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !10}
!14 = !{!15, !6, i64 4}
!15 = !{!"_ZTSSt4pairIiiE", !6, i64 0, !6, i64 4}
!16 = !{!15, !6, i64 0}
!17 = distinct !{!17, !10}


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