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

; 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 }
%struct.Query = type { i32, i32, i32 }

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@qtot = external dso_local global i32, align 4
@stot = external dso_local global i32, align 4
@que = external dso_local global [500001 x i32], align 16
@ans = external dso_local global [500001 x i32], align 16
@a = external dso_local global [500001 x %"struct.std::pair"], align 16
@seq = external dso_local global [2000005 x %struct.Query], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z3aski(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
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %13 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @m)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #7
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %14

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

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

19:                                               ; preds = %14
  %20 = load i32, ptr %2, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [500001 x %"struct.std::pair"], ptr @a, i64 0, i64 %21
  %23 = getelementptr inbounds %"struct.std::pair", ptr %22, i32 0, i32 0
  %24 = load i32, ptr %2, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [500001 x %"struct.std::pair"], ptr @a, i64 0, i64 %25
  %27 = getelementptr inbounds %"struct.std::pair", ptr %26, i32 0, i32 1
  %28 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %23, ptr noundef %27)
  %29 = load i32, ptr %2, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [500001 x %"struct.std::pair"], ptr @a, i64 0, i64 %30
  %32 = getelementptr inbounds %"struct.std::pair", ptr %31, i32 0, i32 1
  %33 = load i32, ptr %32, align 4, !tbaa !9
  %34 = load i32, ptr %2, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [500001 x i32], ptr @que, i64 0, i64 %35
  store i32 %33, ptr %36, align 4, !tbaa !5
  br label %37

37:                                               ; preds = %19
  %38 = load i32, ptr %2, align 4, !tbaa !5
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr %2, align 4, !tbaa !5
  br label %14, !llvm.loop !11

40:                                               ; preds = %18
  %41 = load i32, ptr @n, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds %"struct.std::pair", ptr @a, i64 %42
  call void @_ZSt4sortIPSt4pairIiiEEvT_S3_(ptr noundef @a, ptr noundef %43)
  %44 = load i32, ptr @n, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds i32, ptr @que, i64 %45
  call void @_ZSt4sortIPiEvT_S1_(ptr noundef @que, ptr noundef %46)
  %47 = load i32, ptr @n, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds i32, ptr @que, i64 %48
  %50 = call noundef ptr @_ZSt6uniqueIPiET_S1_S1_(ptr noundef @que, ptr noundef %49)
  %51 = ptrtoint ptr %50 to i64
  %52 = sub i64 %51, ptrtoint (ptr @que to i64)
  %53 = sdiv exact i64 %52, 4
  %54 = trunc i64 %53 to i32
  store i32 %54, ptr @qtot, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #7
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %55

55:                                               ; preds = %100, %40
  %56 = load i32, ptr %3, align 4, !tbaa !5
  %57 = load i32, ptr @m, align 4, !tbaa !5
  %58 = icmp slt i32 %56, %57
  br i1 %58, label %60, label %59

59:                                               ; preds = %55
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #7
  br label %103

