; LLVM IR from lzyrapx/Competitive-Programming :: HDUOJ (4820（线段树）)

; 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.std::pair" = type { i32, i32 }

@t = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@tot = external dso_local global i32, align 4
@que = external dso_local global [500001 x i32], align 16
@op = external dso_local global [500001 x i8], align 16
@a = external dso_local global [500001 x %"struct.std::pair"], align 16
@sta = external dso_local global i64, align 8
@ans = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z8seg_initii(i32 noundef, 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 uwtable
declare dso_local void @_Z7seg_addiiiii(i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) #0

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

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

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #2 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca [3 x i8], align 1
  %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
  store i32 0, ptr %1, align 4
  %11 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @t)
  br label %12

12:                                               ; preds = %220, %82, %0
  %13 = load i32, ptr @t, align 4, !tbaa !5
  %14 = add nsw i32 %13, -1
  store i32 %14, ptr @t, align 4, !tbaa !5
  %15 = icmp ne i32 %13, 0
  br i1 %15, label %16, label %226

16:                                               ; preds = %12
  %17 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @n, ptr noundef @m)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %18

18:                                               ; preds = %31, %16
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = load i32, ptr @n, align 4, !tbaa !5
  %21 = icmp slt i32 %19, %20
  br i1 %21, label %23, label %22

22:                                               ; preds = %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  br label %34

23:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 3, ptr %3) #5
  %24 = getelementptr inbounds [3 x i8], ptr %3, i64 0, i64 0
  %25 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.2, ptr noundef %24)
  %26 = getelementptr inbounds [3 x i8], ptr %3, i64 0, i64 0
  %27 = load i8, ptr %26, align 1, !tbaa !9
  %28 = load i32, ptr %2, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [500001 x i8], ptr @op, i64 0, i64 %29
  store i8 %27, ptr %30, align 1, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 3, ptr %3) #5
  br label %31

31:                                               ; preds = %23
  %32 = load i32, ptr %2, align 4, !tbaa !5
  %33 = add nsw i32 %32, 1
  store i32 %33, ptr %2, align 4, !tbaa !5
  br label %18, !llvm.loop !10

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

35:                                               ; preds = %58, %34
  %36 = load i32, ptr %4, align 4, !tbaa !5
  %37 = load i32, ptr @m, align 4, !tbaa !5
  %38 = icmp sle i32 %36, %37
  br i1 %38, label %40, label %39

39:                                               ; preds = %35
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  br label %61

40:                                               ; preds = %35
  %41 = load i32, ptr %4, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [500001 x %"struct.std::pair"], ptr @a, i64 0, i64 %42
  %44 = getelementptr inbounds %"struct.std::pair", ptr %43, i32 0, i32 1
  %45 = load i32, ptr %4, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [500001 x %"struct.std::pair"], ptr @a, i64 0, i64 %46
  %48 = getelementptr inbounds %"struct.std::pair", ptr %47, i32 0, i32 0
  %49 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %44, ptr noundef %48)
  %50 = load i32, ptr %4, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [500001 x %"struct.std::pair"], ptr @a, i64 0, i64 %51
  %53 = getelementptr inbounds %"struct.std::pair", ptr %52, i32 0, i32 1
  %54 = load i32, ptr %53, align 4, !tbaa !12
  %55 = load i32, ptr %4, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [500001 x i32], ptr @que, i64 0, i64 %56
  store i32 %54, ptr %57, align 4, !tbaa !5
  br label %58

58:                                               ; preds = %40
  %59 = load i32, ptr %4, align 4, !tbaa !5
  %60 = add nsw i32 %59, 1
  store i32 %60, ptr %4, align 4, !tbaa !5
  br label %35, !llvm.loop !14

