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

; 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 { i64, i64 }
%"class.std::multiset" = type { %"class.std::_Rb_tree" }
%"class.std::_Rb_tree" = type { %"struct.std::_Rb_tree<long long, long long, std::_Identity<long long>, std::less<long long>>::_Rb_tree_impl" }
%"struct.std::_Rb_tree<long long, long long, std::_Identity<long long>, std::less<long long>>::_Rb_tree_impl" = type { [8 x i8], %"struct.std::_Rb_tree_header" }
%"struct.std::_Rb_tree_header" = type { %"struct.std::_Rb_tree_node_base", i64 }
%"struct.std::_Rb_tree_node_base" = type { i32, ptr, ptr, ptr }
%"struct.std::_Rb_tree_const_iterator" = type { ptr }

@n = external dso_local global i32, align 4
@a = external dso_local global [300010 x %"struct.std::pair"], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z3cmpRKSt4pairIxxES2_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #1 personality ptr @__gxx_personality_v0 {
  %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 %"class.std::multiset", align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca %"struct.std::_Rb_tree_const_iterator", align 8
  %11 = alloca %"struct.std::_Rb_tree_const_iterator", align 8
  %12 = alloca i32, align 4
  %13 = alloca %"struct.std::_Rb_tree_const_iterator", align 8
  %14 = alloca %"struct.std::_Rb_tree_const_iterator", align 8
  %15 = alloca i64, align 8
  %16 = alloca %"struct.std::_Rb_tree_const_iterator", align 8
  store i32 0, ptr %1, align 4
  %17 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #7
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %18

18:                                               ; preds = %33, %0
  %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) #7
  br label %36

23:                                               ; preds = %18
  %24 = load i32, ptr %2, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [300010 x %"struct.std::pair"], ptr @a, i64 0, i64 %25
  %27 = getelementptr inbounds %"struct.std::pair", ptr %26, i32 0, i32 0
  %28 = load i32, ptr %2, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [300010 x %"struct.std::pair"], ptr @a, i64 0, i64 %29
  %31 = getelementptr inbounds %"struct.std::pair", ptr %30, i32 0, i32 1
  %32 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %27, ptr noundef %31)
  br label %33

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

36:                                               ; preds = %22
  %37 = load i32, ptr @n, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds %"struct.std::pair", ptr @a, i64 %38
  call void @_ZSt4sortIPSt4pairIxxEPFbRKS1_S4_EEvT_S7_T0_(ptr noundef getelementptr inbounds (%"struct.std::pair", ptr @a, i64 1), ptr noundef %39, ptr noundef @_Z3cmpRKSt4pairIxxES2_)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #7
  store i32 0, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 48, ptr %6) #7
  call void @_ZNSt8multisetIxSt4lessIxESaIxEEC2Ev(ptr noundef nonnull align 8 dereferenceable(48) %6) #7
  store i32 1, ptr %4, align 4, !tbaa !5
  br label %40

40:                                               ; preds = %70, %36
  %41 = load i32, ptr %4, align 4, !tbaa !5
  %42 = load i32, ptr @n, align 4, !tbaa !5
  %43 = icmp slt i32 %41, %42
  br i1 %43, label %44, label %52

44:                                               ; preds = %40
  %45 = load i32, ptr %4, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [300010 x %"struct.std::pair"], ptr @a, i64 0, i64 %46
  %48 = getelementptr inbounds %"struct.std::pair", ptr %47, i32 0, i32 0
  %49 = load i64, ptr %48, align 16, !tbaa !11
  %50 = load i64, ptr @a, align 16, !tbaa !11
  %51 = icmp sgt i64 %49, %50
  br label %52

52:                                               ; preds = %44, %40
  %53 = phi i1 [ false, %40 ], [ %51, %44 ]
  br i1 %53, label %54, label %77

