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

; 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, i32 }

@n = external dso_local global i32, align 4
@q = external dso_local global i32, align 4
@a = external dso_local global [200002 x i32], align 16
@tot = external dso_local global i32, align 4
@hh = external dso_local global [200002 x i32], align 16
@pos = external dso_local global [200002 x i32], align 16
@pre = external dso_local global [200002 x i32], align 16
@val = external dso_local global [200002 x i32], align 16
@bit = external dso_local global [200002 x i32], align 16
@ans = external dso_local global [200002 x i32], align 16
@p = external dso_local global [200002 x %struct.Node], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

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

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

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

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

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

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

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

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

16:                                               ; preds = %11
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds i32, ptr @a, i64 %18
  %20 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %19)
  %21 = load i32, ptr %2, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [200002 x i32], ptr @a, i64 0, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = load i32, ptr @tot, align 4, !tbaa !5
  %26 = add nsw i32 %25, 1
  store i32 %26, ptr @tot, align 4, !tbaa !5
  %27 = sext i32 %25 to i64
  %28 = getelementptr inbounds [200002 x i32], ptr @hh, i64 0, i64 %27
  store i32 %24, ptr %28, align 4, !tbaa !5
  br label %29

29:                                               ; preds = %16
  %30 = load i32, ptr %2, align 4, !tbaa !5
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr %2, align 4, !tbaa !5
  br label %11, !llvm.loop !9

32:                                               ; preds = %15
  %33 = load i32, ptr @tot, align 4, !tbaa !5
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr @tot, align 4, !tbaa !5
  %35 = sext i32 %33 to i64
  %36 = getelementptr inbounds [200002 x i32], ptr @hh, i64 0, i64 %35
  store i32 0, ptr %36, align 4, !tbaa !5
  %37 = load i32, ptr @tot, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds i32, ptr @hh, i64 %38
  call void @_ZSt4sortIPiEvT_S1_(ptr noundef @hh, ptr noundef %39)
  %40 = load i32, ptr @tot, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds i32, ptr @hh, i64 %41
  %43 = call noundef ptr @_ZSt6uniqueIPiET_S1_S1_(ptr noundef @hh, ptr noundef %42)
  %44 = ptrtoint ptr %43 to i64
  %45 = sub i64 %44, ptrtoint (ptr @hh to i64)
  %46 = sdiv exact i64 %45, 4
  %47 = trunc i64 %46 to i32
  store i32 %47, ptr @tot, 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 %48

48:                                               ; preds = %85, %32
  %49 = load i32, ptr %3, align 4, !tbaa !5
  %50 = load i32, ptr @n, align 4, !tbaa !5
  %51 = icmp sle i32 %49, %50
  br i1 %51, label %53, label %52

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

53:                                               ; preds = %48
  %54 = load i32, ptr @tot, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds i32, ptr @hh, i64 %55
  %57 = load i32, ptr %3, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [200002 x i32], ptr @a, i64 0, i64 %58
  %60 = call noundef ptr @_ZSt11lower_boundIPiiET_S1_S1_RKT0_(ptr noundef @hh, ptr noundef %56, ptr noundef nonnull align 4 dereferenceable(4) %59)
  %61 = ptrtoint ptr %60 to i64
  %62 = sub i64 %61, ptrtoint (ptr @hh to i64)
  %63 = sdiv exact i64 %62, 4
  %64 = trunc i64 %63 to i32
  %65 = load i32, ptr %3, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [200002 x i32], ptr @a, i64 0, i64 %66
  store i32 %64, ptr %67, align 4, !tbaa !5
  %68 = load i32, ptr %3, align 4, !tbaa !5
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [200002 x i32], ptr @a, i64 0, i64 %69
  %71 = load i32, ptr %70, align 4, !tbaa !5
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds [200002 x i32], ptr @pos, i64 0, i64 %72
  %74 = load i32, ptr %73, align 4, !tbaa !5
  %75 = load i32, ptr %3, align 4, !tbaa !5
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds [200002 x i32], ptr @pre, i64 0, i64 %76
  store i32 %74, ptr %77, align 4, !tbaa !5
  %78 = load i32, ptr %3, align 4, !tbaa !5
  %79 = load i32, ptr %3, align 4, !tbaa !5
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [200002 x i32], ptr @a, i64 0, i64 %80
  %82 = load i32, ptr %81, align 4, !tbaa !5
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds [200002 x i32], ptr @pos, i64 0, i64 %83
  store i32 %78, ptr %84, align 4, !tbaa !5
  br label %85

