; LLVM IR from bqi343/cp-notebook :: Contests/USACO Solutions/2015-16/Jan 2016/Plat (16 Jan P2)

; 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<std::pair<std::pair<int, int>, std::pair<int, int>>, std::allocator<std::pair<std::pair<int, int>, std::pair<int, int>>>>::_Vector_impl" }
%"struct.std::_Vector_base<std::pair<std::pair<int, int>, std::pair<int, int>>, std::allocator<std::pair<std::pair<int, int>, std::pair<int, int>>>>::_Vector_impl" = type { %"struct.std::_Vector_base<std::pair<std::pair<int, int>, std::pair<int, int>>, std::allocator<std::pair<std::pair<int, int>, std::pair<int, int>>>>::_Vector_impl_data" }
%"struct.std::_Vector_base<std::pair<std::pair<int, int>, std::pair<int, int>>, std::allocator<std::pair<std::pair<int, int>, std::pair<int, int>>>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.std::basic_ostream" = type { ptr, %"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.__gnu_cxx::__normal_iterator" = type { ptr }
%"struct.std::pair.2" = type { %"struct.std::pair.0", %"struct.std::pair.0" }
%"struct.std::pair.0" = type { i32, i32 }

@N = external dso_local global i32, align 4
@T = external dso_local global i32, align 4
@ans = external dso_local global i64, align 8
@vquery = external dso_local global %"class.std::vector", align 8
@hseg = external dso_local global %"class.std::vector", align 8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8

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

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

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z4initv() #0

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

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #3 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca %"class.__gnu_cxx::__normal_iterator", align 8
  %5 = alloca %"class.__gnu_cxx::__normal_iterator", align 8
  %6 = alloca %"struct.std::pair.2", align 4
  store i32 0, ptr %1, align 4
  call void @_Z4initv()
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #6
  store i32 -1, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #6
  store ptr @vquery, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #6
  %7 = call ptr @_ZNSt6vectorISt4pairIS0_IiiES1_ESaIS2_EE5beginEv(ptr noundef nonnull align 8 dereferenceable(24) @vquery) #6
  %8 = getelementptr inbounds %"class.__gnu_cxx::__normal_iterator", ptr %4, i32 0, i32 0
  store ptr %7, ptr %8, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #6
  %9 = call ptr @_ZNSt6vectorISt4pairIS0_IiiES1_ESaIS2_EE3endEv(ptr noundef nonnull align 8 dereferenceable(24) @vquery) #6
  %10 = getelementptr inbounds %"class.__gnu_cxx::__normal_iterator", ptr %5, i32 0, i32 0
  store ptr %9, ptr %10, align 8
  br label %11

11:                                               ; preds = %139, %0
  %12 = call noundef zeroext i1 @_ZN9__gnu_cxxneIPSt4pairIS1_IiiES2_ESt6vectorIS3_SaIS3_EEEEbRKNS_17__normal_iteratorIT_T0_EESD_(ptr noundef nonnull align 8 dereferenceable(8) %4, ptr noundef nonnull align 8 dereferenceable(8) %5) #6
  br i1 %12, label %14, label %13

13:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #6
  br label %141

14:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 16, ptr %6) #6
  %15 = call noundef nonnull align 4 dereferenceable(16) ptr @_ZNK9__gnu_cxx17__normal_iteratorIPSt4pairIS1_IiiES2_ESt6vectorIS3_SaIS3_EEEdeEv(ptr noundef nonnull align 8 dereferenceable(8) %4) #6
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %6, ptr align 4 %15, i64 16, i1 false)
  br label %16

16:                                               ; preds = %36, %14
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = add nsw i32 %17, 1
  %19 = sext i32 %18 to i64
  %20 = call noundef i64 @_ZNKSt6vectorISt4pairIS0_IiiES1_ESaIS2_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) @hseg) #6
  %21 = icmp ult i64 %19, %20
  br i1 %21, label %22, label %34