60:                                               ; preds = %55
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #7
  %61 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %4, ptr noundef %5, ptr noundef %6, ptr noundef %7)
  %62 = load i32, ptr %4, align 4, !tbaa !5
  %63 = add nsw i32 %62, -1
  store i32 %63, ptr %4, align 4, !tbaa !5
  %64 = load i32, ptr @qtot, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds i32, ptr @que, i64 %65
  %67 = call noundef ptr @_ZSt11lower_boundIPiiET_S1_S1_RKT0_(ptr noundef @que, ptr noundef %66, ptr noundef nonnull align 4 dereferenceable(4) %5)
  %68 = ptrtoint ptr %67 to i64
  %69 = sub i64 %68, ptrtoint (ptr @que to i64)
  %70 = sdiv exact i64 %69, 4
  %71 = trunc i64 %70 to i32
  store i32 %71, ptr %5, align 4, !tbaa !5
  %72 = load i32, ptr @qtot, align 4, !tbaa !5
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds i32, ptr @que, i64 %73
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #7
  %75 = load i32, ptr %7, align 4, !tbaa !5
  %76 = add nsw i32 %75, 1
  store i32 %76, ptr %8, align 4, !tbaa !5
  %77 = call noundef ptr @_ZSt11lower_boundIPiiET_S1_S1_RKT0_(ptr noundef @que, ptr noundef %74, ptr noundef nonnull align 4 dereferenceable(4) %8)
  %78 = ptrtoint ptr %77 to i64
  %79 = sub i64 %78, ptrtoint (ptr @que to i64)
  %80 = sdiv exact i64 %79, 4
  %81 = trunc i64 %80 to i32
  store i32 %81, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #7
  %82 = load i32, ptr %3, align 4, !tbaa !5
  %83 = add nsw i32 %82, 1
  %84 = load i32, ptr %6, align 4, !tbaa !5
  %85 = load i32, ptr %7, align 4, !tbaa !5
  call void @_Z8addQueryiii(i32 noundef %83, i32 noundef %84, i32 noundef %85)
  %86 = load i32, ptr %3, align 4, !tbaa !5
  %87 = sub nsw i32 0, %86
  %88 = sub nsw i32 %87, 1
  %89 = load i32, ptr %4, align 4, !tbaa !5
  %90 = load i32, ptr %7, align 4, !tbaa !5
  call void @_Z8addQueryiii(i32 noundef %88, i32 noundef %89, i32 noundef %90)
  %91 = load i32, ptr %3, align 4, !tbaa !5
  %92 = sub nsw i32 0, %91
  %93 = sub nsw i32 %92, 1
  %94 = load i32, ptr %6, align 4, !tbaa !5
  %95 = load i32, ptr %5, align 4, !tbaa !5
  call void @_Z8addQueryiii(i32 noundef %93, i32 noundef %94, i32 noundef %95)
  %96 = load i32, ptr %3, align 4, !tbaa !5
  %97 = add nsw i32 %96, 1
  %98 = load i32, ptr %4, align 4, !tbaa !5
  %99 = load i32, ptr %5, align 4, !tbaa !5
  call void @_Z8addQueryiii(i32 noundef %97, i32 noundef %98, i32 noundef %99)
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #7
  br label %100

100:                                              ; preds = %60
  %101 = load i32, ptr %3, align 4, !tbaa !5
  %102 = add nsw i32 %101, 1
  store i32 %102, ptr %3, align 4, !tbaa !5
  br label %55, !llvm.loop !13

103:                                              ; preds = %59
  %104 = load i32, ptr @stot, align 4, !tbaa !5
  %105 = sext i32 %104 to i64
  %106 = getelementptr inbounds %struct.Query, ptr @seq, i64 %105
  call void @_ZSt4sortIP5QueryEvT_S2_(ptr noundef @seq, ptr noundef %106)
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #7
  store i32 0, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #7
  store i32 0, ptr %10, align 4, !tbaa !5
  br label %107

107:                                              ; preds = %184, %103
  %108 = load i32, ptr %9, align 4, !tbaa !5
  %109 = load i32, ptr @stot, align 4, !tbaa !5
  %110 = icmp slt i32 %108, %109
  br i1 %110, label %112, label %111

111:                                              ; preds = %107
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #7
  br label %187

112:                                              ; preds = %107
  br label %113

113:                                              ; preds = %145, %112
  %114 = load i32, ptr %10, align 4, !tbaa !5
  %115 = load i32, ptr @n, align 4, !tbaa !5
  %116 = icmp slt i32 %114, %115
  br i1 %116, label %117, label %129

117:                                              ; preds = %113
  %118 = load i32, ptr %10, align 4, !tbaa !5
  %119 = sext i32 %118 to i64
  %120 = getelementptr inbounds [500001 x %"struct.std::pair"], ptr @a, i64 0, i64 %119
  %121 = getelementptr inbounds %"struct.std::pair", ptr %120, i32 0, i32 0
  %122 = load i32, ptr %121, align 8, !tbaa !14
  %123 = load i32, ptr %9, align 4, !tbaa !5
  %124 = sext i32 %123 to i64
  %125 = getelementptr inbounds [2000005 x %struct.Query], ptr @seq, i64 0, i64 %124
  %126 = getelementptr inbounds %struct.Query, ptr %125, i32 0, i32 1
  %127 = load i32, ptr %126, align 4, !tbaa !15
  %128 = icmp sle i32 %122, %127
  br label %129

129:                                              ; preds = %117, %113
  %130 = phi i1 [ false, %113 ], [ %128, %117 ]
  br i1 %130, label %131, label %148

