; LLVM IR from tangjz/acm-icpc :: codeforces/complete (797D)

; 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
@val = external dso_local global [100001 x i32], align 16
@cL = external dso_local global [100001 x i32], align 16
@cR = external dso_local global [100001 x i32], align 16
@ord = external dso_local global [100001 x i32], align 16
@in = external dso_local global [100001 x i32], align 16
@out = external dso_local global [100001 x i32], align 16
@ans = external dso_local global i32, align 4
@vis = external dso_local global [100001 x i8], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z7bit_sumi(i32 noundef) #1

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

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

; 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)) #1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #3 {
  %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
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %12 = 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 %13

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

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

18:                                               ; preds = %13
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds i32, ptr @val, i64 %20
  %22 = load i32, ptr %2, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds i32, ptr @cL, i64 %23
  %25 = load i32, ptr %2, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds i32, ptr @cR, i64 %26
  %28 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %21, ptr noundef %24, ptr noundef %27)
  %29 = load i32, ptr %2, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [100001 x i32], ptr @cL, i64 0, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = icmp ne i32 %32, -1
  br i1 %33, label %34, label %41

34:                                               ; preds = %18
  %35 = load i32, ptr %2, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [100001 x i32], ptr @cL, i64 0, i64 %36
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [100001 x i8], ptr @vis, i64 0, i64 %39
  store i8 1, ptr %40, align 1, !tbaa !9
  br label %41

41:                                               ; preds = %34, %18
  %42 = load i32, ptr %2, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [100001 x i32], ptr @cR, i64 0, i64 %43
  %45 = load i32, ptr %44, align 4, !tbaa !5
  %46 = icmp ne i32 %45, -1
  br i1 %46, label %47, label %54

47:                                               ; preds = %41
  %48 = load i32, ptr %2, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [100001 x i32], ptr @cR, i64 0, i64 %49
  %51 = load i32, ptr %50, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [100001 x i8], ptr @vis, i64 0, i64 %52
  store i8 1, ptr %53, align 1, !tbaa !9
  br label %54

54:                                               ; preds = %47, %41
  %55 = load i32, ptr %2, align 4, !tbaa !5
  %56 = load i32, ptr %2, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [100001 x i32], ptr @ord, i64 0, i64 %57
  store i32 %55, ptr %58, align 4, !tbaa !5
  br label %59

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

62:                                               ; preds = %17
  %63 = load i32, ptr @n, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds i32, ptr @ord, i64 %64
  %66 = getelementptr inbounds i32, ptr %65, i64 1
  call void @_ZSt4sortIPiPFbRKiS2_EEvT_S5_T0_(ptr noundef getelementptr inbounds (i32, ptr @ord, i64 1), ptr noundef %66, ptr noundef @_Z3cmpRKiS0_)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #6
  store i32 1, ptr %3, align 4, !tbaa !5
  br label %67

67:                                               ; preds = %81, %62
  %68 = load i32, ptr %3, align 4, !tbaa !5
  %69 = load i32, ptr @n, align 4, !tbaa !5
  %70 = icmp sle i32 %68, %69
  br i1 %70, label %72, label %71

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

72:                                               ; preds = %67
  %73 = load i32, ptr %3, align 4, !tbaa !5
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [100001 x i8], ptr @vis, i64 0, i64 %74
  %76 = load i8, ptr %75, align 1, !tbaa !9, !range !13, !noundef !14
  %77 = trunc i8 %76 to i1
  br i1 %77, label %80, label %78

78:                                               ; preds = %72
  %79 = load i32, ptr %3, align 4, !tbaa !5
  call void @_Z3dfsi(i32 noundef %79)
  br label %80

80:                                               ; preds = %78, %72
  br label %81

81:                                               ; preds = %80
  %82 = load i32, ptr %3, align 4, !tbaa !5
  %83 = add nsw i32 %82, 1
  store i32 %83, ptr %3, align 4, !tbaa !5
  br label %67, !llvm.loop !15

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

85:                                               ; preds = %113, %84
  %86 = load i32, ptr %4, align 4, !tbaa !5
  %87 = load i32, ptr @n, align 4, !tbaa !5
  %88 = icmp sle i32 %86, %87
  br i1 %88, label %90, label %89

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