22:                                               ; preds = %16
  %23 = load i32, ptr %2, align 4, !tbaa !5
  %24 = add nsw i32 %23, 1
  %25 = sext i32 %24 to i64
  %26 = call noundef nonnull align 4 dereferenceable(16) ptr @_ZNSt6vectorISt4pairIS0_IiiES1_ESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @hseg, i64 noundef %25) #6
  %27 = getelementptr inbounds %"struct.std::pair.2", ptr %26, i32 0, i32 0
  %28 = getelementptr inbounds %"struct.std::pair.0", ptr %27, i32 0, i32 0
  %29 = load i32, ptr %28, align 4, !tbaa !11
  %30 = getelementptr inbounds %"struct.std::pair.2", ptr %6, i32 0, i32 0
  %31 = getelementptr inbounds %"struct.std::pair.0", ptr %30, i32 0, i32 0
  %32 = load i32, ptr %31, align 4, !tbaa !11
  %33 = icmp sle i32 %29, %32
  br label %34

34:                                               ; preds = %22, %16
  %35 = phi i1 [ false, %16 ], [ %33, %22 ]
  br i1 %35, label %36, label %57

36:                                               ; preds = %34
  %37 = load i32, ptr %2, align 4, !tbaa !5
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr %2, align 4, !tbaa !5
  %39 = load i32, ptr %2, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = call noundef nonnull align 4 dereferenceable(16) ptr @_ZNSt6vectorISt4pairIS0_IiiES1_ESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @hseg, i64 noundef %40) #6
  %42 = getelementptr inbounds %"struct.std::pair.2", ptr %41, i32 0, i32 1
  %43 = getelementptr inbounds %"struct.std::pair.0", ptr %42, i32 0, i32 0
  %44 = load i32, ptr %43, align 4, !tbaa !14
  %45 = load i32, ptr %2, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = call noundef nonnull align 4 dereferenceable(16) ptr @_ZNSt6vectorISt4pairIS0_IiiES1_ESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @hseg, i64 noundef %46) #6
  %48 = getelementptr inbounds %"struct.std::pair.2", ptr %47, i32 0, i32 1
  %49 = getelementptr inbounds %"struct.std::pair.0", ptr %48, i32 0, i32 1
  %50 = load i32, ptr %49, align 4, !tbaa !15
  %51 = load i32, ptr %2, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = call noundef nonnull align 4 dereferenceable(16) ptr @_ZNSt6vectorISt4pairIS0_IiiES1_ESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @hseg, i64 noundef %52) #6
  %54 = getelementptr inbounds %"struct.std::pair.2", ptr %53, i32 0, i32 0
  %55 = getelementptr inbounds %"struct.std::pair.0", ptr %54, i32 0, i32 1
  %56 = load i32, ptr %55, align 4, !tbaa !16
  call void @_Z4updbiii(i32 noundef %44, i32 noundef %50, i32 noundef %56)
  br label %16, !llvm.loop !17

57:                                               ; preds = %34
  %58 = getelementptr inbounds %"struct.std::pair.2", ptr %6, i32 0, i32 0
  %59 = getelementptr inbounds %"struct.std::pair.0", ptr %58, i32 0, i32 1
  %60 = load i32, ptr %59, align 4, !tbaa !16
  %61 = load i32, ptr @T, align 4, !tbaa !5
  %62 = add nsw i32 %60, %61
  %63 = load i32, ptr @N, align 4, !tbaa !5
  %64 = icmp slt i32 %62, %63
  br i1 %64, label %65, label %108

