; LLVM IR from tangjz/acm-icpc :: codeforces/complete (547B)

; 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
@a = external dso_local global [200010 x i32], align 16
@l = external dso_local global [200010 x i32], align 16
@r = external dso_local global [200010 x i32], align 16
@stack = external dso_local global [200010 x i32], align 16
@pos = external dso_local global [200010 x i32], align 16
@top = external dso_local global i32, align 4
@id = external dso_local global [200010 x i32], align 16
@ans = external dso_local global [200010 x i32], align 16
@last = external dso_local global i32, align 4
@.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 [3 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
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %11 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #6
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %12

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

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

17:                                               ; preds = %12
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [200010 x i32], ptr @a, i64 0, i64 %19
  %21 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %20)
  %22 = load i32, ptr %2, align 4, !tbaa !5
  %23 = load i32, ptr %2, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [200010 x i32], ptr @id, i64 0, i64 %24
  store i32 %22, ptr %25, align 4, !tbaa !5
  br label %26

26:                                               ; preds = %17
  %27 = load i32, ptr %2, align 4, !tbaa !5
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr %2, align 4, !tbaa !5
  br label %12, !llvm.loop !9

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

30:                                               ; preds = %85, %29
  %31 = load i32, ptr %3, align 4, !tbaa !5
  %32 = load i32, ptr @n, align 4, !tbaa !5
  %33 = icmp sle i32 %31, %32
  br i1 %33, label %35, label %34

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

35:                                               ; preds = %30
  br label %36

36:                                               ; preds = %52, %35
  %37 = load i32, ptr @top, align 4, !tbaa !5
  %38 = icmp ne i32 %37, 0
  br i1 %38, label %39, label %50

39:                                               ; preds = %36
  %40 = load i32, ptr @top, align 4, !tbaa !5
  %41 = sub nsw i32 %40, 1
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [200010 x i32], ptr @stack, i64 0, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !5
  %45 = load i32, ptr %3, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [200010 x i32], ptr @a, i64 0, i64 %46
  %48 = load i32, ptr %47, align 4, !tbaa !5
  %49 = icmp sge i32 %44, %48
  br label %50

50:                                               ; preds = %39, %36
  %51 = phi i1 [ false, %36 ], [ %49, %39 ]
  br i1 %51, label %52, label %55

52:                                               ; preds = %50
  %53 = load i32, ptr @top, align 4, !tbaa !5
  %54 = add nsw i32 %53, -1
  store i32 %54, ptr @top, align 4, !tbaa !5
  br label %36, !llvm.loop !11

55:                                               ; preds = %50
  %56 = load i32, ptr @top, align 4, !tbaa !5
  %57 = icmp ne i32 %56, 0
  br i1 %57, label %58, label %68

58:                                               ; preds = %55
  %59 = load i32, ptr @top, align 4, !tbaa !5
  %60 = sub nsw i32 %59, 1
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [200010 x i32], ptr @pos, i64 0, i64 %61
  %63 = load i32, ptr %62, align 4, !tbaa !5
  %64 = add nsw i32 %63, 1
  %65 = load i32, ptr %3, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [200010 x i32], ptr @l, i64 0, i64 %66
  store i32 %64, ptr %67, align 4, !tbaa !5
  br label %72

68:                                               ; preds = %55
  %69 = load i32, ptr %3, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [200010 x i32], ptr @l, i64 0, i64 %70
  store i32 1, ptr %71, align 4, !tbaa !5
  br label %72