90:                                               ; preds = %85
  %91 = load i32, ptr %4, align 4, !tbaa !5
  %92 = sext i32 %91 to i64
  %93 = getelementptr inbounds [100001 x i32], ptr @cR, i64 0, i64 %92
  %94 = load i32, ptr %93, align 4, !tbaa !5
  %95 = icmp ne i32 %94, -1
  br i1 %95, label %96, label %112

96:                                               ; preds = %90
  %97 = load i32, ptr %4, align 4, !tbaa !5
  %98 = sext i32 %97 to i64
  %99 = getelementptr inbounds [100001 x i32], ptr @cR, i64 0, i64 %98
  %100 = load i32, ptr %99, align 4, !tbaa !5
  %101 = sext i32 %100 to i64
  %102 = getelementptr inbounds [100001 x i32], ptr @in, i64 0, i64 %101
  %103 = load i32, ptr %102, align 4, !tbaa !5
  call void @_Z7bit_addii(i32 noundef %103, i32 noundef 1)
  %104 = load i32, ptr %4, align 4, !tbaa !5
  %105 = sext i32 %104 to i64
  %106 = getelementptr inbounds [100001 x i32], ptr @cR, i64 0, i64 %105
  %107 = load i32, ptr %106, align 4, !tbaa !5
  %108 = sext i32 %107 to i64
  %109 = getelementptr inbounds [100001 x i32], ptr @out, i64 0, i64 %108
  %110 = load i32, ptr %109, align 4, !tbaa !5
  %111 = add nsw i32 %110, 1
  call void @_Z7bit_addii(i32 noundef %111, i32 noundef -1)
  br label %112

112:                                              ; preds = %96, %90
  br label %113

113:                                              ; preds = %112
  %114 = load i32, ptr %4, align 4, !tbaa !5
  %115 = add nsw i32 %114, 1
  store i32 %115, ptr %4, align 4, !tbaa !5
  br label %85, !llvm.loop !16

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

117:                                              ; preds = %248, %116
  %118 = load i32, ptr %5, align 4, !tbaa !5
  %119 = load i32, ptr @n, align 4, !tbaa !5
  %120 = icmp sle i32 %118, %119
  br i1 %120, label %122, label %121

121:                                              ; preds = %117
  store i32 11, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  br label %249

122:                                              ; preds = %117
  br label %123

123:                                              ; preds = %194, %122
  %124 = load i32, ptr %6, align 4, !tbaa !5
  %125 = load i32, ptr @n, align 4, !tbaa !5
  %126 = icmp sle i32 %124, %125
  br i1 %126, label %127, label %143

127:                                              ; preds = %123
  %128 = load i32, ptr %6, align 4, !tbaa !5
  %129 = sext i32 %128 to i64
  %130 = getelementptr inbounds [100001 x i32], ptr @ord, i64 0, i64 %129
  %131 = load i32, ptr %130, align 4, !tbaa !5
  %132 = sext i32 %131 to i64
  %133 = getelementptr inbounds [100001 x i32], ptr @val, i64 0, i64 %132
  %134 = load i32, ptr %133, align 4, !tbaa !5
  %135 = load i32, ptr %5, align 4, !tbaa !5
  %136 = sext i32 %135 to i64
  %137 = getelementptr inbounds [100001 x i32], ptr @ord, i64 0, i64 %136
  %138 = load i32, ptr %137, align 4, !tbaa !5
  %139 = sext i32 %138 to i64
  %140 = getelementptr inbounds [100001 x i32], ptr @val, i64 0, i64 %139
  %141 = load i32, ptr %140, align 4, !tbaa !5
  %142 = icmp sle i32 %134, %141
  br label %143

143:                                              ; preds = %127, %123
  %144 = phi i1 [ false, %123 ], [ %142, %127 ]
  br i1 %144, label %145, label %197

145:                                              ; preds = %143
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  %146 = load i32, ptr %6, align 4, !tbaa !5
  %147 = sext i32 %146 to i64
  %148 = getelementptr inbounds [100001 x i32], ptr @ord, i64 0, i64 %147
  %149 = load i32, ptr %148, align 4, !tbaa !5
  store i32 %149, ptr %8, align 4, !tbaa !5
  %150 = load i32, ptr %8, align 4, !tbaa !5
  %151 = sext i32 %150 to i64
  %152 = getelementptr inbounds [100001 x i32], ptr @cL, i64 0, i64 %151
  %153 = load i32, ptr %152, align 4, !tbaa !5
  %154 = icmp ne i32 %153, -1
  br i1 %154, label %155, label %171

