; LLVM IR from tangjz/acm-icpc :: 51nod (1349)

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

@n = external dso_local global i32, align 4
@q = external dso_local global i32, align 4
@a = external dso_local global [100001 x i32], align 16
@que = external dso_local global [100001 x i32], align 16
@r = external dso_local global i32, align 4
@L = external dso_local global [100001 x i32], align 16
@R = external dso_local global [100001 x i32], align 16
@id = external dso_local global [100001 x i32], align 16
@last = external dso_local global [100001 x i32], align 16
@ans = external dso_local global [100001 x i64], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z3cmpRKiS0_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #1 {
  %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
  store i32 0, ptr %1, align 4
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #6
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %65, %0
  %9 = load i32, ptr %2, align 4, !tbaa !5
  %10 = load i32, ptr @n, align 4, !tbaa !5
  %11 = icmp slt i32 %9, %10
  br i1 %11, label %13, label %12

12:                                               ; preds = %8
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #6
  br label %68

13:                                               ; preds = %8
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds i32, ptr @a, i64 %15
  %17 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %16)
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [100001 x i32], ptr @id, i64 0, i64 %20
  store i32 %18, ptr %21, align 4, !tbaa !5
  br label %22

22:                                               ; preds = %41, %13
  %23 = load i32, ptr @r, align 4, !tbaa !5
  %24 = icmp sgt i32 %23, 0
  br i1 %24, label %25, label %39

25:                                               ; preds = %22
  %26 = load i32, ptr @r, align 4, !tbaa !5
  %27 = sub nsw i32 %26, 1
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [100001 x i32], ptr @que, i64 0, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = load i32, ptr %2, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %35
  %37 = load i32, ptr %36, align 4, !tbaa !5
  %38 = icmp sle i32 %33, %37
  br label %39

39:                                               ; preds = %25, %22
  %40 = phi i1 [ false, %22 ], [ %38, %25 ]
  br i1 %40, label %41, label %44

41:                                               ; preds = %39
  %42 = load i32, ptr @r, align 4, !tbaa !5
  %43 = add nsw i32 %42, -1
  store i32 %43, ptr @r, align 4, !tbaa !5
  br label %22, !llvm.loop !9

44:                                               ; preds = %39
  %45 = load i32, ptr @r, align 4, !tbaa !5
  %46 = icmp ne i32 %45, 0
  br i1 %46, label %47, label %54

47:                                               ; preds = %44
  %48 = load i32, ptr @r, align 4, !tbaa !5
  %49 = sub nsw i32 %48, 1
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [100001 x i32], ptr @que, i64 0, i64 %50
  %52 = load i32, ptr %51, align 4, !tbaa !5
  %53 = add nsw i32 %52, 1
  br label %55

54:                                               ; preds = %44
  br label %55

55:                                               ; preds = %54, %47
  %56 = phi i32 [ %53, %47 ], [ 0, %54 ]
  %57 = load i32, ptr %2, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [100001 x i32], ptr @L, i64 0, i64 %58
  store i32 %56, ptr %59, align 4, !tbaa !5
  %60 = load i32, ptr %2, align 4, !tbaa !5
  %61 = load i32, ptr @r, align 4, !tbaa !5
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr @r, align 4, !tbaa !5
  %63 = sext i32 %61 to i64
  %64 = getelementptr inbounds [100001 x i32], ptr @que, i64 0, i64 %63
  store i32 %60, ptr %64, align 4, !tbaa !5
  br label %65

65:                                               ; preds = %55
  %66 = load i32, ptr %2, align 4, !tbaa !5
  %67 = add nsw i32 %66, 1
  store i32 %67, ptr %2, align 4, !tbaa !5
  br label %8, !llvm.loop !11

68:                                               ; preds = %12
  store i32 0, ptr @r, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #6
  %69 = load i32, ptr @n, align 4, !tbaa !5
  %70 = sub nsw i32 %69, 1
  store i32 %70, ptr %3, align 4, !tbaa !5
  br label %71