72:                                               ; preds = %68, %58
  %73 = load i32, ptr %3, align 4, !tbaa !5
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [200010 x i32], ptr @a, i64 0, i64 %74
  %76 = load i32, ptr %75, align 4, !tbaa !5
  %77 = load i32, ptr @top, align 4, !tbaa !5
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds [200010 x i32], ptr @stack, i64 0, i64 %78
  store i32 %76, ptr %79, align 4, !tbaa !5
  %80 = load i32, ptr %3, align 4, !tbaa !5
  %81 = load i32, ptr @top, align 4, !tbaa !5
  %82 = add nsw i32 %81, 1
  store i32 %82, ptr @top, align 4, !tbaa !5
  %83 = sext i32 %81 to i64
  %84 = getelementptr inbounds [200010 x i32], ptr @pos, i64 0, i64 %83
  store i32 %80, ptr %84, align 4, !tbaa !5
  br label %85

85:                                               ; preds = %72
  %86 = load i32, ptr %3, align 4, !tbaa !5
  %87 = add nsw i32 %86, 1
  store i32 %87, ptr %3, align 4, !tbaa !5
  br label %30, !llvm.loop !12

88:                                               ; preds = %34
  store i32 0, ptr @top, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #6
  %89 = load i32, ptr @n, align 4, !tbaa !5
  store i32 %89, ptr %4, align 4, !tbaa !5
  br label %90

90:                                               ; preds = %145, %88
  %91 = load i32, ptr %4, align 4, !tbaa !5
  %92 = icmp sge i32 %91, 1
  br i1 %92, label %94, label %93

93:                                               ; preds = %90
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #6
  br label %148

94:                                               ; preds = %90
  br label %95

95:                                               ; preds = %111, %94
  %96 = load i32, ptr @top, align 4, !tbaa !5
  %97 = icmp ne i32 %96, 0
  br i1 %97, label %98, label %109

98:                                               ; preds = %95
  %99 = load i32, ptr @top, align 4, !tbaa !5
  %100 = sub nsw i32 %99, 1
  %101 = sext i32 %100 to i64
  %102 = getelementptr inbounds [200010 x i32], ptr @stack, i64 0, i64 %101
  %103 = load i32, ptr %102, align 4, !tbaa !5
  %104 = load i32, ptr %4, align 4, !tbaa !5
  %105 = sext i32 %104 to i64
  %106 = getelementptr inbounds [200010 x i32], ptr @a, i64 0, i64 %105
  %107 = load i32, ptr %106, align 4, !tbaa !5
  %108 = icmp sge i32 %103, %107
  br label %109

109:                                              ; preds = %98, %95
  %110 = phi i1 [ false, %95 ], [ %108, %98 ]
  br i1 %110, label %111, label %114

111:                                              ; preds = %109
  %112 = load i32, ptr @top, align 4, !tbaa !5
  %113 = add nsw i32 %112, -1
  store i32 %113, ptr @top, align 4, !tbaa !5
  br label %95, !llvm.loop !13

114:                                              ; preds = %109
  %115 = load i32, ptr @top, align 4, !tbaa !5
  %116 = icmp ne i32 %115, 0
  br i1 %116, label %117, label %127

117:                                              ; preds = %114
  %118 = load i32, ptr @top, align 4, !tbaa !5
  %119 = sub nsw i32 %118, 1
  %120 = sext i32 %119 to i64
  %121 = getelementptr inbounds [200010 x i32], ptr @pos, i64 0, i64 %120
  %122 = load i32, ptr %121, align 4, !tbaa !5
  %123 = sub nsw i32 %122, 1
  %124 = load i32, ptr %4, align 4, !tbaa !5
  %125 = sext i32 %124 to i64
  %126 = getelementptr inbounds [200010 x i32], ptr @r, i64 0, i64 %125
  store i32 %123, ptr %126, align 4, !tbaa !5
  br label %132

127:                                              ; preds = %114
  %128 = load i32, ptr @n, align 4, !tbaa !5
  %129 = load i32, ptr %4, align 4, !tbaa !5
  %130 = sext i32 %129 to i64
  %131 = getelementptr inbounds [200010 x i32], ptr @r, i64 0, i64 %130
  store i32 %128, ptr %131, align 4, !tbaa !5
  br label %132