54:                                               ; preds = %52
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #7
  %55 = load i32, ptr %4, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [300010 x %"struct.std::pair"], ptr @a, i64 0, i64 %56
  %58 = getelementptr inbounds %"struct.std::pair", ptr %57, i32 0, i32 1
  %59 = load i64, ptr %58, align 8, !tbaa !14
  %60 = load i32, ptr %4, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [300010 x %"struct.std::pair"], ptr @a, i64 0, i64 %61
  %63 = getelementptr inbounds %"struct.std::pair", ptr %62, i32 0, i32 0
  %64 = load i64, ptr %63, align 16, !tbaa !11
  %65 = sub nsw i64 %59, %64
  %66 = add nsw i64 %65, 1
  store i64 %66, ptr %7, align 8, !tbaa !15
  %67 = invoke ptr @_ZNSt8multisetIxSt4lessIxESaIxEE6insertEOx(ptr noundef nonnull align 8 dereferenceable(48) %6, ptr noundef nonnull align 8 dereferenceable(8) %7)
          to label %68 unwind label %73

68:                                               ; preds = %54
  %69 = getelementptr inbounds %"struct.std::_Rb_tree_const_iterator", ptr %10, i32 0, i32 0
  store ptr %67, ptr %69, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #7
  br label %70

70:                                               ; preds = %68
  %71 = load i32, ptr %4, align 4, !tbaa !5
  %72 = add nsw i32 %71, 1
  store i32 %72, ptr %4, align 4, !tbaa !5
  br label %40, !llvm.loop !16

73:                                               ; preds = %54
  %74 = landingpad { ptr, i32 }
          cleanup
  %75 = extractvalue { ptr, i32 } %74, 0
  store ptr %75, ptr %8, align 8
  %76 = extractvalue { ptr, i32 } %74, 1
  store i32 %76, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #7
  br label %169

77:                                               ; preds = %52
  %78 = load i32, ptr %4, align 4, !tbaa !5
  %79 = load i32, ptr %5, align 4, !tbaa !5
  %80 = sub nsw i32 %78, %79
  store i32 %80, ptr %3, align 4, !tbaa !5
  br label %81

81:                                               ; preds = %158, %77
  %82 = call noundef i64 @_ZNKSt8multisetIxSt4lessIxESaIxEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(48) %6) #7
  %83 = icmp ugt i64 %82, 0
  br i1 %83, label %84, label %160

84:                                               ; preds = %81
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #7
  %85 = call ptr @_ZNKSt8multisetIxSt4lessIxESaIxEE5beginEv(ptr noundef nonnull align 8 dereferenceable(48) %6) #7
  %86 = getelementptr inbounds %"struct.std::_Rb_tree_const_iterator", ptr %11, i32 0, i32 0
  store ptr %85, ptr %86, align 8
  %87 = load i64, ptr @a, align 16, !tbaa !11
  %88 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt23_Rb_tree_const_iteratorIxEdeEv(ptr noundef nonnull align 8 dereferenceable(8) %11) #7
  %89 = load i64, ptr %88, align 8, !tbaa !15
  %90 = icmp slt i64 %87, %89
  br i1 %90, label %91, label %92

91:                                               ; preds = %84
  store i32 9, ptr %12, align 4
  br label %156

92:                                               ; preds = %84
  %93 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt23_Rb_tree_const_iteratorIxEdeEv(ptr noundef nonnull align 8 dereferenceable(8) %11) #7
  %94 = load i64, ptr %93, align 8, !tbaa !15
  %95 = load i64, ptr @a, align 16, !tbaa !11
  %96 = sub nsw i64 %95, %94
  store i64 %96, ptr @a, align 16, !tbaa !11
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %13, ptr align 8 %11, i64 8, i1 false), !tbaa.struct !17
  %97 = getelementptr inbounds %"struct.std::_Rb_tree_const_iterator", ptr %13, i32 0, i32 0
  %98 = load ptr, ptr %97, align 8
  %99 = invoke ptr @_ZNSt8multisetIxSt4lessIxESaIxEE5eraseB5cxx11ESt23_Rb_tree_const_iteratorIxE(ptr noundef nonnull align 8 dereferenceable(48) %6, ptr %98)
          to label %100 unwind label %135