61:                                               ; preds = %39
  %62 = load i32, ptr @m, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds %"struct.std::pair", ptr @a, i64 %63
  %65 = getelementptr inbounds %"struct.std::pair", ptr %64, i64 1
  call void @_ZSt4sortIPSt4pairIiiEEvT_S3_(ptr noundef getelementptr inbounds (%"struct.std::pair", ptr @a, i64 1), ptr noundef %65)
  %66 = load i32, ptr @m, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds i32, ptr @que, i64 %67
  %69 = getelementptr inbounds i32, ptr %68, i64 1
  call void @_ZSt4sortIPiEvT_S1_(ptr noundef getelementptr inbounds (i32, ptr @que, i64 1), ptr noundef %69)
  %70 = load i32, ptr @m, align 4, !tbaa !5
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds i32, ptr @que, i64 %71
  %73 = getelementptr inbounds i32, ptr %72, i64 1
  %74 = call noundef ptr @_ZSt6uniqueIPiET_S1_S1_(ptr noundef getelementptr inbounds (i32, ptr @que, i64 1), ptr noundef %73)
  %75 = ptrtoint ptr %74 to i64
  %76 = sub i64 %75, ptrtoint (ptr @que to i64)
  %77 = sdiv exact i64 %76, 4
  %78 = sub nsw i64 %77, 1
  %79 = trunc i64 %78 to i32
  store i32 %79, ptr @tot, align 4, !tbaa !5
  %80 = load i32, ptr @tot, align 4, !tbaa !5
  %81 = icmp eq i32 %80, 1
  br i1 %81, label %82, label %84

82:                                               ; preds = %61
  %83 = call i32 @puts(ptr noundef @.str.3)
  br label %12, !llvm.loop !15

84:                                               ; preds = %61
  store i64 0, ptr @sta, align 8, !tbaa !16
  %85 = load i32, ptr @tot, align 4, !tbaa !5
  %86 = sub nsw i32 %85, 1
  call void @_Z8seg_initii(i32 noundef 1, i32 noundef %86)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store i32 1, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  store i32 1, ptr %6, align 4, !tbaa !5
  br label %87

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

91:                                               ; preds = %87
  store i32 10, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  br label %220

92:                                               ; preds = %87
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  store i32 0, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  %93 = load i32, ptr %6, align 4, !tbaa !5
  store i32 %93, ptr %10, align 4, !tbaa !5
  br label %94

94:                                               ; preds = %137, %92
  %95 = load i32, ptr %10, align 4, !tbaa !5
  %96 = load i32, ptr @m, align 4, !tbaa !5
  %97 = icmp sle i32 %95, %96
  br i1 %97, label %98, label %106

98:                                               ; preds = %94
  %99 = load i32, ptr %10, align 4, !tbaa !5
  %100 = sext i32 %99 to i64
  %101 = getelementptr inbounds [500001 x %"struct.std::pair"], ptr @a, i64 0, i64 %100
  %102 = getelementptr inbounds %"struct.std::pair", ptr %101, i32 0, i32 0
  %103 = load i32, ptr %102, align 8, !tbaa !18
  %104 = load i32, ptr %5, align 4, !tbaa !5
  %105 = icmp eq i32 %103, %104
  br label %106

106:                                              ; preds = %98, %94
  %107 = phi i1 [ false, %94 ], [ %105, %98 ]
  br i1 %107, label %109, label %108

108:                                              ; preds = %106
  store i32 13, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  br label %142

109:                                              ; preds = %106
  %110 = load i32, ptr %10, align 4, !tbaa !5
  %111 = sext i32 %110 to i64
  %112 = getelementptr inbounds [500001 x %"struct.std::pair"], ptr @a, i64 0, i64 %111
  %113 = getelementptr inbounds %"struct.std::pair", ptr %112, i32 0, i32 1
  %114 = load i32, ptr %113, align 4, !tbaa !12
  %115 = load i32, ptr getelementptr inbounds ([500001 x i32], ptr @que, i64 0, i64 1), align 4, !tbaa !5
  %116 = sub nsw i32 %114, %115
  %117 = sext i32 %116 to i64
  %118 = load i64, ptr @sta, align 8, !tbaa !16
  %119 = add nsw i64 %118, %117
  store i64 %119, ptr @sta, align 8, !tbaa !16
  %120 = load i32, ptr @tot, align 4, !tbaa !5
  %121 = sext i32 %120 to i64
  %122 = getelementptr inbounds i32, ptr @que, i64 %121
  %123 = getelementptr inbounds i32, ptr %122, i64 1
  %124 = load i32, ptr %10, align 4, !tbaa !5
  %125 = sext i32 %124 to i64
  %126 = getelementptr inbounds [500001 x %"struct.std::pair"], ptr @a, i64 0, i64 %125
  %127 = getelementptr inbounds %"struct.std::pair", ptr %126, i32 0, i32 1
  %128 = call noundef ptr @_ZSt11lower_boundIPiiET_S1_S1_RKT0_(ptr noundef getelementptr inbounds (i32, ptr @que, i64 1), ptr noundef %123, ptr noundef nonnull align 4 dereferenceable(4) %127)
  %129 = ptrtoint ptr %128 to i64
  %130 = sub i64 %129, ptrtoint (ptr @que to i64)
  %131 = sdiv exact i64 %130, 4
  %132 = trunc i64 %131 to i32
  %133 = load i32, ptr %10, align 4, !tbaa !5
  %134 = sext i32 %133 to i64
  %135 = getelementptr inbounds [500001 x %"struct.std::pair"], ptr @a, i64 0, i64 %134
  %136 = getelementptr inbounds %"struct.std::pair", ptr %135, i32 0, i32 1
  store i32 %132, ptr %136, align 4, !tbaa !12
  br label %137