132:                                              ; preds = %127, %117
  %133 = load i32, ptr %4, align 4, !tbaa !5
  %134 = sext i32 %133 to i64
  %135 = getelementptr inbounds [200010 x i32], ptr @a, i64 0, i64 %134
  %136 = load i32, ptr %135, align 4, !tbaa !5
  %137 = load i32, ptr @top, align 4, !tbaa !5
  %138 = sext i32 %137 to i64
  %139 = getelementptr inbounds [200010 x i32], ptr @stack, i64 0, i64 %138
  store i32 %136, ptr %139, align 4, !tbaa !5
  %140 = load i32, ptr %4, align 4, !tbaa !5
  %141 = load i32, ptr @top, align 4, !tbaa !5
  %142 = add nsw i32 %141, 1
  store i32 %142, ptr @top, align 4, !tbaa !5
  %143 = sext i32 %141 to i64
  %144 = getelementptr inbounds [200010 x i32], ptr @pos, i64 0, i64 %143
  store i32 %140, ptr %144, align 4, !tbaa !5
  br label %145

145:                                              ; preds = %132
  %146 = load i32, ptr %4, align 4, !tbaa !5
  %147 = add nsw i32 %146, -1
  store i32 %147, ptr %4, align 4, !tbaa !5
  br label %90, !llvm.loop !14

148:                                              ; preds = %93
  %149 = load i32, ptr @n, align 4, !tbaa !5
  %150 = sext i32 %149 to i64
  %151 = getelementptr inbounds i32, ptr @id, i64 %150
  %152 = getelementptr inbounds i32, ptr %151, i64 1
  call void @_ZSt4sortIPiPFbRKiS2_EEvT_S5_T0_(ptr noundef getelementptr inbounds (i32, ptr @id, i64 1), ptr noundef %152, ptr noundef @_Z3cmpRKiS0_)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #6
  %153 = load i32, ptr @n, align 4, !tbaa !5
  store i32 %153, ptr %5, align 4, !tbaa !5
  br label %154

154:                                              ; preds = %199, %148
  %155 = load i32, ptr %5, align 4, !tbaa !5
  %156 = icmp sge i32 %155, 1
  br i1 %156, label %158, label %157

157:                                              ; preds = %154
  store i32 15, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  br label %202

158:                                              ; preds = %154
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #6
  %159 = load i32, ptr %5, align 4, !tbaa !5
  %160 = sext i32 %159 to i64
  %161 = getelementptr inbounds [200010 x i32], ptr @id, i64 0, i64 %160
  %162 = load i32, ptr %161, align 4, !tbaa !5
  %163 = sext i32 %162 to i64
  %164 = getelementptr inbounds [200010 x i32], ptr @r, i64 0, i64 %163
  %165 = load i32, ptr %164, align 4, !tbaa !5
  %166 = load i32, ptr %5, align 4, !tbaa !5
  %167 = sext i32 %166 to i64
  %168 = getelementptr inbounds [200010 x i32], ptr @id, i64 0, i64 %167
  %169 = load i32, ptr %168, align 4, !tbaa !5
  %170 = sext i32 %169 to i64
  %171 = getelementptr inbounds [200010 x i32], ptr @l, i64 0, i64 %170
  %172 = load i32, ptr %171, align 4, !tbaa !5
  %173 = sub nsw i32 %165, %172
  %174 = add nsw i32 %173, 1
  store i32 %174, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #6
  %175 = load i32, ptr %5, align 4, !tbaa !5
  %176 = sext i32 %175 to i64
  %177 = getelementptr inbounds [200010 x i32], ptr @id, i64 0, i64 %176
  %178 = load i32, ptr %177, align 4, !tbaa !5
  %179 = sext i32 %178 to i64
  %180 = getelementptr inbounds [200010 x i32], ptr @a, i64 0, i64 %179
  store ptr %180, ptr %8, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #6
  %181 = load i32, ptr %7, align 4, !tbaa !5
  store i32 %181, ptr %9, align 4, !tbaa !5
  br label %182