100:                                              ; preds = %92
  %101 = getelementptr inbounds %"struct.std::_Rb_tree_const_iterator", ptr %14, i32 0, i32 0
  store ptr %99, ptr %101, align 8
  br label %102

102:                                              ; preds = %132, %100
  %103 = load i32, ptr %4, align 4, !tbaa !5
  %104 = load i32, ptr @n, align 4, !tbaa !5
  %105 = icmp slt i32 %103, %104
  br i1 %105, label %106, label %114

106:                                              ; preds = %102
  %107 = load i32, ptr %4, align 4, !tbaa !5
  %108 = sext i32 %107 to i64
  %109 = getelementptr inbounds [300010 x %"struct.std::pair"], ptr @a, i64 0, i64 %108
  %110 = getelementptr inbounds %"struct.std::pair", ptr %109, i32 0, i32 0
  %111 = load i64, ptr %110, align 16, !tbaa !11
  %112 = load i64, ptr @a, align 16, !tbaa !11
  %113 = icmp sgt i64 %111, %112
  br label %114

114:                                              ; preds = %106, %102
  %115 = phi i1 [ false, %102 ], [ %113, %106 ]
  br i1 %115, label %116, label %143

116:                                              ; preds = %114
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #7
  %117 = load i32, ptr %4, align 4, !tbaa !5
  %118 = sext i32 %117 to i64
  %119 = getelementptr inbounds [300010 x %"struct.std::pair"], ptr @a, i64 0, i64 %118
  %120 = getelementptr inbounds %"struct.std::pair", ptr %119, i32 0, i32 1
  %121 = load i64, ptr %120, align 8, !tbaa !14
  %122 = load i32, ptr %4, align 4, !tbaa !5
  %123 = sext i32 %122 to i64
  %124 = getelementptr inbounds [300010 x %"struct.std::pair"], ptr @a, i64 0, i64 %123
  %125 = getelementptr inbounds %"struct.std::pair", ptr %124, i32 0, i32 0
  %126 = load i64, ptr %125, align 16, !tbaa !11
  %127 = sub nsw i64 %121, %126
  %128 = add nsw i64 %127, 1
  store i64 %128, ptr %15, align 8, !tbaa !15
  %129 = invoke ptr @_ZNSt8multisetIxSt4lessIxESaIxEE6insertEOx(ptr noundef nonnull align 8 dereferenceable(48) %6, ptr noundef nonnull align 8 dereferenceable(8) %15)
          to label %130 unwind label %139

130:                                              ; preds = %116
  %131 = getelementptr inbounds %"struct.std::_Rb_tree_const_iterator", ptr %16, i32 0, i32 0
  store ptr %129, ptr %131, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #7
  br label %132

132:                                              ; preds = %130
  %133 = load i32, ptr %4, align 4, !tbaa !5
  %134 = add nsw i32 %133, 1
  store i32 %134, ptr %4, align 4, !tbaa !5
  br label %102, !llvm.loop !20

135:                                              ; preds = %92
  %136 = landingpad { ptr, i32 }
          cleanup
  %137 = extractvalue { ptr, i32 } %136, 0
  store ptr %137, ptr %8, align 8
  %138 = extractvalue { ptr, i32 } %136, 1
  store i32 %138, ptr %9, align 4
  br label %159

139:                                              ; preds = %116
  %140 = landingpad { ptr, i32 }
          cleanup
  %141 = extractvalue { ptr, i32 } %140, 0
  store ptr %141, ptr %8, align 8
  %142 = extractvalue { ptr, i32 } %140, 1
  store i32 %142, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #7
  br label %159

143:                                              ; preds = %114
  %144 = load i32, ptr %5, align 4, !tbaa !5
  %145 = add nsw i32 %144, 1
  store i32 %145, ptr %5, align 4, !tbaa !5
  %146 = load i32, ptr %3, align 4, !tbaa !5
  %147 = load i32, ptr %4, align 4, !tbaa !5
  %148 = load i32, ptr %5, align 4, !tbaa !5
  %149 = sub nsw i32 %147, %148
  %150 = icmp sgt i32 %146, %149
  br i1 %150, label %151, label %155

