; LLVM IR from xirc/cp-algorithm :: codeforces/762E (main)

; 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"

%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<Station, std::allocator<Station>>::_Vector_impl" }
%"struct.std::_Vector_base<Station, std::allocator<Station>>::_Vector_impl" = type { %"struct.std::_Vector_base<Station, std::allocator<Station>>::_Vector_impl_data" }
%"struct.std::_Vector_base<Station, std::allocator<Station>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.std::vector.0" = type { %"struct.std::_Vector_base.1" }
%"struct.std::_Vector_base.1" = type { %"struct.std::_Vector_base<Treap, std::allocator<Treap>>::_Vector_impl" }
%"struct.std::_Vector_base<Treap, std::allocator<Treap>>::_Vector_impl" = type { %"struct.std::_Vector_base<Treap, std::allocator<Treap>>::_Vector_impl_data" }
%"struct.std::_Vector_base<Treap, std::allocator<Treap>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.std::basic_istream" = type { ptr, i64, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }
%"class.std::basic_ostream" = type { ptr, %"class.std::basic_ios" }
%struct.Station = type { i32, i32, i32 }
%"class.__gnu_cxx::__normal_iterator" = type { ptr }

@N = external dso_local global i32, align 4
@K = external dso_local global i32, align 4
@stations = external dso_local global %"class.std::vector", align 8
@treap_by_freq = external dso_local global %"class.std::vector.0", align 8
@_ZSt3cin = external global %"class.std::basic_istream", align 8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8

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

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #1 {
  %1 = alloca i32, align 4
  %2 = alloca %struct.Station, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca %struct.Station, align 4
  %8 = alloca %"class.__gnu_cxx::__normal_iterator", align 8
  %9 = alloca %"class.__gnu_cxx::__normal_iterator", align 8
  %10 = alloca %"class.__gnu_cxx::__normal_iterator", align 8
  %11 = alloca %"class.__gnu_cxx::__normal_iterator", align 8
  %12 = alloca i64, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca %struct.Station, align 4
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  %19 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %20 = call noundef zeroext i1 @_ZNSt8ios_base15sync_with_stdioEb(i1 noundef zeroext false)
  %21 = load ptr, ptr @_ZSt3cin, align 8, !tbaa !5
  %22 = getelementptr i8, ptr %21, i64 -24
  %23 = load i64, ptr %22, align 8
  %24 = getelementptr inbounds i8, ptr @_ZSt3cin, i64 %23
  %25 = call noundef ptr @_ZNSt9basic_iosIcSt11char_traitsIcEE3tieEPSo(ptr noundef nonnull align 8 dereferenceable(264) %24, ptr noundef null)
  %26 = load ptr, ptr @_ZSt4cout, align 8, !tbaa !5
  %27 = getelementptr i8, ptr %26, i64 -24
  %28 = load i64, ptr %27, align 8
  %29 = getelementptr inbounds i8, ptr @_ZSt4cout, i64 %28
  %30 = call noundef ptr @_ZNSt9basic_iosIcSt11char_traitsIcEE3tieEPSo(ptr noundef nonnull align 8 dereferenceable(264) %29, ptr noundef null)
  %31 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 4 dereferenceable(4) @N)
  %32 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) %31, ptr noundef nonnull align 4 dereferenceable(4) @K)
  %33 = load i32, ptr @N, align 4, !tbaa !8
  %34 = sext i32 %33 to i64
  call void @llvm.lifetime.start.p0(i64 12, ptr %2) #8
  call void @llvm.memset.p0.i64(ptr align 4 %2, i8 0, i64 12, i1 false)
  call void @_ZNSt6vectorI7StationSaIS0_EE6assignEmRKS0_(ptr noundef nonnull align 8 dereferenceable(24) @stations, i64 noundef %34, ptr noundef nonnull align 4 dereferenceable(12) %2)
  call void @llvm.lifetime.end.p0(i64 12, ptr %2) #8
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #8
  store i32 0, ptr %3, align 4, !tbaa !8
  br label %35