182:                                              ; preds = %193, %158
  %183 = load i32, ptr %9, align 4, !tbaa !5
  %184 = load i32, ptr @last, align 4, !tbaa !5
  %185 = icmp sgt i32 %183, %184
  br i1 %185, label %187, label %186

186:                                              ; preds = %182
  store i32 18, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #6
  br label %196

187:                                              ; preds = %182
  %188 = load ptr, ptr %8, align 8, !tbaa !15
  %189 = load i32, ptr %188, align 4, !tbaa !5
  %190 = load i32, ptr %9, align 4, !tbaa !5
  %191 = sext i32 %190 to i64
  %192 = getelementptr inbounds [200010 x i32], ptr @ans, i64 0, i64 %191
  store i32 %189, ptr %192, align 4, !tbaa !5
  br label %193

193:                                              ; preds = %187
  %194 = load i32, ptr %9, align 4, !tbaa !5
  %195 = add nsw i32 %194, -1
  store i32 %195, ptr %9, align 4, !tbaa !5
  br label %182, !llvm.loop !17

196:                                              ; preds = %186
  %197 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) @last, ptr noundef nonnull align 4 dereferenceable(4) %7)
  %198 = load i32, ptr %197, align 4, !tbaa !5
  store i32 %198, ptr @last, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #6
  br label %199

199:                                              ; preds = %196
  %200 = load i32, ptr %5, align 4, !tbaa !5
  %201 = add nsw i32 %200, -1
  store i32 %201, ptr %5, align 4, !tbaa !5
  br label %154, !llvm.loop !18

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

203:                                              ; preds = %221, %202
  %204 = load i32, ptr %10, align 4, !tbaa !5
  %205 = load i32, ptr @n, align 4, !tbaa !5
  %206 = icmp sle i32 %204, %205
  br i1 %206, label %208, label %207

207:                                              ; preds = %203
  store i32 21, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #6
  br label %224

208:                                              ; preds = %203
  %209 = load i32, ptr %10, align 4, !tbaa !5
  %210 = sext i32 %209 to i64
  %211 = getelementptr inbounds [200010 x i32], ptr @ans, i64 0, i64 %210
  %212 = load i32, ptr %211, align 4, !tbaa !5
  %213 = load i32, ptr %10, align 4, !tbaa !5
  %214 = load i32, ptr @n, align 4, !tbaa !5
  %215 = icmp eq i32 %213, %214
  %216 = zext i1 %215 to i64
  %217 = getelementptr inbounds [3 x i8], ptr @.str.2, i64 0, i64 %216
  %218 = load i8, ptr %217, align 1, !tbaa !19
  %219 = sext i8 %218 to i32
  %220 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %212, i32 noundef %219)
  br label %221

221:                                              ; preds = %208
  %222 = load i32, ptr %10, align 4, !tbaa !5
  %223 = add nsw i32 %222, 1
  store i32 %223, ptr %10, align 4, !tbaa !5
  br label %203, !llvm.loop !20

224:                                              ; preds = %207
  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 = distinct !{!14, !10}
