; LLVM IR from tangjz/acm-icpc :: poj (2785)

; 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.Node = type { i32, i32, i64 }

@e = external dso_local global [16008001 x %struct.Node], align 16
@n = external dso_local global i32, align 4
@tot = external dso_local global i32, align 4
@pre = external dso_local global [960991 x i32], align 16
@a = external dso_local global [4001 x [4 x i64]], align 16
@ans = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca %struct.Node, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i64, align 8
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  br label %16

16:                                               ; preds = %209, %0
  %17 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  %18 = icmp ne i32 %17, -1
  br i1 %18, label %19, label %212

19:                                               ; preds = %16
  store i64 0, ptr @ans, align 8, !tbaa !5
  store i32 0, ptr @tot, align 4, !tbaa !9
  call void @llvm.memset.p0.i64(ptr align 16 @pre, i8 0, i64 3843964, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 0, ptr %2, align 4, !tbaa !9
  br label %20

20:                                               ; preds = %42, %19
  %21 = load i32, ptr %2, align 4, !tbaa !9
  %22 = load i32, ptr @n, align 4, !tbaa !9
  %23 = icmp slt i32 %21, %22
  br i1 %23, label %25, label %24

24:                                               ; preds = %20
  store i32 4, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  br label %45

25:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %26

26:                                               ; preds = %38, %25
  %27 = load i32, ptr %4, align 4, !tbaa !9
  %28 = icmp slt i32 %27, 4
  br i1 %28, label %30, label %29

29:                                               ; preds = %26
  store i32 7, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  br label %41

30:                                               ; preds = %26
  %31 = load i32, ptr %2, align 4, !tbaa !9
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [4001 x [4 x i64]], ptr @a, i64 0, i64 %32
  %34 = load i32, ptr %4, align 4, !tbaa !9
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [4 x i64], ptr %33, i64 0, i64 %35
  %37 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %36)
  br label %38

38:                                               ; preds = %30
  %39 = load i32, ptr %4, align 4, !tbaa !9
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %4, align 4, !tbaa !9
  br label %26, !llvm.loop !11

41:                                               ; preds = %29
  br label %42

42:                                               ; preds = %41
  %43 = load i32, ptr %2, align 4, !tbaa !9
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr %2, align 4, !tbaa !9
  br label %20, !llvm.loop !13

45:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %46

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

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

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

52:                                               ; preds = %129, %51
  %53 = load i32, ptr %6, align 4, !tbaa !9
  %54 = load i32, ptr @n, align 4, !tbaa !9
  %55 = icmp slt i32 %53, %54
  br i1 %55, label %57, label %56

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

57:                                               ; preds = %52
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %58 = load i32, ptr %5, align 4, !tbaa !9
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [4001 x [4 x i64]], ptr @a, i64 0, i64 %59
  %61 = getelementptr inbounds [4 x i64], ptr %60, i64 0, i64 0
  %62 = load i64, ptr %61, align 16, !tbaa !5
  %63 = load i32, ptr %6, align 4, !tbaa !9
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [4001 x [4 x i64]], ptr @a, i64 0, i64 %64
  %66 = getelementptr inbounds [4 x i64], ptr %65, i64 0, i64 1
  %67 = load i64, ptr %66, align 8, !tbaa !5
  %68 = add nsw i64 %62, %67
  store i64 %68, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  %69 = load i64, ptr %7, align 8, !tbaa !5
  %70 = srem i64 %69, 960991
  %71 = trunc i64 %70 to i32
  store i32 %71, ptr %9, align 4, !tbaa !9
  %72 = load i32, ptr %9, align 4, !tbaa !9
  %73 = icmp slt i32 %72, 0
  br i1 %73, label %74, label %77

74:                                               ; preds = %57
  %75 = load i32, ptr %9, align 4, !tbaa !9
  %76 = add nsw i32 %75, 960991
  store i32 %76, ptr %9, align 4, !tbaa !9
  br label %77

77:                                               ; preds = %74, %57
  %78 = load i32, ptr %9, align 4, !tbaa !9
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds [960991 x i32], ptr @pre, i64 0, i64 %79
  %81 = load i32, ptr %80, align 4, !tbaa !9
  store i32 %81, ptr %8, align 4, !tbaa !9
  br label %82

82:                                               ; preds = %95, %77
  %83 = load i32, ptr %8, align 4, !tbaa !9
  %84 = icmp ne i32 %83, 0
  br i1 %84, label %85, label %101