137:                                              ; preds = %109
  %138 = load i32, ptr %10, align 4, !tbaa !5
  %139 = add nsw i32 %138, 1
  store i32 %139, ptr %10, align 4, !tbaa !5
  %140 = load i32, ptr %8, align 4, !tbaa !5
  %141 = add nsw i32 %140, -1
  store i32 %141, ptr %8, align 4, !tbaa !5
  br label %94, !llvm.loop !19

142:                                              ; preds = %108
  store i32 1, ptr %9, align 4, !tbaa !5
  br label %143

143:                                              ; preds = %182, %142
  %144 = load i32, ptr %6, align 4, !tbaa !5
  %145 = load i32, ptr @m, align 4, !tbaa !5
  %146 = icmp sle i32 %144, %145
  br i1 %146, label %147, label %155

147:                                              ; preds = %143
  %148 = load i32, ptr %6, align 4, !tbaa !5
  %149 = sext i32 %148 to i64
  %150 = getelementptr inbounds [500001 x %"struct.std::pair"], ptr @a, i64 0, i64 %149
  %151 = getelementptr inbounds %"struct.std::pair", ptr %150, i32 0, i32 0
  %152 = load i32, ptr %151, align 8, !tbaa !18
  %153 = load i32, ptr %5, align 4, !tbaa !5
  %154 = icmp eq i32 %152, %153
  br label %155

155:                                              ; preds = %147, %143
  %156 = phi i1 [ false, %143 ], [ %154, %147 ]
  br i1 %156, label %157, label %187

157:                                              ; preds = %155
  %158 = load i32, ptr %9, align 4, !tbaa !5
  %159 = load i32, ptr %6, align 4, !tbaa !5
  %160 = sext i32 %159 to i64
  %161 = getelementptr inbounds [500001 x %"struct.std::pair"], ptr @a, i64 0, i64 %160
  %162 = getelementptr inbounds %"struct.std::pair", ptr %161, i32 0, i32 1
  %163 = load i32, ptr %162, align 4, !tbaa !12
  %164 = icmp slt i32 %158, %163
  br i1 %164, label %165, label %176

165:                                              ; preds = %157
  %166 = load i32, ptr @tot, align 4, !tbaa !5
  %167 = sub nsw i32 %166, 1
  %168 = load i32, ptr %9, align 4, !tbaa !5
  %169 = load i32, ptr %6, align 4, !tbaa !5
  %170 = sext i32 %169 to i64
  %171 = getelementptr inbounds [500001 x %"struct.std::pair"], ptr @a, i64 0, i64 %170
  %172 = getelementptr inbounds %"struct.std::pair", ptr %171, i32 0, i32 1
  %173 = load i32, ptr %172, align 4, !tbaa !12
  %174 = sub nsw i32 %173, 1
  %175 = load i32, ptr %8, align 4, !tbaa !5
  call void @_Z7seg_addiiiii(i32 noundef 1, i32 noundef %167, i32 noundef %168, i32 noundef %174, i32 noundef %175)
  br label %176

