; LLVM IR from tangjz/acm-icpc :: 51nod (1672)

; 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, i32 }

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@q = external dso_local global i32, align 4
@tot = external dso_local global i32, align 4
@seg = external dso_local global [200020 x i32], align 16
@s = external dso_local global [100010 x i64], align 16
@ans = external dso_local global i64, align 8
@que = external dso_local global [200020 x %struct.Node], align 16
@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [7 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z6updateiiii(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 uwtable
declare dso_local noundef i32 @_Z5queryiii(i32 noundef, i32 noundef, i32 noundef) #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #3 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca %struct.Node, align 4
  %6 = alloca %struct.Node, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i64, align 8
  store i32 0, ptr %1, align 4
  br label %10

10:                                               ; preds = %134, %0
  %11 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @m, ptr noundef @q)
  %12 = icmp eq i32 %11, 3
  br i1 %12, label %13, label %137

13:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #8
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %34, %13
  %15 = load i32, ptr %2, align 4, !tbaa !5
  %16 = load i32, ptr @n, align 4, !tbaa !5
  %17 = icmp sle i32 %15, %16
  br i1 %17, label %19, label %18

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

19:                                               ; preds = %14
  %20 = load i32, ptr %2, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds i64, ptr @s, i64 %21
  %23 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %22)
  %24 = load i32, ptr %2, align 4, !tbaa !5
  %25 = sub nsw i32 %24, 1
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [100010 x i64], ptr @s, i64 0, i64 %26
  %28 = load i64, ptr %27, align 8, !tbaa !9
  %29 = load i32, ptr %2, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [100010 x i64], ptr @s, i64 0, i64 %30
  %32 = load i64, ptr %31, align 8, !tbaa !9
  %33 = add nsw i64 %32, %28
  store i64 %33, ptr %31, align 8, !tbaa !9
  br label %34

34:                                               ; preds = %19
  %35 = load i32, ptr %2, align 4, !tbaa !5
  %36 = add nsw i32 %35, 1
  store i32 %36, ptr %2, align 4, !tbaa !5
  br label %14, !llvm.loop !11

37:                                               ; preds = %18
  store i32 0, ptr @tot, align 4, !tbaa !5
  br label %38

38:                                               ; preds = %42, %37
  %39 = load i32, ptr @q, align 4, !tbaa !5
  %40 = add nsw i32 %39, -1
  store i32 %40, ptr @q, align 4, !tbaa !5
  %41 = icmp ne i32 %39, 0
  br i1 %41, label %42, label %63

42:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #8
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #8
  %43 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.2, ptr noundef %3, ptr noundef %4)
  call void @llvm.lifetime.start.p0(i64 12, ptr %5) #8
  %44 = getelementptr inbounds %struct.Node, ptr %5, i32 0, i32 0
  %45 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %45, ptr %44, align 4, !tbaa !13
  %46 = getelementptr inbounds %struct.Node, ptr %5, i32 0, i32 1
  %47 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %47, ptr %46, align 4, !tbaa !15
  %48 = getelementptr inbounds %struct.Node, ptr %5, i32 0, i32 2
  store i32 1, ptr %48, align 4, !tbaa !16
  %49 = load i32, ptr @tot, align 4, !tbaa !5
  %50 = add nsw i32 %49, 1
  store i32 %50, ptr @tot, align 4, !tbaa !5
  %51 = sext i32 %49 to i64
  %52 = getelementptr inbounds [200020 x %struct.Node], ptr @que, i64 0, i64 %51
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %52, ptr align 4 %5, i64 12, i1 false), !tbaa.struct !17
  call void @llvm.lifetime.end.p0(i64 12, ptr %5) #8
  call void @llvm.lifetime.start.p0(i64 12, ptr %6) #8
  %53 = getelementptr inbounds %struct.Node, ptr %6, i32 0, i32 0
  %54 = load i32, ptr %4, align 4, !tbaa !5
  %55 = add nsw i32 %54, 1
  store i32 %55, ptr %53, align 4, !tbaa !13
  %56 = getelementptr inbounds %struct.Node, ptr %6, i32 0, i32 1
  %57 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %57, ptr %56, align 4, !tbaa !15
  %58 = getelementptr inbounds %struct.Node, ptr %6, i32 0, i32 2
  store i32 -1, ptr %58, align 4, !tbaa !16
  %59 = load i32, ptr @tot, align 4, !tbaa !5
  %60 = add nsw i32 %59, 1
  store i32 %60, ptr @tot, align 4, !tbaa !5
  %61 = sext i32 %59 to i64
  %62 = getelementptr inbounds [200020 x %struct.Node], ptr @que, i64 0, i64 %61
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %62, ptr align 4 %6, i64 12, i1 false), !tbaa.struct !17
  call void @llvm.lifetime.end.p0(i64 12, ptr %6) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #8
  br label %38, !llvm.loop !18