71:                                               ; preds = %121, %68
  %72 = load i32, ptr %3, align 4, !tbaa !5
  %73 = icmp sge i32 %72, 0
  br i1 %73, label %75, label %74

74:                                               ; preds = %71
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #6
  br label %124

75:                                               ; preds = %71
  br label %76

76:                                               ; preds = %95, %75
  %77 = load i32, ptr @r, align 4, !tbaa !5
  %78 = icmp sgt i32 %77, 0
  br i1 %78, label %79, label %93

79:                                               ; preds = %76
  %80 = load i32, ptr @r, align 4, !tbaa !5
  %81 = sub nsw i32 %80, 1
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds [100001 x i32], ptr @que, i64 0, i64 %82
  %84 = load i32, ptr %83, align 4, !tbaa !5
  %85 = sext i32 %84 to i64
  %86 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %85
  %87 = load i32, ptr %86, align 4, !tbaa !5
  %88 = load i32, ptr %3, align 4, !tbaa !5
  %89 = sext i32 %88 to i64
  %90 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %89
  %91 = load i32, ptr %90, align 4, !tbaa !5
  %92 = icmp sle i32 %87, %91
  br label %93

93:                                               ; preds = %79, %76
  %94 = phi i1 [ false, %76 ], [ %92, %79 ]
  br i1 %94, label %95, label %98

95:                                               ; preds = %93
  %96 = load i32, ptr @r, align 4, !tbaa !5
  %97 = add nsw i32 %96, -1
  store i32 %97, ptr @r, align 4, !tbaa !5
  br label %76, !llvm.loop !12

98:                                               ; preds = %93
  %99 = load i32, ptr @r, align 4, !tbaa !5
  %100 = icmp ne i32 %99, 0
  br i1 %100, label %101, label %108

101:                                              ; preds = %98
  %102 = load i32, ptr @r, align 4, !tbaa !5
  %103 = sub nsw i32 %102, 1
  %104 = sext i32 %103 to i64
  %105 = getelementptr inbounds [100001 x i32], ptr @que, i64 0, i64 %104
  %106 = load i32, ptr %105, align 4, !tbaa !5
  %107 = sub nsw i32 %106, 1
  br label %111

108:                                              ; preds = %98
  %109 = load i32, ptr @n, align 4, !tbaa !5
  %110 = sub nsw i32 %109, 1
  br label %111

111:                                              ; preds = %108, %101
  %112 = phi i32 [ %107, %101 ], [ %110, %108 ]
  %113 = load i32, ptr %3, align 4, !tbaa !5
  %114 = sext i32 %113 to i64
  %115 = getelementptr inbounds [100001 x i32], ptr @R, i64 0, i64 %114
  store i32 %112, ptr %115, align 4, !tbaa !5
  %116 = load i32, ptr %3, align 4, !tbaa !5
  %117 = load i32, ptr @r, align 4, !tbaa !5
  %118 = add nsw i32 %117, 1
  store i32 %118, ptr @r, align 4, !tbaa !5
  %119 = sext i32 %117 to i64
  %120 = getelementptr inbounds [100001 x i32], ptr @que, i64 0, i64 %119
  store i32 %116, ptr %120, align 4, !tbaa !5
  br label %121

121:                                              ; preds = %111
  %122 = load i32, ptr %3, align 4, !tbaa !5
  %123 = add nsw i32 %122, -1
  store i32 %123, ptr %3, align 4, !tbaa !5
  br label %71, !llvm.loop !13

124:                                              ; preds = %74
  %125 = load i32, ptr @n, align 4, !tbaa !5
  %126 = sext i32 %125 to i64
  %127 = getelementptr inbounds i32, ptr @id, i64 %126
  call void @_ZSt4sortIPiPFbRKiS2_EEvT_S5_T0_(ptr noundef @id, ptr noundef %127, ptr noundef @_Z3cmpRKiS0_)
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #6
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %128