151:                                              ; preds = %143
  %152 = load i32, ptr %4, align 4, !tbaa !5
  %153 = load i32, ptr %5, align 4, !tbaa !5
  %154 = sub nsw i32 %152, %153
  store i32 %154, ptr %3, align 4, !tbaa !5
  br label %155

155:                                              ; preds = %151, %143
  store i32 0, ptr %12, align 4
  br label %156

156:                                              ; preds = %155, %91
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #7
  %157 = load i32, ptr %12, align 4
  switch i32 %157, label %175 [
    i32 0, label %158
    i32 9, label %160
  ]

158:                                              ; preds = %156
  br label %81, !llvm.loop !21

159:                                              ; preds = %139, %135
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #7
  br label %169

160:                                              ; preds = %156, %81
  %161 = load i32, ptr %3, align 4, !tbaa !5
  %162 = invoke i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %161)
          to label %163 unwind label %165

163:                                              ; preds = %160
  store i32 0, ptr %1, align 4
  store i32 1, ptr %12, align 4
  call void @_ZNSt8multisetIxSt4lessIxESaIxEED2Ev(ptr noundef nonnull align 8 dereferenceable(48) %6) #7
  call void @llvm.lifetime.end.p0(i64 48, 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
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #7
  %164 = load i32, ptr %1, align 4
  ret i32 %164

165:                                              ; preds = %160
  %166 = landingpad { ptr, i32 }
          cleanup
  %167 = extractvalue { ptr, i32 } %166, 0
  store ptr %167, ptr %8, align 8
  %168 = extractvalue { ptr, i32 } %166, 1
  store i32 %168, ptr %9, align 4
  br label %169

169:                                              ; preds = %165, %159, %73
  call void @_ZNSt8multisetIxSt4lessIxESaIxEED2Ev(ptr noundef nonnull align 8 dereferenceable(48) %6) #7
  call void @llvm.lifetime.end.p0(i64 48, 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
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #7
  br label %170

170:                                              ; preds = %169
  %171 = load ptr, ptr %8, align 8
  %172 = load i32, ptr %9, align 4
  %173 = insertvalue { ptr, i32 } poison, ptr %171, 0
  %174 = insertvalue { ptr, i32 } %173, i32 %172, 1
  resume { ptr, i32 } %174

175:                                              ; preds = %156
  unreachable
}

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

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

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt8multisetIxSt4lessIxESaIxEEC2Ev(ptr noundef nonnull align 8 dereferenceable(48)) unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local ptr @_ZNSt8multisetIxSt4lessIxESaIxEE6insertEOx(ptr noundef nonnull align 8 dereferenceable(48), ptr noundef nonnull align 8 dereferenceable(8)) #5 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt8multisetIxSt4lessIxESaIxEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(48)) #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local ptr @_ZNKSt8multisetIxSt4lessIxESaIxEE5beginEv(ptr noundef nonnull align 8 dereferenceable(48)) #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt23_Rb_tree_const_iteratorIxEdeEv(ptr noundef nonnull align 8 dereferenceable(8)) #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local ptr @_ZNSt8multisetIxSt4lessIxESaIxEE5eraseB5cxx11ESt23_Rb_tree_const_iteratorIxE(ptr noundef nonnull align 8 dereferenceable(48), ptr) #5 align 2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #6

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt8multisetIxSt4lessIxESaIxEED2Ev(ptr noundef nonnull align 8 dereferenceable(48)) unnamed_addr #0 align 2

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

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

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


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

%"struct.std::pair" = type { i64, i64 }
%"class.std::multiset" = type { %"class.std::_Rb_tree" }
%"class.std::_Rb_tree" = type { %"struct.std::_Rb_tree<long long, long long, std::_Identity<long long>, std::less<long long>>::_Rb_tree_impl" }
%"struct.std::_Rb_tree<long long, long long, std::_Identity<long long>, std::less<long long>>::_Rb_tree_impl" = type { [8 x i8], %"struct.std::_Rb_tree_header" }
%"struct.std::_Rb_tree_header" = type { %"struct.std::_Rb_tree_node_base", i64 }
%"struct.std::_Rb_tree_node_base" = type { i32, ptr, ptr, ptr }
%"struct.std::_Rb_tree_const_iterator" = type { ptr }

@n = external dso_local global i32, align 4
@a = external dso_local global [300010 x %"struct.std::pair"], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z3cmpRKSt4pairIxxES2_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 personality ptr @__gxx_personality_v0 {
  %1 = alloca %"class.std::multiset", align 8
  %2 = alloca i64, align 8
  %3 = alloca %"struct.std::_Rb_tree_const_iterator", align 8
  %4 = alloca i64, align 8
  %5 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %6 = load i32, ptr @n, align 4, !tbaa !5
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %.lr.ph, label %.._crit_edge_crit_edge

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

._crit_edge:                                      ; preds = %.lr.ph, %.._crit_edge_crit_edge
  %.pre-phi = phi i64 [ %.pre, %.._crit_edge_crit_edge ], [ %15, %.lr.ph ]
  %8 = getelementptr inbounds %"struct.std::pair", ptr @a, i64 %.pre-phi
  tail call void @_ZSt4sortIPSt4pairIxxEPFbRKS1_S4_EEvT_S7_T0_(ptr noundef nonnull getelementptr inbounds (i8, ptr @a, i64 16), ptr noundef nonnull %8, ptr noundef nonnull @_Z3cmpRKSt4pairIxxES2_)
  call void @llvm.lifetime.start.p0(i64 48, ptr nonnull %1) #7
  call void @_ZNSt8multisetIxSt4lessIxESaIxEEC2Ev(ptr noundef nonnull align 8 dereferenceable(48) %1) #7
  %9 = load i32, ptr @n, align 4, !tbaa !5
  %10 = icmp sgt i32 %9, 1
  br i1 %10, label %.lr.ph63, label %.critedge

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %0 ]
  %11 = getelementptr inbounds [300010 x %"struct.std::pair"], ptr @a, i64 0, i64 %indvars.iv
  %12 = getelementptr inbounds i8, ptr %11, i64 8
  %13 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %11, ptr noundef nonnull %12)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %14 = load i32, ptr @n, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = icmp slt i64 %indvars.iv.next, %15
  br i1 %16, label %.lr.ph, label %._crit_edge, !llvm.loop !9