63:                                               ; preds = %38
  %64 = load i32, ptr @tot, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds %struct.Node, ptr @que, i64 %65
  call void @_ZSt4sortIP4NodeEvT_S2_(ptr noundef @que, ptr noundef %66)
  %67 = load i32, ptr @n, align 4, !tbaa !5
  %68 = add nsw i32 %67, 1
  %69 = shl i32 %68, 1
  %70 = sext i32 %69 to i64
  %71 = mul i64 %70, 4
  call void @llvm.memset.p0.i64(ptr align 16 @seg, i8 0, i64 %71, i1 false)
  store i64 0, ptr @ans, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #8
  store i32 1, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #8
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %72

72:                                               ; preds = %131, %63
  %73 = load i32, ptr %7, align 4, !tbaa !5
  %74 = load i32, ptr @n, align 4, !tbaa !5
  %75 = icmp sle i32 %73, %74
  br i1 %75, label %77, label %76

76:                                               ; preds = %72
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #8
  br label %134

77:                                               ; preds = %72
  br label %78

78:                                               ; preds = %104, %77
  %79 = load i32, ptr %8, align 4, !tbaa !5
  %80 = load i32, ptr @tot, align 4, !tbaa !5
  %81 = icmp slt i32 %79, %80
  br i1 %81, label %82, label %90

82:                                               ; preds = %78
  %83 = load i32, ptr %8, align 4, !tbaa !5
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds [200020 x %struct.Node], ptr @que, i64 0, i64 %84
  %86 = getelementptr inbounds %struct.Node, ptr %85, i32 0, i32 0
  %87 = load i32, ptr %86, align 4, !tbaa !13
  %88 = load i32, ptr %7, align 4, !tbaa !5
  %89 = icmp eq i32 %87, %88
  br label %90

90:                                               ; preds = %82, %78
  %91 = phi i1 [ false, %78 ], [ %89, %82 ]
  br i1 %91, label %92, label %107

92:                                               ; preds = %90
  %93 = load i32, ptr @n, align 4, !tbaa !5
  %94 = load i32, ptr %8, align 4, !tbaa !5
  %95 = sext i32 %94 to i64
  %96 = getelementptr inbounds [200020 x %struct.Node], ptr @que, i64 0, i64 %95
  %97 = getelementptr inbounds %struct.Node, ptr %96, i32 0, i32 1
  %98 = load i32, ptr %97, align 4, !tbaa !15
  %99 = load i32, ptr %8, align 4, !tbaa !5
  %100 = sext i32 %99 to i64
  %101 = getelementptr inbounds [200020 x %struct.Node], ptr @que, i64 0, i64 %100
  %102 = getelementptr inbounds %struct.Node, ptr %101, i32 0, i32 2
  %103 = load i32, ptr %102, align 4, !tbaa !16
  call void @_Z6updateiiii(i32 noundef 1, i32 noundef %93, i32 noundef %98, i32 noundef %103)
  br label %104

104:                                              ; preds = %92
  %105 = load i32, ptr %8, align 4, !tbaa !5
  %106 = add nsw i32 %105, 1
  store i32 %106, ptr %8, align 4, !tbaa !5
  br label %78, !llvm.loop !19

107:                                              ; preds = %90
  %108 = load i32, ptr @n, align 4, !tbaa !5
  %109 = call noundef i32 @_Z7seg_idxii(i32 noundef 1, i32 noundef %108)
  %110 = sext i32 %109 to i64
  %111 = getelementptr inbounds [200020 x i32], ptr @seg, i64 0, i64 %110
  %112 = load i32, ptr %111, align 4, !tbaa !5
  %113 = load i32, ptr @m, align 4, !tbaa !5
  %114 = icmp sge i32 %112, %113
  br i1 %114, label %115, label %130