128:                                              ; preds = %198, %124
  %129 = load i32, ptr %4, align 4, !tbaa !5
  %130 = load i32, ptr @n, align 4, !tbaa !5
  %131 = icmp slt i32 %129, %130
  br i1 %131, label %133, label %132

132:                                              ; preds = %128
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #6
  br label %201

133:                                              ; preds = %128
  %134 = load i32, ptr %4, align 4, !tbaa !5
  %135 = sext i32 %134 to i64
  %136 = getelementptr inbounds [100001 x i32], ptr @id, i64 0, i64 %135
  %137 = load i32, ptr %136, align 4, !tbaa !5
  %138 = sext i32 %137 to i64
  %139 = getelementptr inbounds [100001 x i32], ptr @R, i64 0, i64 %138
  %140 = load i32, ptr %139, align 4, !tbaa !5
  %141 = load i32, ptr %4, align 4, !tbaa !5
  %142 = sext i32 %141 to i64
  %143 = getelementptr inbounds [100001 x i32], ptr @id, i64 0, i64 %142
  %144 = load i32, ptr %143, align 4, !tbaa !5
  %145 = sub nsw i32 %140, %144
  %146 = sext i32 %145 to i64
  %147 = add nsw i64 %146, 1
  %148 = load i32, ptr %4, align 4, !tbaa !5
  %149 = sext i32 %148 to i64
  %150 = getelementptr inbounds [100001 x i32], ptr @id, i64 0, i64 %149
  %151 = load i32, ptr %150, align 4, !tbaa !5
  %152 = load i32, ptr %4, align 4, !tbaa !5
  %153 = sext i32 %152 to i64
  %154 = getelementptr inbounds [100001 x i32], ptr @id, i64 0, i64 %153
  %155 = load i32, ptr %154, align 4, !tbaa !5
  %156 = sext i32 %155 to i64
  %157 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %156
  %158 = load i32, ptr %157, align 4, !tbaa !5
  %159 = sext i32 %158 to i64
  %160 = getelementptr inbounds [100001 x i32], ptr @last, i64 0, i64 %159
  %161 = load i32, ptr %4, align 4, !tbaa !5
  %162 = sext i32 %161 to i64
  %163 = getelementptr inbounds [100001 x i32], ptr @id, i64 0, i64 %162
  %164 = load i32, ptr %163, align 4, !tbaa !5
  %165 = sext i32 %164 to i64
  %166 = getelementptr inbounds [100001 x i32], ptr @L, i64 0, i64 %165
  %167 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %160, ptr noundef nonnull align 4 dereferenceable(4) %166)
  %168 = load i32, ptr %167, align 4, !tbaa !5
  %169 = sub nsw i32 %151, %168
  %170 = sext i32 %169 to i64
  %171 = add nsw i64 %170, 1
  %172 = mul nsw i64 %147, %171
  %173 = load i32, ptr %4, align 4, !tbaa !5
  %174 = sext i32 %173 to i64
  %175 = getelementptr inbounds [100001 x i32], ptr @id, i64 0, i64 %174
  %176 = load i32, ptr %175, align 4, !tbaa !5
  %177 = sext i32 %176 to i64
  %178 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %177
  %179 = load i32, ptr %178, align 4, !tbaa !5
  %180 = sext i32 %179 to i64
  %181 = getelementptr inbounds [100001 x i64], ptr @ans, i64 0, i64 %180
  %182 = load i64, ptr %181, align 8, !tbaa !14
  %183 = add nsw i64 %182, %172
  store i64 %183, ptr %181, align 8, !tbaa !14
  %184 = load i32, ptr %4, align 4, !tbaa !5
  %185 = sext i32 %184 to i64
  %186 = getelementptr inbounds [100001 x i32], ptr @id, i64 0, i64 %185
  %187 = load i32, ptr %186, align 4, !tbaa !5
  %188 = add nsw i32 %187, 1
  %189 = load i32, ptr %4, align 4, !tbaa !5
  %190 = sext i32 %189 to i64
  %191 = getelementptr inbounds [100001 x i32], ptr @id, i64 0, i64 %190
  %192 = load i32, ptr %191, align 4, !tbaa !5
  %193 = sext i32 %192 to i64
  %194 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %193
  %195 = load i32, ptr %194, align 4, !tbaa !5
  %196 = sext i32 %195 to i64
  %197 = getelementptr inbounds [100001 x i32], ptr @last, i64 0, i64 %196
  store i32 %188, ptr %197, align 4, !tbaa !5
  br label %198