176:                                              ; preds = %165, %157
  %177 = load i32, ptr %6, align 4, !tbaa !5
  %178 = sext i32 %177 to i64
  %179 = getelementptr inbounds [500001 x %"struct.std::pair"], ptr @a, i64 0, i64 %178
  %180 = getelementptr inbounds %"struct.std::pair", ptr %179, i32 0, i32 1
  %181 = load i32, ptr %180, align 4, !tbaa !12
  store i32 %181, ptr %9, align 4, !tbaa !5
  br label %182

182:                                              ; preds = %176
  %183 = load i32, ptr %6, align 4, !tbaa !5
  %184 = add nsw i32 %183, 1
  store i32 %184, ptr %6, align 4, !tbaa !5
  %185 = load i32, ptr %8, align 4, !tbaa !5
  %186 = add nsw i32 %185, 2
  store i32 %186, ptr %8, align 4, !tbaa !5
  br label %143, !llvm.loop !20

187:                                              ; preds = %155
  %188 = load i32, ptr %9, align 4, !tbaa !5
  %189 = load i32, ptr @tot, align 4, !tbaa !5
  %190 = icmp slt i32 %188, %189
  br i1 %190, label %191, label %198

191:                                              ; preds = %187
  %192 = load i32, ptr @tot, align 4, !tbaa !5
  %193 = sub nsw i32 %192, 1
  %194 = load i32, ptr %9, align 4, !tbaa !5
  %195 = load i32, ptr @tot, align 4, !tbaa !5
  %196 = sub nsw i32 %195, 1
  %197 = load i32, ptr %8, align 4, !tbaa !5
  call void @_Z7seg_addiiiii(i32 noundef 1, i32 noundef %193, i32 noundef %194, i32 noundef %196, i32 noundef %197)
  br label %198

198:                                              ; preds = %191, %187
  %199 = load i32, ptr %5, align 4, !tbaa !5
  %200 = load i32, ptr @n, align 4, !tbaa !5
  %201 = icmp slt i32 %199, %200
  br i1 %201, label %202, label %216

202:                                              ; preds = %198
  %203 = load i32, ptr %5, align 4, !tbaa !5
  %204 = sext i32 %203 to i64
  %205 = getelementptr inbounds [500001 x i8], ptr @op, i64 0, i64 %204
  %206 = load i8, ptr %205, align 1, !tbaa !9
  %207 = sext i8 %206 to i32
  %208 = icmp eq i32 %207, 60
  br i1 %208, label %209, label %212

209:                                              ; preds = %202
  %210 = load i32, ptr @tot, align 4, !tbaa !5
  %211 = sub nsw i32 %210, 1
  call void @_Z15seg_erase_rightii(i32 noundef 1, i32 noundef %211)
  br label %215

212:                                              ; preds = %202
  %213 = load i32, ptr @tot, align 4, !tbaa !5
  %214 = sub nsw i32 %213, 1
  call void @_Z14seg_erase_leftii(i32 noundef 1, i32 noundef %214)
  br label %215

215:                                              ; preds = %212, %209
  br label %216

216:                                              ; preds = %215, %198
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  br label %217

217:                                              ; preds = %216
  %218 = load i32, ptr %5, align 4, !tbaa !5
  %219 = add nsw i32 %218, 1
  store i32 %219, ptr %5, align 4, !tbaa !5
  br label %87, !llvm.loop !21

220:                                              ; preds = %91
  %221 = load i64, ptr @sta, align 8, !tbaa !16
  store i64 %221, ptr @ans, align 8, !tbaa !16
  %222 = load i32, ptr @tot, align 4, !tbaa !5
  %223 = sub nsw i32 %222, 1
  call void @_Z8seg_calcii(i32 noundef 1, i32 noundef %223)
  %224 = load i64, ptr @ans, align 8, !tbaa !16
  %225 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, i64 noundef %224)
  br label %12, !llvm.loop !15

226:                                              ; preds = %12
  ret i32 0
}

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

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

; 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

declare i32 @puts(ptr noundef) #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)) #4