!15 = !{!16, !16, i64 0}
!16 = !{!"any pointer", !7, i64 0}
!17 = distinct !{!17, !10}
!18 = distinct !{!18, !10}
!19 = !{!7, !7, i64 0}
!20 = distinct !{!20, !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
@a = external dso_local global [200010 x i32], align 16
@l = external dso_local local_unnamed_addr global [200010 x i32], align 16
@r = external dso_local local_unnamed_addr global [200010 x i32], align 16
@stack = external dso_local local_unnamed_addr global [200010 x i32], align 16
@pos = external dso_local local_unnamed_addr global [200010 x i32], align 16
@top = external dso_local local_unnamed_addr global i32, align 4
@id = external dso_local global [200010 x i32], align 16
@ans = external dso_local local_unnamed_addr global [200010 x i32], align 16
@last = external dso_local global i32, align 4
@.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 [3 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
  %.not57 = icmp slt i32 %3, 1
  br i1 %.not57, label %.sink.split, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph
  %.not4364 = icmp slt i32 %9, 1
  br i1 %.not4364, label %.sink.split, label %thread-pre-split.preheader

thread-pre-split.preheader:                       ; preds = %._crit_edge
  %4 = add nuw i32 %9, 1
  %wide.trip.count = zext i32 %4 to i64
  br label %thread-pre-split

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 1, %0 ]
  %5 = getelementptr inbounds [200010 x i32], ptr @a, i64 0, i64 %indvars.iv
  %6 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %5)
  %7 = getelementptr inbounds [200010 x i32], ptr @id, i64 0, i64 %indvars.iv
  %8 = trunc nuw nsw i64 %indvars.iv to i32
  store i32 %8, ptr %7, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %9 = load i32, ptr @n, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %.not.not = icmp slt i64 %indvars.iv, %10
  br i1 %.not.not, label %.lr.ph, label %._crit_edge, !llvm.loop !9

thread-pre-split51.preheader:                     ; preds = %._crit_edge61
  store i32 0, ptr @top, align 4, !tbaa !5
  %11 = zext nneg i32 %9 to i64
  br label %thread-pre-split51

thread-pre-split:                                 ; preds = %thread-pre-split.preheader, %._crit_edge61
  %indvars.iv105 = phi i64 [ 1, %thread-pre-split.preheader ], [ %indvars.iv.next106, %._crit_edge61 ]
  %.pr6365 = phi i32 [ 0, %thread-pre-split.preheader ], [ %27, %._crit_edge61 ]
  %.not4859 = icmp eq i32 %.pr6365, 0
  %.phi.trans.insert.phi.trans.insert = getelementptr inbounds [200010 x i32], ptr @a, i64 0, i64 %indvars.iv105
  %.pre.pre = load i32, ptr %.phi.trans.insert.phi.trans.insert, align 4, !tbaa !5
  br i1 %.not4859, label %._crit_edge61, label %.lr.ph60

.lr.ph60:                                         ; preds = %thread-pre-split
  %12 = sext i32 %.pr6365 to i64
  br label %13

13:                                               ; preds = %.lr.ph60, %16
  %indvars.iv102 = phi i64 [ %12, %.lr.ph60 ], [ %indvars.iv.next103, %16 ]
  %indvars.iv.next103 = add nsw i64 %indvars.iv102, -1
  %14 = getelementptr inbounds [200010 x i32], ptr @stack, i64 0, i64 %indvars.iv.next103
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %.not49 = icmp slt i32 %15, %.pre.pre
  br i1 %.not49, label %.critedge, label %16

16:                                               ; preds = %13
  %.not48 = icmp eq i64 %indvars.iv.next103, 0
  br i1 %.not48, label %._crit_edge61, label %13, !llvm.loop !11

.critedge:                                        ; preds = %13
  %17 = trunc nsw i64 %indvars.iv102 to i32
  %18 = shl i64 %indvars.iv102, 32
  %sext = add i64 %18, -4294967296
  %19 = ashr exact i64 %sext, 32
  %20 = getelementptr inbounds [200010 x i32], ptr @pos, i64 0, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = add nsw i32 %21, 1
  br label %._crit_edge61