198:                                              ; preds = %133
  %199 = load i32, ptr %4, align 4, !tbaa !5
  %200 = add nsw i32 %199, 1
  store i32 %200, ptr %4, align 4, !tbaa !5
  br label %128, !llvm.loop !16

201:                                              ; preds = %132
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #6
  store i32 99999, ptr %5, align 4, !tbaa !5
  br label %202

202:                                              ; preds = %217, %201
  %203 = load i32, ptr %5, align 4, !tbaa !5
  %204 = icmp sge i32 %203, 0
  br i1 %204, label %206, label %205

205:                                              ; preds = %202
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  br label %220

206:                                              ; preds = %202
  %207 = load i32, ptr %5, align 4, !tbaa !5
  %208 = add nsw i32 %207, 1
  %209 = sext i32 %208 to i64
  %210 = getelementptr inbounds [100001 x i64], ptr @ans, i64 0, i64 %209
  %211 = load i64, ptr %210, align 8, !tbaa !14
  %212 = load i32, ptr %5, align 4, !tbaa !5
  %213 = sext i32 %212 to i64
  %214 = getelementptr inbounds [100001 x i64], ptr @ans, i64 0, i64 %213
  %215 = load i64, ptr %214, align 8, !tbaa !14
  %216 = add nsw i64 %215, %211
  store i64 %216, ptr %214, align 8, !tbaa !14
  br label %217

217:                                              ; preds = %206
  %218 = load i32, ptr %5, align 4, !tbaa !5
  %219 = add nsw i32 %218, -1
  store i32 %219, ptr %5, align 4, !tbaa !5
  br label %202, !llvm.loop !17

220:                                              ; preds = %205
  %221 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @q)
  br label %222

222:                                              ; preds = %236, %220
  %223 = load i32, ptr @q, align 4, !tbaa !5
  %224 = add nsw i32 %223, -1
  store i32 %224, ptr @q, align 4, !tbaa !5
  %225 = icmp sgt i32 %223, 0
  br i1 %225, label %226, label %239

226:                                              ; preds = %222
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  %227 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %6)
  %228 = load i32, ptr %6, align 4, !tbaa !5
  %229 = icmp slt i32 %228, 100001
  br i1 %229, label %230, label %235

230:                                              ; preds = %226
  %231 = load i32, ptr %6, align 4, !tbaa !5
  %232 = sext i32 %231 to i64
  %233 = getelementptr inbounds [100001 x i64], ptr @ans, i64 0, i64 %232
  %234 = load i64, ptr %233, align 8, !tbaa !14
  br label %236

235:                                              ; preds = %226
  br label %236

236:                                              ; preds = %235, %230
  %237 = phi i64 [ %234, %230 ], [ 0, %235 ]
  %238 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %237)
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  br label %222, !llvm.loop !18

239:                                              ; preds = %222
  ret i32 0
}

declare i32 @__isoc99_scanf(ptr noundef, ...) #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: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPiPFbRKiS2_EEvT_S5_T0_(ptr noundef, ptr noundef, ptr noundef) #4

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #5

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

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 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 #2 = { "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 nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { inlinehint mustprogress uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #5 = { inlinehint 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 #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, !15, i64 0}
!15 = !{!"long long", !7, i64 0}
!16 = distinct !{!16, !10}
!17 = distinct !{!17, !10}
!18 = distinct !{!18, !10}


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