65:                                               ; preds = %57
  %66 = load i32, ptr @N, align 4, !tbaa !5
  %67 = sub nsw i32 %66, 1
  %68 = getelementptr inbounds %"struct.std::pair.2", ptr %6, i32 0, i32 1
  %69 = getelementptr inbounds %"struct.std::pair.0", ptr %68, i32 0, i32 1
  %70 = load i32, ptr %69, align 4, !tbaa !15
  %71 = call noundef i32 @_Z6querybii(i32 noundef %67, i32 noundef %70)
  %72 = load i32, ptr @N, align 4, !tbaa !5
  %73 = sub nsw i32 %72, 1
  %74 = getelementptr inbounds %"struct.std::pair.2", ptr %6, i32 0, i32 1
  %75 = getelementptr inbounds %"struct.std::pair.0", ptr %74, i32 0, i32 0
  %76 = load i32, ptr %75, align 4, !tbaa !14
  %77 = sub nsw i32 %76, 1
  %78 = call noundef i32 @_Z6querybii(i32 noundef %73, i32 noundef %77)
  %79 = sub nsw i32 %71, %78
  %80 = sext i32 %79 to i64
  %81 = load i64, ptr @ans, align 8, !tbaa !19
  %82 = add nsw i64 %81, %80
  store i64 %82, ptr @ans, align 8, !tbaa !19
  %83 = getelementptr inbounds %"struct.std::pair.2", ptr %6, i32 0, i32 0
  %84 = getelementptr inbounds %"struct.std::pair.0", ptr %83, i32 0, i32 1
  %85 = load i32, ptr %84, align 4, !tbaa !16
  %86 = load i32, ptr @T, align 4, !tbaa !5
  %87 = add nsw i32 %85, %86
  %88 = sub nsw i32 %87, 1
  %89 = getelementptr inbounds %"struct.std::pair.2", ptr %6, i32 0, i32 1
  %90 = getelementptr inbounds %"struct.std::pair.0", ptr %89, i32 0, i32 1
  %91 = load i32, ptr %90, align 4, !tbaa !15
  %92 = call noundef i32 @_Z6querybii(i32 noundef %88, i32 noundef %91)
  %93 = getelementptr inbounds %"struct.std::pair.2", ptr %6, i32 0, i32 0
  %94 = getelementptr inbounds %"struct.std::pair.0", ptr %93, i32 0, i32 1
  %95 = load i32, ptr %94, align 4, !tbaa !16
  %96 = load i32, ptr @T, align 4, !tbaa !5
  %97 = add nsw i32 %95, %96
  %98 = sub nsw i32 %97, 1
  %99 = getelementptr inbounds %"struct.std::pair.2", ptr %6, i32 0, i32 1
  %100 = getelementptr inbounds %"struct.std::pair.0", ptr %99, i32 0, i32 0
  %101 = load i32, ptr %100, align 4, !tbaa !14
  %102 = sub nsw i32 %101, 1
  %103 = call noundef i32 @_Z6querybii(i32 noundef %98, i32 noundef %102)
  %104 = sub nsw i32 %92, %103
  %105 = sext i32 %104 to i64
  %106 = load i64, ptr @ans, align 8, !tbaa !19
  %107 = sub nsw i64 %106, %105
  store i64 %107, ptr @ans, align 8, !tbaa !19
  br label %108

108:                                              ; preds = %65, %57
  %109 = getelementptr inbounds %"struct.std::pair.2", ptr %6, i32 0, i32 0
  %110 = getelementptr inbounds %"struct.std::pair.0", ptr %109, i32 0, i32 1
  %111 = load i32, ptr %110, align 4, !tbaa !16
  %112 = load i32, ptr @T, align 4, !tbaa !5
  %113 = icmp sgt i32 %111, %112
  br i1 %113, label %114, label %138

114:                                              ; preds = %108
  %115 = getelementptr inbounds %"struct.std::pair.2", ptr %6, i32 0, i32 0
  %116 = getelementptr inbounds %"struct.std::pair.0", ptr %115, i32 0, i32 1
  %117 = load i32, ptr %116, align 4, !tbaa !16
  %118 = load i32, ptr @T, align 4, !tbaa !5
  %119 = sub nsw i32 %117, %118
  %120 = getelementptr inbounds %"struct.std::pair.2", ptr %6, i32 0, i32 1
  %121 = getelementptr inbounds %"struct.std::pair.0", ptr %120, i32 0, i32 1
  %122 = load i32, ptr %121, align 4, !tbaa !15
  %123 = call noundef i32 @_Z6querybii(i32 noundef %119, i32 noundef %122)
  %124 = getelementptr inbounds %"struct.std::pair.2", ptr %6, i32 0, i32 0
  %125 = getelementptr inbounds %"struct.std::pair.0", ptr %124, i32 0, i32 1
  %126 = load i32, ptr %125, align 4, !tbaa !16
  %127 = load i32, ptr @T, align 4, !tbaa !5
  %128 = sub nsw i32 %126, %127
  %129 = getelementptr inbounds %"struct.std::pair.2", ptr %6, i32 0, i32 1
  %130 = getelementptr inbounds %"struct.std::pair.0", ptr %129, i32 0, i32 0
  %131 = load i32, ptr %130, align 4, !tbaa !14
  %132 = sub nsw i32 %131, 1
  %133 = call noundef i32 @_Z6querybii(i32 noundef %128, i32 noundef %132)
  %134 = sub nsw i32 %123, %133
  %135 = sext i32 %134 to i64
  %136 = load i64, ptr @ans, align 8, !tbaa !19
  %137 = add nsw i64 %136, %135
  store i64 %137, ptr @ans, align 8, !tbaa !19
  br label %138