._crit_edge61:                                    ; preds = %16, %thread-pre-split, %.critedge
  %.sink = phi i32 [ %22, %.critedge ], [ 1, %thread-pre-split ], [ 1, %16 ]
  %23 = phi i32 [ %17, %.critedge ], [ 0, %thread-pre-split ], [ 0, %16 ]
  %24 = getelementptr inbounds [200010 x i32], ptr @l, i64 0, i64 %indvars.iv105
  store i32 %.sink, ptr %24, align 4, !tbaa !5
  %25 = sext i32 %23 to i64
  %26 = getelementptr inbounds [200010 x i32], ptr @stack, i64 0, i64 %25
  store i32 %.pre.pre, ptr %26, align 4, !tbaa !5
  %27 = add nsw i32 %23, 1
  %28 = getelementptr inbounds [200010 x i32], ptr @pos, i64 0, i64 %25
  %29 = trunc nuw nsw i64 %indvars.iv105 to i32
  store i32 %29, ptr %28, align 4, !tbaa !5
  %indvars.iv.next106 = add nuw nsw i64 %indvars.iv105, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next106, %wide.trip.count
  br i1 %exitcond.not, label %thread-pre-split51.preheader, label %thread-pre-split, !llvm.loop !12

.sink.split:                                      ; preds = %._crit_edge71, %._crit_edge, %0
  %.sink140 = phi i32 [ 0, %0 ], [ 0, %._crit_edge ], [ %51, %._crit_edge71 ]
  %.lcssa56132134.ph = phi i32 [ %3, %0 ], [ %9, %._crit_edge ], [ %9, %._crit_edge71 ]
  store i32 %.sink140, ptr @top, align 4, !tbaa !5
  %30 = sext i32 %.lcssa56132134.ph to i64
  %31 = getelementptr inbounds i32, ptr @id, i64 %30
  %32 = getelementptr inbounds i8, ptr %31, i64 4
  tail call void @_ZSt4sortIPiPFbRKiS2_EEvT_S5_T0_(ptr noundef nonnull getelementptr inbounds (i8, ptr @id, i64 4), ptr noundef nonnull %32, ptr noundef nonnull @_Z3cmpRKiS0_)
  %33 = load i32, ptr @n, align 4, !tbaa !5
  %34 = icmp sgt i32 %33, 0
  br i1 %34, label %.lr.ph85.preheader, label %._crit_edge89

.lr.ph85.preheader:                               ; preds = %.sink.split
  %35 = zext nneg i32 %33 to i64
  %.pre125 = load i32, ptr @last, align 4, !tbaa !5
  br label %.lr.ph85

thread-pre-split51:                               ; preds = %thread-pre-split51.preheader, %._crit_edge71
  %indvars.iv111 = phi i64 [ %11, %thread-pre-split51.preheader ], [ %indvars.iv.next112, %._crit_edge71 ]
  %.pr527475 = phi i32 [ 0, %thread-pre-split51.preheader ], [ %51, %._crit_edge71 ]
  %.not4569 = icmp eq i32 %.pr527475, 0
  %.phi.trans.insert123.phi.trans.insert = getelementptr inbounds [200010 x i32], ptr @a, i64 0, i64 %indvars.iv111
  %.pre124.pre = load i32, ptr %.phi.trans.insert123.phi.trans.insert, align 4, !tbaa !5
  br i1 %.not4569, label %._crit_edge71, label %.lr.ph70

.lr.ph70:                                         ; preds = %thread-pre-split51
  %36 = sext i32 %.pr527475 to i64
  br label %37

37:                                               ; preds = %.lr.ph70, %40
  %indvars.iv108 = phi i64 [ %36, %.lr.ph70 ], [ %indvars.iv.next109, %40 ]
  %indvars.iv.next109 = add nsw i64 %indvars.iv108, -1
  %38 = getelementptr inbounds [200010 x i32], ptr @stack, i64 0, i64 %indvars.iv.next109
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %.not46 = icmp slt i32 %39, %.pre124.pre
  br i1 %.not46, label %.critedge2, label %40

40:                                               ; preds = %37
  %.not45 = icmp eq i64 %indvars.iv.next109, 0
  br i1 %.not45, label %._crit_edge71, label %37, !llvm.loop !13

.critedge2:                                       ; preds = %37
  %41 = trunc nsw i64 %indvars.iv108 to i32
  %42 = shl i64 %indvars.iv108, 32
  %sext129 = add i64 %42, -4294967296
  %43 = ashr exact i64 %sext129, 32
  %44 = getelementptr inbounds [200010 x i32], ptr @pos, i64 0, i64 %43
  %45 = load i32, ptr %44, align 4, !tbaa !5
  %46 = add nsw i32 %45, -1
  br label %._crit_edge71