declare i32 @printf(ptr noundef, ...) #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 = { 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 = { 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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = !{!13, !6, i64 4}
!13 = !{!"_ZTSSt4pairIiiE", !6, i64 0, !6, i64 4}
!14 = distinct !{!14, !11}
!15 = distinct !{!15, !11}
!16 = !{!17, !17, i64 0}
!17 = !{!"long long", !7, i64 0}
!18 = !{!13, !6, i64 0}
!19 = distinct !{!19, !11}
!20 = distinct !{!20, !11}
!21 = distinct !{!21, !11}


; 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.std::pair" = type { i32, i32 }

@t = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@tot = external dso_local local_unnamed_addr global i32, align 4
@que = external dso_local global [500001 x i32], align 16
@op = external dso_local local_unnamed_addr global [500001 x i8], align 16
@a = external dso_local global [500001 x %"struct.std::pair"], align 16
@sta = external dso_local local_unnamed_addr global i64, align 8
@ans = external dso_local local_unnamed_addr global i64, align 8
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [6 x i8], align 1

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

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

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

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

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

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

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #2 {
  %1 = alloca [3 x i8], align 1
  %2 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @t)
  %3 = load i32, ptr @t, align 4, !tbaa !5
  %4 = add nsw i32 %3, -1
  store i32 %4, ptr @t, align 4, !tbaa !5
  %.not83 = icmp eq i32 %3, 0
  br i1 %.not83, label %._crit_edge86, label %.lr.ph85

.lr.ph85:                                         ; preds = %0, %.backedge
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @n, ptr noundef nonnull @m)
  %6 = load i32, ptr @n, align 4, !tbaa !5
  %7 = icmp sgt i32 %6, 1
  br i1 %7, label %.lr.ph, label %.preheader52

.preheader52:                                     ; preds = %.lr.ph, %.lr.ph85
  %8 = load i32, ptr @m, align 4, !tbaa !5
  %.not4854 = icmp slt i32 %8, 1
  br i1 %.not4854, label %.preheader52.._crit_edge_crit_edge, label %.lr.ph56

.preheader52.._crit_edge_crit_edge:               ; preds = %.preheader52
  %.pre103 = sext i32 %8 to i64
  br label %._crit_edge

.lr.ph:                                           ; preds = %.lr.ph85, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 1, %.lr.ph85 ]
  call void @llvm.lifetime.start.p0(i64 3, ptr nonnull %1) #5
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.2, ptr noundef nonnull %1)
  %10 = load i8, ptr %1, align 1, !tbaa !9
  %11 = getelementptr inbounds [500001 x i8], ptr @op, i64 0, i64 %indvars.iv
  store i8 %10, ptr %11, align 1, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 3, ptr nonnull %1) #5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %12 = load i32, ptr @n, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = icmp slt i64 %indvars.iv.next, %13
  br i1 %14, label %.lr.ph, label %.preheader52, !llvm.loop !10

._crit_edge:                                      ; preds = %.lr.ph56, %.preheader52.._crit_edge_crit_edge
  %.pre-phi = phi i64 [ %.pre103, %.preheader52.._crit_edge_crit_edge ], [ %32, %.lr.ph56 ]
  %gep80 = getelementptr %"struct.std::pair", ptr getelementptr inbounds (i8, ptr @a, i64 8), i64 %.pre-phi
  call void @_ZSt4sortIPSt4pairIiiEEvT_S3_(ptr noundef nonnull getelementptr inbounds (i8, ptr @a, i64 8), ptr noundef nonnull %gep80)
  %15 = load i32, ptr @m, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %gep81 = getelementptr i32, ptr getelementptr inbounds (i8, ptr @que, i64 4), i64 %16
  call void @_ZSt4sortIPiEvT_S1_(ptr noundef nonnull getelementptr inbounds (i8, ptr @que, i64 4), ptr noundef nonnull %gep81)
  %17 = load i32, ptr @m, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %gep82 = getelementptr i32, ptr getelementptr inbounds (i8, ptr @que, i64 4), i64 %18
  %19 = call noundef ptr @_ZSt6uniqueIPiET_S1_S1_(ptr noundef nonnull getelementptr inbounds (i8, ptr @que, i64 4), ptr noundef nonnull %gep82)
  %20 = ptrtoint ptr %19 to i64
  %21 = sub i64 %20, ptrtoint (ptr @que to i64)
  %22 = lshr exact i64 %21, 2
  %23 = trunc i64 %22 to i32
  %24 = add i32 %23, -1
  store i32 %24, ptr @tot, align 4, !tbaa !5
  %25 = icmp eq i32 %24, 1
  br i1 %25, label %33, label %37