@n = external dso_local global i32, align 4
@q = external dso_local global i32, align 4
@a = external dso_local global [100001 x i32], align 16
@que = external dso_local local_unnamed_addr global [100001 x i32], align 16
@r = external dso_local local_unnamed_addr global i32, align 4
@L = external dso_local global [100001 x i32], align 16
@R = external dso_local local_unnamed_addr global [100001 x i32], align 16
@id = external dso_local global [100001 x i32], align 16
@last = external dso_local global [100001 x i32], align 16
@ans = external dso_local local_unnamed_addr global [100001 x i64], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z3cmpRKiS0_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = alloca i32, align 4
  %2 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %3 = load i32, ptr @n, align 4, !tbaa !5
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %.lr.ph46, label %._crit_edge.thread

._crit_edge.thread:                               ; preds = %0
  store i32 0, ptr @r, align 4, !tbaa !5
  br label %._crit_edge._crit_edge

._crit_edge:                                      ; preds = %30
  store i32 0, ptr @r, align 4, !tbaa !5
  %5 = icmp sgt i32 %37, 0
  br i1 %5, label %thread-pre-split.preheader, label %._crit_edge._crit_edge

._crit_edge._crit_edge:                           ; preds = %._crit_edge.thread, %._crit_edge
  %.lcssa4490 = phi i32 [ %3, %._crit_edge.thread ], [ %37, %._crit_edge ]
  %.pre87 = sext i32 %.lcssa4490 to i64
  br label %40

thread-pre-split.preheader:                       ; preds = %._crit_edge
  %6 = zext nneg i32 %37 to i64
  br label %thread-pre-split

.lr.ph46:                                         ; preds = %0, %30
  %indvars.iv72 = phi i64 [ %indvars.iv.next73, %30 ], [ 0, %0 ]
  %7 = getelementptr inbounds i32, ptr @a, i64 %indvars.iv72
  %8 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %7)
  %9 = getelementptr inbounds [100001 x i32], ptr @id, i64 0, i64 %indvars.iv72
  %10 = trunc nuw nsw i64 %indvars.iv72 to i32
  store i32 %10, ptr %9, align 4, !tbaa !5
  %.pr = load i32, ptr @r, align 4, !tbaa !5
  %11 = icmp sgt i32 %.pr, 0
  br i1 %11, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %.lr.ph46
  %12 = load i32, ptr %7, align 4, !tbaa !5
  %13 = zext nneg i32 %.pr to i64
  br label %14

14:                                               ; preds = %.lr.ph, %20
  %indvars.iv = phi i64 [ %13, %.lr.ph ], [ %indvars.iv.next, %20 ]
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %15 = getelementptr inbounds [100001 x i32], ptr @que, i64 0, i64 %indvars.iv.next
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %17
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %.not38 = icmp sgt i32 %19, %12
  br i1 %.not38, label %.critedge.thread.loopexit, label %20

20:                                               ; preds = %14
  %21 = icmp ugt i64 %indvars.iv, 1
  br i1 %21, label %14, label %.critedge.loopexit, !llvm.loop !9

.critedge.loopexit:                               ; preds = %20
  %22 = trunc nuw nsw i64 %indvars.iv.next to i32
  br label %.critedge

.critedge:                                        ; preds = %.critedge.loopexit, %.lr.ph46
  %.lcssa42 = phi i32 [ %.pr, %.lr.ph46 ], [ %22, %.critedge.loopexit ]
  %.not39 = icmp eq i32 %.lcssa42, 0
  br i1 %.not39, label %30, label %.critedge.thread

.critedge.thread.loopexit:                        ; preds = %14
  %23 = trunc nuw nsw i64 %indvars.iv to i32
  br label %.critedge.thread

.critedge.thread:                                 ; preds = %.critedge.thread.loopexit, %.critedge
  %24 = phi i32 [ %.lcssa42, %.critedge ], [ %23, %.critedge.thread.loopexit ]
  %25 = add nsw i32 %24, -1
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [100001 x i32], ptr @que, i64 0, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = add nsw i32 %28, 1
  br label %30