138:                                              ; preds = %114, %108
  call void @llvm.lifetime.end.p0(i64 16, ptr %6) #6
  br label %139

139:                                              ; preds = %138
  %140 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZN9__gnu_cxx17__normal_iteratorIPSt4pairIS1_IiiES2_ESt6vectorIS3_SaIS3_EEEppEv(ptr noundef nonnull align 8 dereferenceable(8) %4) #6
  br label %11

141:                                              ; preds = %13
  %142 = load i64, ptr @ans, align 8, !tbaa !19
  %143 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %142)
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #6
  %144 = load i32, ptr %1, align 4
  ret i32 %144
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN9__gnu_cxxneIPSt4pairIS1_IiiES2_ESt6vectorIS3_SaIS3_EEEEbRKNS_17__normal_iteratorIT_T0_EESD_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #4

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(16) ptr @_ZNK9__gnu_cxx17__normal_iteratorIPSt4pairIS1_IiiES2_ESt6vectorIS3_SaIS3_EEEdeEv(ptr noundef nonnull align 8 dereferenceable(8)) #2 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) #5

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

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

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

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

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

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

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


; 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<std::pair<std::pair<int, int>, std::pair<int, int>>, std::allocator<std::pair<std::pair<int, int>, std::pair<int, int>>>>::_Vector_impl" }
%"struct.std::_Vector_base<std::pair<std::pair<int, int>, std::pair<int, int>>, std::allocator<std::pair<std::pair<int, int>, std::pair<int, int>>>>::_Vector_impl" = type { %"struct.std::_Vector_base<std::pair<std::pair<int, int>, std::pair<int, int>>, std::allocator<std::pair<std::pair<int, int>, std::pair<int, int>>>>::_Vector_impl_data" }
%"struct.std::_Vector_base<std::pair<std::pair<int, int>, std::pair<int, int>>, std::allocator<std::pair<std::pair<int, int>, std::pair<int, int>>>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.std::basic_ostream" = type { ptr, %"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.__gnu_cxx::__normal_iterator" = type { ptr }

@N = external dso_local local_unnamed_addr global i32, align 4
@T = external dso_local local_unnamed_addr global i32, align 4
@ans = external dso_local local_unnamed_addr global i64, align 8
@vquery = external dso_local global %"class.std::vector", align 8
@hseg = external dso_local global %"class.std::vector", align 8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8

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

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

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z4initv() local_unnamed_addr #0

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

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #3 {
  %1 = alloca %"class.__gnu_cxx::__normal_iterator", align 8
  %2 = alloca %"class.__gnu_cxx::__normal_iterator", align 8
  tail call void @_Z4initv()
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #5
  %3 = tail call ptr @_ZNSt6vectorISt4pairIS0_IiiES1_ESaIS2_EE5beginEv(ptr noundef nonnull align 8 dereferenceable(24) @vquery) #5
  store ptr %3, ptr %1, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  %4 = tail call ptr @_ZNSt6vectorISt4pairIS0_IiiES1_ESaIS2_EE3endEv(ptr noundef nonnull align 8 dereferenceable(24) @vquery) #5
  store ptr %4, ptr %2, align 8
  %5 = call noundef zeroext i1 @_ZN9__gnu_cxxneIPSt4pairIS1_IiiES2_ESt6vectorIS3_SaIS3_EEEEbRKNS_17__normal_iteratorIT_T0_EESD_(ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef nonnull align 8 dereferenceable(8) %2) #5
  br i1 %5, label %.lr.ph23, label %._crit_edge

._crit_edge:                                      ; preds = %69, %0
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #5
  %6 = load i64, ptr @ans, align 8, !tbaa !5
  %7 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %6)
  ret i32 0