155:                                              ; preds = %145
  %156 = load i32, ptr %8, align 4, !tbaa !5
  %157 = sext i32 %156 to i64
  %158 = getelementptr inbounds [100001 x i32], ptr @cL, i64 0, i64 %157
  %159 = load i32, ptr %158, align 4, !tbaa !5
  %160 = sext i32 %159 to i64
  %161 = getelementptr inbounds [100001 x i32], ptr @in, i64 0, i64 %160
  %162 = load i32, ptr %161, align 4, !tbaa !5
  call void @_Z7bit_addii(i32 noundef %162, i32 noundef 1)
  %163 = load i32, ptr %8, align 4, !tbaa !5
  %164 = sext i32 %163 to i64
  %165 = getelementptr inbounds [100001 x i32], ptr @cL, i64 0, i64 %164
  %166 = load i32, ptr %165, align 4, !tbaa !5
  %167 = sext i32 %166 to i64
  %168 = getelementptr inbounds [100001 x i32], ptr @out, i64 0, i64 %167
  %169 = load i32, ptr %168, align 4, !tbaa !5
  %170 = add nsw i32 %169, 1
  call void @_Z7bit_addii(i32 noundef %170, i32 noundef -1)
  br label %171

171:                                              ; preds = %155, %145
  %172 = load i32, ptr %8, align 4, !tbaa !5
  %173 = sext i32 %172 to i64
  %174 = getelementptr inbounds [100001 x i32], ptr @cR, i64 0, i64 %173
  %175 = load i32, ptr %174, align 4, !tbaa !5
  %176 = icmp ne i32 %175, -1
  br i1 %176, label %177, label %193

177:                                              ; preds = %171
  %178 = load i32, ptr %8, align 4, !tbaa !5
  %179 = sext i32 %178 to i64
  %180 = getelementptr inbounds [100001 x i32], ptr @cR, i64 0, i64 %179
  %181 = load i32, ptr %180, align 4, !tbaa !5
  %182 = sext i32 %181 to i64
  %183 = getelementptr inbounds [100001 x i32], ptr @in, i64 0, i64 %182
  %184 = load i32, ptr %183, align 4, !tbaa !5
  call void @_Z7bit_addii(i32 noundef %184, i32 noundef -1)
  %185 = load i32, ptr %8, align 4, !tbaa !5
  %186 = sext i32 %185 to i64
  %187 = getelementptr inbounds [100001 x i32], ptr @cR, i64 0, i64 %186
  %188 = load i32, ptr %187, align 4, !tbaa !5
  %189 = sext i32 %188 to i64
  %190 = getelementptr inbounds [100001 x i32], ptr @out, i64 0, i64 %189
  %191 = load i32, ptr %190, align 4, !tbaa !5
  %192 = add nsw i32 %191, 1
  call void @_Z7bit_addii(i32 noundef %192, i32 noundef 1)
  br label %193

193:                                              ; preds = %177, %171
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  br label %194

194:                                              ; preds = %193
  %195 = load i32, ptr %6, align 4, !tbaa !5
  %196 = add nsw i32 %195, 1
  store i32 %196, ptr %6, align 4, !tbaa !5
  br label %123, !llvm.loop !17

197:                                              ; preds = %143
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #6
  store i32 0, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #6
  store i32 0, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #6
  %198 = load i32, ptr %5, align 4, !tbaa !5
  %199 = sext i32 %198 to i64
  %200 = getelementptr inbounds [100001 x i32], ptr @ord, i64 0, i64 %199
  %201 = load i32, ptr %200, align 4, !tbaa !5
  %202 = sext i32 %201 to i64
  %203 = getelementptr inbounds [100001 x i32], ptr @val, i64 0, i64 %202
  %204 = load i32, ptr %203, align 4, !tbaa !5
  store i32 %204, ptr %11, align 4, !tbaa !5
  br label %205