35:                                               ; preds = %53, %0
  %36 = load i32, ptr %3, align 4, !tbaa !8
  %37 = load i32, ptr @N, align 4, !tbaa !8
  %38 = icmp slt i32 %36, %37
  br i1 %38, label %40, label %39

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

40:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #8
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #8
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #8
  %41 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 4 dereferenceable(4) %4)
  %42 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) %41, ptr noundef nonnull align 4 dereferenceable(4) %5)
  %43 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) %42, ptr noundef nonnull align 4 dereferenceable(4) %6)
  call void @llvm.lifetime.start.p0(i64 12, ptr %7) #8
  %44 = getelementptr inbounds %struct.Station, ptr %7, i32 0, i32 0
  %45 = load i32, ptr %4, align 4, !tbaa !8
  store i32 %45, ptr %44, align 4, !tbaa !11
  %46 = getelementptr inbounds %struct.Station, ptr %7, i32 0, i32 1
  %47 = load i32, ptr %5, align 4, !tbaa !8
  store i32 %47, ptr %46, align 4, !tbaa !13
  %48 = getelementptr inbounds %struct.Station, ptr %7, i32 0, i32 2
  %49 = load i32, ptr %6, align 4, !tbaa !8
  store i32 %49, ptr %48, align 4, !tbaa !14
  %50 = load i32, ptr %3, align 4, !tbaa !8
  %51 = sext i32 %50 to i64
  %52 = call noundef nonnull align 4 dereferenceable(12) ptr @_ZNSt6vectorI7StationSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @stations, i64 noundef %51) #8
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %52, ptr align 4 %7, i64 12, i1 false), !tbaa.struct !15
  call void @llvm.lifetime.end.p0(i64 12, ptr %7) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #8
  br label %53

53:                                               ; preds = %40
  %54 = load i32, ptr %3, align 4, !tbaa !8
  %55 = add nsw i32 %54, 1
  store i32 %55, ptr %3, align 4, !tbaa !8
  br label %35, !llvm.loop !16

56:                                               ; preds = %39
  %57 = call ptr @_ZNSt6vectorI7StationSaIS0_EE5beginEv(ptr noundef nonnull align 8 dereferenceable(24) @stations) #8
  %58 = getelementptr inbounds %"class.__gnu_cxx::__normal_iterator", ptr %8, i32 0, i32 0
  store ptr %57, ptr %58, align 8
  %59 = call ptr @_ZNSt6vectorI7StationSaIS0_EE3endEv(ptr noundef nonnull align 8 dereferenceable(24) @stations) #8
  %60 = getelementptr inbounds %"class.__gnu_cxx::__normal_iterator", ptr %9, i32 0, i32 0
  store ptr %59, ptr %60, align 8
  %61 = getelementptr inbounds %"class.__gnu_cxx::__normal_iterator", ptr %8, i32 0, i32 0
  %62 = load ptr, ptr %61, align 8
  %63 = getelementptr inbounds %"class.__gnu_cxx::__normal_iterator", ptr %9, i32 0, i32 0
  %64 = load ptr, ptr %63, align 8
  call void @_ZSt4sortIN9__gnu_cxx17__normal_iteratorIP7StationSt6vectorIS2_SaIS2_EEEEEvT_S8_(ptr %62, ptr %64)
  %65 = call ptr @_ZNSt6vectorI7StationSaIS0_EE5beginEv(ptr noundef nonnull align 8 dereferenceable(24) @stations) #8
  %66 = getelementptr inbounds %"class.__gnu_cxx::__normal_iterator", ptr %10, i32 0, i32 0
  store ptr %65, ptr %66, align 8
  %67 = call ptr @_ZNSt6vectorI7StationSaIS0_EE3endEv(ptr noundef nonnull align 8 dereferenceable(24) @stations) #8
  %68 = getelementptr inbounds %"class.__gnu_cxx::__normal_iterator", ptr %11, i32 0, i32 0
  store ptr %67, ptr %68, align 8
  %69 = getelementptr inbounds %"class.__gnu_cxx::__normal_iterator", ptr %10, i32 0, i32 0
  %70 = load ptr, ptr %69, align 8
  %71 = getelementptr inbounds %"class.__gnu_cxx::__normal_iterator", ptr %11, i32 0, i32 0
  %72 = load ptr, ptr %71, align 8
  call void @_ZSt7reverseIN9__gnu_cxx17__normal_iteratorIP7StationSt6vectorIS2_SaIS2_EEEEEvT_S8_(ptr %70, ptr %72)
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #8
  store i64 0, ptr %12, align 8, !tbaa !18
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #8
  store i32 0, ptr %13, align 4, !tbaa !8
  br label %73