.lr.ph56:                                         ; preds = %.preheader52, %.lr.ph56
  %indvars.iv89 = phi i64 [ %indvars.iv.next90, %.lr.ph56 ], [ 1, %.preheader52 ]
  %26 = getelementptr inbounds [500001 x %"struct.std::pair"], ptr @a, i64 0, i64 %indvars.iv89
  %27 = getelementptr inbounds i8, ptr %26, i64 4
  %28 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %27, ptr noundef nonnull %26)
  %29 = load i32, ptr %27, align 4, !tbaa !12
  %30 = getelementptr inbounds [500001 x i32], ptr @que, i64 0, i64 %indvars.iv89
  store i32 %29, ptr %30, align 4, !tbaa !5
  %indvars.iv.next90 = add nuw nsw i64 %indvars.iv89, 1
  %31 = load i32, ptr @m, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %.not48.not = icmp slt i64 %indvars.iv89, %32
  br i1 %.not48.not, label %.lr.ph56, label %._crit_edge, !llvm.loop !14

33:                                               ; preds = %._crit_edge
  %34 = call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.3)
  br label %.backedge

.backedge:                                        ; preds = %33, %._crit_edge79
  %35 = load i32, ptr @t, align 4, !tbaa !5
  %36 = add nsw i32 %35, -1
  store i32 %36, ptr @t, align 4, !tbaa !5
  %.not = icmp eq i32 %35, 0
  br i1 %.not, label %._crit_edge86, label %.lr.ph85, !llvm.loop !15

37:                                               ; preds = %._crit_edge
  store i64 0, ptr @sta, align 8, !tbaa !16
  %38 = add i32 %23, -2
  call void @_Z8seg_initii(i32 noundef 1, i32 noundef %38)
  %39 = load i32, ptr @n, align 4, !tbaa !5
  %.not4976 = icmp slt i32 %39, 1
  br i1 %.not4976, label %._crit_edge79, label %.preheader

.preheader:                                       ; preds = %37, %108
  %indvars.iv98 = phi i64 [ %indvars.iv.next99, %108 ], [ 1, %37 ]
  %.04078 = phi i32 [ %.141.lcssa, %108 ], [ 1, %37 ]
  %40 = load i32, ptr @m, align 4, !tbaa !5
  %.not5057 = icmp sgt i32 %.04078, %40
  br i1 %.not5057, label %.critedge, label %.lr.ph60.preheader

.lr.ph60.preheader:                               ; preds = %.preheader
  %41 = sext i32 %.04078 to i64
  %42 = getelementptr inbounds [500001 x %"struct.std::pair"], ptr @a, i64 0, i64 %41
  %43 = load i32, ptr %42, align 8, !tbaa !18
  %44 = zext i32 %43 to i64
  %45 = icmp eq i64 %indvars.iv98, %44
  br i1 %45, label %.lr.ph106, label %.critedge

._crit_edge79:                                    ; preds = %108, %37
  %46 = load i64, ptr @sta, align 8, !tbaa !16
  store i64 %46, ptr @ans, align 8, !tbaa !16
  %47 = load i32, ptr @tot, align 4, !tbaa !5
  %48 = add nsw i32 %47, -1
  call void @_Z8seg_calcii(i32 noundef 1, i32 noundef %48)
  %49 = load i64, ptr @ans, align 8, !tbaa !16
  %50 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, i64 noundef %49)
  br label %.backedge

.lr.ph60:                                         ; preds = %.lr.ph106
  %indvars.iv.next93 = add nsw i64 %indvars.iv92104, 1
  %51 = getelementptr inbounds [500001 x %"struct.std::pair"], ptr @a, i64 0, i64 %indvars.iv.next93
  %52 = load i32, ptr %51, align 8, !tbaa !18
  %53 = zext i32 %52 to i64
  %54 = icmp eq i64 %indvars.iv98, %53
  br i1 %54, label %.lr.ph106, label %.critedge, !llvm.loop !19

