; LLVM IR from eyangch/competitive-programming :: USACOcontests/platinum/2016.02 (balancing)

; 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 }
%struct.segtree = type { [3 x [2000005 x i64]] }
%"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" }

@N = external dso_local global i64, align 8
@P = external dso_local global [100000 x %"struct.std::pair"], align 16
@S = external dso_local global %struct.segtree, align 8
@_ZSt3cin = external global %"class.std::basic_istream", align 8
@.str = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@stdin = external global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1
@stdout = external global ptr, align 8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  store i32 0, ptr %1, align 4
  %7 = load ptr, ptr @_ZSt3cin, align 8, !tbaa !5
  %8 = getelementptr i8, ptr %7, i64 -24
  %9 = load i64, ptr %8, align 8
  %10 = getelementptr inbounds i8, ptr @_ZSt3cin, i64 %9
  %11 = call noundef ptr @_ZNSt9basic_iosIcSt11char_traitsIcEE3tieEPSo(ptr noundef nonnull align 8 dereferenceable(264) %10, ptr noundef null)
  %12 = call noundef zeroext i1 @_ZNSt8ios_base15sync_with_stdioEb(i1 noundef zeroext false)
  %13 = load ptr, ptr @stdin, align 8, !tbaa !8
  %14 = call ptr @freopen(ptr noundef @.str, ptr noundef @.str.1, ptr noundef %13)
  %15 = load ptr, ptr @stdout, align 8, !tbaa !8
  %16 = call ptr @freopen(ptr noundef @.str.2, ptr noundef @.str.3, ptr noundef %15)
  %17 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) @N)
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #7
  store i64 0, ptr %2, align 8, !tbaa !11
  br label %18

18:                                               ; preds = %42, %0
  %19 = load i64, ptr %2, align 8, !tbaa !11
  %20 = load i64, ptr @N, align 8, !tbaa !11
  %21 = icmp slt i64 %19, %20
  br i1 %21, label %23, label %22

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

23:                                               ; preds = %18
  %24 = load i64, ptr %2, align 8, !tbaa !11
  %25 = getelementptr inbounds [100000 x %"struct.std::pair"], ptr @P, i64 0, i64 %24
  %26 = getelementptr inbounds %"struct.std::pair", ptr %25, i32 0, i32 0
  %27 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) %26)
  %28 = load i64, ptr %2, align 8, !tbaa !11
  %29 = getelementptr inbounds [100000 x %"struct.std::pair"], ptr @P, i64 0, i64 %28
  %30 = getelementptr inbounds %"struct.std::pair", ptr %29, i32 0, i32 1
  %31 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) %27, ptr noundef nonnull align 8 dereferenceable(8) %30)
  %32 = load i64, ptr %2, align 8, !tbaa !11
  %33 = getelementptr inbounds [100000 x %"struct.std::pair"], ptr @P, i64 0, i64 %32
  %34 = getelementptr inbounds %"struct.std::pair", ptr %33, i32 0, i32 0
  %35 = load i64, ptr %34, align 16, !tbaa !13
  %36 = sdiv i64 %35, 2
  store i64 %36, ptr %34, align 16, !tbaa !13
  %37 = load i64, ptr %2, align 8, !tbaa !11
  %38 = getelementptr inbounds [100000 x %"struct.std::pair"], ptr @P, i64 0, i64 %37
  %39 = getelementptr inbounds %"struct.std::pair", ptr %38, i32 0, i32 1
  %40 = load i64, ptr %39, align 8, !tbaa !15
  %41 = sdiv i64 %40, 2
  store i64 %41, ptr %39, align 8, !tbaa !15
  br label %42

42:                                               ; preds = %23
  %43 = load i64, ptr %2, align 8, !tbaa !11
  %44 = add nsw i64 %43, 1
  store i64 %44, ptr %2, align 8, !tbaa !11
  br label %18, !llvm.loop !16

45:                                               ; preds = %22
  %46 = load i64, ptr @N, align 8, !tbaa !11
  %47 = getelementptr inbounds %"struct.std::pair", ptr @P, i64 %46
  call void @_ZSt4sortIPSt4pairIxxEEvT_S3_(ptr noundef @P, ptr noundef %47)
  call void @_ZN7segtree4initEv(ptr noundef nonnull align 8 dereferenceable(48000120) @S)
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #7
  store i64 0, ptr %3, align 8, !tbaa !11
  br label %48