30:                                               ; preds = %.critedge, %.critedge.thread
  %31 = phi i32 [ %24, %.critedge.thread ], [ 0, %.critedge ]
  %32 = phi i32 [ %29, %.critedge.thread ], [ 0, %.critedge ]
  %33 = getelementptr inbounds [100001 x i32], ptr @L, i64 0, i64 %indvars.iv72
  store i32 %32, ptr %33, align 4, !tbaa !5
  %34 = add nsw i32 %31, 1
  store i32 %34, ptr @r, align 4, !tbaa !5
  %35 = sext i32 %31 to i64
  %36 = getelementptr inbounds [100001 x i32], ptr @que, i64 0, i64 %35
  store i32 %10, ptr %36, align 4, !tbaa !5
  %indvars.iv.next73 = add nuw nsw i64 %indvars.iv72, 1
  %37 = load i32, ptr @n, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = icmp slt i64 %indvars.iv.next73, %38
  br i1 %39, label %.lr.ph46, label %._crit_edge, !llvm.loop !11

._crit_edge56:                                    ; preds = %.critedge2.thread
  store i32 %63, ptr @r, align 4, !tbaa !5
  br label %40

40:                                               ; preds = %._crit_edge._crit_edge, %._crit_edge56
  %.pre-phi = phi i64 [ %.pre87, %._crit_edge._crit_edge ], [ %6, %._crit_edge56 ]
  %41 = getelementptr inbounds i32, ptr @id, i64 %.pre-phi
  tail call void @_ZSt4sortIPiPFbRKiS2_EEvT_S5_T0_(ptr noundef nonnull @id, ptr noundef nonnull %41, ptr noundef nonnull @_Z3cmpRKiS0_)
  %42 = load i32, ptr @n, align 4, !tbaa !5
  %43 = icmp sgt i32 %42, 0
  br i1 %43, label %.lr.ph60, label %.preheader

thread-pre-split:                                 ; preds = %thread-pre-split.preheader, %.critedge2.thread
  %indvars.iv78 = phi i64 [ %6, %thread-pre-split.preheader ], [ %indvars.iv.next79, %.critedge2.thread ]
  %.pr415254 = phi i32 [ 0, %thread-pre-split.preheader ], [ %63, %.critedge2.thread ]
  %indvars.iv.next79 = add nsw i64 %indvars.iv78, -1
  %44 = icmp sgt i32 %.pr415254, 0
  br i1 %44, label %.lr.ph48, label %.critedge2

.lr.ph48:                                         ; preds = %thread-pre-split
  %45 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %indvars.iv.next79
  %46 = load i32, ptr %45, align 4, !tbaa !5
  %47 = zext nneg i32 %.pr415254 to i64
  br label %48

48:                                               ; preds = %.lr.ph48, %54
  %indvars.iv75 = phi i64 [ %47, %.lr.ph48 ], [ %indvars.iv.next76, %54 ]
  %indvars.iv.next76 = add nsw i64 %indvars.iv75, -1
  %49 = getelementptr inbounds [100001 x i32], ptr @que, i64 0, i64 %indvars.iv.next76
  %50 = load i32, ptr %49, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %51
  %53 = load i32, ptr %52, align 4, !tbaa !5
  %.not = icmp sgt i32 %53, %46
  br i1 %.not, label %.critedge2.loopexit, label %54

54:                                               ; preds = %48
  %55 = icmp ugt i64 %indvars.iv75, 1
  br i1 %55, label %48, label %.critedge2.thread, !llvm.loop !12

.critedge2.loopexit:                              ; preds = %48
  %56 = trunc nuw nsw i64 %indvars.iv75 to i32
  br label %.critedge2

.critedge2:                                       ; preds = %.critedge2.loopexit, %thread-pre-split
  %.lcssa = phi i32 [ %.pr415254, %thread-pre-split ], [ %56, %.critedge2.loopexit ]
  %.lcssa.fr = freeze i32 %.lcssa
  %.not37 = icmp eq i32 %.lcssa.fr, 0
  %57 = add nsw i32 %.lcssa.fr, -1
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [100001 x i32], ptr @que, i64 0, i64 %58
  %spec.select = select i1 %.not37, ptr @n, ptr %59
  br label %.critedge2.thread