85:                                               ; preds = %82
  %86 = load i32, ptr %8, align 4, !tbaa !9
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds [16008001 x %struct.Node], ptr @e, i64 0, i64 %87
  %89 = getelementptr inbounds %struct.Node, ptr %88, i32 0, i32 2
  %90 = load i64, ptr %89, align 8, !tbaa !14
  %91 = load i64, ptr %7, align 8, !tbaa !5
  %92 = icmp eq i64 %90, %91
  br i1 %92, label %93, label %94

93:                                               ; preds = %85
  br label %101

94:                                               ; preds = %85
  br label %95

95:                                               ; preds = %94
  %96 = load i32, ptr %8, align 4, !tbaa !9
  %97 = sext i32 %96 to i64
  %98 = getelementptr inbounds [16008001 x %struct.Node], ptr @e, i64 0, i64 %97
  %99 = getelementptr inbounds %struct.Node, ptr %98, i32 0, i32 1
  %100 = load i32, ptr %99, align 4, !tbaa !16
  store i32 %100, ptr %8, align 4, !tbaa !9
  br label %82, !llvm.loop !17

101:                                              ; preds = %93, %82
  %102 = load i32, ptr %8, align 4, !tbaa !9
  %103 = icmp ne i32 %102, 0
  br i1 %103, label %104, label %111

104:                                              ; preds = %101
  %105 = load i32, ptr %8, align 4, !tbaa !9
  %106 = sext i32 %105 to i64
  %107 = getelementptr inbounds [16008001 x %struct.Node], ptr @e, i64 0, i64 %106
  %108 = getelementptr inbounds %struct.Node, ptr %107, i32 0, i32 0
  %109 = load i32, ptr %108, align 16, !tbaa !18
  %110 = add nsw i32 %109, 1
  store i32 %110, ptr %108, align 16, !tbaa !18
  br label %128

111:                                              ; preds = %101
  call void @llvm.lifetime.start.p0(i64 16, ptr %10) #5
  %112 = getelementptr inbounds %struct.Node, ptr %10, i32 0, i32 0
  store i32 1, ptr %112, align 8, !tbaa !18
  %113 = getelementptr inbounds %struct.Node, ptr %10, i32 0, i32 1
  %114 = load i32, ptr %9, align 4, !tbaa !9
  %115 = sext i32 %114 to i64
  %116 = getelementptr inbounds [960991 x i32], ptr @pre, i64 0, i64 %115
  %117 = load i32, ptr %116, align 4, !tbaa !9
  store i32 %117, ptr %113, align 4, !tbaa !16
  %118 = getelementptr inbounds %struct.Node, ptr %10, i32 0, i32 2
  %119 = load i64, ptr %7, align 8, !tbaa !5
  store i64 %119, ptr %118, align 8, !tbaa !14
  %120 = load i32, ptr @tot, align 4, !tbaa !9
  %121 = add nsw i32 %120, 1
  store i32 %121, ptr @tot, align 4, !tbaa !9
  %122 = sext i32 %121 to i64
  %123 = getelementptr inbounds [16008001 x %struct.Node], ptr @e, i64 0, i64 %122
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %123, ptr align 8 %10, i64 16, i1 false), !tbaa.struct !19
  call void @llvm.lifetime.end.p0(i64 16, ptr %10) #5
  %124 = load i32, ptr @tot, align 4, !tbaa !9
  %125 = load i32, ptr %9, align 4, !tbaa !9
  %126 = sext i32 %125 to i64
  %127 = getelementptr inbounds [960991 x i32], ptr @pre, i64 0, i64 %126
  store i32 %124, ptr %127, align 4, !tbaa !9
  br label %128

128:                                              ; preds = %111, %104
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  br label %129

129:                                              ; preds = %128
  %130 = load i32, ptr %6, align 4, !tbaa !9
  %131 = add nsw i32 %130, 1
  store i32 %131, ptr %6, align 4, !tbaa !9
  br label %52, !llvm.loop !20

132:                                              ; preds = %56
  br label %133

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

136:                                              ; preds = %50
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %137

137:                                              ; preds = %206, %136
  %138 = load i32, ptr %11, align 4, !tbaa !9
  %139 = load i32, ptr @n, align 4, !tbaa !9
  %140 = icmp slt i32 %138, %139
  br i1 %140, label %142, label %141

141:                                              ; preds = %137
  store i32 19, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  br label %209