48:                                               ; preds = %58, %45
  %49 = load i64, ptr %3, align 8, !tbaa !11
  %50 = load i64, ptr @N, align 8, !tbaa !11
  %51 = icmp slt i64 %49, %50
  br i1 %51, label %53, label %52

52:                                               ; preds = %48
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #7
  br label %61

53:                                               ; preds = %48
  %54 = load i64, ptr %3, align 8, !tbaa !11
  %55 = getelementptr inbounds [100000 x %"struct.std::pair"], ptr @P, i64 0, i64 %54
  %56 = getelementptr inbounds %"struct.std::pair", ptr %55, i32 0, i32 1
  %57 = load i64, ptr %56, align 8, !tbaa !15
  call void @_ZN7segtree3updExxxxxx(ptr noundef nonnull align 8 dereferenceable(48000120) @S, i64 noundef %57, i64 noundef 0, i64 noundef 1, i64 noundef 1, i64 noundef 0, i64 noundef 500000)
  br label %58

58:                                               ; preds = %53
  %59 = load i64, ptr %3, align 8, !tbaa !11
  %60 = add nsw i64 %59, 1
  store i64 %60, ptr %3, align 8, !tbaa !11
  br label %48, !llvm.loop !18

61:                                               ; preds = %52
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #7
  %62 = call noundef i64 @_ZN7segtree3qryExxxxxxx(ptr noundef nonnull align 8 dereferenceable(48000120) @S, i64 noundef 1, i64 noundef 0, i64 noundef 500000, i64 noundef 0, i64 noundef 0, i64 noundef 0, i64 noundef 0)
  store i64 %62, ptr %4, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #7
  store i64 0, ptr %5, align 8, !tbaa !11
  br label %63

63:                                               ; preds = %97, %61
  %64 = load i64, ptr %5, align 8, !tbaa !11
  %65 = load i64, ptr @N, align 8, !tbaa !11
  %66 = icmp slt i64 %64, %65
  br i1 %66, label %68, label %67

67:                                               ; preds = %63
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #7
  br label %100

68:                                               ; preds = %63
  %69 = load i64, ptr %5, align 8, !tbaa !11
  %70 = getelementptr inbounds [100000 x %"struct.std::pair"], ptr @P, i64 0, i64 %69
  %71 = getelementptr inbounds %"struct.std::pair", ptr %70, i32 0, i32 1
  %72 = load i64, ptr %71, align 8, !tbaa !15
  call void @_ZN7segtree3updExxxxxx(ptr noundef nonnull align 8 dereferenceable(48000120) @S, i64 noundef %72, i64 noundef 1, i64 noundef 1, i64 noundef 1, i64 noundef 0, i64 noundef 500000)
  %73 = load i64, ptr %5, align 8, !tbaa !11
  %74 = getelementptr inbounds [100000 x %"struct.std::pair"], ptr @P, i64 0, i64 %73
  %75 = getelementptr inbounds %"struct.std::pair", ptr %74, i32 0, i32 1
  %76 = load i64, ptr %75, align 8, !tbaa !15
  call void @_ZN7segtree3updExxxxxx(ptr noundef nonnull align 8 dereferenceable(48000120) @S, i64 noundef %76, i64 noundef 0, i64 noundef -1, i64 noundef 1, i64 noundef 0, i64 noundef 500000)
  %77 = load i64, ptr %5, align 8, !tbaa !11
  %78 = load i64, ptr @N, align 8, !tbaa !11
  %79 = sub nsw i64 %78, 1
  %80 = icmp eq i64 %77, %79
  br i1 %80, label %92, label %81

81:                                               ; preds = %68
  %82 = load i64, ptr %5, align 8, !tbaa !11
  %83 = getelementptr inbounds [100000 x %"struct.std::pair"], ptr @P, i64 0, i64 %82
  %84 = getelementptr inbounds %"struct.std::pair", ptr %83, i32 0, i32 0
  %85 = load i64, ptr %84, align 16, !tbaa !13
  %86 = load i64, ptr %5, align 8, !tbaa !11
  %87 = add nsw i64 %86, 1
  %88 = getelementptr inbounds [100000 x %"struct.std::pair"], ptr @P, i64 0, i64 %87
  %89 = getelementptr inbounds %"struct.std::pair", ptr %88, i32 0, i32 0
  %90 = load i64, ptr %89, align 16, !tbaa !13
  %91 = icmp ne i64 %85, %90
  br i1 %91, label %92, label %96

