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

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

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@tot = external dso_local global i32, align 4
@que = external dso_local global [1000003 x i32], align 16
@ans = external dso_local global i32, align 4
@a = external dso_local global [500001 x %struct.Node], align 16
@seg = external dso_local global [2000005 x %struct.Seg], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z7seg_updiiiii(i32 noundef, i32 noundef, 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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z7seg_idxii(i32 noundef, i32 noundef) #2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z3updRii(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef) #3

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #4 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @m)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #7
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %10

10:                                               ; preds = %19, %0
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = load i32, ptr @n, align 4, !tbaa !5
  %13 = icmp slt i32 %11, %12
  br i1 %13, label %15, label %14

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

15:                                               ; preds = %10
  %16 = load i32, ptr %2, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [500001 x %struct.Node], ptr @a, i64 0, i64 %17
  call void @_ZN4Node5parseEv(ptr noundef nonnull align 4 dereferenceable(8) %18)
  br label %19

19:                                               ; preds = %15
  %20 = load i32, ptr %2, align 4, !tbaa !5
  %21 = add nsw i32 %20, 1
  store i32 %21, ptr %2, align 4, !tbaa !5
  br label %10, !llvm.loop !9

22:                                               ; preds = %14
  %23 = load i32, ptr @n, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds %struct.Node, ptr @a, i64 %24
  call void @_ZSt4sortIP4NodeEvT_S2_(ptr noundef @a, ptr noundef %25)
  %26 = load i32, ptr @tot, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds i32, ptr @que, i64 %27
  call void @_ZSt4sortIPiEvT_S1_(ptr noundef @que, ptr noundef %28)
  %29 = load i32, ptr @tot, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds i32, ptr @que, i64 %30
  %32 = call noundef ptr @_ZSt6uniqueIPiET_S1_S1_(ptr noundef @que, ptr noundef %31)
  %33 = ptrtoint ptr %32 to i64
  %34 = sub i64 %33, ptrtoint (ptr @que to i64)
  %35 = sdiv exact i64 %34, 4
  %36 = trunc i64 %35 to i32
  store i32 %36, ptr @tot, align 4, !tbaa !5
  store i32 1061109567, ptr @ans, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #7
  store i32 0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #7
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %37

37:                                               ; preds = %143, %22
  %38 = load i32, ptr %3, align 4, !tbaa !5
  %39 = load i32, ptr @n, align 4, !tbaa !5
  %40 = icmp slt i32 %38, %39
  br i1 %40, label %42, label %41

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

42:                                               ; preds = %37
  br label %43

43:                                               ; preds = %89, %42
  %44 = load i32, ptr %4, align 4, !tbaa !5
  %45 = load i32, ptr @n, align 4, !tbaa !5
  %46 = icmp slt i32 %44, %45
  br i1 %46, label %47, label %57

47:                                               ; preds = %43
  %48 = load i32, ptr @tot, align 4, !tbaa !5
  %49 = sub nsw i32 %48, 1
  %50 = call noundef i32 @_Z7seg_idxii(i32 noundef 0, i32 noundef %49)
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [2000005 x %struct.Seg], ptr @seg, i64 0, i64 %51
  %53 = getelementptr inbounds %struct.Seg, ptr %52, i32 0, i32 0
  %54 = load i32, ptr %53, align 8, !tbaa !11
  %55 = load i32, ptr @m, align 4, !tbaa !5
  %56 = icmp slt i32 %54, %55
  br label %57

57:                                               ; preds = %47, %43
  %58 = phi i1 [ false, %43 ], [ %56, %47 ]
  br i1 %58, label %59, label %92

59:                                               ; preds = %57
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #7
  %60 = load i32, ptr @tot, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds i32, ptr @que, i64 %61
  %63 = load i32, ptr %4, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [500001 x %struct.Node], ptr @a, i64 0, i64 %64
  %66 = getelementptr inbounds %struct.Node, ptr %65, i32 0, i32 0
  %67 = call noundef ptr @_ZSt11lower_boundIPiiET_S1_S1_RKT0_(ptr noundef @que, ptr noundef %62, ptr noundef nonnull align 4 dereferenceable(4) %66)
  %68 = ptrtoint ptr %67 to i64
  %69 = sub i64 %68, ptrtoint (ptr @que to i64)
  %70 = sdiv exact i64 %69, 4
  %71 = trunc i64 %70 to i32
  store i32 %71, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #7
  %72 = load i32, ptr @tot, align 4, !tbaa !5
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds i32, ptr @que, i64 %73
  %75 = load i32, ptr %4, align 4, !tbaa !5
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds [500001 x %struct.Node], ptr @a, i64 0, i64 %76
  %78 = getelementptr inbounds %struct.Node, ptr %77, i32 0, i32 1
  %79 = call noundef ptr @_ZSt11lower_boundIPiiET_S1_S1_RKT0_(ptr noundef @que, ptr noundef %74, ptr noundef nonnull align 4 dereferenceable(4) %78)
  %80 = ptrtoint ptr %79 to i64
  %81 = sub i64 %80, ptrtoint (ptr @que to i64)
  %82 = sdiv exact i64 %81, 4
  %83 = trunc i64 %82 to i32
  store i32 %83, ptr %6, align 4, !tbaa !5
  %84 = load i32, ptr @tot, align 4, !tbaa !5
  %85 = sub nsw i32 %84, 1
  %86 = load i32, ptr %5, align 4, !tbaa !5
  %87 = load i32, ptr %6, align 4, !tbaa !5
  %88 = sub nsw i32 %87, 1
  call void @_Z7seg_updiiiii(i32 noundef 0, i32 noundef %85, i32 noundef %86, i32 noundef %88, i32 noundef 1)
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #7
  br label %89

89:                                               ; preds = %59
  %90 = load i32, ptr %4, align 4, !tbaa !5
  %91 = add nsw i32 %90, 1
  store i32 %91, ptr %4, align 4, !tbaa !5
  br label %43, !llvm.loop !13

92:                                               ; preds = %57
  %93 = load i32, ptr @tot, align 4, !tbaa !5
  %94 = sub nsw i32 %93, 1
  %95 = call noundef i32 @_Z7seg_idxii(i32 noundef 0, i32 noundef %94)
  %96 = sext i32 %95 to i64
  %97 = getelementptr inbounds [2000005 x %struct.Seg], ptr @seg, i64 0, i64 %96
  %98 = getelementptr inbounds %struct.Seg, ptr %97, i32 0, i32 0
  %99 = load i32, ptr %98, align 8, !tbaa !11
  %100 = load i32, ptr @m, align 4, !tbaa !5
  %101 = icmp sge i32 %99, %100
  br i1 %101, label %102, label %113

102:                                              ; preds = %92
  %103 = load i32, ptr %4, align 4, !tbaa !5
  %104 = sub nsw i32 %103, 1
  %105 = sext i32 %104 to i64
  %106 = getelementptr inbounds [500001 x %struct.Node], ptr @a, i64 0, i64 %105
  %107 = call noundef i32 @_ZNK4Node3lenEv(ptr noundef nonnull align 4 dereferenceable(8) %106)
  %108 = load i32, ptr %3, align 4, !tbaa !5
  %109 = sext i32 %108 to i64
  %110 = getelementptr inbounds [500001 x %struct.Node], ptr @a, i64 0, i64 %109
  %111 = call noundef i32 @_ZNK4Node3lenEv(ptr noundef nonnull align 4 dereferenceable(8) %110)
  %112 = sub nsw i32 %107, %111
  call void @_Z3updRii(ptr noundef nonnull align 4 dereferenceable(4) @ans, i32 noundef %112)
  br label %113

113:                                              ; preds = %102, %92
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #7
  %114 = load i32, ptr @tot, align 4, !tbaa !5
  %115 = sext i32 %114 to i64
  %116 = getelementptr inbounds i32, ptr @que, i64 %115
  %117 = load i32, ptr %3, align 4, !tbaa !5
  %118 = sext i32 %117 to i64
  %119 = getelementptr inbounds [500001 x %struct.Node], ptr @a, i64 0, i64 %118
  %120 = getelementptr inbounds %struct.Node, ptr %119, i32 0, i32 0
  %121 = call noundef ptr @_ZSt11lower_boundIPiiET_S1_S1_RKT0_(ptr noundef @que, ptr noundef %116, ptr noundef nonnull align 4 dereferenceable(4) %120)
  %122 = ptrtoint ptr %121 to i64
  %123 = sub i64 %122, ptrtoint (ptr @que to i64)
  %124 = sdiv exact i64 %123, 4
  %125 = trunc i64 %124 to i32
  store i32 %125, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #7
  %126 = load i32, ptr @tot, align 4, !tbaa !5
  %127 = sext i32 %126 to i64
  %128 = getelementptr inbounds i32, ptr @que, i64 %127
  %129 = load i32, ptr %3, align 4, !tbaa !5
  %130 = sext i32 %129 to i64
  %131 = getelementptr inbounds [500001 x %struct.Node], ptr @a, i64 0, i64 %130
  %132 = getelementptr inbounds %struct.Node, ptr %131, i32 0, i32 1
  %133 = call noundef ptr @_ZSt11lower_boundIPiiET_S1_S1_RKT0_(ptr noundef @que, ptr noundef %128, ptr noundef nonnull align 4 dereferenceable(4) %132)
  %134 = ptrtoint ptr %133 to i64
  %135 = sub i64 %134, ptrtoint (ptr @que to i64)
  %136 = sdiv exact i64 %135, 4
  %137 = trunc i64 %136 to i32
  store i32 %137, ptr %8, align 4, !tbaa !5
  %138 = load i32, ptr @tot, align 4, !tbaa !5
  %139 = sub nsw i32 %138, 1
  %140 = load i32, ptr %7, align 4, !tbaa !5
  %141 = load i32, ptr %8, align 4, !tbaa !5
  %142 = sub nsw i32 %141, 1
  call void @_Z7seg_updiiiii(i32 noundef 0, i32 noundef %139, i32 noundef %140, i32 noundef %142, i32 noundef -1)
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #7
  br label %143

143:                                              ; preds = %113
  %144 = load i32, ptr %3, align 4, !tbaa !5
  %145 = add nsw i32 %144, 1
  store i32 %145, ptr %3, align 4, !tbaa !5
  br label %37, !llvm.loop !14

146:                                              ; preds = %41
  %147 = load i32, ptr @ans, align 4, !tbaa !5
  %148 = icmp eq i32 %147, 1061109567
  br i1 %148, label %149, label %150

149:                                              ; preds = %146
  br label %152

150:                                              ; preds = %146
  %151 = load i32, ptr @ans, align 4, !tbaa !5
  br label %152

152:                                              ; preds = %150, %149
  %153 = phi i32 [ -1, %149 ], [ %151, %150 ]
  %154 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %153)
  ret i32 0
}

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

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

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZSt6uniqueIPiET_S1_S1_(ptr noundef, ptr noundef) #6

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

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

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

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 = { 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 #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 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 #5 = { "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 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !6, i64 0}
!12 = !{!"_ZTS3Seg", !6, i64 0, !6, i64 4}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10}


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