.critedge2.thread:                                ; preds = %54, %.critedge2
  %.lcssa94 = phi i32 [ %.lcssa.fr, %.critedge2 ], [ 0, %54 ]
  %60 = phi ptr [ %spec.select, %.critedge2 ], [ @n, %54 ]
  %.in = load i32, ptr %60, align 4, !tbaa !5
  %61 = add nsw i32 %.in, -1
  %62 = getelementptr inbounds [100001 x i32], ptr @R, i64 0, i64 %indvars.iv.next79
  store i32 %61, ptr %62, align 4, !tbaa !5
  %63 = add nsw i32 %.lcssa94, 1
  %64 = sext i32 %.lcssa94 to i64
  %65 = getelementptr inbounds [100001 x i32], ptr @que, i64 0, i64 %64
  %66 = trunc nuw nsw i64 %indvars.iv.next79 to i32
  store i32 %66, ptr %65, align 4, !tbaa !5
  %67 = icmp sgt i64 %indvars.iv78, 1
  br i1 %67, label %thread-pre-split, label %._crit_edge56, !llvm.loop !13

.preheader:                                       ; preds = %.lr.ph60, %40
  %.pre = load i64, ptr getelementptr inbounds (i8, ptr @ans, i64 800000), align 16, !tbaa !14
  br label %105

.lr.ph60:                                         ; preds = %40, %.lr.ph60
  %indvars.iv81 = phi i64 [ %indvars.iv.next82, %.lr.ph60 ], [ 0, %40 ]
  %68 = getelementptr inbounds [100001 x i32], ptr @id, i64 0, i64 %indvars.iv81
  %69 = load i32, ptr %68, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [100001 x i32], ptr @R, i64 0, i64 %70
  %72 = load i32, ptr %71, align 4, !tbaa !5
  %73 = sub nsw i32 %72, %69
  %74 = sext i32 %73 to i64
  %75 = add nsw i64 %74, 1
  %76 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %70
  %77 = load i32, ptr %76, align 4, !tbaa !5
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds [100001 x i32], ptr @last, i64 0, i64 %78
  %80 = getelementptr inbounds [100001 x i32], ptr @L, i64 0, i64 %70
  %81 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %79, ptr noundef nonnull align 4 dereferenceable(4) %80)
  %82 = load i32, ptr %81, align 4, !tbaa !5
  %83 = sub nsw i32 %69, %82
  %84 = sext i32 %83 to i64
  %85 = add nsw i64 %84, 1
  %86 = mul nsw i64 %85, %75
  %87 = load i32, ptr %68, align 4, !tbaa !5
  %88 = sext i32 %87 to i64
  %89 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %88
  %90 = load i32, ptr %89, align 4, !tbaa !5
  %91 = sext i32 %90 to i64
  %92 = getelementptr inbounds [100001 x i64], ptr @ans, i64 0, i64 %91
  %93 = load i64, ptr %92, align 8, !tbaa !14
  %94 = add nsw i64 %86, %93
  store i64 %94, ptr %92, align 8, !tbaa !14
  %95 = add nsw i32 %87, 1
  %96 = getelementptr inbounds [100001 x i32], ptr @last, i64 0, i64 %91
  store i32 %95, ptr %96, align 4, !tbaa !5
  %indvars.iv.next82 = add nuw nsw i64 %indvars.iv81, 1
  %97 = load i32, ptr @n, align 4, !tbaa !5
  %98 = sext i32 %97 to i64
  %99 = icmp slt i64 %indvars.iv.next82, %98
  br i1 %99, label %.lr.ph60, label %.preheader, !llvm.loop !16

100:                                              ; preds = %105
  %101 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @q)
  %102 = load i32, ptr @q, align 4, !tbaa !5
  %103 = add nsw i32 %102, -1
  store i32 %103, ptr @q, align 4, !tbaa !5
  %104 = icmp sgt i32 %102, 0
  br i1 %104, label %.lr.ph63, label %._crit_edge64