205:                                              ; preds = %236, %197
  %206 = load i32, ptr %5, align 4, !tbaa !5
  %207 = load i32, ptr @n, align 4, !tbaa !5
  %208 = icmp sle i32 %206, %207
  br i1 %208, label %209, label %219

209:                                              ; preds = %205
  %210 = load i32, ptr %5, align 4, !tbaa !5
  %211 = sext i32 %210 to i64
  %212 = getelementptr inbounds [100001 x i32], ptr @ord, i64 0, i64 %211
  %213 = load i32, ptr %212, align 4, !tbaa !5
  %214 = sext i32 %213 to i64
  %215 = getelementptr inbounds [100001 x i32], ptr @val, i64 0, i64 %214
  %216 = load i32, ptr %215, align 4, !tbaa !5
  %217 = load i32, ptr %11, align 4, !tbaa !5
  %218 = icmp eq i32 %216, %217
  br label %219

219:                                              ; preds = %209, %205
  %220 = phi i1 [ false, %205 ], [ %218, %209 ]
  br i1 %220, label %222, label %221

221:                                              ; preds = %219
  store i32 16, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #6
  br label %241

222:                                              ; preds = %219
  %223 = load i32, ptr %5, align 4, !tbaa !5
  %224 = sext i32 %223 to i64
  %225 = getelementptr inbounds [100001 x i32], ptr @ord, i64 0, i64 %224
  %226 = load i32, ptr %225, align 4, !tbaa !5
  %227 = sext i32 %226 to i64
  %228 = getelementptr inbounds [100001 x i32], ptr @in, i64 0, i64 %227
  %229 = load i32, ptr %228, align 4, !tbaa !5
  %230 = call noundef i32 @_Z7bit_sumi(i32 noundef %229)
  %231 = icmp ne i32 %230, 0
  %232 = xor i1 %231, true
  %233 = zext i1 %232 to i32
  %234 = load i32, ptr %10, align 4, !tbaa !5
  %235 = or i32 %234, %233
  store i32 %235, ptr %10, align 4, !tbaa !5
  br label %236

236:                                              ; preds = %222
  %237 = load i32, ptr %5, align 4, !tbaa !5
  %238 = add nsw i32 %237, 1
  store i32 %238, ptr %5, align 4, !tbaa !5
  %239 = load i32, ptr %9, align 4, !tbaa !5
  %240 = add nsw i32 %239, 1
  store i32 %240, ptr %9, align 4, !tbaa !5
  br label %205, !llvm.loop !18

241:                                              ; preds = %221
  %242 = load i32, ptr %10, align 4, !tbaa !5
  %243 = icmp ne i32 %242, 0
  br i1 %243, label %248, label %244

244:                                              ; preds = %241
  %245 = load i32, ptr %9, align 4, !tbaa !5
  %246 = load i32, ptr @ans, align 4, !tbaa !5
  %247 = add nsw i32 %246, %245
  store i32 %247, ptr @ans, align 4, !tbaa !5
  br label %248

248:                                              ; preds = %244, %241
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #6
  br label %117, !llvm.loop !19

249:                                              ; preds = %121
  %250 = load i32, ptr @ans, align 4, !tbaa !5
  %251 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %250)
  ret i32 0
}

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

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

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

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


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

@n = external dso_local global i32, align 4
@val = external dso_local global [100001 x i32], align 16
@cL = external dso_local global [100001 x i32], align 16
@cR = external dso_local global [100001 x i32], align 16
@ord = external dso_local global [100001 x i32], align 16
@in = external dso_local local_unnamed_addr global [100001 x i32], align 16
@out = external dso_local local_unnamed_addr global [100001 x i32], align 16
@ans = external dso_local local_unnamed_addr global i32, align 4
@vis = external dso_local local_unnamed_addr global [100001 x i8], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z7bit_sumi(i32 noundef) local_unnamed_addr #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)) #1

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

.._crit_edge_crit_edge:                           ; preds = %0
  %.pre119 = sext i32 %2 to i64
  br label %._crit_edge