%struct.Node = type { i32, i32 }
%struct.Seg = type { i32, i32 }

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@tot = external dso_local local_unnamed_addr global i32, align 4
@que = external dso_local global [1000003 x i32], align 16
@ans = external dso_local global i32, align 4
@a = external dso_local global [500001 x %struct.Node], align 16
@seg = external dso_local local_unnamed_addr global [2000005 x %struct.Seg], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z7seg_idxii(i32 noundef, i32 noundef) local_unnamed_addr #1

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #3 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @m)
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %3 = icmp sgt i32 %2, 0
  br i1 %3, label %.lr.ph, label %.._crit_edge_crit_edge

.._crit_edge_crit_edge:                           ; preds = %0
  %.pre38 = sext i32 %2 to i64
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %.._crit_edge_crit_edge
  %.pre-phi = phi i64 [ %.pre38, %.._crit_edge_crit_edge ], [ %20, %.lr.ph ]
  %4 = getelementptr inbounds %struct.Node, ptr @a, i64 %.pre-phi
  tail call void @_ZSt4sortIP4NodeEvT_S2_(ptr noundef nonnull @a, ptr noundef nonnull %4)
  %5 = load i32, ptr @tot, align 4, !tbaa !5
  %6 = sext i32 %5 to i64
  %7 = getelementptr inbounds i32, ptr @que, i64 %6
  tail call void @_ZSt4sortIPiEvT_S1_(ptr noundef nonnull @que, ptr noundef nonnull %7)
  %8 = load i32, ptr @tot, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds i32, ptr @que, i64 %9
  %11 = tail call noundef ptr @_ZSt6uniqueIPiET_S1_S1_(ptr noundef nonnull @que, ptr noundef nonnull %10)
  %12 = ptrtoint ptr %11 to i64
  %13 = sub i64 %12, ptrtoint (ptr @que to i64)
  %14 = lshr exact i64 %13, 2
  %15 = trunc i64 %14 to i32
  store i32 %15, ptr @tot, align 4, !tbaa !5
  store i32 1061109567, ptr @ans, align 4, !tbaa !5
  %16 = load i32, ptr @n, align 4, !tbaa !5
  %17 = icmp sgt i32 %16, 0
  br i1 %17, label %.preheader, label %._crit_edge28.thread

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %0 ]
  %18 = getelementptr inbounds [500001 x %struct.Node], ptr @a, i64 0, i64 %indvars.iv
  tail call void @_ZN4Node5parseEv(ptr noundef nonnull align 4 dereferenceable(8) %18)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %19 = load i32, ptr @n, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = icmp slt i64 %indvars.iv.next, %20
  br i1 %21, label %.lr.ph, label %._crit_edge, !llvm.loop !9