92:                                               ; preds = %81, %68
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #7
  %93 = call noundef i64 @_ZN7segtree3qryExxxxxxx(ptr noundef nonnull align 8 dereferenceable(48000120) @S, i64 noundef 1, i64 noundef 0, i64 noundef 500000, i64 noundef 0, i64 noundef 0, i64 noundef 0, i64 noundef 0)
  store i64 %93, ptr %6, align 8, !tbaa !11
  %94 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %4, ptr noundef nonnull align 8 dereferenceable(8) %6)
  %95 = load i64, ptr %94, align 8, !tbaa !11
  store i64 %95, ptr %4, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #7
  br label %96

96:                                               ; preds = %92, %81
  br label %97

97:                                               ; preds = %96
  %98 = load i64, ptr %5, align 8, !tbaa !11
  %99 = add nsw i64 %98, 1
  store i64 %99, ptr %5, align 8, !tbaa !11
  br label %63, !llvm.loop !19

100:                                              ; preds = %67
  %101 = load i64, ptr %4, align 8, !tbaa !11
  %102 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %101)
  %103 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c(ptr noundef nonnull align 8 dereferenceable(8) %102, i8 noundef signext 10)
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #7
  %104 = load i32, ptr %1, align 4
  ret i32 %104
}

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

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

declare ptr @freopen(ptr noundef, ptr noundef, ptr noundef) #2

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

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

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7segtree4initEv(ptr noundef nonnull align 8 dereferenceable(48000120)) #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7segtree3updExxxxxx(ptr noundef nonnull align 8 dereferenceable(48000120), i64 noundef, i64 noundef, i64 noundef, i64 noundef, i64 noundef, i64 noundef) #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_ZN7segtree3qryExxxxxxx(ptr noundef nonnull align 8 dereferenceable(48000120), i64 noundef, i64 noundef, i64 noundef, i64 noundef, i64 noundef, i64 noundef, i64 noundef) #3 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #6

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c(ptr noundef nonnull align 8 dereferenceable(8), i8 noundef signext) #5

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

attributes #0 = { 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 #1 = { 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 #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 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { 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 #6 = { 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 #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 = !{!"any pointer", !10, i64 0}
!10 = !{!"omnipotent char", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !10, i64 0}
!13 = !{!14, !12, i64 0}
!14 = !{!"_ZTSSt4pairIxxE", !12, i64 0, !12, i64 8}
!15 = !{!14, !12, i64 8}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}
!19 = distinct !{!19, !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"

%"struct.std::pair" = type { i64, i64 }
%struct.segtree = type { [3 x [2000005 x i64]] }
%"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" }

@N = external dso_local global i64, align 8
@P = external dso_local global [100000 x %"struct.std::pair"], align 16
@S = external dso_local global %struct.segtree, align 8
@_ZSt3cin = external global %"class.std::basic_istream", align 8
@.str = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@stdin = external local_unnamed_addr global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1
@stdout = external local_unnamed_addr global ptr, align 8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i64, align 8
  %2 = alloca i64, align 8
  %3 = load ptr, ptr @_ZSt3cin, align 8, !tbaa !5
  %4 = getelementptr i8, ptr %3, i64 -24
  %5 = load i64, ptr %4, align 8
  %6 = getelementptr inbounds i8, ptr @_ZSt3cin, i64 %5
  %7 = tail call noundef ptr @_ZNSt9basic_iosIcSt11char_traitsIcEE3tieEPSo(ptr noundef nonnull align 8 dereferenceable(264) %6, ptr noundef null)
  %8 = tail call noundef zeroext i1 @_ZNSt8ios_base15sync_with_stdioEb(i1 noundef zeroext false)
  %9 = load ptr, ptr @stdin, align 8, !tbaa !8
  %10 = tail call ptr @freopen(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, ptr noundef %9)
  %11 = load ptr, ptr @stdout, align 8, !tbaa !8
  %12 = tail call ptr @freopen(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.3, ptr noundef %11)
  %13 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) @N)
  %14 = load i64, ptr @N, align 8, !tbaa !11
  %15 = icmp sgt i64 %14, 0
  br i1 %15, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %0
  %.lcssa = phi i64 [ %14, %0 ], [ %26, %.lr.ph ]
  %16 = getelementptr inbounds %"struct.std::pair", ptr @P, i64 %.lcssa
  tail call void @_ZSt4sortIPSt4pairIxxEEvT_S3_(ptr noundef nonnull @P, ptr noundef nonnull %16)
  tail call void @_ZN7segtree4initEv(ptr noundef nonnull align 8 dereferenceable(48000120) @S)
  %17 = load i64, ptr @N, align 8, !tbaa !11
  %18 = icmp sgt i64 %17, 0
  br i1 %18, label %.lr.ph23, label %._crit_edge24