73:                                               ; preds = %130, %56
  %74 = load i32, ptr %13, align 4, !tbaa !8
  %75 = load i32, ptr @N, align 4, !tbaa !8
  %76 = icmp slt i32 %74, %75
  br i1 %76, label %78, label %77

77:                                               ; preds = %73
  store i32 5, ptr %14, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #8
  br label %133

78:                                               ; preds = %73
  call void @llvm.lifetime.start.p0(i64 12, ptr %15) #8
  %79 = load i32, ptr %13, align 4, !tbaa !8
  %80 = sext i32 %79 to i64
  %81 = call noundef nonnull align 4 dereferenceable(12) ptr @_ZNSt6vectorI7StationSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @stations, i64 noundef %80) #8
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %15, ptr align 4 %81, i64 12, i1 false), !tbaa.struct !15
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #8
  %82 = load i32, ptr @K, align 4, !tbaa !8
  %83 = sub nsw i32 0, %82
  store i32 %83, ptr %16, align 4, !tbaa !8
  br label %84

84:                                               ; preds = %120, %78
  %85 = load i32, ptr %16, align 4, !tbaa !8
  %86 = load i32, ptr @K, align 4, !tbaa !8
  %87 = icmp sle i32 %85, %86
  br i1 %87, label %89, label %88

88:                                               ; preds = %84
  store i32 8, ptr %14, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #8
  br label %123

89:                                               ; preds = %84
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #8
  %90 = getelementptr inbounds %struct.Station, ptr %15, i32 0, i32 2
  %91 = load i32, ptr %90, align 4, !tbaa !14
  %92 = load i32, ptr %16, align 4, !tbaa !8
  %93 = add nsw i32 %91, %92
  store i32 %93, ptr %17, align 4, !tbaa !8
  %94 = load i32, ptr %17, align 4, !tbaa !8
  %95 = icmp sle i32 %94, 0
  br i1 %95, label %96, label %97

96:                                               ; preds = %89
  store i32 10, ptr %14, align 4
  br label %117

97:                                               ; preds = %89
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #8
  %98 = getelementptr inbounds %struct.Station, ptr %15, i32 0, i32 0
  %99 = load i32, ptr %98, align 4, !tbaa !11
  %100 = getelementptr inbounds %struct.Station, ptr %15, i32 0, i32 1
  %101 = load i32, ptr %100, align 4, !tbaa !13
  %102 = sub nsw i32 %99, %101
  store i32 %102, ptr %18, align 4, !tbaa !8
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #8
  %103 = getelementptr inbounds %struct.Station, ptr %15, i32 0, i32 0
  %104 = load i32, ptr %103, align 4, !tbaa !11
  %105 = getelementptr inbounds %struct.Station, ptr %15, i32 0, i32 1
  %106 = load i32, ptr %105, align 4, !tbaa !13
  %107 = add nsw i32 %104, %106
  store i32 %107, ptr %19, align 4, !tbaa !8
  %108 = load i32, ptr %17, align 4, !tbaa !8
  %109 = sext i32 %108 to i64
  %110 = call noundef nonnull align 8 dereferenceable(5008) ptr @_ZNSt6vectorI5TreapSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @treap_by_freq, i64 noundef %109) #8
  %111 = load i32, ptr %18, align 4, !tbaa !8
  %112 = load i32, ptr %19, align 4, !tbaa !8
  %113 = add nsw i32 %112, 1
  %114 = call noundef i64 @_ZN5Treap5countEii(ptr noundef nonnull align 8 dereferenceable(5008) %110, i32 noundef %111, i32 noundef %113)
  %115 = load i64, ptr %12, align 8, !tbaa !18
  %116 = add nsw i64 %115, %114
  store i64 %116, ptr %12, align 8, !tbaa !18
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #8
  store i32 0, ptr %14, align 4
  br label %117