.preheader:                                       ; preds = %._crit_edge, %77
  %22 = phi i32 [ %99, %77 ], [ %16, %._crit_edge ]
  %indvars.iv34 = phi i64 [ %indvars.iv.next35, %77 ], [ 0, %._crit_edge ]
  %.01826 = phi i32 [ %.1.lcssa, %77 ], [ 0, %._crit_edge ]
  %23 = icmp slt i32 %.01826, %22
  br i1 %23, label %.lr.ph22.preheader, label %.critedge

.lr.ph22.preheader:                               ; preds = %.preheader
  %24 = sext i32 %.01826 to i64
  br label %.lr.ph22

._crit_edge28:                                    ; preds = %77
  %.pre = load i32, ptr @ans, align 4
  %.pre.fr = freeze i32 %.pre
  %25 = icmp eq i32 %.pre.fr, 1061109567
  br i1 %25, label %._crit_edge28.thread, label %26

._crit_edge28.thread:                             ; preds = %._crit_edge, %._crit_edge28
  br label %26

26:                                               ; preds = %._crit_edge28, %._crit_edge28.thread
  %27 = phi i32 [ -1, %._crit_edge28.thread ], [ %.pre.fr, %._crit_edge28 ]
  %28 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %27)
  ret i32 0

.lr.ph22:                                         ; preds = %.lr.ph22.preheader, %37
  %indvars.iv31 = phi i64 [ %24, %.lr.ph22.preheader ], [ %indvars.iv.next32, %37 ]
  %29 = load i32, ptr @tot, align 4, !tbaa !5
  %30 = add nsw i32 %29, -1
  %31 = tail call noundef i32 @_Z7seg_idxii(i32 noundef 0, i32 noundef %30)
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [2000005 x %struct.Seg], ptr @seg, i64 0, i64 %32
  %34 = load i32, ptr %33, align 8, !tbaa !11
  %35 = load i32, ptr @m, align 4, !tbaa !5
  %36 = icmp slt i32 %34, %35
  br i1 %36, label %37, label %.critedge.loopexit