._crit_edge:                                      ; preds = %19, %.._crit_edge_crit_edge
  %.pre-phi = phi i64 [ %.pre119, %.._crit_edge_crit_edge ], [ %23, %19 ]
  %3 = getelementptr inbounds i32, ptr @ord, i64 %.pre-phi
  %4 = getelementptr inbounds i8, ptr %3, i64 4
  tail call void @_ZSt4sortIPiPFbRKiS2_EEvT_S5_T0_(ptr noundef nonnull getelementptr inbounds (i8, ptr @ord, i64 4), ptr noundef nonnull %4, ptr noundef nonnull @_Z3cmpRKiS0_)
  %5 = load i32, ptr @n, align 4, !tbaa !5
  %.not5774 = icmp slt i32 %5, 1
  br i1 %.not5774, label %._crit_edge102, label %.lr.ph77

.lr.ph:                                           ; preds = %0, %19
  %indvars.iv = phi i64 [ %indvars.iv.next, %19 ], [ 1, %0 ]
  %6 = getelementptr inbounds i32, ptr @val, i64 %indvars.iv
  %7 = getelementptr inbounds i32, ptr @cL, i64 %indvars.iv
  %8 = getelementptr inbounds i32, ptr @cR, i64 %indvars.iv
  %9 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %6, ptr noundef nonnull %7, ptr noundef nonnull %8)
  %10 = load i32, ptr %7, align 4, !tbaa !5
  %.not68 = icmp eq i32 %10, -1
  br i1 %.not68, label %14, label %11

11:                                               ; preds = %.lr.ph
  %12 = sext i32 %10 to i64
  %13 = getelementptr inbounds [100001 x i8], ptr @vis, i64 0, i64 %12
  store i8 1, ptr %13, align 1, !tbaa !9
  br label %14

14:                                               ; preds = %11, %.lr.ph
  %15 = load i32, ptr %8, align 4, !tbaa !5
  %.not69 = icmp eq i32 %15, -1
  br i1 %.not69, label %19, label %16

16:                                               ; preds = %14
  %17 = sext i32 %15 to i64
  %18 = getelementptr inbounds [100001 x i8], ptr @vis, i64 0, i64 %17
  store i8 1, ptr %18, align 1, !tbaa !9
  br label %19

19:                                               ; preds = %16, %14
  %20 = getelementptr inbounds [100001 x i32], ptr @ord, i64 0, i64 %indvars.iv
  %21 = trunc nuw nsw i64 %indvars.iv to i32
  store i32 %21, ptr %20, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %22 = load i32, ptr @n, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %.not.not = icmp slt i64 %indvars.iv, %23
  br i1 %.not.not, label %.lr.ph, label %._crit_edge, !llvm.loop !11

.preheader71:                                     ; preds = %30
  %.not5878 = icmp slt i32 %31, 1
  br i1 %.not5878, label %._crit_edge102, label %.lr.ph80

.lr.ph77:                                         ; preds = %._crit_edge, %30
  %24 = phi i32 [ %31, %30 ], [ %5, %._crit_edge ]
  %indvars.iv105 = phi i64 [ %indvars.iv.next106, %30 ], [ 1, %._crit_edge ]
  %25 = getelementptr inbounds [100001 x i8], ptr @vis, i64 0, i64 %indvars.iv105
  %26 = load i8, ptr %25, align 1, !tbaa !9, !range !13, !noundef !14
  %27 = trunc nuw i8 %26 to i1
  br i1 %27, label %30, label %28

28:                                               ; preds = %.lr.ph77
  %29 = trunc nuw nsw i64 %indvars.iv105 to i32
  tail call void @_Z3dfsi(i32 noundef %29)
  %.pre = load i32, ptr @n, align 4, !tbaa !5
  br label %30

30:                                               ; preds = %.lr.ph77, %28
  %31 = phi i32 [ %24, %.lr.ph77 ], [ %.pre, %28 ]
  %indvars.iv.next106 = add nuw nsw i64 %indvars.iv105, 1
  %32 = sext i32 %31 to i64
  %.not57.not = icmp slt i64 %indvars.iv105, %32
  br i1 %.not57.not, label %.lr.ph77, label %.preheader71, !llvm.loop !15

.preheader70:                                     ; preds = %45
  %.not5999 = icmp slt i32 %46, 1
  br i1 %.not5999, label %._crit_edge102, label %.preheader