117:                                              ; preds = %97, %96
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #8
  %118 = load i32, ptr %14, align 4
  switch i32 %118, label %138 [
    i32 0, label %119
    i32 10, label %120
  ]

119:                                              ; preds = %117
  br label %120

120:                                              ; preds = %119, %117
  %121 = load i32, ptr %16, align 4, !tbaa !8
  %122 = add nsw i32 %121, 1
  store i32 %122, ptr %16, align 4, !tbaa !8
  br label %84, !llvm.loop !20

123:                                              ; preds = %88
  %124 = getelementptr inbounds %struct.Station, ptr %15, i32 0, i32 2
  %125 = load i32, ptr %124, align 4, !tbaa !14
  %126 = sext i32 %125 to i64
  %127 = call noundef nonnull align 8 dereferenceable(5008) ptr @_ZNSt6vectorI5TreapSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @treap_by_freq, i64 noundef %126) #8
  %128 = getelementptr inbounds %struct.Station, ptr %15, i32 0, i32 0
  %129 = load i32, ptr %128, align 4, !tbaa !11
  call void @_ZN5Treap6insertEi(ptr noundef nonnull align 8 dereferenceable(5008) %127, i32 noundef %129)
  call void @llvm.lifetime.end.p0(i64 12, ptr %15) #8
  br label %130

130:                                              ; preds = %123
  %131 = load i32, ptr %13, align 4, !tbaa !8
  %132 = add nsw i32 %131, 1
  store i32 %132, ptr %13, align 4, !tbaa !8
  br label %73, !llvm.loop !21

133:                                              ; preds = %77
  %134 = load i64, ptr %12, align 8, !tbaa !18
  %135 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %134)
  %136 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %135, ptr noundef @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %14, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #8
  %137 = load i32, ptr %1, align 4
  ret i32 %137

138:                                              ; preds = %117
  unreachable
}

declare noundef zeroext i1 @_ZNSt8ios_base15sync_with_stdioEb(i1 noundef zeroext) #2

; Function Attrs: mustprogress nounwind uwtable
declare noundef ptr @_ZNSt9basic_iosIcSt11char_traitsIcEE3tieEPSo(ptr noundef nonnull align 8 dereferenceable(264), ptr noundef) #3 align 2

declare noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 4 dereferenceable(4)) #2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt6vectorI7StationSaIS0_EE6assignEmRKS0_(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef, ptr noundef nonnull align 4 dereferenceable(12)) #4 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(12) ptr @_ZNSt6vectorI7StationSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #3 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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIN9__gnu_cxx17__normal_iteratorIP7StationSt6vectorIS2_SaIS2_EEEEEvT_S8_(ptr, ptr) #7

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt7reverseIN9__gnu_cxx17__normal_iteratorIP7StationSt6vectorIS2_SaIS2_EEEEEvT_S8_(ptr, ptr) #7

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(5008) ptr @_ZNSt6vectorI5TreapSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_ZN5Treap5countEii(ptr noundef nonnull align 8 dereferenceable(5008), i32 noundef, i32 noundef) #4 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN5Treap6insertEi(ptr noundef nonnull align 8 dereferenceable(5008), i32 noundef) #4 align 2

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) #4 align 2

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) #4 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_(ptr noundef nonnull align 8 dereferenceable(8)) #7

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #4 = { mustprogress uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #5 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #6 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #7 = { 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 #8 = { 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 = !{!"vtable pointer", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !10, i64 0}
!10 = !{!"omnipotent char", !7, i64 0}
!11 = !{!12, !9, i64 0}
!12 = !{!"_ZTS7Station", !9, i64 0, !9, i64 4, !9, i64 8}
!13 = !{!12, !9, i64 4}
!14 = !{!12, !9, i64 8}
!15 = !{i64 0, i64 4, !8, i64 4, i64 4, !8, i64 8, i64 4, !8}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!19, !19, i64 0}
!19 = !{!"long long", !10, i64 0}
!20 = distinct !{!20, !17}
!21 = distinct !{!21, !17}