105:                                              ; preds = %105, %.preheader
  %106 = phi i64 [ %.pre, %.preheader ], [ %121, %105 ]
  %indvars.iv84 = phi i64 [ 99999, %.preheader ], [ %indvars.iv.next85.4, %105 ]
  %107 = getelementptr inbounds [100001 x i64], ptr @ans, i64 0, i64 %indvars.iv84
  %108 = load i64, ptr %107, align 8, !tbaa !14
  %109 = add nsw i64 %108, %106
  store i64 %109, ptr %107, align 8, !tbaa !14
  %indvars.iv.next85 = add nsw i64 %indvars.iv84, -1
  %110 = getelementptr inbounds [100001 x i64], ptr @ans, i64 0, i64 %indvars.iv.next85
  %111 = load i64, ptr %110, align 8, !tbaa !14
  %112 = add nsw i64 %111, %109
  store i64 %112, ptr %110, align 8, !tbaa !14
  %indvars.iv.next85.1 = add nsw i64 %indvars.iv84, -2
  %113 = getelementptr inbounds [100001 x i64], ptr @ans, i64 0, i64 %indvars.iv.next85.1
  %114 = load i64, ptr %113, align 8, !tbaa !14
  %115 = add nsw i64 %114, %112
  store i64 %115, ptr %113, align 8, !tbaa !14
  %indvars.iv.next85.2 = add nsw i64 %indvars.iv84, -3
  %116 = getelementptr inbounds [100001 x i64], ptr @ans, i64 0, i64 %indvars.iv.next85.2
  %117 = load i64, ptr %116, align 8, !tbaa !14
  %118 = add nsw i64 %117, %115
  store i64 %118, ptr %116, align 8, !tbaa !14
  %indvars.iv.next85.3 = add nsw i64 %indvars.iv84, -4
  %119 = getelementptr inbounds [100001 x i64], ptr @ans, i64 0, i64 %indvars.iv.next85.3
  %120 = load i64, ptr %119, align 8, !tbaa !14
  %121 = add nsw i64 %120, %118
  store i64 %121, ptr %119, align 8, !tbaa !14
  %indvars.iv.next85.4 = add nsw i64 %indvars.iv84, -5
  %.not88.4 = icmp eq i64 %indvars.iv.next85.3, 0
  br i1 %.not88.4, label %100, label %105, !llvm.loop !17

.lr.ph63:                                         ; preds = %100, %129
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #6
  %122 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %123 = load i32, ptr %1, align 4, !tbaa !5
  %124 = icmp slt i32 %123, 100001
  br i1 %124, label %125, label %129

125:                                              ; preds = %.lr.ph63
  %126 = sext i32 %123 to i64
  %127 = getelementptr inbounds [100001 x i64], ptr @ans, i64 0, i64 %126
  %128 = load i64, ptr %127, align 8, !tbaa !14
  br label %129

129:                                              ; preds = %.lr.ph63, %125
  %130 = phi i64 [ %128, %125 ], [ 0, %.lr.ph63 ]
  %131 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %130)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #6
  %132 = load i32, ptr @q, align 4, !tbaa !5
  %133 = add nsw i32 %132, -1
  store i32 %133, ptr @q, align 4, !tbaa !5
  %134 = icmp sgt i32 %132, 0
  br i1 %134, label %.lr.ph63, label %._crit_edge64, !llvm.loop !18

._crit_edge64:                                    ; preds = %129, %100
  ret i32 0
}

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

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPiPFbRKiS2_EEvT_S5_T0_(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #4

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #5

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

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 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 #2 = { 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 #3 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { inlinehint mustprogress uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #5 = { inlinehint 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 #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, !15, i64 0}
!15 = !{!"long long", !7, i64 0}
!16 = distinct !{!16, !10}
!17 = distinct !{!17, !10}
!18 = distinct !{!18, !10}


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