.lr.ph80:                                         ; preds = %.preheader71, %45
  %33 = phi i32 [ %46, %45 ], [ %31, %.preheader71 ]
  %indvars.iv108 = phi i64 [ %indvars.iv.next109, %45 ], [ 1, %.preheader71 ]
  %34 = getelementptr inbounds [100001 x i32], ptr @cR, i64 0, i64 %indvars.iv108
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %.not67 = icmp eq i32 %35, -1
  br i1 %.not67, label %45, label %36

36:                                               ; preds = %.lr.ph80
  %37 = sext i32 %35 to i64
  %38 = getelementptr inbounds [100001 x i32], ptr @in, i64 0, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !5
  tail call void @_Z7bit_addii(i32 noundef %39, i32 noundef 1)
  %40 = load i32, ptr %34, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [100001 x i32], ptr @out, i64 0, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !5
  %44 = add nsw i32 %43, 1
  tail call void @_Z7bit_addii(i32 noundef %44, i32 noundef -1)
  %.pre118 = load i32, ptr @n, align 4, !tbaa !5
  br label %45

45:                                               ; preds = %.lr.ph80, %36
  %46 = phi i32 [ %33, %.lr.ph80 ], [ %.pre118, %36 ]
  %indvars.iv.next109 = add nuw nsw i64 %indvars.iv108, 1
  %47 = sext i32 %46 to i64
  %.not58.not = icmp slt i64 %indvars.iv108, %47
  br i1 %.not58.not, label %.lr.ph80, label %.preheader70, !llvm.loop !16

.preheader:                                       ; preds = %.preheader70, %131
  %48 = phi i32 [ %132, %131 ], [ %46, %.preheader70 ]
  %.047101 = phi i32 [ %.1.lcssa, %131 ], [ 1, %.preheader70 ]
  %.048100 = phi i32 [ %.149.lcssa128, %131 ], [ 1, %.preheader70 ]
  %.not6081 = icmp sgt i32 %.047101, %48
  %.pre120 = sext i32 %.048100 to i64
  br i1 %.not6081, label %.critedge, label %.lr.ph83

.lr.ph83:                                         ; preds = %.preheader
  %49 = getelementptr inbounds [100001 x i32], ptr @ord, i64 0, i64 %.pre120
  %50 = sext i32 %.047101 to i64
  %51 = getelementptr inbounds [100001 x i32], ptr @ord, i64 0, i64 %50
  %52 = load i32, ptr %51, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [100001 x i32], ptr @val, i64 0, i64 %53
  %55 = load i32, ptr %54, align 4, !tbaa !5
  %56 = load i32, ptr %49, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [100001 x i32], ptr @val, i64 0, i64 %57
  %59 = load i32, ptr %58, align 4, !tbaa !5
  %.not61135 = icmp sgt i32 %55, %59
  br i1 %.not61135, label %.critedge.loopexit, label %.lr.ph137

._crit_edge102:                                   ; preds = %131, %._crit_edge, %.preheader71, %.preheader70
  %60 = load i32, ptr @ans, align 4, !tbaa !5
  %61 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %60)
  ret i32 0

62:                                               ; preds = %96
  %63 = getelementptr inbounds [100001 x i32], ptr @ord, i64 0, i64 %indvars.iv.next112
  %64 = load i32, ptr %63, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [100001 x i32], ptr @val, i64 0, i64 %65
  %67 = load i32, ptr %66, align 4, !tbaa !5
  %68 = load i32, ptr %49, align 4, !tbaa !5
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [100001 x i32], ptr @val, i64 0, i64 %69
  %71 = load i32, ptr %70, align 4, !tbaa !5
  %.not61 = icmp sgt i32 %67, %71
  br i1 %.not61, label %.critedge.loopexit, label %.lr.ph137, !llvm.loop !17

.lr.ph137:                                        ; preds = %.lr.ph83, %62
  %72 = phi i64 [ %65, %62 ], [ %53, %.lr.ph83 ]
  %indvars.iv111136 = phi i64 [ %indvars.iv.next112, %62 ], [ %50, %.lr.ph83 ]
  %73 = getelementptr inbounds [100001 x i32], ptr @cL, i64 0, i64 %72
  %74 = load i32, ptr %73, align 4, !tbaa !5
  %.not65 = icmp eq i32 %74, -1
  br i1 %.not65, label %84, label %75