.lr.ph:                                           ; preds = %0, %.lr.ph
  %.01820 = phi i64 [ %25, %.lr.ph ], [ 0, %0 ]
  %19 = getelementptr inbounds [100000 x %"struct.std::pair"], ptr @P, i64 0, i64 %.01820
  %20 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) %19)
  %21 = getelementptr inbounds i8, ptr %19, i64 8
  %22 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) %20, ptr noundef nonnull align 8 dereferenceable(8) %21)
  %23 = load <2 x i64>, ptr %19, align 16, !tbaa !11
  %24 = sdiv <2 x i64> %23, <i64 2, i64 2>
  store <2 x i64> %24, ptr %19, align 16, !tbaa !11
  %25 = add nuw nsw i64 %.01820, 1
  %26 = load i64, ptr @N, align 8, !tbaa !11
  %27 = icmp slt i64 %25, %26
  br i1 %27, label %.lr.ph, label %._crit_edge, !llvm.loop !13

._crit_edge24:                                    ; preds = %.lr.ph23, %._crit_edge
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #7
  %28 = tail call noundef i64 @_ZN7segtree3qryExxxxxxx(ptr noundef nonnull align 8 dereferenceable(48000120) @S, i64 noundef 1, i64 noundef 0, i64 noundef 500000, i64 noundef 0, i64 noundef 0, i64 noundef 0, i64 noundef 0)
  store i64 %28, ptr %1, align 8, !tbaa !11
  %29 = load i64, ptr @N, align 8, !tbaa !11
  %30 = icmp sgt i64 %29, 0
  br i1 %30, label %.lr.ph27, label %._crit_edge28

.lr.ph23:                                         ; preds = %._crit_edge, %.lr.ph23
  %.01721 = phi i64 [ %33, %.lr.ph23 ], [ 0, %._crit_edge ]
  %31 = getelementptr inbounds [100000 x %"struct.std::pair"], ptr @P, i64 0, i64 %.01721, i32 1
  %32 = load i64, ptr %31, align 8, !tbaa !15
  tail call void @_ZN7segtree3updExxxxxx(ptr noundef nonnull align 8 dereferenceable(48000120) @S, i64 noundef %32, i64 noundef 0, i64 noundef 1, i64 noundef 1, i64 noundef 0, i64 noundef 500000)
  %33 = add nuw nsw i64 %.01721, 1
  %34 = load i64, ptr @N, align 8, !tbaa !11
  %35 = icmp slt i64 %33, %34
  br i1 %35, label %.lr.ph23, label %._crit_edge24, !llvm.loop !17

._crit_edge28.loopexit:                           ; preds = %55
  %.pre30 = load i64, ptr %1, align 8, !tbaa !11
  br label %._crit_edge28

._crit_edge28:                                    ; preds = %._crit_edge28.loopexit, %._crit_edge24
  %36 = phi i64 [ %.pre30, %._crit_edge28.loopexit ], [ %28, %._crit_edge24 ]
  %37 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %36)
  %38 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c(ptr noundef nonnull align 8 dereferenceable(8) %37, i8 noundef signext 10)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #7
  ret i32 0