131:                                              ; preds = %129
  %132 = load i32, ptr @qtot, align 4, !tbaa !5
  %133 = sext i32 %132 to i64
  %134 = getelementptr inbounds i32, ptr @que, i64 %133
  %135 = load i32, ptr %10, align 4, !tbaa !5
  %136 = sext i32 %135 to i64
  %137 = getelementptr inbounds [500001 x %"struct.std::pair"], ptr @a, i64 0, i64 %136
  %138 = getelementptr inbounds %"struct.std::pair", ptr %137, i32 0, i32 1
  %139 = call noundef ptr @_ZSt11lower_boundIPiiET_S1_S1_RKT0_(ptr noundef @que, ptr noundef %134, ptr noundef nonnull align 4 dereferenceable(4) %138)
  %140 = ptrtoint ptr %139 to i64
  %141 = sub i64 %140, ptrtoint (ptr @que to i64)
  %142 = sdiv exact i64 %141, 4
  %143 = add nsw i64 %142, 1
  %144 = trunc i64 %143 to i32
  call void @_Z3updi(i32 noundef %144)
  br label %145

145:                                              ; preds = %131
  %146 = load i32, ptr %10, align 4, !tbaa !5
  %147 = add nsw i32 %146, 1
  store i32 %147, ptr %10, align 4, !tbaa !5
  br label %113, !llvm.loop !17

148:                                              ; preds = %129
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #7
  %149 = load i32, ptr %9, align 4, !tbaa !5
  %150 = sext i32 %149 to i64
  %151 = getelementptr inbounds [2000005 x %struct.Query], ptr @seq, i64 0, i64 %150
  %152 = getelementptr inbounds %struct.Query, ptr %151, i32 0, i32 0
  %153 = load i32, ptr %152, align 4, !tbaa !18
  %154 = call i32 @llvm.abs.i32(i32 %153, i1 true)
  %155 = sext i32 %154 to i64
  %156 = getelementptr inbounds [500001 x i32], ptr @ans, i64 0, i64 %155
  store ptr %156, ptr %11, align 8, !tbaa !19
  %157 = load i32, ptr %9, align 4, !tbaa !5
  %158 = sext i32 %157 to i64
  %159 = getelementptr inbounds [2000005 x %struct.Query], ptr @seq, i64 0, i64 %158
  %160 = getelementptr inbounds %struct.Query, ptr %159, i32 0, i32 0
  %161 = load i32, ptr %160, align 4, !tbaa !18
  %162 = icmp sgt i32 %161, 0
  br i1 %162, label %163, label %173

163:                                              ; preds = %148
  %164 = load i32, ptr %9, align 4, !tbaa !5
  %165 = sext i32 %164 to i64
  %166 = getelementptr inbounds [2000005 x %struct.Query], ptr @seq, i64 0, i64 %165
  %167 = getelementptr inbounds %struct.Query, ptr %166, i32 0, i32 2
  %168 = load i32, ptr %167, align 4, !tbaa !21
  %169 = call noundef i32 @_Z3aski(i32 noundef %168)
  %170 = load ptr, ptr %11, align 8, !tbaa !19
  %171 = load i32, ptr %170, align 4, !tbaa !5
  %172 = add nsw i32 %171, %169
  store i32 %172, ptr %170, align 4, !tbaa !5
  br label %183

173:                                              ; preds = %148
  %174 = load i32, ptr %9, align 4, !tbaa !5
  %175 = sext i32 %174 to i64
  %176 = getelementptr inbounds [2000005 x %struct.Query], ptr @seq, i64 0, i64 %175
  %177 = getelementptr inbounds %struct.Query, ptr %176, i32 0, i32 2
  %178 = load i32, ptr %177, align 4, !tbaa !21
  %179 = call noundef i32 @_Z3aski(i32 noundef %178)
  %180 = load ptr, ptr %11, align 8, !tbaa !19
  %181 = load i32, ptr %180, align 4, !tbaa !5
  %182 = sub nsw i32 %181, %179
  store i32 %182, ptr %180, align 4, !tbaa !5
  br label %183

183:                                              ; preds = %173, %163
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #7
  br label %184

184:                                              ; preds = %183
  %185 = load i32, ptr %9, align 4, !tbaa !5
  %186 = add nsw i32 %185, 1
  store i32 %186, ptr %9, align 4, !tbaa !5
  br label %107, !llvm.loop !22

187:                                              ; preds = %111
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #7
  store i32 1, ptr %12, align 4, !tbaa !5
  br label %188

188:                                              ; preds = %199, %187
  %189 = load i32, ptr %12, align 4, !tbaa !5
  %190 = load i32, ptr @m, align 4, !tbaa !5
  %191 = icmp sle i32 %189, %190
  br i1 %191, label %193, label %192