37:                                               ; preds = %.lr.ph22
  %38 = load i32, ptr @tot, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds i32, ptr @que, i64 %39
  %41 = getelementptr inbounds [500001 x %struct.Node], ptr @a, i64 0, i64 %indvars.iv31
  %42 = tail call noundef ptr @_ZSt11lower_boundIPiiET_S1_S1_RKT0_(ptr noundef nonnull @que, ptr noundef nonnull %40, ptr noundef nonnull align 4 dereferenceable(4) %41)
  %43 = ptrtoint ptr %42 to i64
  %44 = sub i64 %43, ptrtoint (ptr @que to i64)
  %45 = lshr exact i64 %44, 2
  %46 = trunc i64 %45 to i32
  %47 = load i32, ptr @tot, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds i32, ptr @que, i64 %48
  %50 = getelementptr inbounds i8, ptr %41, i64 4
  %51 = tail call noundef ptr @_ZSt11lower_boundIPiiET_S1_S1_RKT0_(ptr noundef nonnull @que, ptr noundef nonnull %49, ptr noundef nonnull align 4 dereferenceable(4) %50)
  %52 = ptrtoint ptr %51 to i64
  %53 = sub i64 %52, ptrtoint (ptr @que to i64)
  %54 = lshr exact i64 %53, 2
  %55 = trunc i64 %54 to i32
  %56 = load i32, ptr @tot, align 4, !tbaa !5
  %57 = add nsw i32 %56, -1
  %58 = add nsw i32 %55, -1
  tail call void @_Z7seg_updiiiii(i32 noundef 0, i32 noundef %57, i32 noundef %46, i32 noundef %58, i32 noundef 1)
  %indvars.iv.next32 = add nsw i64 %indvars.iv31, 1
  %59 = load i32, ptr @n, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = icmp slt i64 %indvars.iv.next32, %60
  br i1 %61, label %.lr.ph22, label %.critedge.loopexit, !llvm.loop !13