75:                                               ; preds = %.lr.ph137
  %76 = sext i32 %74 to i64
  %77 = getelementptr inbounds [100001 x i32], ptr @in, i64 0, i64 %76
  %78 = load i32, ptr %77, align 4, !tbaa !5
  tail call void @_Z7bit_addii(i32 noundef %78, i32 noundef 1)
  %79 = load i32, ptr %73, align 4, !tbaa !5
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [100001 x i32], ptr @out, i64 0, i64 %80
  %82 = load i32, ptr %81, align 4, !tbaa !5
  %83 = add nsw i32 %82, 1
  tail call void @_Z7bit_addii(i32 noundef %83, i32 noundef -1)
  br label %84

84:                                               ; preds = %75, %.lr.ph137
  %85 = getelementptr inbounds [100001 x i32], ptr @cR, i64 0, i64 %72
  %86 = load i32, ptr %85, align 4, !tbaa !5
  %.not66 = icmp eq i32 %86, -1
  br i1 %.not66, label %96, label %87

87:                                               ; preds = %84
  %88 = sext i32 %86 to i64
  %89 = getelementptr inbounds [100001 x i32], ptr @in, i64 0, i64 %88
  %90 = load i32, ptr %89, align 4, !tbaa !5
  tail call void @_Z7bit_addii(i32 noundef %90, i32 noundef -1)
  %91 = load i32, ptr %85, align 4, !tbaa !5
  %92 = sext i32 %91 to i64
  %93 = getelementptr inbounds [100001 x i32], ptr @out, i64 0, i64 %92
  %94 = load i32, ptr %93, align 4, !tbaa !5
  %95 = add nsw i32 %94, 1
  tail call void @_Z7bit_addii(i32 noundef %95, i32 noundef 1)
  br label %96

96:                                               ; preds = %87, %84
  %indvars.iv.next112 = add nsw i64 %indvars.iv111136, 1
  %97 = load i32, ptr @n, align 4, !tbaa !5
  %98 = sext i32 %97 to i64
  %.not60.not = icmp slt i64 %indvars.iv111136, %98
  br i1 %.not60.not, label %62, label %.critedge.loopexit, !llvm.loop !17

.critedge.loopexit:                               ; preds = %62, %96, %.lr.ph83
  %99 = phi i32 [ %48, %.lr.ph83 ], [ %97, %96 ], [ %97, %62 ]
  %.1.lcssa.ph.in = phi i64 [ %50, %.lr.ph83 ], [ %indvars.iv.next112, %96 ], [ %indvars.iv.next112, %62 ]
  %.1.lcssa.ph = trunc i64 %.1.lcssa.ph.in to i32
  br label %.critedge

.critedge:                                        ; preds = %.preheader, %.critedge.loopexit
  %100 = phi i32 [ %99, %.critedge.loopexit ], [ %48, %.preheader ]
  %.1.lcssa = phi i32 [ %.1.lcssa.ph, %.critedge.loopexit ], [ %.047101, %.preheader ]
  %101 = getelementptr inbounds [100001 x i32], ptr @ord, i64 0, i64 %.pre120
  %102 = load i32, ptr %101, align 4, !tbaa !5
  %103 = sext i32 %102 to i64
  %104 = getelementptr inbounds [100001 x i32], ptr @val, i64 0, i64 %103
  %105 = load i32, ptr %104, align 4, !tbaa !5
  %.not6287 = icmp sgt i32 %.048100, %100
  br i1 %.not6287, label %.critedge2.thread, label %.lr.ph91.preheader

.lr.ph91.preheader:                               ; preds = %.critedge
  %106 = getelementptr inbounds [100001 x i32], ptr @ord, i64 0, i64 %.pre120
  %107 = load i32, ptr %106, align 4, !tbaa !5
  %108 = sext i32 %107 to i64
  %109 = getelementptr inbounds [100001 x i32], ptr @val, i64 0, i64 %108
  %110 = load i32, ptr %109, align 4, !tbaa !5
  %111 = icmp eq i32 %110, %105
  br i1 %111, label %.lr.ph145, label %.critedge2