.critedge:                                        ; preds = %.lr.ph106, %.lr.ph60, %.lr.ph60.preheader, %.preheader
  %55 = phi i32 [ %40, %.preheader ], [ %40, %.lr.ph60.preheader ], [ %72, %.lr.ph60 ], [ %72, %.lr.ph106 ]
  %.039.lcssa = phi i32 [ 0, %.preheader ], [ 0, %.lr.ph60.preheader ], [ %71, %.lr.ph60 ], [ %71, %.lr.ph106 ]
  %.not5164 = icmp sgt i32 %.04078, %55
  br i1 %.not5164, label %.critedge2, label %.lr.ph68.preheader

.lr.ph68.preheader:                               ; preds = %.critedge
  %56 = sext i32 %.04078 to i64
  br label %.lr.ph68

.lr.ph106:                                        ; preds = %.lr.ph60.preheader, %.lr.ph60
  %.03958105 = phi i32 [ %71, %.lr.ph60 ], [ 0, %.lr.ph60.preheader ]
  %indvars.iv92104 = phi i64 [ %indvars.iv.next93, %.lr.ph60 ], [ %41, %.lr.ph60.preheader ]
  %57 = getelementptr inbounds [500001 x %"struct.std::pair"], ptr @a, i64 0, i64 %indvars.iv92104, i32 1
  %58 = load i32, ptr %57, align 4, !tbaa !12
  %59 = load i32, ptr getelementptr inbounds (i8, ptr @que, i64 4), align 4, !tbaa !5
  %60 = sub nsw i32 %58, %59
  %61 = sext i32 %60 to i64
  %62 = load i64, ptr @sta, align 8, !tbaa !16
  %63 = add nsw i64 %62, %61
  store i64 %63, ptr @sta, align 8, !tbaa !16
  %64 = load i32, ptr @tot, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %gep = getelementptr i32, ptr getelementptr inbounds (i8, ptr @que, i64 4), i64 %65
  %66 = call noundef ptr @_ZSt11lower_boundIPiiET_S1_S1_RKT0_(ptr noundef nonnull getelementptr inbounds (i8, ptr @que, i64 4), ptr noundef nonnull %gep, ptr noundef nonnull align 4 dereferenceable(4) %57)
  %67 = ptrtoint ptr %66 to i64
  %68 = sub i64 %67, ptrtoint (ptr @que to i64)
  %69 = lshr exact i64 %68, 2
  %70 = trunc i64 %69 to i32
  store i32 %70, ptr %57, align 4, !tbaa !12
  %71 = add nsw i32 %.03958105, -1
  %72 = load i32, ptr @m, align 4, !tbaa !5
  %73 = sext i32 %72 to i64
  %.not50.not = icmp slt i64 %indvars.iv92104, %73
  br i1 %.not50.not, label %.lr.ph60, label %.critedge, !llvm.loop !19

.lr.ph68:                                         ; preds = %.lr.ph68.preheader, %87
  %74 = phi i32 [ %55, %.lr.ph68.preheader ], [ %88, %87 ]
  %indvars.iv95 = phi i64 [ %56, %.lr.ph68.preheader ], [ %indvars.iv.next96, %87 ]
  %.03867 = phi i32 [ 1, %.lr.ph68.preheader ], [ %89, %87 ]
  %.166 = phi i32 [ %.039.lcssa, %.lr.ph68.preheader ], [ %90, %87 ]
  %75 = getelementptr inbounds [500001 x %"struct.std::pair"], ptr @a, i64 0, i64 %indvars.iv95
  %76 = load i32, ptr %75, align 8, !tbaa !18
  %77 = zext i32 %76 to i64
  %78 = icmp eq i64 %indvars.iv98, %77
  br i1 %78, label %79, label %.critedge2.loopexit

79:                                               ; preds = %.lr.ph68
  %80 = getelementptr inbounds i8, ptr %75, i64 4
  %81 = load i32, ptr %80, align 4, !tbaa !12
  %82 = icmp slt i32 %.03867, %81
  br i1 %82, label %83, label %87