85:                                               ; preds = %53
  %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 %48, !llvm.loop !11

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

89:                                               ; preds = %109, %88
  %90 = load i32, ptr %4, align 4, !tbaa !5
  %91 = load i32, ptr @q, align 4, !tbaa !5
  %92 = icmp slt i32 %90, %91
  br i1 %92, label %94, label %93

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

94:                                               ; preds = %89
  %95 = load i32, ptr %4, align 4, !tbaa !5
  %96 = load i32, ptr %4, align 4, !tbaa !5
  %97 = sext i32 %96 to i64
  %98 = getelementptr inbounds [200002 x %struct.Node], ptr @p, i64 0, i64 %97
  %99 = getelementptr inbounds %struct.Node, ptr %98, i32 0, i32 0
  store i32 %95, ptr %99, align 4, !tbaa !12
  %100 = load i32, ptr %4, align 4, !tbaa !5
  %101 = sext i32 %100 to i64
  %102 = getelementptr inbounds [200002 x %struct.Node], ptr @p, i64 0, i64 %101
  %103 = getelementptr inbounds %struct.Node, ptr %102, i32 0, i32 1
  %104 = load i32, ptr %4, align 4, !tbaa !5
  %105 = sext i32 %104 to i64
  %106 = getelementptr inbounds [200002 x %struct.Node], ptr @p, i64 0, i64 %105
  %107 = getelementptr inbounds %struct.Node, ptr %106, i32 0, i32 2
  %108 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %103, ptr noundef %107)
  br label %109

109:                                              ; preds = %94
  %110 = load i32, ptr %4, align 4, !tbaa !5
  %111 = add nsw i32 %110, 1
  store i32 %111, ptr %4, align 4, !tbaa !5
  br label %89, !llvm.loop !14