.lr.ph63:                                         ; preds = %._crit_edge, %26
  %indvars.iv85 = phi i64 [ %indvars.iv.next86, %26 ], [ 1, %._crit_edge ]
  %17 = getelementptr inbounds [300010 x %"struct.std::pair"], ptr @a, i64 0, i64 %indvars.iv85
  %18 = load i64, ptr %17, align 16, !tbaa !11
  %19 = load i64, ptr @a, align 16, !tbaa !11
  %20 = icmp sgt i64 %18, %19
  br i1 %20, label %21, label %.critedge.loopexit

21:                                               ; preds = %.lr.ph63
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #7
  %22 = getelementptr inbounds i8, ptr %17, i64 8
  %23 = load i64, ptr %22, align 8, !tbaa !14
  %reass.sub = sub i64 %23, %18
  %24 = add i64 %reass.sub, 1
  store i64 %24, ptr %2, align 8, !tbaa !15
  %25 = invoke ptr @_ZNSt8multisetIxSt4lessIxESaIxEE6insertEOx(ptr noundef nonnull align 8 dereferenceable(48) %1, ptr noundef nonnull align 8 dereferenceable(8) %2)
          to label %26 unwind label %30

26:                                               ; preds = %21
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #7
  %indvars.iv.next86 = add nuw nsw i64 %indvars.iv85, 1
  %27 = load i32, ptr @n, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = icmp slt i64 %indvars.iv.next86, %28
  br i1 %29, label %.lr.ph63, label %.critedge.loopexit, !llvm.loop !16

30:                                               ; preds = %21
  %31 = landingpad { ptr, i32 }
          cleanup
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #7
  br label %69