.lr.ph23:                                         ; preds = %0, %69
  %.022 = phi i32 [ %.1.lcssa, %69 ], [ -1, %0 ]
  %8 = call noundef nonnull align 4 dereferenceable(16) ptr @_ZNK9__gnu_cxx17__normal_iteratorIPSt4pairIS1_IiiES2_ESt6vectorIS3_SaIS3_EEEdeEv(ptr noundef nonnull align 8 dereferenceable(8) %1) #5
  %.sroa.0.0.copyload = load i32, ptr %8, align 4
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %8, i64 4
  %.sroa.4.0.copyload = load i32, ptr %.sroa.4.0..sroa_idx, align 4
  %.sroa.10.0..sroa_idx = getelementptr inbounds i8, ptr %8, i64 8
  %.sroa.10.0.copyload = load i32, ptr %.sroa.10.0..sroa_idx, align 4
  %.sroa.13.0..sroa_idx = getelementptr inbounds i8, ptr %8, i64 12
  %.sroa.13.0.copyload = load i32, ptr %.sroa.13.0..sroa_idx, align 4
  %9 = add i32 %.022, 1
  %10 = sext i32 %9 to i64
  %11 = call noundef i64 @_ZNKSt6vectorISt4pairIS0_IiiES1_ESaIS2_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) @hseg) #5
  %12 = icmp ugt i64 %11, %10
  br i1 %12, label %.lr.ph.preheader, label %.critedge

.lr.ph.preheader:                                 ; preds = %.lr.ph23
  %13 = call noundef nonnull align 4 dereferenceable(16) ptr @_ZNSt6vectorISt4pairIS0_IiiES1_ESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @hseg, i64 noundef %10) #5
  %14 = load i32, ptr %13, align 4, !tbaa !9
  %.not25 = icmp sgt i32 %14, %.sroa.0.0.copyload
  br i1 %.not25, label %.critedge, label %.lr.ph27

.lr.ph:                                           ; preds = %.lr.ph27
  %15 = call noundef nonnull align 4 dereferenceable(16) ptr @_ZNSt6vectorISt4pairIS0_IiiES1_ESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @hseg, i64 noundef %indvars.iv.next) #5
  %16 = load i32, ptr %15, align 4, !tbaa !9
  %.not = icmp sgt i32 %16, %.sroa.0.0.copyload
  br i1 %.not, label %.critedge.loopexit, label %.lr.ph27, !llvm.loop !13

.lr.ph27:                                         ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv26 = phi i64 [ %indvars.iv.next, %.lr.ph ], [ %10, %.lr.ph.preheader ]
  %17 = call noundef nonnull align 4 dereferenceable(16) ptr @_ZNSt6vectorISt4pairIS0_IiiES1_ESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @hseg, i64 noundef %indvars.iv26) #5
  %18 = getelementptr inbounds i8, ptr %17, i64 8
  %19 = load i32, ptr %18, align 4, !tbaa !15
  %20 = call noundef nonnull align 4 dereferenceable(16) ptr @_ZNSt6vectorISt4pairIS0_IiiES1_ESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @hseg, i64 noundef %indvars.iv26) #5
  %21 = getelementptr inbounds i8, ptr %20, i64 12
  %22 = load i32, ptr %21, align 4, !tbaa !16
  %23 = call noundef nonnull align 4 dereferenceable(16) ptr @_ZNSt6vectorISt4pairIS0_IiiES1_ESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @hseg, i64 noundef %indvars.iv26) #5
  %24 = getelementptr inbounds i8, ptr %23, i64 4
  %25 = load i32, ptr %24, align 4, !tbaa !17
  call void @_Z4updbiii(i32 noundef %19, i32 noundef %22, i32 noundef %25)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv26, 1
  %26 = call noundef i64 @_ZNKSt6vectorISt4pairIS0_IiiES1_ESaIS2_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) @hseg) #5
  %27 = icmp ugt i64 %26, %indvars.iv.next
  br i1 %27, label %.lr.ph, label %.critedge.loopexit, !llvm.loop !13

.critedge.loopexit:                               ; preds = %.lr.ph, %.lr.ph27
  %28 = trunc nsw i64 %indvars.iv26 to i32
  br label %.critedge