.critedge.loopexit:                               ; preds = %37, %.lr.ph22
  %.1.lcssa.ph.in = phi i64 [ %indvars.iv31, %.lr.ph22 ], [ %indvars.iv.next32, %37 ]
  %.1.lcssa.ph = trunc i64 %.1.lcssa.ph.in to i32
  br label %.critedge

.critedge:                                        ; preds = %.critedge.loopexit, %.preheader
  %.1.lcssa = phi i32 [ %.01826, %.preheader ], [ %.1.lcssa.ph, %.critedge.loopexit ]
  %62 = load i32, ptr @tot, align 4, !tbaa !5
  %63 = add nsw i32 %62, -1
  %64 = tail call noundef i32 @_Z7seg_idxii(i32 noundef 0, i32 noundef %63)
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [2000005 x %struct.Seg], ptr @seg, i64 0, i64 %65
  %67 = load i32, ptr %66, align 8, !tbaa !11
  %68 = load i32, ptr @m, align 4, !tbaa !5
  %.not = icmp slt i32 %67, %68
  br i1 %.not, label %77, label %69

69:                                               ; preds = %.critedge
  %70 = add nsw i32 %.1.lcssa, -1
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [500001 x %struct.Node], ptr @a, i64 0, i64 %71
  %73 = tail call noundef i32 @_ZNK4Node3lenEv(ptr noundef nonnull align 4 dereferenceable(8) %72)
  %74 = getelementptr inbounds [500001 x %struct.Node], ptr @a, i64 0, i64 %indvars.iv34
  %75 = tail call noundef i32 @_ZNK4Node3lenEv(ptr noundef nonnull align 4 dereferenceable(8) %74)
  %76 = sub nsw i32 %73, %75
  tail call void @_Z3updRii(ptr noundef nonnull align 4 dereferenceable(4) @ans, i32 noundef %76)
  br label %77

77:                                               ; preds = %69, %.critedge
  %78 = load i32, ptr @tot, align 4, !tbaa !5
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds i32, ptr @que, i64 %79
  %81 = getelementptr inbounds [500001 x %struct.Node], ptr @a, i64 0, i64 %indvars.iv34
  %82 = tail call noundef ptr @_ZSt11lower_boundIPiiET_S1_S1_RKT0_(ptr noundef nonnull @que, ptr noundef nonnull %80, ptr noundef nonnull align 4 dereferenceable(4) %81)
  %83 = ptrtoint ptr %82 to i64
  %84 = sub i64 %83, ptrtoint (ptr @que to i64)
  %85 = lshr exact i64 %84, 2
  %86 = trunc i64 %85 to i32
  %87 = load i32, ptr @tot, align 4, !tbaa !5
  %88 = sext i32 %87 to i64
  %89 = getelementptr inbounds i32, ptr @que, i64 %88
  %90 = getelementptr inbounds i8, ptr %81, i64 4
  %91 = tail call noundef ptr @_ZSt11lower_boundIPiiET_S1_S1_RKT0_(ptr noundef nonnull @que, ptr noundef nonnull %89, ptr noundef nonnull align 4 dereferenceable(4) %90)
  %92 = ptrtoint ptr %91 to i64
  %93 = sub i64 %92, ptrtoint (ptr @que to i64)
  %94 = lshr exact i64 %93, 2
  %95 = trunc i64 %94 to i32
  %96 = load i32, ptr @tot, align 4, !tbaa !5
  %97 = add nsw i32 %96, -1
  %98 = add nsw i32 %95, -1
  tail call void @_Z7seg_updiiiii(i32 noundef 0, i32 noundef %97, i32 noundef %86, i32 noundef %98, i32 noundef -1)
  %indvars.iv.next35 = add nuw nsw i64 %indvars.iv34, 1
  %99 = load i32, ptr @n, align 4, !tbaa !5
  %100 = sext i32 %99 to i64
  %101 = icmp slt i64 %indvars.iv.next35, %100
  br i1 %101, label %.preheader, label %._crit_edge28, !llvm.loop !14
}

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

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

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

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZSt11lower_boundIPiiET_S1_S1_RKT0_(ptr noundef, ptr noundef, ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #5

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

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

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 = { 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 #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 = { nofree nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #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" }

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

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


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