192:                                              ; preds = %188
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #7
  br label %202

193:                                              ; preds = %188
  %194 = load i32, ptr %12, align 4, !tbaa !5
  %195 = sext i32 %194 to i64
  %196 = getelementptr inbounds [500001 x i32], ptr @ans, i64 0, i64 %195
  %197 = load i32, ptr %196, align 4, !tbaa !5
  %198 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %197)
  br label %199

199:                                              ; preds = %193
  %200 = load i32, ptr %12, align 4, !tbaa !5
  %201 = add nsw i32 %200, 1
  store i32 %201, ptr %12, align 4, !tbaa !5
  br label %188, !llvm.loop !23

202:                                              ; preds = %192
  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

; 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 nounwind uwtable
declare dso_local void @_Z8addQueryiii(i32 noundef, i32 noundef, i32 noundef) #5

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #6

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 = { inlinehint mustprogress nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #6 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #7 = { nounwind }

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

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

%"struct.std::pair" = type { i32, i32 }
%struct.Query = type { i32, i32, i32 }

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@qtot = external dso_local local_unnamed_addr global i32, align 4
@stot = external dso_local local_unnamed_addr global i32, align 4
@que = external dso_local global [500001 x i32], align 16
@ans = external dso_local local_unnamed_addr global [500001 x i32], align 16
@a = external dso_local global [500001 x %"struct.std::pair"], align 16
@seq = external dso_local global [2000005 x %struct.Query], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z3aski(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 norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #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 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @m)
  %7 = load i32, ptr @n, align 4, !tbaa !5
  %8 = icmp sgt i32 %7, 0
  br i1 %8, label %.lr.ph, label %.._crit_edge_crit_edge

.._crit_edge_crit_edge:                           ; preds = %0
  %.pre = sext i32 %7 to i64
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %.._crit_edge_crit_edge
  %.pre-phi = phi i64 [ %.pre, %.._crit_edge_crit_edge ], [ %29, %.lr.ph ]
  %9 = getelementptr inbounds %"struct.std::pair", ptr @a, i64 %.pre-phi
  tail call void @_ZSt4sortIPSt4pairIiiEEvT_S3_(ptr noundef nonnull @a, ptr noundef nonnull %9)
  %10 = load i32, ptr @n, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds i32, ptr @que, i64 %11
  tail call void @_ZSt4sortIPiEvT_S1_(ptr noundef nonnull @que, ptr noundef nonnull %12)
  %13 = load i32, ptr @n, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds i32, ptr @que, i64 %14
  %16 = tail call noundef ptr @_ZSt6uniqueIPiET_S1_S1_(ptr noundef nonnull @que, ptr noundef nonnull %15)
  %17 = ptrtoint ptr %16 to i64
  %18 = sub i64 %17, ptrtoint (ptr @que to i64)
  %19 = lshr exact i64 %18, 2
  %20 = trunc i64 %19 to i32
  store i32 %20, ptr @qtot, align 4, !tbaa !5
  %21 = load i32, ptr @m, align 4, !tbaa !5
  %22 = icmp sgt i32 %21, 0
  br i1 %22, label %.lr.ph37, label %._crit_edge38

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %0 ]
  %23 = getelementptr inbounds [500001 x %"struct.std::pair"], ptr @a, i64 0, i64 %indvars.iv
  %24 = getelementptr inbounds i8, ptr %23, i64 4
  %25 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %23, ptr noundef nonnull %24)
  %26 = load i32, ptr %24, align 4, !tbaa !9
  %27 = getelementptr inbounds [500001 x i32], ptr @que, i64 0, i64 %indvars.iv
  store i32 %26, ptr %27, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %28 = load i32, ptr @n, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = icmp slt i64 %indvars.iv.next, %29
  br i1 %30, label %.lr.ph, label %._crit_edge, !llvm.loop !11

._crit_edge38:                                    ; preds = %.lr.ph37, %._crit_edge
  %31 = load i32, ptr @stot, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds %struct.Query, ptr @seq, i64 %32
  call void @_ZSt4sortIP5QueryEvT_S2_(ptr noundef nonnull @seq, ptr noundef nonnull %33)
  %34 = load i32, ptr @stot, align 4, !tbaa !5
  %35 = icmp sgt i32 %34, 0
  br i1 %35, label %.preheader33, label %.preheader