._crit_edge71:                                    ; preds = %40, %thread-pre-split51, %.critedge2
  %.lcssa138.sink = phi i32 [ %46, %.critedge2 ], [ %9, %thread-pre-split51 ], [ %9, %40 ]
  %47 = phi i32 [ %41, %.critedge2 ], [ 0, %thread-pre-split51 ], [ 0, %40 ]
  %48 = getelementptr inbounds [200010 x i32], ptr @r, i64 0, i64 %indvars.iv111
  store i32 %.lcssa138.sink, ptr %48, align 4, !tbaa !5
  %49 = sext i32 %47 to i64
  %50 = getelementptr inbounds [200010 x i32], ptr @stack, i64 0, i64 %49
  store i32 %.pre124.pre, ptr %50, align 4, !tbaa !5
  %51 = add nsw i32 %47, 1
  %52 = getelementptr inbounds [200010 x i32], ptr @pos, i64 0, i64 %49
  %53 = trunc nuw nsw i64 %indvars.iv111 to i32
  store i32 %53, ptr %52, align 4, !tbaa !5
  %indvars.iv.next112 = add nsw i64 %indvars.iv111, -1
  %54 = icmp sgt i64 %indvars.iv111, 1
  br i1 %54, label %thread-pre-split51, label %.sink.split, !llvm.loop !14

.preheader:                                       ; preds = %._crit_edge82
  %.pre126 = load i32, ptr @n, align 4, !tbaa !5
  %.not4486 = icmp slt i32 %.pre126, 1
  br i1 %.not4486, label %._crit_edge89, label %.lr.ph88