142:                                              ; preds = %137
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  store i32 0, ptr %12, align 4, !tbaa !9
  br label %143

143:                                              ; preds = %202, %142
  %144 = load i32, ptr %12, align 4, !tbaa !9
  %145 = load i32, ptr @n, align 4, !tbaa !9
  %146 = icmp slt i32 %144, %145
  br i1 %146, label %148, label %147

147:                                              ; preds = %143
  store i32 22, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  br label %205

148:                                              ; preds = %143
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #5
  %149 = load i32, ptr %11, align 4, !tbaa !9
  %150 = sext i32 %149 to i64
  %151 = getelementptr inbounds [4001 x [4 x i64]], ptr @a, i64 0, i64 %150
  %152 = getelementptr inbounds [4 x i64], ptr %151, i64 0, i64 2
  %153 = load i64, ptr %152, align 16, !tbaa !5
  %154 = sub nsw i64 0, %153
  %155 = load i32, ptr %12, align 4, !tbaa !9
  %156 = sext i32 %155 to i64
  %157 = getelementptr inbounds [4001 x [4 x i64]], ptr @a, i64 0, i64 %156
  %158 = getelementptr inbounds [4 x i64], ptr %157, i64 0, i64 3
  %159 = load i64, ptr %158, align 8, !tbaa !5
  %160 = sub nsw i64 %154, %159
  store i64 %160, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #5
  %161 = load i64, ptr %13, align 8, !tbaa !5
  %162 = srem i64 %161, 960991
  %163 = trunc i64 %162 to i32
  store i32 %163, ptr %15, align 4, !tbaa !9
  %164 = load i32, ptr %15, align 4, !tbaa !9
  %165 = icmp slt i32 %164, 0
  br i1 %165, label %166, label %169

166:                                              ; preds = %148
  %167 = load i32, ptr %15, align 4, !tbaa !9
  %168 = add nsw i32 %167, 960991
  store i32 %168, ptr %15, align 4, !tbaa !9
  br label %169

169:                                              ; preds = %166, %148
  %170 = load i32, ptr %15, align 4, !tbaa !9
  %171 = sext i32 %170 to i64
  %172 = getelementptr inbounds [960991 x i32], ptr @pre, i64 0, i64 %171
  %173 = load i32, ptr %172, align 4, !tbaa !9
  store i32 %173, ptr %14, align 4, !tbaa !9
  br label %174

174:                                              ; preds = %187, %169
  %175 = load i32, ptr %14, align 4, !tbaa !9
  %176 = icmp ne i32 %175, 0
  br i1 %176, label %177, label %193

177:                                              ; preds = %174
  %178 = load i32, ptr %14, align 4, !tbaa !9
  %179 = sext i32 %178 to i64
  %180 = getelementptr inbounds [16008001 x %struct.Node], ptr @e, i64 0, i64 %179
  %181 = getelementptr inbounds %struct.Node, ptr %180, i32 0, i32 2
  %182 = load i64, ptr %181, align 8, !tbaa !14
  %183 = load i64, ptr %13, align 8, !tbaa !5
  %184 = icmp eq i64 %182, %183
  br i1 %184, label %185, label %186

185:                                              ; preds = %177
  br label %193

186:                                              ; preds = %177
  br label %187

187:                                              ; preds = %186
  %188 = load i32, ptr %14, align 4, !tbaa !9
  %189 = sext i32 %188 to i64
  %190 = getelementptr inbounds [16008001 x %struct.Node], ptr @e, i64 0, i64 %189
  %191 = getelementptr inbounds %struct.Node, ptr %190, i32 0, i32 1
  %192 = load i32, ptr %191, align 4, !tbaa !16
  store i32 %192, ptr %14, align 4, !tbaa !9
  br label %174, !llvm.loop !22

193:                                              ; preds = %185, %174
  %194 = load i32, ptr %14, align 4, !tbaa !9
  %195 = sext i32 %194 to i64
  %196 = getelementptr inbounds [16008001 x %struct.Node], ptr @e, i64 0, i64 %195
  %197 = getelementptr inbounds %struct.Node, ptr %196, i32 0, i32 0
  %198 = load i32, ptr %197, align 16, !tbaa !18
  %199 = sext i32 %198 to i64
  %200 = load i64, ptr @ans, align 8, !tbaa !5
  %201 = add nsw i64 %200, %199
  store i64 %201, ptr @ans, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  br label %202