112:                                              ; preds = %93
  %113 = load i32, ptr @q, align 4, !tbaa !5
  %114 = sext i32 %113 to i64
  %115 = getelementptr inbounds %struct.Node, ptr @p, i64 %114
  call void @_ZSt4sortIP4NodeEvT_S2_(ptr noundef @p, ptr noundef %115)
  call void @llvm.memset.p0.i64(ptr align 16 @pos, i8 0, i64 800008, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #6
  %116 = load i32, ptr @n, align 4, !tbaa !5
  store i32 %116, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %117

117:                                              ; preds = %173, %112
  %118 = load i32, ptr %5, align 4, !tbaa !5
  %119 = icmp ne i32 %118, 0
  br i1 %119, label %121, label %120

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

121:                                              ; preds = %117
  %122 = load i32, ptr %5, align 4, !tbaa !5
  %123 = sext i32 %122 to i64
  %124 = getelementptr inbounds [200002 x i32], ptr @a, i64 0, i64 %123
  %125 = load i32, ptr %124, align 4, !tbaa !5
  %126 = sext i32 %125 to i64
  %127 = getelementptr inbounds [200002 x i32], ptr @pos, i64 0, i64 %126
  store i32 1, ptr %127, align 4, !tbaa !5
  br label %128

128:                                              ; preds = %154, %121
  %129 = load i32, ptr %6, align 4, !tbaa !5
  %130 = sext i32 %129 to i64
  %131 = getelementptr inbounds [200002 x i32], ptr @pos, i64 0, i64 %130
  %132 = load i32, ptr %131, align 4, !tbaa !5
  %133 = icmp ne i32 %132, 0
  br i1 %133, label %134, label %151

134:                                              ; preds = %128
  %135 = load i32, ptr %6, align 4, !tbaa !5
  %136 = icmp ne i32 %135, 0
  br i1 %136, label %137, label %149

137:                                              ; preds = %134
  %138 = load i32, ptr %6, align 4, !tbaa !5
  %139 = sub nsw i32 %138, 1
  %140 = sext i32 %139 to i64
  %141 = getelementptr inbounds [200002 x i32], ptr @hh, i64 0, i64 %140
  %142 = load i32, ptr %141, align 4, !tbaa !5
  %143 = add nsw i32 %142, 1
  %144 = load i32, ptr %6, align 4, !tbaa !5
  %145 = sext i32 %144 to i64
  %146 = getelementptr inbounds [200002 x i32], ptr @hh, i64 0, i64 %145
  %147 = load i32, ptr %146, align 4, !tbaa !5
  %148 = icmp eq i32 %143, %147
  br label %149

149:                                              ; preds = %137, %134
  %150 = phi i1 [ true, %134 ], [ %148, %137 ]
  br label %151

151:                                              ; preds = %149, %128
  %152 = phi i1 [ false, %128 ], [ %150, %149 ]
  br i1 %152, label %153, label %157

153:                                              ; preds = %151
  br label %154

154:                                              ; preds = %153
  %155 = load i32, ptr %6, align 4, !tbaa !5
  %156 = add nsw i32 %155, 1
  store i32 %156, ptr %6, align 4, !tbaa !5
  br label %128, !llvm.loop !15

157:                                              ; preds = %151
  %158 = load i32, ptr %6, align 4, !tbaa !5
  %159 = icmp ne i32 %158, 0
  br i1 %159, label %160, label %167

160:                                              ; preds = %157
  %161 = load i32, ptr %6, align 4, !tbaa !5
  %162 = sub nsw i32 %161, 1
  %163 = sext i32 %162 to i64
  %164 = getelementptr inbounds [200002 x i32], ptr @hh, i64 0, i64 %163
  %165 = load i32, ptr %164, align 4, !tbaa !5
  %166 = add nsw i32 %165, 1
  br label %168

167:                                              ; preds = %157
  br label %168

168:                                              ; preds = %167, %160
  %169 = phi i32 [ %166, %160 ], [ 0, %167 ]
  %170 = load i32, ptr %5, align 4, !tbaa !5
  %171 = sext i32 %170 to i64
  %172 = getelementptr inbounds [200002 x i32], ptr @val, i64 0, i64 %171
  store i32 %169, ptr %172, align 4, !tbaa !5
  br label %173

173:                                              ; preds = %168
  %174 = load i32, ptr %5, align 4, !tbaa !5
  %175 = add nsw i32 %174, -1
  store i32 %175, ptr %5, align 4, !tbaa !5
  br label %117, !llvm.loop !16

176:                                              ; preds = %120
  call void @llvm.memset.p0.i64(ptr align 16 @bit, i8 63, i64 800008, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #6
  %177 = load i32, ptr @n, align 4, !tbaa !5
  store i32 %177, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %178

178:                                              ; preds = %236, %176
  %179 = load i32, ptr %7, align 4, !tbaa !5
  %180 = icmp ne i32 %179, 0
  br i1 %180, label %182, label %181

181:                                              ; preds = %178
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #6
  br label %239

182:                                              ; preds = %178
  br label %183

183:                                              ; preds = %220, %182
  %184 = load i32, ptr %8, align 4, !tbaa !5
  %185 = load i32, ptr @q, align 4, !tbaa !5
  %186 = icmp slt i32 %184, %185
  br i1 %186, label %187, label %195

187:                                              ; preds = %183
  %188 = load i32, ptr %8, align 4, !tbaa !5
  %189 = sext i32 %188 to i64
  %190 = getelementptr inbounds [200002 x %struct.Node], ptr @p, i64 0, i64 %189
  %191 = getelementptr inbounds %struct.Node, ptr %190, i32 0, i32 2
  %192 = load i32, ptr %191, align 4, !tbaa !17
  %193 = load i32, ptr %7, align 4, !tbaa !5
  %194 = icmp eq i32 %192, %193
  br label %195

195:                                              ; preds = %187, %183
  %196 = phi i1 [ false, %183 ], [ %194, %187 ]
  br i1 %196, label %197, label %223

197:                                              ; preds = %195
  %198 = load i32, ptr %8, align 4, !tbaa !5
  %199 = sext i32 %198 to i64
  %200 = getelementptr inbounds [200002 x %struct.Node], ptr @p, i64 0, i64 %199
  %201 = getelementptr inbounds %struct.Node, ptr %200, i32 0, i32 1
  %202 = load i32, ptr %201, align 4, !tbaa !18
  %203 = sext i32 %202 to i64
  %204 = getelementptr inbounds [200002 x i32], ptr @val, i64 0, i64 %203
  %205 = load i32, ptr %204, align 4, !tbaa !5
  %206 = load i32, ptr %8, align 4, !tbaa !5
  %207 = sext i32 %206 to i64
  %208 = getelementptr inbounds [200002 x %struct.Node], ptr @p, i64 0, i64 %207
  %209 = getelementptr inbounds %struct.Node, ptr %208, i32 0, i32 1
  %210 = load i32, ptr %209, align 4, !tbaa !18
  %211 = call noundef i32 @_Z3quei(i32 noundef %210)
  %212 = call noundef i32 @_Z3minii(i32 noundef %205, i32 noundef %211)
  %213 = load i32, ptr %8, align 4, !tbaa !5
  %214 = sext i32 %213 to i64
  %215 = getelementptr inbounds [200002 x %struct.Node], ptr @p, i64 0, i64 %214
  %216 = getelementptr inbounds %struct.Node, ptr %215, i32 0, i32 0
  %217 = load i32, ptr %216, align 4, !tbaa !12
  %218 = sext i32 %217 to i64
  %219 = getelementptr inbounds [200002 x i32], ptr @ans, i64 0, i64 %218
  store i32 %212, ptr %219, align 4, !tbaa !5
  br label %220

220:                                              ; preds = %197
  %221 = load i32, ptr %8, align 4, !tbaa !5
  %222 = add nsw i32 %221, 1
  store i32 %222, ptr %8, align 4, !tbaa !5
  br label %183, !llvm.loop !19

223:                                              ; preds = %195
  %224 = load i32, ptr %7, align 4, !tbaa !5
  %225 = sext i32 %224 to i64
  %226 = getelementptr inbounds [200002 x i32], ptr @pre, i64 0, i64 %225
  %227 = load i32, ptr %226, align 4, !tbaa !5
  %228 = add nsw i32 %227, 1
  %229 = load i32, ptr %7, align 4, !tbaa !5
  %230 = sext i32 %229 to i64
  %231 = getelementptr inbounds [200002 x i32], ptr @a, i64 0, i64 %230
  %232 = load i32, ptr %231, align 4, !tbaa !5
  %233 = sext i32 %232 to i64
  %234 = getelementptr inbounds [200002 x i32], ptr @hh, i64 0, i64 %233
  %235 = load i32, ptr %234, align 4, !tbaa !5
  call void @_Z3updii(i32 noundef %228, i32 noundef %235)
  br label %236

236:                                              ; preds = %223
  %237 = load i32, ptr %7, align 4, !tbaa !5
  %238 = add nsw i32 %237, -1
  store i32 %238, ptr %7, align 4, !tbaa !5
  br label %178, !llvm.loop !20

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

240:                                              ; preds = %251, %239
  %241 = load i32, ptr %9, align 4, !tbaa !5
  %242 = load i32, ptr @q, align 4, !tbaa !5
  %243 = icmp slt i32 %241, %242
  br i1 %243, label %245, label %244

244:                                              ; preds = %240
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #6
  br label %254

245:                                              ; preds = %240
  %246 = load i32, ptr %9, align 4, !tbaa !5
  %247 = sext i32 %246 to i64
  %248 = getelementptr inbounds [200002 x i32], ptr @ans, i64 0, i64 %247
  %249 = load i32, ptr %248, align 4, !tbaa !5
  %250 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %249)
  br label %251

251:                                              ; preds = %245
  %252 = load i32, ptr %9, align 4, !tbaa !5
  %253 = add nsw i32 %252, 1
  store i32 %253, ptr %9, align 4, !tbaa !5
  br label %240, !llvm.loop !21

254:                                              ; preds = %244
  ret i32 0
}

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

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

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

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

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

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

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

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