115:                                              ; preds = %107
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #8
  %116 = load i32, ptr %7, align 4, !tbaa !5
  %117 = sext i32 %116 to i64
  %118 = getelementptr inbounds [100010 x i64], ptr @s, i64 0, i64 %117
  %119 = load i64, ptr %118, align 8, !tbaa !9
  %120 = load i32, ptr @n, align 4, !tbaa !5
  %121 = load i32, ptr @m, align 4, !tbaa !5
  %122 = call noundef i32 @_Z5queryiii(i32 noundef 1, i32 noundef %120, i32 noundef %121)
  %123 = sub nsw i32 %122, 1
  %124 = sext i32 %123 to i64
  %125 = getelementptr inbounds [100010 x i64], ptr @s, i64 0, i64 %124
  %126 = load i64, ptr %125, align 8, !tbaa !9
  %127 = sub nsw i64 %119, %126
  store i64 %127, ptr %9, align 8, !tbaa !9
  %128 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) @ans, ptr noundef nonnull align 8 dereferenceable(8) %9)
  %129 = load i64, ptr %128, align 8, !tbaa !9
  store i64 %129, ptr @ans, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #8
  br label %130

130:                                              ; preds = %115, %107
  br label %131

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

134:                                              ; preds = %76
  %135 = load i64, ptr @ans, align 8, !tbaa !9
  %136 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i64 noundef %135)
  br label %10, !llvm.loop !21

137:                                              ; preds = %10
  ret i32 0
}

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

; 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: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIP4NodeEvT_S2_(ptr noundef, ptr noundef) #6

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

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

declare i32 @printf(ptr noundef, ...) #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 = { 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 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 = { "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 = { 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !6, i64 0}
!14 = !{!"_ZTS4Node", !6, i64 0, !6, i64 4, !6, i64 8}
!15 = !{!14, !6, i64 4}
!16 = !{!14, !6, i64 8}
!17 = !{i64 0, i64 4, !5, i64 4, i64 4, !5, i64 8, i64 4, !5}
!18 = distinct !{!18, !12}
!19 = distinct !{!19, !12}
!20 = distinct !{!20, !12}
!21 = distinct !{!21, !12}


; 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, i32 }

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@q = external dso_local global i32, align 4
@tot = external dso_local local_unnamed_addr global i32, align 4
@seg = external dso_local local_unnamed_addr global [200020 x i32], align 16
@s = external dso_local global [100010 x i64], align 16
@ans = external dso_local global i64, align 8
@que = external dso_local global [200020 x %struct.Node], align 16
@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [7 x i8], align 1

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

; 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 @_Z5queryiii(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #3 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i64, align 8
  %4 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @m, ptr noundef nonnull @q)
  %5 = icmp eq i32 %4, 3
  br i1 %5, label %.preheader22, label %._crit_edge37

.preheader22:                                     ; preds = %0, %._crit_edge36
  %6 = load i32, ptr @n, align 4, !tbaa !5
  %.not23 = icmp slt i32 %6, 1
  br i1 %.not23, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %.preheader22
  store i32 0, ptr @tot, align 4, !tbaa !5
  %7 = load i32, ptr @q, align 4, !tbaa !5
  %8 = add nsw i32 %7, -1
  store i32 %8, ptr @q, align 4, !tbaa !5
  %.not1925 = icmp eq i32 %7, 0
  br i1 %.not1925, label %._crit_edge28, label %.lr.ph27

.lr.ph:                                           ; preds = %.preheader22, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 1, %.preheader22 ]
  %9 = getelementptr inbounds i64, ptr @s, i64 %indvars.iv
  %10 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %9)
  %11 = add nsw i64 %indvars.iv, -1
  %12 = getelementptr inbounds [100010 x i64], ptr @s, i64 0, i64 %11
  %13 = load i64, ptr %12, align 8, !tbaa !9
  %14 = load i64, ptr %9, align 8, !tbaa !9
  %15 = add nsw i64 %14, %13
  store i64 %15, ptr %9, align 8, !tbaa !9
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %16 = load i32, ptr @n, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %.not.not = icmp slt i64 %indvars.iv, %17
  br i1 %.not.not, label %.lr.ph, label %._crit_edge, !llvm.loop !11