202:                                              ; preds = %193
  %203 = load i32, ptr %12, align 4, !tbaa !9
  %204 = add nsw i32 %203, 1
  store i32 %204, ptr %12, align 4, !tbaa !9
  br label %143, !llvm.loop !23

205:                                              ; preds = %147
  br label %206

206:                                              ; preds = %205
  %207 = load i32, ptr %11, align 4, !tbaa !9
  %208 = add nsw i32 %207, 1
  store i32 %208, ptr %11, align 4, !tbaa !9
  br label %137, !llvm.loop !24

209:                                              ; preds = %141
  %210 = load i64, ptr @ans, align 8, !tbaa !5
  %211 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %210)
  br label %16, !llvm.loop !25

212:                                              ; preds = %16
  ret i32 0
}

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

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

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

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

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

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

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


; 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.Node = type { i32, i32, i64 }

@e = external dso_local local_unnamed_addr global [16008001 x %struct.Node], align 16
@n = 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 [960991 x i32], align 16
@a = external dso_local global [4001 x [4 x i64]], align 16
@ans = external dso_local local_unnamed_addr global i64, align 8
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %.not92 = icmp eq i32 %1, -1
  br i1 %.not92, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %0, %68
  store i64 0, ptr @ans, align 8, !tbaa !5
  store i32 0, ptr @tot, align 4, !tbaa !9
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(3843964) @pre, i8 0, i64 3843964, i1 false)
  %2 = load i32, ptr @n, align 4, !tbaa !9
  %3 = icmp sgt i32 %2, 0
  br i1 %3, label %.preheader56, label %.preheader57.thread

.preheader58:                                     ; preds = %.preheader56
  %4 = icmp sgt i32 %40, 0
  br i1 %4, label %.preheader55.us.preheader, label %.preheader57.thread

.preheader55.us.preheader:                        ; preds = %.preheader58
  %tot.promoted67.pre = load i32, ptr @tot, align 4, !tbaa !9
  %wide.trip.count105 = zext nneg i32 %40 to i64
  br label %.preheader55.us

.preheader55.us:                                  ; preds = %.preheader55.us.preheader, %._crit_edge.us
  %indvars.iv102 = phi i64 [ 0, %.preheader55.us.preheader ], [ %indvars.iv.next103, %._crit_edge.us ]
  %tot.promoted7172.us = phi i32 [ %tot.promoted67.pre, %.preheader55.us.preheader ], [ %tot.promoted69.us, %._crit_edge.us ]
  %5 = getelementptr inbounds [4001 x [4 x i64]], ptr @a, i64 0, i64 %indvars.iv102
  %6 = load i64, ptr %5, align 16, !tbaa !5
  br label %7

7:                                                ; preds = %.preheader55.us, %30
  %indvars.iv99 = phi i64 [ 0, %.preheader55.us ], [ %indvars.iv.next100, %30 ]
  %tot.promoted70.us = phi i32 [ %tot.promoted7172.us, %.preheader55.us ], [ %tot.promoted69.us, %30 ]
  %8 = phi i32 [ %tot.promoted7172.us, %.preheader55.us ], [ %31, %30 ]
  %9 = getelementptr inbounds [4001 x [4 x i64]], ptr @a, i64 0, i64 %indvars.iv99, i64 1
  %10 = load i64, ptr %9, align 8, !tbaa !5
  %11 = add nsw i64 %10, %6
  %12 = srem i64 %11, 960991
  %13 = icmp slt i64 %12, 0
  %14 = add nsw i64 %12, 960991
  %spec.select.us = select i1 %13, i64 %14, i64 %12
  %15 = and i64 %spec.select.us, 4294967295
  %16 = getelementptr inbounds [960991 x i32], ptr @pre, i64 0, i64 %15
  %.04762.us = load i32, ptr %16, align 4, !tbaa !9
  %.not5363.us = icmp eq i32 %.04762.us, 0
  br i1 %.not5363.us, label %.critedge.us, label %.lr.ph.us

.lr.ph.us:                                        ; preds = %7, %22
  %.04764.us = phi i32 [ %.047.us, %22 ], [ %.04762.us, %7 ]
  %17 = sext i32 %.04764.us to i64
  %18 = getelementptr inbounds [16008001 x %struct.Node], ptr @e, i64 0, i64 %17
  %19 = getelementptr inbounds i8, ptr %18, i64 8
  %20 = load i64, ptr %19, align 8, !tbaa !11
  %21 = icmp eq i64 %20, %11
  br i1 %21, label %24, label %22