.lr.ph37:                                         ; preds = %._crit_edge, %.lr.ph37
  %.03035 = phi i32 [ %57, %.lr.ph37 ], [ 0, %._crit_edge ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #7
  %36 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %1, ptr noundef nonnull %2, ptr noundef nonnull %3, ptr noundef nonnull %4)
  %37 = load i32, ptr %1, align 4, !tbaa !5
  %38 = add nsw i32 %37, -1
  store i32 %38, ptr %1, align 4, !tbaa !5
  %39 = load i32, ptr @qtot, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds i32, ptr @que, i64 %40
  %42 = call noundef ptr @_ZSt11lower_boundIPiiET_S1_S1_RKT0_(ptr noundef nonnull @que, ptr noundef nonnull %41, ptr noundef nonnull align 4 dereferenceable(4) %2)
  %43 = ptrtoint ptr %42 to i64
  %44 = sub i64 %43, ptrtoint (ptr @que to i64)
  %45 = lshr exact i64 %44, 2
  %46 = trunc i64 %45 to i32
  store i32 %46, ptr %2, align 4, !tbaa !5
  %47 = load i32, ptr @qtot, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds i32, ptr @que, i64 %48
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #7
  %50 = load i32, ptr %4, align 4, !tbaa !5
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %5, align 4, !tbaa !5
  %52 = call noundef ptr @_ZSt11lower_boundIPiiET_S1_S1_RKT0_(ptr noundef nonnull @que, ptr noundef nonnull %49, ptr noundef nonnull align 4 dereferenceable(4) %5)
  %53 = ptrtoint ptr %52 to i64
  %54 = sub i64 %53, ptrtoint (ptr @que to i64)
  %55 = lshr exact i64 %54, 2
  %56 = trunc i64 %55 to i32
  store i32 %56, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #7
  %57 = add nuw nsw i32 %.03035, 1
  %58 = load i32, ptr %3, align 4, !tbaa !5
  call void @_Z8addQueryiii(i32 noundef %57, i32 noundef %58, i32 noundef %56)
  %59 = xor i32 %.03035, -1
  %60 = load i32, ptr %1, align 4, !tbaa !5
  %61 = load i32, ptr %4, align 4, !tbaa !5
  call void @_Z8addQueryiii(i32 noundef %59, i32 noundef %60, i32 noundef %61)
  %62 = load i32, ptr %3, align 4, !tbaa !5
  %63 = load i32, ptr %2, align 4, !tbaa !5
  call void @_Z8addQueryiii(i32 noundef %59, i32 noundef %62, i32 noundef %63)
  %64 = load i32, ptr %1, align 4, !tbaa !5
  %65 = load i32, ptr %2, align 4, !tbaa !5
  call void @_Z8addQueryiii(i32 noundef %57, i32 noundef %64, i32 noundef %65)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #7
  %66 = load i32, ptr @m, align 4, !tbaa !5
  %67 = icmp slt i32 %57, %66
  br i1 %67, label %.lr.ph37, label %._crit_edge38, !llvm.loop !13

.preheader33:                                     ; preds = %._crit_edge38, %.critedge
  %indvars.iv55 = phi i64 [ %indvars.iv.next56, %.critedge ], [ 0, %._crit_edge38 ]
  %.02845 = phi i32 [ %.1.lcssa, %.critedge ], [ 0, %._crit_edge38 ]
  %68 = load i32, ptr @n, align 4, !tbaa !5
  %69 = icmp slt i32 %.02845, %68
  br i1 %69, label %.lr.ph40, label %.critedge

.lr.ph40:                                         ; preds = %.preheader33
  %70 = getelementptr inbounds [2000005 x %struct.Query], ptr @seq, i64 0, i64 %indvars.iv55, i32 1
  %71 = sext i32 %.02845 to i64
  br label %73

.preheader:                                       ; preds = %.critedge, %._crit_edge38
  %72 = load i32, ptr @m, align 4, !tbaa !5
  %.not46 = icmp slt i32 %72, 1
  br i1 %.not46, label %._crit_edge49, label %.lr.ph48

73:                                               ; preds = %.lr.ph40, %77
  %indvars.iv52 = phi i64 [ %71, %.lr.ph40 ], [ %indvars.iv.next53, %77 ]
  %74 = getelementptr inbounds [500001 x %"struct.std::pair"], ptr @a, i64 0, i64 %indvars.iv52
  %75 = load i32, ptr %74, align 8, !tbaa !14
  %76 = load i32, ptr %70, align 4, !tbaa !15
  %.not32 = icmp sgt i32 %75, %76
  br i1 %.not32, label %.critedge.loopexit, label %77