; 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"

%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<Station, std::allocator<Station>>::_Vector_impl" }
%"struct.std::_Vector_base<Station, std::allocator<Station>>::_Vector_impl" = type { %"struct.std::_Vector_base<Station, std::allocator<Station>>::_Vector_impl_data" }
%"struct.std::_Vector_base<Station, std::allocator<Station>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.std::vector.0" = type { %"struct.std::_Vector_base.1" }
%"struct.std::_Vector_base.1" = type { %"struct.std::_Vector_base<Treap, std::allocator<Treap>>::_Vector_impl" }
%"struct.std::_Vector_base<Treap, std::allocator<Treap>>::_Vector_impl" = type { %"struct.std::_Vector_base<Treap, std::allocator<Treap>>::_Vector_impl_data" }
%"struct.std::_Vector_base<Treap, std::allocator<Treap>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.std::basic_istream" = type { ptr, i64, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }
%"class.std::basic_ostream" = type { ptr, %"class.std::basic_ios" }
%struct.Station = type { i32, i32, i32 }

@N = external dso_local global i32, align 4
@K = external dso_local global i32, align 4
@stations = external dso_local global %"class.std::vector", align 8
@treap_by_freq = external dso_local global %"class.std::vector.0", align 8
@_ZSt3cin = external global %"class.std::basic_istream", align 8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8

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

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = alloca %struct.Station, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = tail call noundef zeroext i1 @_ZNSt8ios_base15sync_with_stdioEb(i1 noundef zeroext false)
  %6 = load ptr, ptr @_ZSt3cin, align 8, !tbaa !5
  %7 = getelementptr i8, ptr %6, i64 -24
  %8 = load i64, ptr %7, align 8
  %9 = getelementptr inbounds i8, ptr @_ZSt3cin, i64 %8
  %10 = tail call noundef ptr @_ZNSt9basic_iosIcSt11char_traitsIcEE3tieEPSo(ptr noundef nonnull align 8 dereferenceable(264) %9, ptr noundef null)
  %11 = load ptr, ptr @_ZSt4cout, align 8, !tbaa !5
  %12 = getelementptr i8, ptr %11, i64 -24
  %13 = load i64, ptr %12, align 8
  %14 = getelementptr inbounds i8, ptr @_ZSt4cout, i64 %13
  %15 = tail call noundef ptr @_ZNSt9basic_iosIcSt11char_traitsIcEE3tieEPSo(ptr noundef nonnull align 8 dereferenceable(264) %14, ptr noundef null)
  %16 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 4 dereferenceable(4) @N)
  %17 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) %16, ptr noundef nonnull align 4 dereferenceable(4) @K)
  %18 = load i32, ptr @N, align 4, !tbaa !8
  %19 = sext i32 %18 to i64
  call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %1) #7
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(12) %1, i8 0, i64 12, i1 false)
  call void @_ZNSt6vectorI7StationSaIS0_EE6assignEmRKS0_(ptr noundef nonnull align 8 dereferenceable(24) @stations, i64 noundef %19, ptr noundef nonnull align 4 dereferenceable(12) %1)
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %1) #7
  %20 = load i32, ptr @N, align 4, !tbaa !8
  %21 = icmp sgt i32 %20, 0
  br i1 %21, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %0
  %22 = call ptr @_ZNSt6vectorI7StationSaIS0_EE5beginEv(ptr noundef nonnull align 8 dereferenceable(24) @stations) #7
  %23 = call ptr @_ZNSt6vectorI7StationSaIS0_EE3endEv(ptr noundef nonnull align 8 dereferenceable(24) @stations) #7
  call void @_ZSt4sortIN9__gnu_cxx17__normal_iteratorIP7StationSt6vectorIS2_SaIS2_EEEEEvT_S8_(ptr %22, ptr %23)
  %24 = call ptr @_ZNSt6vectorI7StationSaIS0_EE5beginEv(ptr noundef nonnull align 8 dereferenceable(24) @stations) #7
  %25 = call ptr @_ZNSt6vectorI7StationSaIS0_EE3endEv(ptr noundef nonnull align 8 dereferenceable(24) @stations) #7
  call void @_ZSt7reverseIN9__gnu_cxx17__normal_iteratorIP7StationSt6vectorIS2_SaIS2_EEEEEvT_S8_(ptr %24, ptr %25)
  %26 = load i32, ptr @N, align 4, !tbaa !8
  %27 = icmp sgt i32 %26, 0
  br i1 %27, label %.lr.ph39, label %._crit_edge40

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %0 ]
  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
  %28 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 4 dereferenceable(4) %2)
  %29 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) %28, ptr noundef nonnull align 4 dereferenceable(4) %3)
  %30 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) %29, ptr noundef nonnull align 4 dereferenceable(4) %4)
  %31 = load i32, ptr %2, align 4, !tbaa !8
  %32 = load i32, ptr %3, align 4, !tbaa !8
  %33 = load i32, ptr %4, align 4, !tbaa !8
  %34 = call noundef nonnull align 4 dereferenceable(12) ptr @_ZNSt6vectorI7StationSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @stations, i64 noundef %indvars.iv) #7
  store i32 %31, ptr %34, align 4, !tbaa !8
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %34, i64 4
  store i32 %32, ptr %.sroa.4.0..sroa_idx, align 4, !tbaa !8
  %.sroa.5.0..sroa_idx = getelementptr inbounds i8, ptr %34, i64 8
  store i32 %33, ptr %.sroa.5.0..sroa_idx, align 4, !tbaa !8
  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
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %35 = load i32, ptr @N, align 4, !tbaa !8
  %36 = sext i32 %35 to i64
  %37 = icmp slt i64 %indvars.iv.next, %36
  br i1 %37, label %.lr.ph, label %._crit_edge, !llvm.loop !11