22:                                               ; preds = %.lr.ph.us
  %23 = getelementptr inbounds i8, ptr %18, i64 4
  %.047.us = load i32, ptr %23, align 4, !tbaa !9
  %.not53.us = icmp eq i32 %.047.us, 0
  br i1 %.not53.us, label %.critedge.us, label %.lr.ph.us, !llvm.loop !13

24:                                               ; preds = %.lr.ph.us
  %25 = load i32, ptr %18, align 16, !tbaa !15
  %26 = add nsw i32 %25, 1
  store i32 %26, ptr %18, align 16, !tbaa !15
  br label %30

.critedge.us:                                     ; preds = %22, %7
  %27 = add nsw i32 %8, 1
  store i32 %27, ptr @tot, align 4, !tbaa !9
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [16008001 x %struct.Node], ptr @e, i64 0, i64 %28
  store i32 1, ptr %29, align 16, !tbaa !9
  %.sroa.4.0..sroa_idx.us = getelementptr inbounds i8, ptr %29, i64 4
  store i32 %.04762.us, ptr %.sroa.4.0..sroa_idx.us, align 4, !tbaa !9
  %.sroa.5.0..sroa_idx.us = getelementptr inbounds i8, ptr %29, i64 8
  store i64 %11, ptr %.sroa.5.0..sroa_idx.us, align 8, !tbaa !5
  store i32 %27, ptr %16, align 4, !tbaa !9
  br label %30

30:                                               ; preds = %.critedge.us, %24
  %tot.promoted69.us = phi i32 [ %27, %.critedge.us ], [ %tot.promoted70.us, %24 ]
  %31 = phi i32 [ %27, %.critedge.us ], [ %8, %24 ]
  %indvars.iv.next100 = add nuw nsw i64 %indvars.iv99, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next100, %wide.trip.count105
  br i1 %exitcond.not, label %._crit_edge.us, label %7, !llvm.loop !16

._crit_edge.us:                                   ; preds = %30
  %indvars.iv.next103 = add nuw nsw i64 %indvars.iv102, 1
  %exitcond106.not = icmp eq i64 %indvars.iv.next103, %wide.trip.count105
  br i1 %exitcond106.not, label %.preheader57, label %.preheader55.us, !llvm.loop !17

.preheader56:                                     ; preds = %.lr.ph, %.preheader56
  %indvars.iv = phi i64 [ %indvars.iv.next, %.preheader56 ], [ 0, %.lr.ph ]
  %32 = getelementptr inbounds [4001 x [4 x i64]], ptr @a, i64 0, i64 %indvars.iv, i64 0
  %33 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %32)
  %34 = getelementptr inbounds [4001 x [4 x i64]], ptr @a, i64 0, i64 %indvars.iv, i64 1
  %35 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %34)
  %36 = getelementptr inbounds [4001 x [4 x i64]], ptr @a, i64 0, i64 %indvars.iv, i64 2
  %37 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %36)
  %38 = getelementptr inbounds [4001 x [4 x i64]], ptr @a, i64 0, i64 %indvars.iv, i64 3
  %39 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %38)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %40 = load i32, ptr @n, align 4, !tbaa !9
  %41 = sext i32 %40 to i64
  %42 = icmp slt i64 %indvars.iv.next, %41
  br i1 %42, label %.preheader56, label %.preheader58, !llvm.loop !18

.preheader57.thread:                              ; preds = %.preheader58, %.lr.ph
  %ans.promoted84122 = load i64, ptr @ans, align 8, !tbaa !5
  br label %68

.preheader57:                                     ; preds = %._crit_edge.us
  %ans.promoted84 = load i64, ptr @ans, align 8, !tbaa !5
  br i1 %4, label %.preheader.us.preheader, label %68

.preheader.us.preheader:                          ; preds = %.preheader57
  %wide.trip.count115 = zext nneg i32 %40 to i64
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge82.us
  %indvars.iv112 = phi i64 [ 0, %.preheader.us.preheader ], [ %indvars.iv.next113, %._crit_edge82.us ]
  %.lcssa838687.us = phi i64 [ %ans.promoted84, %.preheader.us.preheader ], [ %67, %._crit_edge82.us ]
  %43 = getelementptr inbounds [4001 x [4 x i64]], ptr @a, i64 0, i64 %indvars.iv112, i64 2
  %44 = load i64, ptr %43, align 16, !tbaa !5
  br label %45