%struct.Node = type { i32, i32, i32 }

@n = external dso_local global i32, align 4
@q = external dso_local global i32, align 4
@a = external dso_local global [200002 x i32], align 16
@tot = external dso_local local_unnamed_addr global i32, align 4
@hh = external dso_local global [200002 x i32], align 16
@pos = external dso_local local_unnamed_addr global [200002 x i32], align 16
@pre = external dso_local local_unnamed_addr global [200002 x i32], align 16
@val = external dso_local local_unnamed_addr global [200002 x i32], align 16
@bit = external dso_local local_unnamed_addr global [200002 x i32], align 16
@ans = external dso_local local_unnamed_addr global [200002 x i32], align 16
@p = external dso_local global [200002 x %struct.Node], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

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

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

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @q)
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %.not69 = icmp slt i32 %2, 1
  br i1 %.not69, label %.._crit_edge_crit_edge, label %.lr.ph

.._crit_edge_crit_edge:                           ; preds = %0
  %.pre = load i32, ptr @tot, align 4, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %.._crit_edge_crit_edge
  %3 = phi i32 [ %.pre, %.._crit_edge_crit_edge ], [ %22, %.lr.ph ]
  %4 = add nsw i32 %3, 1
  store i32 %4, ptr @tot, align 4, !tbaa !5
  %5 = sext i32 %3 to i64
  %6 = getelementptr inbounds [200002 x i32], ptr @hh, i64 0, i64 %5
  store i32 0, ptr %6, align 4, !tbaa !5
  %7 = sext i32 %4 to i64
  %8 = getelementptr inbounds i32, ptr @hh, i64 %7
  tail call void @_ZSt4sortIPiEvT_S1_(ptr noundef nonnull @hh, ptr noundef nonnull %8)
  %9 = load i32, ptr @tot, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds i32, ptr @hh, i64 %10
  %12 = tail call noundef ptr @_ZSt6uniqueIPiET_S1_S1_(ptr noundef nonnull @hh, ptr noundef nonnull %11)
  %13 = ptrtoint ptr %12 to i64
  %14 = sub i64 %13, ptrtoint (ptr @hh to i64)
  %15 = lshr exact i64 %14, 2
  %16 = trunc i64 %15 to i32
  store i32 %16, ptr @tot, align 4, !tbaa !5
  %17 = load i32, ptr @n, align 4, !tbaa !5
  %.not5671 = icmp slt i32 %17, 1
  br i1 %.not5671, label %.preheader65, label %.lr.ph74

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 1, %0 ]
  %18 = getelementptr inbounds i32, ptr @a, i64 %indvars.iv
  %19 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %18)
  %20 = load i32, ptr %18, align 4, !tbaa !5
  %21 = load i32, ptr @tot, align 4, !tbaa !5
  %22 = add nsw i32 %21, 1
  store i32 %22, ptr @tot, align 4, !tbaa !5
  %23 = sext i32 %21 to i64
  %24 = getelementptr inbounds [200002 x i32], ptr @hh, i64 0, i64 %23
  store i32 %20, ptr %24, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %25 = load i32, ptr @n, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %.not.not = icmp slt i64 %indvars.iv, %26
  br i1 %.not.not, label %.lr.ph, label %._crit_edge, !llvm.loop !9