.critedge.loopexit:                               ; preds = %26, %.lr.ph63
  %.033.lcssa.ph.in = phi i64 [ %indvars.iv85, %.lr.ph63 ], [ %indvars.iv.next86, %26 ]
  %.033.lcssa.ph = trunc i64 %.033.lcssa.ph.in to i32
  br label %.critedge

.critedge:                                        ; preds = %.critedge.loopexit, %._crit_edge
  %.033.lcssa = phi i32 [ 1, %._crit_edge ], [ %.033.lcssa.ph, %.critedge.loopexit ]
  %32 = call noundef i64 @_ZNKSt8multisetIxSt4lessIxESaIxEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(48) %1) #7
  %.not73 = icmp eq i64 %32, 0
  br i1 %.not73, label %.loopexit, label %.lr.ph77

.lr.ph77:                                         ; preds = %.critedge, %._crit_edge69
  %.03176 = phi i32 [ %spec.select, %._crit_edge69 ], [ %.033.lcssa, %.critedge ]
  %.13475 = phi i32 [ %.235.lcssa, %._crit_edge69 ], [ %.033.lcssa, %.critedge ]
  %.04174 = phi i32 [ %64, %._crit_edge69 ], [ 0, %.critedge ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #7
  %33 = call ptr @_ZNKSt8multisetIxSt4lessIxESaIxEE5beginEv(ptr noundef nonnull align 8 dereferenceable(48) %1) #7
  store ptr %33, ptr %3, align 8
  %34 = load i64, ptr @a, align 16, !tbaa !11
  %35 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt23_Rb_tree_const_iteratorIxEdeEv(ptr noundef nonnull align 8 dereferenceable(8) %3) #7
  %36 = load i64, ptr %35, align 8, !tbaa !15
  %37 = icmp slt i64 %34, %36
  br i1 %37, label %.thread, label %38

.thread:                                          ; preds = %.lr.ph77
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #7
  br label %.loopexit

38:                                               ; preds = %.lr.ph77
  %39 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt23_Rb_tree_const_iteratorIxEdeEv(ptr noundef nonnull align 8 dereferenceable(8) %3) #7
  %40 = load i64, ptr %39, align 8, !tbaa !15
  %41 = load i64, ptr @a, align 16, !tbaa !11
  %42 = sub nsw i64 %41, %40
  store i64 %42, ptr @a, align 16, !tbaa !11
  %.sroa.04.0.copyload = load ptr, ptr %3, align 8, !tbaa !17
  %43 = invoke ptr @_ZNSt8multisetIxSt4lessIxESaIxEE5eraseB5cxx11ESt23_Rb_tree_const_iteratorIxE(ptr noundef nonnull align 8 dereferenceable(48) %1, ptr %.sroa.04.0.copyload)
          to label %.preheader unwind label %60

.preheader:                                       ; preds = %38
  %44 = load i32, ptr @n, align 4, !tbaa !5
  %45 = icmp slt i32 %.13475, %44
  br i1 %45, label %.lr.ph68.preheader, label %._crit_edge69

.lr.ph68.preheader:                               ; preds = %.preheader
  %46 = sext i32 %.13475 to i64
  br label %.lr.ph68

.lr.ph68:                                         ; preds = %.lr.ph68.preheader, %56
  %indvars.iv88 = phi i64 [ %46, %.lr.ph68.preheader ], [ %indvars.iv.next89, %56 ]
  %47 = getelementptr inbounds [300010 x %"struct.std::pair"], ptr @a, i64 0, i64 %indvars.iv88
  %48 = load i64, ptr %47, align 16, !tbaa !11
  %49 = load i64, ptr @a, align 16, !tbaa !11
  %50 = icmp sgt i64 %48, %49
  br i1 %50, label %51, label %._crit_edge69.loopexit

51:                                               ; preds = %.lr.ph68
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #7
  %52 = getelementptr inbounds i8, ptr %47, i64 8
  %53 = load i64, ptr %52, align 8, !tbaa !14
  %reass.sub79 = sub i64 %53, %48
  %54 = add i64 %reass.sub79, 1
  store i64 %54, ptr %4, align 8, !tbaa !15
  %55 = invoke ptr @_ZNSt8multisetIxSt4lessIxESaIxEE6insertEOx(ptr noundef nonnull align 8 dereferenceable(48) %1, ptr noundef nonnull align 8 dereferenceable(8) %4)
          to label %56 unwind label %62

56:                                               ; preds = %51
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #7
  %indvars.iv.next89 = add nsw i64 %indvars.iv88, 1
  %57 = load i32, ptr @n, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = icmp slt i64 %indvars.iv.next89, %58
  br i1 %59, label %.lr.ph68, label %._crit_edge69.loopexit, !llvm.loop !19

60:                                               ; preds = %38
  %61 = landingpad { ptr, i32 }
          cleanup
  br label %67

62:                                               ; preds = %51
  %63 = landingpad { ptr, i32 }
          cleanup
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #7
  br label %67

._crit_edge69.loopexit:                           ; preds = %.lr.ph68, %56
  %.235.lcssa.ph.in = phi i64 [ %indvars.iv.next89, %56 ], [ %indvars.iv88, %.lr.ph68 ]
  %.235.lcssa.ph = trunc i64 %.235.lcssa.ph.in to i32
  br label %._crit_edge69

._crit_edge69:                                    ; preds = %._crit_edge69.loopexit, %.preheader
  %.235.lcssa = phi i32 [ %.13475, %.preheader ], [ %.235.lcssa.ph, %._crit_edge69.loopexit ]
  %64 = add nuw nsw i32 %.04174, 1
  %65 = sub nsw i32 %.235.lcssa, %64
  %spec.select = call i32 @llvm.smin.i32(i32 %.03176, i32 %65)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #7
  %66 = call noundef i64 @_ZNKSt8multisetIxSt4lessIxESaIxEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(48) %1) #7
  %.not = icmp eq i64 %66, 0
  br i1 %.not, label %.loopexit, label %.lr.ph77