.lr.ph27:                                         ; preds = %._crit_edge, %.lr.ph27
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #7
  %18 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.2, ptr noundef nonnull %1, ptr noundef nonnull %2)
  %19 = load i32, ptr %1, align 4, !tbaa !5
  %20 = load i32, ptr @tot, align 4, !tbaa !5
  %21 = add nsw i32 %20, 1
  %22 = sext i32 %20 to i64
  %23 = getelementptr inbounds [200020 x %struct.Node], ptr @que, i64 0, i64 %22
  store i32 %19, ptr %23, align 4, !tbaa !5
  %.sroa.410.0..sroa_idx = getelementptr inbounds i8, ptr %23, i64 4
  store i32 %19, ptr %.sroa.410.0..sroa_idx, align 4, !tbaa !5
  %.sroa.511.0..sroa_idx = getelementptr inbounds i8, ptr %23, i64 8
  store i32 1, ptr %.sroa.511.0..sroa_idx, align 4, !tbaa !5
  %24 = load i32, ptr %2, align 4, !tbaa !5
  %25 = add nsw i32 %24, 1
  %26 = add nsw i32 %20, 2
  store i32 %26, ptr @tot, align 4, !tbaa !5
  %27 = sext i32 %21 to i64
  %28 = getelementptr inbounds [200020 x %struct.Node], ptr @que, i64 0, i64 %27
  store i32 %25, ptr %28, align 4, !tbaa !5
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %28, i64 4
  store i32 %19, ptr %.sroa.4.0..sroa_idx, align 4, !tbaa !5
  %.sroa.5.0..sroa_idx = getelementptr inbounds i8, ptr %28, i64 8
  store i32 -1, ptr %.sroa.5.0..sroa_idx, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #7
  %29 = load i32, ptr @q, align 4, !tbaa !5
  %30 = add nsw i32 %29, -1
  store i32 %30, ptr @q, align 4, !tbaa !5
  %.not19 = icmp eq i32 %29, 0
  br i1 %.not19, label %._crit_edge28, label %.lr.ph27, !llvm.loop !13

._crit_edge28:                                    ; preds = %.lr.ph27, %._crit_edge
  %31 = phi i32 [ 0, %._crit_edge ], [ %26, %.lr.ph27 ]
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds %struct.Node, ptr @que, i64 %32
  call void @_ZSt4sortIP4NodeEvT_S2_(ptr noundef nonnull @que, ptr noundef nonnull %33)
  %34 = load i32, ptr @n, align 4, !tbaa !5
  %35 = shl i32 %34, 1
  %36 = add i32 %35, 2
  %37 = sext i32 %36 to i64
  %38 = shl nsw i64 %37, 2
  call void @llvm.memset.p0.i64(ptr nonnull align 16 @seg, i8 0, i64 %38, i1 false)
  store i64 0, ptr @ans, align 8, !tbaa !9
  %.not2033 = icmp slt i32 %34, 1
  br i1 %.not2033, label %._crit_edge36, label %.preheader

.preheader:                                       ; preds = %._crit_edge28, %77
  %39 = phi i32 [ %78, %77 ], [ %34, %._crit_edge28 ]
  %indvars.iv42 = phi i64 [ %indvars.iv.next43, %77 ], [ 1, %._crit_edge28 ]
  %.035 = phi i32 [ %.1.lcssa, %77 ], [ 0, %._crit_edge28 ]
  %40 = load i32, ptr @tot, align 4, !tbaa !5
  %41 = icmp slt i32 %.035, %40
  br i1 %41, label %.lr.ph30.preheader, label %.critedge

.lr.ph30.preheader:                               ; preds = %.preheader
  %42 = sext i32 %.035 to i64
  br label %.lr.ph30

._crit_edge36.loopexit:                           ; preds = %77
  %.pre46 = load i64, ptr @ans, align 8, !tbaa !9
  br label %._crit_edge36

._crit_edge36:                                    ; preds = %._crit_edge36.loopexit, %._crit_edge28
  %43 = phi i64 [ %.pre46, %._crit_edge36.loopexit ], [ 0, %._crit_edge28 ]
  %44 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i64 noundef %43)
  %45 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @m, ptr noundef nonnull @q)
  %46 = icmp eq i32 %45, 3
  br i1 %46, label %.preheader22, label %._crit_edge37, !llvm.loop !14

.lr.ph30:                                         ; preds = %.lr.ph30.preheader, %51
  %indvars.iv39 = phi i64 [ %42, %.lr.ph30.preheader ], [ %indvars.iv.next40, %51 ]
  %47 = getelementptr inbounds [200020 x %struct.Node], ptr @que, i64 0, i64 %indvars.iv39
  %48 = load i32, ptr %47, align 4, !tbaa !15
  %49 = zext i32 %48 to i64
  %50 = icmp eq i64 %indvars.iv42, %49
  %.pre.pre47 = load i32, ptr @n, align 4, !tbaa !5
  br i1 %50, label %51, label %.critedge.loopexit