.preheader65:                                     ; preds = %.lr.ph74, %._crit_edge
  %27 = load i32, ptr @q, align 4, !tbaa !5
  %28 = icmp sgt i32 %27, 0
  br i1 %28, label %.lr.ph76, label %.preheader65.._crit_edge77_crit_edge

.preheader65.._crit_edge77_crit_edge:             ; preds = %.preheader65
  %.pre127 = sext i32 %27 to i64
  br label %._crit_edge77

.lr.ph74:                                         ; preds = %._crit_edge, %.lr.ph74
  %indvars.iv104 = phi i64 [ %indvars.iv.next105, %.lr.ph74 ], [ 1, %._crit_edge ]
  %29 = load i32, ptr @tot, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds i32, ptr @hh, i64 %30
  %32 = getelementptr inbounds [200002 x i32], ptr @a, i64 0, i64 %indvars.iv104
  %33 = tail call noundef ptr @_ZSt11lower_boundIPiiET_S1_S1_RKT0_(ptr noundef nonnull @hh, ptr noundef nonnull %31, ptr noundef nonnull align 4 dereferenceable(4) %32)
  %34 = ptrtoint ptr %33 to i64
  %35 = sub i64 %34, ptrtoint (ptr @hh to i64)
  %36 = lshr exact i64 %35, 2
  %37 = trunc i64 %36 to i32
  store i32 %37, ptr %32, align 4, !tbaa !5
  %sext = shl i64 %35, 30
  %38 = ashr i64 %sext, 32
  %39 = getelementptr inbounds [200002 x i32], ptr @pos, i64 0, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %41 = getelementptr inbounds [200002 x i32], ptr @pre, i64 0, i64 %indvars.iv104
  store i32 %40, ptr %41, align 4, !tbaa !5
  %42 = trunc nuw nsw i64 %indvars.iv104 to i32
  store i32 %42, ptr %39, align 4, !tbaa !5
  %indvars.iv.next105 = add nuw nsw i64 %indvars.iv104, 1
  %43 = load i32, ptr @n, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %.not56.not = icmp slt i64 %indvars.iv104, %44
  br i1 %.not56.not, label %.lr.ph74, label %.preheader65, !llvm.loop !11