45:                                               ; preds = %.preheader.us, %._crit_edge.us91
  %indvars.iv107 = phi i64 [ 0, %.preheader.us ], [ %indvars.iv.next108, %._crit_edge.us91 ]
  %46 = phi i64 [ %.lcssa838687.us, %.preheader.us ], [ %67, %._crit_edge.us91 ]
  %47 = getelementptr inbounds [4001 x [4 x i64]], ptr @a, i64 0, i64 %indvars.iv107, i64 3
  %48 = load i64, ptr %47, align 8, !tbaa !5
  %49 = add i64 %44, %48
  %50 = sub i64 0, %49
  %51 = srem i64 %50, 960991
  %52 = icmp slt i64 %51, 0
  %53 = add nsw i64 %51, 960991
  %spec.select54.us = select i1 %52, i64 %53, i64 %51
  %54 = and i64 %spec.select54.us, 4294967295
  %55 = getelementptr inbounds [960991 x i32], ptr @pre, i64 0, i64 %54
  %.04074.us = load i32, ptr %55, align 4, !tbaa !9
  %.not5275.us = icmp eq i32 %.04074.us, 0
  br i1 %.not5275.us, label %._crit_edge.us91, label %.lr.ph.us90

56:                                               ; preds = %.lr.ph.us90
  %57 = getelementptr inbounds i8, ptr %59, i64 4
  %.040.us = load i32, ptr %57, align 4, !tbaa !9
  %.not52.us = icmp eq i32 %.040.us, 0
  br i1 %.not52.us, label %._crit_edge.us91, label %.lr.ph.us90, !llvm.loop !19

.lr.ph.us90:                                      ; preds = %45, %56
  %.04076.us = phi i32 [ %.040.us, %56 ], [ %.04074.us, %45 ]
  %58 = sext i32 %.04076.us to i64
  %59 = getelementptr inbounds [16008001 x %struct.Node], ptr @e, i64 0, i64 %58
  %60 = getelementptr inbounds i8, ptr %59, i64 8
  %61 = load i64, ptr %60, align 8, !tbaa !11
  %62 = icmp eq i64 %61, %50
  br i1 %62, label %._crit_edge.us91, label %56

._crit_edge.us91:                                 ; preds = %56, %.lr.ph.us90, %45
  %.040.lcssa.us = phi i32 [ 0, %45 ], [ %.04076.us, %.lr.ph.us90 ], [ 0, %56 ]
  %63 = sext i32 %.040.lcssa.us to i64
  %64 = getelementptr inbounds [16008001 x %struct.Node], ptr @e, i64 0, i64 %63
  %65 = load i32, ptr %64, align 16, !tbaa !15
  %66 = sext i32 %65 to i64
  %67 = add nsw i64 %46, %66
  %indvars.iv.next108 = add nuw nsw i64 %indvars.iv107, 1
  %exitcond111.not = icmp eq i64 %indvars.iv.next108, %wide.trip.count115
  br i1 %exitcond111.not, label %._crit_edge82.us, label %45, !llvm.loop !20

._crit_edge82.us:                                 ; preds = %._crit_edge.us91
  %indvars.iv.next113 = add nuw nsw i64 %indvars.iv112, 1
  %exitcond116.not = icmp eq i64 %indvars.iv.next113, %wide.trip.count115
  br i1 %exitcond116.not, label %._crit_edge89.split.us, label %.preheader.us, !llvm.loop !21

._crit_edge89.split.us:                           ; preds = %._crit_edge82.us
  store i64 %67, ptr @ans, align 8, !tbaa !5
  br label %68

68:                                               ; preds = %.preheader57.thread, %._crit_edge89.split.us, %.preheader57
  %69 = phi i64 [ %67, %._crit_edge89.split.us ], [ %ans.promoted84, %.preheader57 ], [ %ans.promoted84122, %.preheader57.thread ]
  %70 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %69)
  %71 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %.not = icmp eq i32 %71, -1
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !22

._crit_edge:                                      ; preds = %68, %0
  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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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

attributes #0 = { mustprogress nofree norecurse nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { nofree nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }

!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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 8}
!12 = !{!"_ZTS4Node", !10, i64 0, !10, i64 4, !6, i64 8}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!12, !10, i64 0}
!16 = distinct !{!16, !14}
!17 = distinct !{!17, !14}
!18 = distinct !{!18, !14}
!19 = distinct !{!19, !14}
!20 = distinct !{!20, !14}
!21 = distinct !{!21, !14}
!22 = distinct !{!22, !14}


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