83:                                               ; preds = %79
  %84 = load i32, ptr @tot, align 4, !tbaa !5
  %85 = add nsw i32 %84, -1
  %86 = add nsw i32 %81, -1
  call void @_Z7seg_addiiiii(i32 noundef 1, i32 noundef %85, i32 noundef %.03867, i32 noundef %86, i32 noundef %.166)
  %.pre = load i32, ptr %80, align 4, !tbaa !12
  %.pre102 = load i32, ptr @m, align 4, !tbaa !5
  br label %87

87:                                               ; preds = %83, %79
  %88 = phi i32 [ %.pre102, %83 ], [ %74, %79 ]
  %89 = phi i32 [ %.pre, %83 ], [ %81, %79 ]
  %indvars.iv.next96 = add nsw i64 %indvars.iv95, 1
  %90 = add nsw i32 %.166, 2
  %91 = sext i32 %88 to i64
  %.not51.not = icmp slt i64 %indvars.iv95, %91
  br i1 %.not51.not, label %.lr.ph68, label %.critedge2.loopexit, !llvm.loop !20

.critedge2.loopexit:                              ; preds = %87, %.lr.ph68
  %.141.lcssa.ph.in = phi i64 [ %indvars.iv95, %.lr.ph68 ], [ %indvars.iv.next96, %87 ]
  %.1.lcssa.ph = phi i32 [ %.166, %.lr.ph68 ], [ %90, %87 ]
  %.038.lcssa.ph = phi i32 [ %.03867, %.lr.ph68 ], [ %89, %87 ]
  %.141.lcssa.ph = trunc i64 %.141.lcssa.ph.in to i32
  br label %.critedge2

.critedge2:                                       ; preds = %.critedge2.loopexit, %.critedge
  %.141.lcssa = phi i32 [ %.04078, %.critedge ], [ %.141.lcssa.ph, %.critedge2.loopexit ]
  %.1.lcssa = phi i32 [ %.039.lcssa, %.critedge ], [ %.1.lcssa.ph, %.critedge2.loopexit ]
  %.038.lcssa = phi i32 [ 1, %.critedge ], [ %.038.lcssa.ph, %.critedge2.loopexit ]
  %92 = load i32, ptr @tot, align 4, !tbaa !5
  %93 = icmp slt i32 %.038.lcssa, %92
  br i1 %93, label %94, label %96

94:                                               ; preds = %.critedge2
  %95 = add nsw i32 %92, -1
  call void @_Z7seg_addiiiii(i32 noundef 1, i32 noundef %95, i32 noundef %.038.lcssa, i32 noundef %95, i32 noundef %.1.lcssa)
  br label %96

96:                                               ; preds = %94, %.critedge2
  %97 = load i32, ptr @n, align 4, !tbaa !5
  %98 = sext i32 %97 to i64
  %99 = icmp slt i64 %indvars.iv98, %98
  br i1 %99, label %100, label %108

100:                                              ; preds = %96
  %101 = getelementptr inbounds [500001 x i8], ptr @op, i64 0, i64 %indvars.iv98
  %102 = load i8, ptr %101, align 1, !tbaa !9
  %103 = icmp eq i8 %102, 60
  %104 = load i32, ptr @tot, align 4, !tbaa !5
  %105 = add nsw i32 %104, -1
  br i1 %103, label %106, label %107

106:                                              ; preds = %100
  call void @_Z15seg_erase_rightii(i32 noundef 1, i32 noundef %105)
  br label %108

107:                                              ; preds = %100
  call void @_Z14seg_erase_leftii(i32 noundef 1, i32 noundef %105)
  br label %108

108:                                              ; preds = %106, %107, %96
  %indvars.iv.next99 = add nuw nsw i64 %indvars.iv98, 1
  %109 = load i32, ptr @n, align 4, !tbaa !5
  %110 = sext i32 %109 to i64
  %.not49.not = icmp slt i64 %indvars.iv98, %110
  br i1 %.not49.not, label %.preheader, label %._crit_edge79, !llvm.loop !21

._crit_edge86:                                    ; preds = %.backedge, %0
  ret i32 0
}

; 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 @_ZSt4sortIPSt4pairIiiEEvT_S3_(ptr noundef, ptr noundef) local_unnamed_addr #4

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

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

; Function Attrs: nofree nounwind
declare noundef i32 @puts(ptr nocapture noundef readonly) 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 #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 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 = { 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" }
attributes #5 = { nounwind }

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

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


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