._crit_edge77:                                    ; preds = %.lr.ph76, %.preheader65.._crit_edge77_crit_edge
  %.pre-phi = phi i64 [ %.pre127, %.preheader65.._crit_edge77_crit_edge ], [ %54, %.lr.ph76 ]
  %45 = getelementptr inbounds %struct.Node, ptr @p, i64 %.pre-phi
  tail call void @_ZSt4sortIP4NodeEvT_S2_(ptr noundef nonnull @p, ptr noundef nonnull %45)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(800008) @pos, i8 0, i64 800008, i1 false)
  %46 = load i32, ptr @n, align 4, !tbaa !5
  %.not5783 = icmp eq i32 %46, 0
  br i1 %.not5783, label %._crit_edge88.thread, label %.lr.ph87.preheader

._crit_edge88.thread:                             ; preds = %._crit_edge77
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(800008) @bit, i8 63, i64 800008, i1 false)
  br label %.preheader

.lr.ph87.preheader:                               ; preds = %._crit_edge77
  %47 = sext i32 %46 to i64
  br label %.lr.ph87

.lr.ph76:                                         ; preds = %.preheader65, %.lr.ph76
  %indvars.iv107 = phi i64 [ %indvars.iv.next108, %.lr.ph76 ], [ 0, %.preheader65 ]
  %48 = getelementptr inbounds [200002 x %struct.Node], ptr @p, i64 0, i64 %indvars.iv107
  %49 = trunc nuw nsw i64 %indvars.iv107 to i32
  store i32 %49, ptr %48, align 4, !tbaa !12
  %50 = getelementptr inbounds i8, ptr %48, i64 4
  %51 = getelementptr inbounds i8, ptr %48, i64 8
  %52 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %50, ptr noundef nonnull %51)
  %indvars.iv.next108 = add nuw nsw i64 %indvars.iv107, 1
  %53 = load i32, ptr @q, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = icmp slt i64 %indvars.iv.next108, %54
  br i1 %55, label %.lr.ph76, label %._crit_edge77, !llvm.loop !14

._crit_edge88:                                    ; preds = %82
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(800008) @bit, i8 63, i64 800008, i1 false)
  br i1 %.not5783, label %.preheader, label %.preheader64.preheader

.preheader64.preheader:                           ; preds = %._crit_edge88
  %56 = sext i32 %46 to i64
  br label %.preheader64

.lr.ph87:                                         ; preds = %.lr.ph87.preheader, %82
  %indvars.iv113 = phi i64 [ %47, %.lr.ph87.preheader ], [ %indvars.iv.next114, %82 ]
  %.04985 = phi i32 [ 0, %.lr.ph87.preheader ], [ %.15068, %82 ]
  %57 = getelementptr inbounds [200002 x i32], ptr @a, i64 0, i64 %indvars.iv113
  %58 = load i32, ptr %57, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [200002 x i32], ptr @pos, i64 0, i64 %59
  store i32 1, ptr %60, align 4, !tbaa !5
  %61 = sext i32 %.04985 to i64
  %62 = getelementptr inbounds [200002 x i32], ptr @pos, i64 0, i64 %61
  %63 = load i32, ptr %62, align 4, !tbaa !5
  %.not5978 = icmp eq i32 %63, 0
  br i1 %.not5978, label %.critedge, label %.lr.ph81

.lr.ph81:                                         ; preds = %.lr.ph87, %.critedge2
  %indvars.iv110 = phi i64 [ %indvars.iv.next111, %.critedge2 ], [ %61, %.lr.ph87 ]
  %64 = icmp eq i64 %indvars.iv110, 0
  br i1 %64, label %.critedge2, label %65