51:                                               ; preds = %.lr.ph30
  %52 = getelementptr inbounds i8, ptr %47, i64 4
  %53 = load i32, ptr %52, align 4, !tbaa !17
  %54 = getelementptr inbounds i8, ptr %47, i64 8
  %55 = load i32, ptr %54, align 4, !tbaa !18
  call void @_Z6updateiiii(i32 noundef 1, i32 noundef %.pre.pre47, i32 noundef %53, i32 noundef %55)
  %indvars.iv.next40 = add nsw i64 %indvars.iv39, 1
  %56 = load i32, ptr @tot, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = icmp slt i64 %indvars.iv.next40, %57
  br i1 %58, label %.lr.ph30, label %..critedge.loopexit_crit_edge, !llvm.loop !19

..critedge.loopexit_crit_edge:                    ; preds = %51
  %.pre.pre = load i32, ptr @n, align 4, !tbaa !5
  br label %.critedge.loopexit

.critedge.loopexit:                               ; preds = %.lr.ph30, %..critedge.loopexit_crit_edge
  %.pre = phi i32 [ %.pre.pre, %..critedge.loopexit_crit_edge ], [ %.pre.pre47, %.lr.ph30 ]
  %.1.lcssa.ph.in = phi i64 [ %indvars.iv.next40, %..critedge.loopexit_crit_edge ], [ %indvars.iv39, %.lr.ph30 ]
  %.1.lcssa.ph = trunc i64 %.1.lcssa.ph.in to i32
  br label %.critedge

.critedge:                                        ; preds = %.critedge.loopexit, %.preheader
  %59 = phi i32 [ %39, %.preheader ], [ %.pre, %.critedge.loopexit ]
  %.1.lcssa = phi i32 [ %.035, %.preheader ], [ %.1.lcssa.ph, %.critedge.loopexit ]
  %60 = call noundef i32 @_Z7seg_idxii(i32 noundef 1, i32 noundef %59)
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [200020 x i32], ptr @seg, i64 0, i64 %61
  %63 = load i32, ptr %62, align 4, !tbaa !5
  %64 = load i32, ptr @m, align 4, !tbaa !5
  %.not21 = icmp slt i32 %63, %64
  br i1 %.not21, label %77, label %65

65:                                               ; preds = %.critedge
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #7
  %66 = getelementptr inbounds [100010 x i64], ptr @s, i64 0, i64 %indvars.iv42
  %67 = load i64, ptr %66, align 8, !tbaa !9
  %68 = load i32, ptr @n, align 4, !tbaa !5
  %69 = call noundef i32 @_Z5queryiii(i32 noundef 1, i32 noundef %68, i32 noundef %64)
  %70 = add nsw i32 %69, -1
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [100010 x i64], ptr @s, i64 0, i64 %71
  %73 = load i64, ptr %72, align 8, !tbaa !9
  %74 = sub nsw i64 %67, %73
  store i64 %74, ptr %3, align 8, !tbaa !9
  %75 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) @ans, ptr noundef nonnull align 8 dereferenceable(8) %3)
  %76 = load i64, ptr %75, align 8, !tbaa !9
  store i64 %76, ptr @ans, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #7
  br label %77

77:                                               ; preds = %.critedge, %65
  %indvars.iv.next43 = add nuw nsw i64 %indvars.iv42, 1
  %78 = load i32, ptr @n, align 4, !tbaa !5
  %79 = sext i32 %78 to i64
  %.not20.not = icmp slt i64 %indvars.iv42, %79
  br i1 %.not20.not, label %.preheader, label %._crit_edge36.loopexit, !llvm.loop !20

._crit_edge37:                                    ; preds = %._crit_edge36, %0
  ret i32 0
}

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

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #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 = { mustprogress 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 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" }
attributes #6 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}
!15 = !{!16, !6, i64 0}
!16 = !{!"_ZTS4Node", !6, i64 0, !6, i64 4, !6, i64 8}
!17 = !{!16, !6, i64 4}
!18 = !{!16, !6, i64 8}
!19 = distinct !{!19, !12}
!20 = distinct !{!20, !12}


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