.lr.ph27:                                         ; preds = %._crit_edge24, %55
  %.025 = phi i64 [ %.pre-phi, %55 ], [ 0, %._crit_edge24 ]
  %39 = getelementptr inbounds [100000 x %"struct.std::pair"], ptr @P, i64 0, i64 %.025
  %40 = getelementptr inbounds i8, ptr %39, i64 8
  %41 = load i64, ptr %40, align 8, !tbaa !15
  call void @_ZN7segtree3updExxxxxx(ptr noundef nonnull align 8 dereferenceable(48000120) @S, i64 noundef %41, i64 noundef 1, i64 noundef 1, i64 noundef 1, i64 noundef 0, i64 noundef 500000)
  %42 = load i64, ptr %40, align 8, !tbaa !15
  call void @_ZN7segtree3updExxxxxx(ptr noundef nonnull align 8 dereferenceable(48000120) @S, i64 noundef %42, i64 noundef 0, i64 noundef -1, i64 noundef 1, i64 noundef 0, i64 noundef 500000)
  %43 = load i64, ptr @N, align 8, !tbaa !11
  %44 = add nsw i64 %43, -1
  %45 = icmp eq i64 %.025, %44
  br i1 %45, label %.lr.ph27._crit_edge, label %46

.lr.ph27._crit_edge:                              ; preds = %.lr.ph27
  %.pre32 = add nuw nsw i64 %.025, 1
  br label %51

46:                                               ; preds = %.lr.ph27
  %47 = load i64, ptr %39, align 16, !tbaa !18
  %48 = add nuw nsw i64 %.025, 1
  %49 = getelementptr inbounds [100000 x %"struct.std::pair"], ptr @P, i64 0, i64 %48
  %50 = load i64, ptr %49, align 16, !tbaa !18
  %.not = icmp eq i64 %47, %50
  br i1 %.not, label %55, label %51

51:                                               ; preds = %.lr.ph27._crit_edge, %46
  %.pre31.pre-phi = phi i64 [ %.pre32, %.lr.ph27._crit_edge ], [ %48, %46 ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #7
  %52 = call noundef i64 @_ZN7segtree3qryExxxxxxx(ptr noundef nonnull align 8 dereferenceable(48000120) @S, i64 noundef 1, i64 noundef 0, i64 noundef 500000, i64 noundef 0, i64 noundef 0, i64 noundef 0, i64 noundef 0)
  store i64 %52, ptr %2, align 8, !tbaa !11
  %53 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef nonnull align 8 dereferenceable(8) %2)
  %54 = load i64, ptr %53, align 8, !tbaa !11
  store i64 %54, ptr %1, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #7
  %.pre = load i64, ptr @N, align 8, !tbaa !11
  br label %55

55:                                               ; preds = %46, %51
  %.pre-phi = phi i64 [ %48, %46 ], [ %.pre31.pre-phi, %51 ]
  %56 = phi i64 [ %43, %46 ], [ %.pre, %51 ]
  %57 = icmp slt i64 %.pre-phi, %56
  br i1 %57, label %.lr.ph27, label %._crit_edge28.loopexit, !llvm.loop !19
}

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

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

declare ptr @freopen(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

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

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

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7segtree4initEv(ptr noundef nonnull align 8 dereferenceable(48000120)) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7segtree3updExxxxxx(ptr noundef nonnull align 8 dereferenceable(48000120), i64 noundef, i64 noundef, i64 noundef, i64 noundef, i64 noundef, i64 noundef) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_ZN7segtree3qryExxxxxxx(ptr noundef nonnull align 8 dereferenceable(48000120), i64 noundef, i64 noundef, i64 noundef, i64 noundef, i64 noundef, i64 noundef, i64 noundef) local_unnamed_addr #3 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #6

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c(ptr noundef nonnull align 8 dereferenceable(8), i8 noundef signext) local_unnamed_addr #5

; 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 #3 align 2

attributes #0 = { 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 #1 = { 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 #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 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { 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 #6 = { 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 #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 = !{!"any pointer", !10, i64 0}
!10 = !{!"omnipotent char", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !10, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !12, i64 8}
!16 = !{!"_ZTSSt4pairIxxE", !12, i64 0, !12, i64 8}
!17 = distinct !{!17, !14}
!18 = !{!16, !12, i64 0}
!19 = distinct !{!19, !14}


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