65:                                               ; preds = %.lr.ph81
  %66 = add nsw i64 %indvars.iv110, -1
  %67 = getelementptr inbounds [200002 x i32], ptr @hh, i64 0, i64 %66
  %68 = load i32, ptr %67, align 4, !tbaa !5
  %69 = add nsw i32 %68, 1
  %70 = getelementptr inbounds [200002 x i32], ptr @hh, i64 0, i64 %indvars.iv110
  %71 = load i32, ptr %70, align 4, !tbaa !5
  %72 = icmp eq i32 %69, %71
  br i1 %72, label %.critedge2, label %.critedge.thread.loopexit

.critedge2:                                       ; preds = %.lr.ph81, %65
  %indvars.iv.next111 = add nsw i64 %indvars.iv110, 1
  %73 = getelementptr inbounds [200002 x i32], ptr @pos, i64 0, i64 %indvars.iv.next111
  %74 = load i32, ptr %73, align 4, !tbaa !5
  %.not59 = icmp eq i32 %74, 0
  br i1 %.not59, label %.critedge.loopexit, label %.lr.ph81, !llvm.loop !15

.critedge.loopexit:                               ; preds = %.critedge2
  %75 = trunc nsw i64 %indvars.iv.next111 to i32
  br label %.critedge

.critedge:                                        ; preds = %.critedge.loopexit, %.lr.ph87
  %.150.lcssa = phi i32 [ %.04985, %.lr.ph87 ], [ %75, %.critedge.loopexit ]
  %.not61 = icmp eq i32 %.150.lcssa, 0
  br i1 %.not61, label %82, label %.critedge.thread

.critedge.thread.loopexit:                        ; preds = %65
  %76 = trunc nsw i64 %indvars.iv110 to i32
  br label %.critedge.thread

.critedge.thread:                                 ; preds = %.critedge.thread.loopexit, %.critedge
  %.15067 = phi i32 [ %.150.lcssa, %.critedge ], [ %76, %.critedge.thread.loopexit ]
  %77 = add nsw i32 %.15067, -1
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds [200002 x i32], ptr @hh, i64 0, i64 %78
  %80 = load i32, ptr %79, align 4, !tbaa !5
  %81 = add nsw i32 %80, 1
  br label %82

82:                                               ; preds = %.critedge, %.critedge.thread
  %.15068 = phi i32 [ %.15067, %.critedge.thread ], [ 0, %.critedge ]
  %83 = phi i32 [ %81, %.critedge.thread ], [ 0, %.critedge ]
  %84 = getelementptr inbounds [200002 x i32], ptr @val, i64 0, i64 %indvars.iv113
  store i32 %83, ptr %84, align 4, !tbaa !5
  %indvars.iv.next114 = add nsw i64 %indvars.iv113, -1
  %.not57 = icmp eq i64 %indvars.iv.next114, 0
  br i1 %.not57, label %._crit_edge88, label %.lr.ph87, !llvm.loop !16

.preheader64:                                     ; preds = %.preheader64.preheader, %.critedge4
  %indvars.iv119 = phi i64 [ %56, %.preheader64.preheader ], [ %indvars.iv.next120, %.critedge4 ]
  %.04796 = phi i32 [ 0, %.preheader64.preheader ], [ %.1.lcssa, %.critedge4 ]
  %85 = load i32, ptr @q, align 4, !tbaa !5
  %86 = icmp slt i32 %.04796, %85
  br i1 %86, label %.lr.ph90.preheader, label %.critedge4

.lr.ph90.preheader:                               ; preds = %.preheader64
  %87 = sext i32 %.04796 to i64
  %88 = trunc nsw i64 %indvars.iv119 to i32
  br label %.lr.ph90

.preheader:                                       ; preds = %.critedge4, %._crit_edge88.thread, %._crit_edge88
  %89 = load i32, ptr @q, align 4, !tbaa !5
  %90 = icmp sgt i32 %89, 0
  br i1 %90, label %.lr.ph98, label %._crit_edge99

.lr.ph90:                                         ; preds = %.lr.ph90.preheader, %95
  %indvars.iv116 = phi i64 [ %87, %.lr.ph90.preheader ], [ %indvars.iv.next117, %95 ]
  %91 = getelementptr inbounds [200002 x %struct.Node], ptr @p, i64 0, i64 %indvars.iv116
  %92 = getelementptr inbounds i8, ptr %91, i64 8
  %93 = load i32, ptr %92, align 4, !tbaa !17
  %94 = icmp eq i32 %93, %88
  br i1 %94, label %95, label %.critedge4.loopexit