._crit_edge40:                                    ; preds = %._crit_edge35, %._crit_edge
  %.025.lcssa = phi i64 [ 0, %._crit_edge ], [ %.1.lcssa, %._crit_edge35 ]
  %38 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %.025.lcssa)
  %39 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %38, ptr noundef nonnull @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  ret i32 0

.lr.ph39:                                         ; preds = %._crit_edge, %._crit_edge35
  %indvars.iv43 = phi i64 [ %indvars.iv.next44, %._crit_edge35 ], [ 0, %._crit_edge ]
  %.02537 = phi i64 [ %.1.lcssa, %._crit_edge35 ], [ 0, %._crit_edge ]
  %40 = call noundef nonnull align 4 dereferenceable(12) ptr @_ZNSt6vectorI7StationSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @stations, i64 noundef %indvars.iv43) #7
  %.sroa.0.0.copyload = load i32, ptr %40, align 4, !tbaa !8
  %.sroa.8.0..sroa_idx = getelementptr inbounds i8, ptr %40, i64 8
  %.sroa.8.0.copyload = load i32, ptr %.sroa.8.0..sroa_idx, align 4, !tbaa !8
  %41 = load i32, ptr @K, align 4, !tbaa !8
  %.not30 = icmp slt i32 %41, 0
  br i1 %.not30, label %._crit_edge35, label %.lr.ph34

.lr.ph34:                                         ; preds = %.lr.ph39
  %42 = sub nsw i32 0, %41
  %.sroa.6.0..sroa_idx = getelementptr inbounds i8, ptr %40, i64 4
  %.sroa.6.0.copyload = load i32, ptr %.sroa.6.0..sroa_idx, align 4, !tbaa !8
  %43 = sub nsw i32 %.sroa.0.0.copyload, %.sroa.6.0.copyload
  %44 = add i32 %.sroa.0.0.copyload, 1
  %45 = add i32 %44, %.sroa.6.0.copyload
  br label %51