.lr.ph91:                                         ; preds = %.lr.ph145
  %112 = getelementptr inbounds [100001 x i32], ptr @ord, i64 0, i64 %indvars.iv.next115
  %113 = load i32, ptr %112, align 4, !tbaa !5
  %114 = sext i32 %113 to i64
  %115 = getelementptr inbounds [100001 x i32], ptr @val, i64 0, i64 %114
  %116 = load i32, ptr %115, align 4, !tbaa !5
  %117 = icmp eq i32 %116, %105
  br i1 %117, label %.lr.ph145, label %.critedge2, !llvm.loop !18

.critedge2:                                       ; preds = %.lr.ph145, %.lr.ph91, %.lr.ph91.preheader
  %118 = phi i32 [ %100, %.lr.ph91.preheader ], [ %126, %.lr.ph91 ], [ %126, %.lr.ph145 ]
  %.149.lcssa.ph.in = phi i64 [ %.pre120, %.lr.ph91.preheader ], [ %indvars.iv.next115, %.lr.ph91 ], [ %indvars.iv.next115, %.lr.ph145 ]
  %.045.lcssa.ph = phi i32 [ 0, %.lr.ph91.preheader ], [ %125, %.lr.ph91 ], [ %125, %.lr.ph145 ]
  %.044.lcssa.ph = phi i32 [ 0, %.lr.ph91.preheader ], [ %124, %.lr.ph91 ], [ %124, %.lr.ph145 ]
  %.149.lcssa.ph = trunc i64 %.149.lcssa.ph.in to i32
  %.not63 = icmp eq i32 %.044.lcssa.ph, 0
  br i1 %.not63, label %.critedge2.thread, label %131

.lr.ph145:                                        ; preds = %.lr.ph91.preheader, %.lr.ph91
  %119 = phi i64 [ %114, %.lr.ph91 ], [ %108, %.lr.ph91.preheader ]
  %.04589144 = phi i32 [ %125, %.lr.ph91 ], [ 0, %.lr.ph91.preheader ]
  %.04490143 = phi i32 [ %124, %.lr.ph91 ], [ 0, %.lr.ph91.preheader ]
  %indvars.iv114142 = phi i64 [ %indvars.iv.next115, %.lr.ph91 ], [ %.pre120, %.lr.ph91.preheader ]
  %120 = getelementptr inbounds [100001 x i32], ptr @in, i64 0, i64 %119
  %121 = load i32, ptr %120, align 4, !tbaa !5
  %122 = tail call noundef i32 @_Z7bit_sumi(i32 noundef %121)
  %.not64 = icmp eq i32 %122, 0
  %123 = zext i1 %.not64 to i32
  %124 = or i32 %.04490143, %123
  %indvars.iv.next115 = add nsw i64 %indvars.iv114142, 1
  %125 = add nuw nsw i32 %.04589144, 1
  %126 = load i32, ptr @n, align 4, !tbaa !5
  %127 = sext i32 %126 to i64
  %.not62.not = icmp slt i64 %indvars.iv114142, %127
  br i1 %.not62.not, label %.lr.ph91, label %.critedge2, !llvm.loop !18

.critedge2.thread:                                ; preds = %.critedge, %.critedge2
  %.045.lcssa130 = phi i32 [ %.045.lcssa.ph, %.critedge2 ], [ 0, %.critedge ]
  %.149.lcssa129 = phi i32 [ %.149.lcssa.ph, %.critedge2 ], [ %.048100, %.critedge ]
  %128 = phi i32 [ %118, %.critedge2 ], [ %100, %.critedge ]
  %129 = load i32, ptr @ans, align 4, !tbaa !5
  %130 = add nsw i32 %129, %.045.lcssa130
  store i32 %130, ptr @ans, align 4, !tbaa !5
  br label %131

131:                                              ; preds = %.critedge2.thread, %.critedge2
  %.149.lcssa128 = phi i32 [ %.149.lcssa129, %.critedge2.thread ], [ %.149.lcssa.ph, %.critedge2 ]
  %132 = phi i32 [ %128, %.critedge2.thread ], [ %118, %.critedge2 ]
  %.not59 = icmp sgt i32 %.149.lcssa128, %132
  br i1 %.not59, label %._crit_edge102, label %.preheader, !llvm.loop !19
}

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #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: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #3

attributes #0 = { 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 #1 = { 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 #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 = { 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 #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" }

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

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


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