.lr.ph85:                                         ; preds = %.lr.ph85.preheader, %._crit_edge82
  %55 = phi i32 [ %.pre125, %.lr.ph85.preheader ], [ %76, %._crit_edge82 ]
  %indvars.iv117 = phi i64 [ %35, %.lr.ph85.preheader ], [ %indvars.iv.next118, %._crit_edge82 ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #7
  %56 = getelementptr inbounds [200010 x i32], ptr @id, i64 0, i64 %indvars.iv117
  %57 = load i32, ptr %56, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [200010 x i32], ptr @r, i64 0, i64 %58
  %60 = load i32, ptr %59, align 4, !tbaa !5
  %61 = getelementptr inbounds [200010 x i32], ptr @l, i64 0, i64 %58
  %62 = load i32, ptr %61, align 4, !tbaa !5
  %63 = sub nsw i32 %60, %62
  %64 = add i32 %63, 1
  store i32 %64, ptr %1, align 4, !tbaa !5
  %.not = icmp slt i32 %63, %55
  br i1 %.not, label %._crit_edge82, label %.lr.ph81

.lr.ph81:                                         ; preds = %.lr.ph85
  %65 = getelementptr inbounds [200010 x i32], ptr @a, i64 0, i64 %58
  %66 = load i32, ptr %65, align 4, !tbaa !5
  %67 = sext i32 %64 to i64
  %68 = sext i32 %55 to i64
  %69 = add nsw i64 %67, -1
  %smin = call i64 @llvm.smin.i64(i64 %69, i64 %68)
  %70 = sub i64 %67, %smin
  %min.iters.check = icmp ult i64 %70, 8
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

scalar.ph.preheader:                              ; preds = %middle.block, %.lr.ph81
  %indvars.iv114.ph = phi i64 [ %67, %.lr.ph81 ], [ %ind.end, %middle.block ]
  br label %scalar.ph

vector.ph:                                        ; preds = %.lr.ph81
  %n.vec = and i64 %70, -8
  %ind.end = sub i64 %67, %n.vec
  %broadcast.splatinsert = insertelement <4 x i32> poison, i32 %66, i64 0
  %broadcast.splat = shufflevector <4 x i32> %broadcast.splatinsert, <4 x i32> poison, <4 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %offset.idx = sub i64 %67, %index
  %71 = getelementptr inbounds [200010 x i32], ptr @ans, i64 0, i64 %offset.idx
  %72 = getelementptr inbounds i8, ptr %71, i64 -12
  %73 = getelementptr inbounds i8, ptr %71, i64 -28
  store <4 x i32> %broadcast.splat, ptr %72, align 4, !tbaa !5
  store <4 x i32> %broadcast.splat, ptr %73, align 4, !tbaa !5
  %index.next = add nuw i64 %index, 8
  %74 = icmp eq i64 %index.next, %n.vec
  br i1 %74, label %middle.block, label %vector.body, !llvm.loop !15

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %70, %n.vec
  br i1 %cmp.n, label %._crit_edge82, label %scalar.ph.preheader

._crit_edge82:                                    ; preds = %scalar.ph, %middle.block, %.lr.ph85
  %75 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) @last, ptr noundef nonnull align 4 dereferenceable(4) %1)
  %76 = load i32, ptr %75, align 4, !tbaa !5
  store i32 %76, ptr @last, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #7
  %indvars.iv.next118 = add nsw i64 %indvars.iv117, -1
  %77 = icmp sgt i64 %indvars.iv117, 1
  br i1 %77, label %.lr.ph85, label %.preheader, !llvm.loop !18

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %indvars.iv114 = phi i64 [ %indvars.iv.next115, %scalar.ph ], [ %indvars.iv114.ph, %scalar.ph.preheader ]
  %78 = getelementptr inbounds [200010 x i32], ptr @ans, i64 0, i64 %indvars.iv114
  store i32 %66, ptr %78, align 4, !tbaa !5
  %indvars.iv.next115 = add nsw i64 %indvars.iv114, -1
  %79 = icmp sgt i64 %indvars.iv.next115, %68
  br i1 %79, label %scalar.ph, label %._crit_edge82, !llvm.loop !19

._crit_edge89:                                    ; preds = %.lr.ph88, %.sink.split, %.preheader
  ret i32 0

.lr.ph88:                                         ; preds = %.preheader, %.lr.ph88
  %indvars.iv120 = phi i64 [ %indvars.iv.next121, %.lr.ph88 ], [ 1, %.preheader ]
  %80 = phi i32 [ %90, %.lr.ph88 ], [ %.pre126, %.preheader ]
  %81 = getelementptr inbounds [200010 x i32], ptr @ans, i64 0, i64 %indvars.iv120
  %82 = load i32, ptr %81, align 4, !tbaa !5
  %83 = zext i32 %80 to i64
  %84 = icmp eq i64 %indvars.iv120, %83
  %85 = zext i1 %84 to i64
  %86 = getelementptr inbounds [3 x i8], ptr @.str.2, i64 0, i64 %85
  %87 = load i8, ptr %86, align 1, !tbaa !20
  %88 = sext i8 %87 to i32
  %89 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %82, i32 noundef %88)
  %indvars.iv.next121 = add nuw nsw i64 %indvars.iv120, 1
  %90 = load i32, ptr @n, align 4, !tbaa !5
  %91 = sext i32 %90 to i64
  %.not44.not = icmp slt i64 %indvars.iv120, %91
  br i1 %.not44.not, label %.lr.ph88, label %._crit_edge89, !llvm.loop !21
}

; 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

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

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10}
!15 = distinct !{!15, !10, !16, !17}
!16 = !{!"llvm.loop.isvectorized", i32 1}
!17 = !{!"llvm.loop.unroll.runtime.disable"}
!18 = distinct !{!18, !10}
!19 = distinct !{!19, !10, !17, !16}
!20 = !{!7, !7, i64 0}
!21 = distinct !{!21, !10}


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