77:                                               ; preds = %73
  %78 = load i32, ptr @qtot, align 4, !tbaa !5
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds i32, ptr @que, i64 %79
  %81 = getelementptr inbounds i8, ptr %74, i64 4
  %82 = call noundef ptr @_ZSt11lower_boundIPiiET_S1_S1_RKT0_(ptr noundef nonnull @que, ptr noundef nonnull %80, ptr noundef nonnull align 4 dereferenceable(4) %81)
  %83 = ptrtoint ptr %82 to i64
  %84 = sub i64 %83, ptrtoint (ptr @que to i64)
  %85 = lshr exact i64 %84, 2
  %86 = trunc i64 %85 to i32
  %87 = add i32 %86, 1
  call void @_Z3updi(i32 noundef %87)
  %indvars.iv.next53 = add nsw i64 %indvars.iv52, 1
  %88 = load i32, ptr @n, align 4, !tbaa !5
  %89 = sext i32 %88 to i64
  %90 = icmp slt i64 %indvars.iv.next53, %89
  br i1 %90, label %73, label %.critedge.loopexit, !llvm.loop !17

.critedge.loopexit:                               ; preds = %77, %73
  %.1.lcssa.ph.in = phi i64 [ %indvars.iv52, %73 ], [ %indvars.iv.next53, %77 ]
  %.1.lcssa.ph = trunc i64 %.1.lcssa.ph.in to i32
  br label %.critedge

.critedge:                                        ; preds = %.critedge.loopexit, %.preheader33
  %.1.lcssa = phi i32 [ %.02845, %.preheader33 ], [ %.1.lcssa.ph, %.critedge.loopexit ]
  %91 = getelementptr inbounds [2000005 x %struct.Query], ptr @seq, i64 0, i64 %indvars.iv55
  %92 = load i32, ptr %91, align 4, !tbaa !18
  %93 = call i32 @llvm.abs.i32(i32 %92, i1 true)
  %94 = zext nneg i32 %93 to i64
  %95 = getelementptr inbounds [500001 x i32], ptr @ans, i64 0, i64 %94
  %96 = icmp sgt i32 %92, 0
  %97 = getelementptr inbounds i8, ptr %91, i64 8
  %98 = load i32, ptr %97, align 4, !tbaa !19
  %99 = call noundef i32 @_Z3aski(i32 noundef %98)
  %100 = load i32, ptr %95, align 4, !tbaa !5
  %101 = sub i32 0, %99
  %storemerge.p = select i1 %96, i32 %99, i32 %101
  %storemerge = add i32 %100, %storemerge.p
  store i32 %storemerge, ptr %95, align 4, !tbaa !5
  %indvars.iv.next56 = add nuw nsw i64 %indvars.iv55, 1
  %102 = load i32, ptr @stot, align 4, !tbaa !5
  %103 = sext i32 %102 to i64
  %104 = icmp slt i64 %indvars.iv.next56, %103
  br i1 %104, label %.preheader33, label %.preheader, !llvm.loop !20

._crit_edge49:                                    ; preds = %.lr.ph48, %.preheader
  ret i32 0

.lr.ph48:                                         ; preds = %.preheader, %.lr.ph48
  %indvars.iv59 = phi i64 [ %indvars.iv.next60, %.lr.ph48 ], [ 1, %.preheader ]
  %105 = getelementptr inbounds [500001 x i32], ptr @ans, i64 0, i64 %indvars.iv59
  %106 = load i32, ptr %105, align 4, !tbaa !5
  %107 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %106)
  %indvars.iv.next60 = add nuw nsw i64 %indvars.iv59, 1
  %108 = load i32, ptr @m, align 4, !tbaa !5
  %109 = sext i32 %108 to i64
  %.not.not = icmp slt i64 %indvars.iv59, %109
  br i1 %.not.not, label %.lr.ph48, label %._crit_edge49, !llvm.loop !21
}

; 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: 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: inlinehint mustprogress nounwind uwtable
declare dso_local void @_Z8addQueryiii(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #5

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #6

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #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 = { 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 = { inlinehint mustprogress nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #6 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #7 = { nounwind }

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

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


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