67:                                               ; preds = %62, %60
  %.pn = phi { ptr, i32 } [ %63, %62 ], [ %61, %60 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #7
  br label %69

.loopexit:                                        ; preds = %._crit_edge69, %.critedge, %.thread
  %.03158 = phi i32 [ %.03176, %.thread ], [ %.033.lcssa, %.critedge ], [ %spec.select, %._crit_edge69 ]
  %68 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %.03158)
  call void @_ZNSt8multisetIxSt4lessIxESaIxEED2Ev(ptr noundef nonnull align 8 dereferenceable(48) %1) #7
  call void @llvm.lifetime.end.p0(i64 48, ptr nonnull %1) #7
  ret i32 0

69:                                               ; preds = %67, %30
  %.pn46 = phi { ptr, i32 } [ %31, %30 ], [ %.pn, %67 ]
  call void @_ZNSt8multisetIxSt4lessIxESaIxEED2Ev(ptr noundef nonnull align 8 dereferenceable(48) %1) #7
  call void @llvm.lifetime.end.p0(i64 48, ptr nonnull %1) #7
  resume { ptr, i32 } %.pn46
}

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

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

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt8multisetIxSt4lessIxESaIxEEC2Ev(ptr noundef nonnull align 8 dereferenceable(48)) unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local ptr @_ZNSt8multisetIxSt4lessIxESaIxEE6insertEOx(ptr noundef nonnull align 8 dereferenceable(48), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #5 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt8multisetIxSt4lessIxESaIxEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(48)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local ptr @_ZNKSt8multisetIxSt4lessIxESaIxEE5beginEv(ptr noundef nonnull align 8 dereferenceable(48)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt23_Rb_tree_const_iteratorIxEdeEv(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local ptr @_ZNSt8multisetIxSt4lessIxESaIxEE5eraseB5cxx11ESt23_Rb_tree_const_iteratorIxE(ptr noundef nonnull align 8 dereferenceable(48), ptr) local_unnamed_addr #5 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt8multisetIxSt4lessIxESaIxEED2Ev(ptr noundef nonnull align 8 dereferenceable(48)) unnamed_addr #0 align 2

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

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

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

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


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