95:                                               ; preds = %.lr.ph90
  %96 = getelementptr inbounds i8, ptr %91, i64 4
  %97 = load i32, ptr %96, align 4, !tbaa !18
  %98 = sext i32 %97 to i64
  %99 = getelementptr inbounds [200002 x i32], ptr @val, i64 0, i64 %98
  %100 = load i32, ptr %99, align 4, !tbaa !5
  %101 = tail call noundef i32 @_Z3quei(i32 noundef %97)
  %102 = tail call noundef i32 @_Z3minii(i32 noundef %100, i32 noundef %101)
  %103 = load i32, ptr %91, align 4, !tbaa !12
  %104 = sext i32 %103 to i64
  %105 = getelementptr inbounds [200002 x i32], ptr @ans, i64 0, i64 %104
  store i32 %102, ptr %105, align 4, !tbaa !5
  %indvars.iv.next117 = add nsw i64 %indvars.iv116, 1
  %106 = load i32, ptr @q, align 4, !tbaa !5
  %107 = sext i32 %106 to i64
  %108 = icmp slt i64 %indvars.iv.next117, %107
  br i1 %108, label %.lr.ph90, label %.critedge4.loopexit, !llvm.loop !19

.critedge4.loopexit:                              ; preds = %95, %.lr.ph90
  %.1.lcssa.ph.in = phi i64 [ %indvars.iv116, %.lr.ph90 ], [ %indvars.iv.next117, %95 ]
  %.1.lcssa.ph = trunc i64 %.1.lcssa.ph.in to i32
  br label %.critedge4

.critedge4:                                       ; preds = %.critedge4.loopexit, %.preheader64
  %.1.lcssa = phi i32 [ %.04796, %.preheader64 ], [ %.1.lcssa.ph, %.critedge4.loopexit ]
  %109 = getelementptr inbounds [200002 x i32], ptr @pre, i64 0, i64 %indvars.iv119
  %110 = load i32, ptr %109, align 4, !tbaa !5
  %111 = add nsw i32 %110, 1
  %112 = getelementptr inbounds [200002 x i32], ptr @a, i64 0, i64 %indvars.iv119
  %113 = load i32, ptr %112, align 4, !tbaa !5
  %114 = sext i32 %113 to i64
  %115 = getelementptr inbounds [200002 x i32], ptr @hh, i64 0, i64 %114
  %116 = load i32, ptr %115, align 4, !tbaa !5
  tail call void @_Z3updii(i32 noundef %111, i32 noundef %116)
  %indvars.iv.next120 = add nsw i64 %indvars.iv119, -1
  %.not58 = icmp eq i64 %indvars.iv.next120, 0
  br i1 %.not58, label %.preheader, label %.preheader64, !llvm.loop !20

._crit_edge99:                                    ; preds = %.lr.ph98, %.preheader
  ret i32 0

.lr.ph98:                                         ; preds = %.preheader, %.lr.ph98
  %indvars.iv123 = phi i64 [ %indvars.iv.next124, %.lr.ph98 ], [ 0, %.preheader ]
  %117 = getelementptr inbounds [200002 x i32], ptr @ans, i64 0, i64 %indvars.iv123
  %118 = load i32, ptr %117, align 4, !tbaa !5
  %119 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %118)
  %indvars.iv.next124 = add nuw nsw i64 %indvars.iv123, 1
  %120 = load i32, ptr @q, align 4, !tbaa !5
  %121 = sext i32 %120 to i64
  %122 = icmp slt i64 %indvars.iv.next124, %121
  br i1 %122, label %.lr.ph98, label %._crit_edge99, !llvm.loop !21
}

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZSt6uniqueIPiET_S1_S1_(ptr noundef, ptr noundef) local_unnamed_addr #3

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

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

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

; 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 = { 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 #4 = { 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 = !{!"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 = !{!13, !6, i64 0}
!13 = !{!"_ZTS4Node", !6, i64 0, !6, i64 4, !6, i64 8}
!14 = distinct !{!14, !10}
!15 = distinct !{!15, !10}
!16 = distinct !{!16, !10}
!17 = !{!13, !6, i64 8}
!18 = !{!13, !6, i64 4}
!19 = distinct !{!19, !10}
!20 = distinct !{!20, !10}
!21 = distinct !{!21, !10}


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