._crit_edge35:                                    ; preds = %60, %.lr.ph39
  %.1.lcssa = phi i64 [ %.02537, %.lr.ph39 ], [ %.2, %60 ]
  %46 = sext i32 %.sroa.8.0.copyload to i64
  %47 = call noundef nonnull align 8 dereferenceable(5008) ptr @_ZNSt6vectorI5TreapSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @treap_by_freq, i64 noundef %46) #7
  call void @_ZN5Treap6insertEi(ptr noundef nonnull align 8 dereferenceable(5008) %47, i32 noundef %.sroa.0.0.copyload)
  %indvars.iv.next44 = add nuw nsw i64 %indvars.iv43, 1
  %48 = load i32, ptr @N, align 4, !tbaa !8
  %49 = sext i32 %48 to i64
  %50 = icmp slt i64 %indvars.iv.next44, %49
  br i1 %50, label %.lr.ph39, label %._crit_edge40, !llvm.loop !13

51:                                               ; preds = %.lr.ph34, %60
  %52 = phi i32 [ %41, %.lr.ph34 ], [ %61, %60 ]
  %.132 = phi i64 [ %.02537, %.lr.ph34 ], [ %.2, %60 ]
  %.02631 = phi i32 [ %42, %.lr.ph34 ], [ %62, %60 ]
  %53 = add nsw i32 %.02631, %.sroa.8.0.copyload
  %54 = icmp slt i32 %53, 1
  br i1 %54, label %60, label %55

55:                                               ; preds = %51
  %56 = zext nneg i32 %53 to i64
  %57 = call noundef nonnull align 8 dereferenceable(5008) ptr @_ZNSt6vectorI5TreapSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @treap_by_freq, i64 noundef %56) #7
  %58 = call noundef i64 @_ZN5Treap5countEii(ptr noundef nonnull align 8 dereferenceable(5008) %57, i32 noundef %43, i32 noundef %45)
  %59 = add nsw i64 %58, %.132
  %.pre = load i32, ptr @K, align 4, !tbaa !8
  br label %60

60:                                               ; preds = %51, %55
  %61 = phi i32 [ %.pre, %55 ], [ %52, %51 ]
  %.2 = phi i64 [ %59, %55 ], [ %.132, %51 ]
  %62 = add nsw i32 %.02631, 1
  %.not.not = icmp slt i32 %.02631, %61
  br i1 %.not.not, label %51, label %._crit_edge35, !llvm.loop !14
}

declare noundef zeroext i1 @_ZNSt8ios_base15sync_with_stdioEb(i1 noundef zeroext) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
declare noundef ptr @_ZNSt9basic_iosIcSt11char_traitsIcEE3tieEPSo(ptr noundef nonnull align 8 dereferenceable(264), ptr noundef) local_unnamed_addr #3 align 2

declare noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt6vectorI7StationSaIS0_EE6assignEmRKS0_(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef, ptr noundef nonnull align 4 dereferenceable(12)) local_unnamed_addr #4 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(12) ptr @_ZNSt6vectorI7StationSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #3 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIN9__gnu_cxx17__normal_iteratorIP7StationSt6vectorIS2_SaIS2_EEEEEvT_S8_(ptr, ptr) local_unnamed_addr #6

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt7reverseIN9__gnu_cxx17__normal_iteratorIP7StationSt6vectorIS2_SaIS2_EEEEEvT_S8_(ptr, ptr) local_unnamed_addr #6

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(5008) ptr @_ZNSt6vectorI5TreapSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_ZN5Treap5countEii(ptr noundef nonnull align 8 dereferenceable(5008), i32 noundef, i32 noundef) local_unnamed_addr #4 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN5Treap6insertEi(ptr noundef nonnull align 8 dereferenceable(5008), i32 noundef) local_unnamed_addr #4 align 2

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) local_unnamed_addr #4 align 2

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) local_unnamed_addr #4 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_(ptr noundef nonnull align 8 dereferenceable(8)) #6

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #4 = { 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 nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #6 = { 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 #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 = !{!"vtable pointer", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !10, i64 0}
!10 = !{!"omnipotent char", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}


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