.critedge:                                        ; preds = %.critedge.loopexit, %.lr.ph.preheader, %.lr.ph23
  %.1.lcssa = phi i32 [ %.022, %.lr.ph23 ], [ %.022, %.lr.ph.preheader ], [ %28, %.critedge.loopexit ]
  %29 = load i32, ptr @T, align 4, !tbaa !18
  %30 = add nsw i32 %29, %.sroa.4.0.copyload
  %31 = load i32, ptr @N, align 4, !tbaa !18
  %32 = icmp slt i32 %30, %31
  br i1 %32, label %33, label %55

33:                                               ; preds = %.critedge
  %34 = add nsw i32 %31, -1
  %35 = call noundef i32 @_Z6querybii(i32 noundef %34, i32 noundef %.sroa.13.0.copyload)
  %36 = load i32, ptr @N, align 4, !tbaa !18
  %37 = add nsw i32 %36, -1
  %38 = add nsw i32 %.sroa.10.0.copyload, -1
  %39 = call noundef i32 @_Z6querybii(i32 noundef %37, i32 noundef %38)
  %40 = sub nsw i32 %35, %39
  %41 = sext i32 %40 to i64
  %42 = load i64, ptr @ans, align 8, !tbaa !5
  %43 = add nsw i64 %42, %41
  store i64 %43, ptr @ans, align 8, !tbaa !5
  %44 = load i32, ptr @T, align 4, !tbaa !18
  %45 = add i32 %.sroa.4.0.copyload, -1
  %46 = add i32 %45, %44
  %47 = call noundef i32 @_Z6querybii(i32 noundef %46, i32 noundef %.sroa.13.0.copyload)
  %48 = load i32, ptr @T, align 4, !tbaa !18
  %49 = add i32 %45, %48
  %50 = call noundef i32 @_Z6querybii(i32 noundef %49, i32 noundef %38)
  %51 = sub nsw i32 %47, %50
  %52 = sext i32 %51 to i64
  %53 = load i64, ptr @ans, align 8, !tbaa !5
  %54 = sub nsw i64 %53, %52
  store i64 %54, ptr @ans, align 8, !tbaa !5
  %.pre = load i32, ptr @T, align 4, !tbaa !18
  br label %55

55:                                               ; preds = %33, %.critedge
  %56 = phi i32 [ %.pre, %33 ], [ %29, %.critedge ]
  %57 = icmp sgt i32 %.sroa.4.0.copyload, %56
  br i1 %57, label %58, label %69

58:                                               ; preds = %55
  %59 = sub nsw i32 %.sroa.4.0.copyload, %56
  %60 = call noundef i32 @_Z6querybii(i32 noundef %59, i32 noundef %.sroa.13.0.copyload)
  %61 = load i32, ptr @T, align 4, !tbaa !18
  %62 = sub nsw i32 %.sroa.4.0.copyload, %61
  %63 = add nsw i32 %.sroa.10.0.copyload, -1
  %64 = call noundef i32 @_Z6querybii(i32 noundef %62, i32 noundef %63)
  %65 = sub nsw i32 %60, %64
  %66 = sext i32 %65 to i64
  %67 = load i64, ptr @ans, align 8, !tbaa !5
  %68 = add nsw i64 %67, %66
  store i64 %68, ptr @ans, align 8, !tbaa !5
  br label %69

69:                                               ; preds = %58, %55
  %70 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZN9__gnu_cxx17__normal_iteratorIPSt4pairIS1_IiiES2_ESt6vectorIS3_SaIS3_EEEppEv(ptr noundef nonnull align 8 dereferenceable(8) %1) #5
  %71 = call noundef zeroext i1 @_ZN9__gnu_cxxneIPSt4pairIS1_IiiES2_ESt6vectorIS3_SaIS3_EEEEbRKNS_17__normal_iteratorIT_T0_EESD_(ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef nonnull align 8 dereferenceable(8) %2) #5
  br i1 %71, label %.lr.ph23, label %._crit_edge
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN9__gnu_cxxneIPSt4pairIS1_IiiES2_ESt6vectorIS3_SaIS3_EEEEbRKNS_17__normal_iteratorIT_T0_EESD_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #4

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

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZN9__gnu_cxx17__normal_iteratorIPSt4pairIS1_IiiES2_ESt6vectorIS3_SaIS3_EEEppEv(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #2 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 #0 align 2

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

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

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


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