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

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

@n = external dso_local global i32, align 4
@rN = external dso_local global i32, align 4
@cN = 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 [100002 x i32], align 16
@ans = external dso_local global i32, align 4
@e = external dso_local global [100002 x %struct.Event], align 16
@seg = external dso_local global [200004 x %struct.Segment], align 16
@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z3updiiiii(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 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.Event, align 4
  %6 = alloca %struct.Event, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %10 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @rN, ptr noundef @cN)
  br label %11

11:                                               ; preds = %15, %0
  %12 = load i32, ptr @n, align 4, !tbaa !5
  %13 = add nsw i32 %12, -1
  store i32 %13, ptr @n, align 4, !tbaa !5
  %14 = icmp ne i32 %12, 0
  br i1 %14, label %15, label %64

15:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #7
  %16 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2, ptr noundef %3, ptr noundef %4)
  call void @llvm.lifetime.start.p0(i64 16, ptr %5) #7
  %17 = getelementptr inbounds %struct.Event, ptr %5, i32 0, i32 0
  %18 = load i32, ptr %2, align 4, !tbaa !5
  store i32 %18, ptr %17, align 4, !tbaa !9
  %19 = getelementptr inbounds %struct.Event, ptr %5, i32 0, i32 1
  %20 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %20, ptr %19, align 4, !tbaa !11
  %21 = getelementptr inbounds %struct.Event, ptr %5, i32 0, i32 2
  %22 = load i32, ptr %3, align 4, !tbaa !5
  %23 = load i32, ptr @cN, align 4, !tbaa !5
  %24 = add nsw i32 %22, %23
  %25 = add nsw i32 %24, 1
  store i32 %25, ptr %21, align 4, !tbaa !12
  %26 = getelementptr inbounds %struct.Event, ptr %5, i32 0, i32 3
  %27 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %27, ptr %26, align 4, !tbaa !13
  %28 = load i32, ptr @m, align 4, !tbaa !5
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr @m, align 4, !tbaa !5
  %30 = sext i32 %28 to i64
  %31 = getelementptr inbounds [100002 x %struct.Event], ptr @e, i64 0, i64 %30
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %31, ptr align 4 %5, i64 16, i1 false), !tbaa.struct !14
  call void @llvm.lifetime.end.p0(i64 16, ptr %5) #7
  call void @llvm.lifetime.start.p0(i64 16, ptr %6) #7
  %32 = getelementptr inbounds %struct.Event, ptr %6, i32 0, i32 0
  %33 = load i32, ptr %2, align 4, !tbaa !5
  %34 = load i32, ptr @rN, align 4, !tbaa !5
  %35 = add nsw i32 %33, %34
  %36 = add nsw i32 %35, 1
  store i32 %36, ptr %32, align 4, !tbaa !9
  %37 = getelementptr inbounds %struct.Event, ptr %6, i32 0, i32 1
  %38 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %38, ptr %37, align 4, !tbaa !11
  %39 = getelementptr inbounds %struct.Event, ptr %6, i32 0, i32 2
  %40 = load i32, ptr %3, align 4, !tbaa !5
  %41 = load i32, ptr @cN, align 4, !tbaa !5
  %42 = add nsw i32 %40, %41
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr %39, align 4, !tbaa !12
  %44 = getelementptr inbounds %struct.Event, ptr %6, i32 0, i32 3
  %45 = load i32, ptr %4, align 4, !tbaa !5
  %46 = sub nsw i32 0, %45
  store i32 %46, ptr %44, align 4, !tbaa !13
  %47 = load i32, ptr @m, align 4, !tbaa !5
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr @m, align 4, !tbaa !5
  %49 = sext i32 %47 to i64
  %50 = getelementptr inbounds [100002 x %struct.Event], ptr @e, i64 0, i64 %49
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %50, ptr align 4 %6, i64 16, i1 false), !tbaa.struct !14
  call void @llvm.lifetime.end.p0(i64 16, ptr %6) #7
  %51 = load i32, ptr %3, align 4, !tbaa !5
  %52 = load i32, ptr @tot, align 4, !tbaa !5
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr @tot, align 4, !tbaa !5
  %54 = sext i32 %52 to i64
  %55 = getelementptr inbounds [100002 x i32], ptr @que, i64 0, i64 %54
  store i32 %51, ptr %55, align 4, !tbaa !5
  %56 = load i32, ptr %3, align 4, !tbaa !5
  %57 = load i32, ptr @cN, align 4, !tbaa !5
  %58 = add nsw i32 %56, %57
  %59 = add nsw i32 %58, 1
  %60 = load i32, ptr @tot, align 4, !tbaa !5
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr @tot, align 4, !tbaa !5
  %62 = sext i32 %60 to i64
  %63 = getelementptr inbounds [100002 x i32], ptr @que, i64 0, i64 %62
  store i32 %59, ptr %63, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #7
  br label %11, !llvm.loop !15

64:                                               ; preds = %11
  %65 = load i32, ptr @m, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds %struct.Event, ptr @e, i64 %66
  call void @_ZSt4sortIP5EventEvT_S2_(ptr noundef @e, ptr noundef %67)
  %68 = load i32, ptr @tot, align 4, !tbaa !5
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds i32, ptr @que, i64 %69
  call void @_ZSt4sortIPiEvT_S1_(ptr noundef @que, ptr noundef %70)
  %71 = load i32, ptr @tot, align 4, !tbaa !5
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds i32, ptr @que, i64 %72
  %74 = call noundef ptr @_ZSt6uniqueIPiET_S1_S1_(ptr noundef @que, ptr noundef %73)
  %75 = ptrtoint ptr %74 to i64
  %76 = sub i64 %75, ptrtoint (ptr @que to i64)
  %77 = sdiv exact i64 %76, 4
  %78 = trunc i64 %77 to i32
  store i32 %78, ptr @tot, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #7
  %79 = load i32, ptr @tot, align 4, !tbaa !5
  %80 = sub nsw i32 %79, 1
  %81 = call noundef i32 @_Z7seg_idxii(i32 noundef 0, i32 noundef %80)
  store i32 %81, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #7
  store i32 0, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #7
  store i32 0, ptr %9, align 4, !tbaa !5
  br label %82

82:                                               ; preds = %175, %64
  %83 = load i32, ptr %8, align 4, !tbaa !5
  %84 = load i32, ptr @m, align 4, !tbaa !5
  %85 = icmp slt i32 %83, %84
  br i1 %85, label %87, label %86

86:                                               ; preds = %82
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #7
  br label %177

87:                                               ; preds = %82
  br label %88

88:                                               ; preds = %157, %87
  %89 = load i32, ptr %9, align 4, !tbaa !5
  %90 = load i32, ptr @m, align 4, !tbaa !5
  %91 = icmp slt i32 %89, %90
  br i1 %91, label %92, label %104

92:                                               ; preds = %88
  %93 = load i32, ptr %8, align 4, !tbaa !5
  %94 = sext i32 %93 to i64
  %95 = getelementptr inbounds [100002 x %struct.Event], ptr @e, i64 0, i64 %94
  %96 = getelementptr inbounds %struct.Event, ptr %95, i32 0, i32 0
  %97 = load i32, ptr %96, align 16, !tbaa !9
  %98 = load i32, ptr %9, align 4, !tbaa !5
  %99 = sext i32 %98 to i64
  %100 = getelementptr inbounds [100002 x %struct.Event], ptr @e, i64 0, i64 %99
  %101 = getelementptr inbounds %struct.Event, ptr %100, i32 0, i32 0
  %102 = load i32, ptr %101, align 16, !tbaa !9
  %103 = icmp eq i32 %97, %102
  br label %104

104:                                              ; preds = %92, %88
  %105 = phi i1 [ false, %88 ], [ %103, %92 ]
  br i1 %105, label %106, label %160

106:                                              ; preds = %104
  %107 = load i32, ptr @tot, align 4, !tbaa !5
  %108 = sext i32 %107 to i64
  %109 = getelementptr inbounds i32, ptr @que, i64 %108
  %110 = load i32, ptr %9, align 4, !tbaa !5
  %111 = sext i32 %110 to i64
  %112 = getelementptr inbounds [100002 x %struct.Event], ptr @e, i64 0, i64 %111
  %113 = getelementptr inbounds %struct.Event, ptr %112, i32 0, i32 1
  %114 = call noundef ptr @_ZSt11lower_boundIPiiET_S1_S1_RKT0_(ptr noundef @que, ptr noundef %109, ptr noundef nonnull align 4 dereferenceable(4) %113)
  %115 = ptrtoint ptr %114 to i64
  %116 = sub i64 %115, ptrtoint (ptr @que to i64)
  %117 = sdiv exact i64 %116, 4
  %118 = trunc i64 %117 to i32
  %119 = load i32, ptr %9, align 4, !tbaa !5
  %120 = sext i32 %119 to i64
  %121 = getelementptr inbounds [100002 x %struct.Event], ptr @e, i64 0, i64 %120
  %122 = getelementptr inbounds %struct.Event, ptr %121, i32 0, i32 1
  store i32 %118, ptr %122, align 4, !tbaa !11
  %123 = load i32, ptr @tot, align 4, !tbaa !5
  %124 = sext i32 %123 to i64
  %125 = getelementptr inbounds i32, ptr @que, i64 %124
  %126 = load i32, ptr %9, align 4, !tbaa !5
  %127 = sext i32 %126 to i64
  %128 = getelementptr inbounds [100002 x %struct.Event], ptr @e, i64 0, i64 %127
  %129 = getelementptr inbounds %struct.Event, ptr %128, i32 0, i32 2
  %130 = call noundef ptr @_ZSt11lower_boundIPiiET_S1_S1_RKT0_(ptr noundef @que, ptr noundef %125, ptr noundef nonnull align 4 dereferenceable(4) %129)
  %131 = ptrtoint ptr %130 to i64
  %132 = sub i64 %131, ptrtoint (ptr @que to i64)
  %133 = sdiv exact i64 %132, 4
  %134 = trunc i64 %133 to i32
  %135 = load i32, ptr %9, align 4, !tbaa !5
  %136 = sext i32 %135 to i64
  %137 = getelementptr inbounds [100002 x %struct.Event], ptr @e, i64 0, i64 %136
  %138 = getelementptr inbounds %struct.Event, ptr %137, i32 0, i32 2
  store i32 %134, ptr %138, align 8, !tbaa !12
  %139 = load i32, ptr @tot, align 4, !tbaa !5
  %140 = sub nsw i32 %139, 1
  %141 = load i32, ptr %9, align 4, !tbaa !5
  %142 = sext i32 %141 to i64
  %143 = getelementptr inbounds [100002 x %struct.Event], ptr @e, i64 0, i64 %142
  %144 = getelementptr inbounds %struct.Event, ptr %143, i32 0, i32 1
  %145 = load i32, ptr %144, align 4, !tbaa !11
  %146 = load i32, ptr %9, align 4, !tbaa !5
  %147 = sext i32 %146 to i64
  %148 = getelementptr inbounds [100002 x %struct.Event], ptr @e, i64 0, i64 %147
  %149 = getelementptr inbounds %struct.Event, ptr %148, i32 0, i32 2
  %150 = load i32, ptr %149, align 8, !tbaa !12
  %151 = sub nsw i32 %150, 1
  %152 = load i32, ptr %9, align 4, !tbaa !5
  %153 = sext i32 %152 to i64
  %154 = getelementptr inbounds [100002 x %struct.Event], ptr @e, i64 0, i64 %153
  %155 = getelementptr inbounds %struct.Event, ptr %154, i32 0, i32 3
  %156 = load i32, ptr %155, align 4, !tbaa !13
  call void @_Z3updiiiii(i32 noundef 0, i32 noundef %140, i32 noundef %145, i32 noundef %151, i32 noundef %156)
  br label %157

157:                                              ; preds = %106
  %158 = load i32, ptr %9, align 4, !tbaa !5
  %159 = add nsw i32 %158, 1
  store i32 %159, ptr %9, align 4, !tbaa !5
  br label %88, !llvm.loop !17

160:                                              ; preds = %104
  %161 = load i32, ptr @ans, align 4, !tbaa !5
  %162 = load i32, ptr %7, align 4, !tbaa !5
  %163 = sext i32 %162 to i64
  %164 = getelementptr inbounds [200004 x %struct.Segment], ptr @seg, i64 0, i64 %163
  %165 = getelementptr inbounds %struct.Segment, ptr %164, i32 0, i32 0
  %166 = load i32, ptr %165, align 8, !tbaa !18
  %167 = icmp slt i32 %161, %166
  br i1 %167, label %168, label %174

168:                                              ; preds = %160
  %169 = load i32, ptr %7, align 4, !tbaa !5
  %170 = sext i32 %169 to i64
  %171 = getelementptr inbounds [200004 x %struct.Segment], ptr @seg, i64 0, i64 %170
  %172 = getelementptr inbounds %struct.Segment, ptr %171, i32 0, i32 0
  %173 = load i32, ptr %172, align 8, !tbaa !18
  store i32 %173, ptr @ans, align 4, !tbaa !5
  br label %174

174:                                              ; preds = %168, %160
  br label %175

175:                                              ; preds = %174
  %176 = load i32, ptr %9, align 4, !tbaa !5
  store i32 %176, ptr %8, align 4, !tbaa !5
  br label %82, !llvm.loop !20

177:                                              ; preds = %86
  %178 = load i32, ptr @ans, align 4, !tbaa !5
  %179 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %178)
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #7
  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 @_ZSt4sortIP5EventEvT_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

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 = { 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, !6, i64 0}
!10 = !{!"_ZTS5Event", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12}
!11 = !{!10, !6, i64 4}
!12 = !{!10, !6, i64 8}
!13 = !{!10, !6, i64 12}
!14 = !{i64 0, i64 4, !5, i64 4, i64 4, !5, i64 8, i64 4, !5, i64 12, i64 4, !5}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}
!18 = !{!19, !6, i64 0}
!19 = !{!"_ZTS7Segment", !6, i64 0, !6, i64 4}
!20 = distinct !{!20, !16}


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

@n = external dso_local global i32, align 4
@rN = external dso_local global i32, align 4
@cN = external dso_local global i32, align 4
@m = external dso_local local_unnamed_addr global i32, align 4
@tot = external dso_local local_unnamed_addr global i32, align 4
@que = external dso_local global [100002 x i32], align 16
@ans = external dso_local local_unnamed_addr global i32, align 4
@e = external dso_local global [100002 x %struct.Event], align 16
@seg = external dso_local local_unnamed_addr global [200004 x %struct.Segment], align 16
@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z3updiiiii(i32 noundef, 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 norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #3 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @rN, ptr noundef nonnull @cN)
  %5 = load i32, ptr @n, align 4, !tbaa !5
  %6 = add nsw i32 %5, -1
  store i32 %6, ptr @n, align 4, !tbaa !5
  %.not21 = icmp eq i32 %5, 0
  br i1 %.not21, label %.._crit_edge_crit_edge, label %.lr.ph

.._crit_edge_crit_edge:                           ; preds = %0
  %.pre = load i32, ptr @m, align 4, !tbaa !5
  br label %._crit_edge

.lr.ph:                                           ; preds = %0, %.lr.ph
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #6
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1, ptr noundef nonnull %2, ptr noundef nonnull %3)
  %8 = load i32, ptr %1, align 4, !tbaa !5
  %9 = load i32, ptr %2, align 4, !tbaa !5
  %10 = load i32, ptr @cN, align 4, !tbaa !5
  %11 = add i32 %9, 1
  %12 = add i32 %11, %10
  %13 = load i32, ptr %3, align 4, !tbaa !5
  %14 = load i32, ptr @m, align 4, !tbaa !5
  %15 = add nsw i32 %14, 1
  %16 = sext i32 %14 to i64
  %17 = getelementptr inbounds [100002 x %struct.Event], ptr @e, i64 0, i64 %16
  store i32 %8, ptr %17, align 16, !tbaa !5
  %.sroa.416.0..sroa_idx = getelementptr inbounds i8, ptr %17, i64 4
  store i32 %9, ptr %.sroa.416.0..sroa_idx, align 4, !tbaa !5
  %.sroa.517.0..sroa_idx = getelementptr inbounds i8, ptr %17, i64 8
  store i32 %12, ptr %.sroa.517.0..sroa_idx, align 8, !tbaa !5
  %.sroa.618.0..sroa_idx = getelementptr inbounds i8, ptr %17, i64 12
  store i32 %13, ptr %.sroa.618.0..sroa_idx, align 4, !tbaa !5
  %18 = load i32, ptr @rN, align 4, !tbaa !5
  %19 = add i32 %8, 1
  %20 = add i32 %19, %18
  %21 = sub nsw i32 0, %13
  %22 = add nsw i32 %14, 2
  store i32 %22, ptr @m, align 4, !tbaa !5
  %23 = sext i32 %15 to i64
  %24 = getelementptr inbounds [100002 x %struct.Event], ptr @e, i64 0, i64 %23
  store i32 %20, ptr %24, align 16, !tbaa !5
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %24, i64 4
  store i32 %9, ptr %.sroa.4.0..sroa_idx, align 4, !tbaa !5
  %.sroa.5.0..sroa_idx = getelementptr inbounds i8, ptr %24, i64 8
  store i32 %12, ptr %.sroa.5.0..sroa_idx, align 8, !tbaa !5
  %.sroa.6.0..sroa_idx = getelementptr inbounds i8, ptr %24, i64 12
  store i32 %21, ptr %.sroa.6.0..sroa_idx, align 4, !tbaa !5
  %25 = load i32, ptr @tot, align 4, !tbaa !5
  %26 = add nsw i32 %25, 1
  %27 = sext i32 %25 to i64
  %28 = getelementptr inbounds [100002 x i32], ptr @que, i64 0, i64 %27
  store i32 %9, ptr %28, align 4, !tbaa !5
  %29 = add nsw i32 %25, 2
  store i32 %29, ptr @tot, align 4, !tbaa !5
  %30 = sext i32 %26 to i64
  %31 = getelementptr inbounds [100002 x i32], ptr @que, i64 0, i64 %30
  store i32 %12, ptr %31, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #6
  %32 = load i32, ptr @n, align 4, !tbaa !5
  %33 = add nsw i32 %32, -1
  store i32 %33, ptr @n, align 4, !tbaa !5
  %.not = icmp eq i32 %32, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %.._crit_edge_crit_edge
  %34 = phi i32 [ %.pre, %.._crit_edge_crit_edge ], [ %22, %.lr.ph ]
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds %struct.Event, ptr @e, i64 %35
  call void @_ZSt4sortIP5EventEvT_S2_(ptr noundef nonnull @e, ptr noundef nonnull %36)
  %37 = load i32, ptr @tot, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds i32, ptr @que, i64 %38
  call void @_ZSt4sortIPiEvT_S1_(ptr noundef nonnull @que, ptr noundef nonnull %39)
  %40 = load i32, ptr @tot, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds i32, ptr @que, i64 %41
  %43 = call noundef ptr @_ZSt6uniqueIPiET_S1_S1_(ptr noundef nonnull @que, ptr noundef nonnull %42)
  %44 = ptrtoint ptr %43 to i64
  %45 = sub i64 %44, ptrtoint (ptr @que to i64)
  %46 = lshr exact i64 %45, 2
  %47 = trunc i64 %46 to i32
  store i32 %47, ptr @tot, align 4, !tbaa !5
  %48 = add nsw i32 %47, -1
  %49 = call noundef i32 @_Z7seg_idxii(i32 noundef 0, i32 noundef %48)
  %50 = load i32, ptr @m, align 4, !tbaa !5
  %51 = icmp sgt i32 %50, 0
  br i1 %51, label %.preheader.lr.ph, label %._crit_edge.._crit_edge27_crit_edge

._crit_edge.._crit_edge27_crit_edge:              ; preds = %._crit_edge
  %.pre29 = load i32, ptr @ans, align 4, !tbaa !5
  br label %._crit_edge27

.preheader.lr.ph:                                 ; preds = %._crit_edge
  %52 = sext i32 %49 to i64
  %53 = getelementptr inbounds [200004 x %struct.Segment], ptr @seg, i64 0, i64 %52
  br label %.preheader

.preheader:                                       ; preds = %.preheader.lr.ph, %99
  %54 = phi i32 [ %50, %.preheader.lr.ph ], [ %94, %99 ]
  %.026 = phi i32 [ 0, %.preheader.lr.ph ], [ %.1.lcssa, %99 ]
  %55 = sext i32 %.026 to i64
  %56 = getelementptr inbounds [100002 x %struct.Event], ptr @e, i64 0, i64 %55
  %57 = icmp slt i32 %.026, %54
  br i1 %57, label %.lr.ph33, label %.critedge

.lr.ph33:                                         ; preds = %.preheader
  %58 = getelementptr inbounds [100002 x %struct.Event], ptr @e, i64 0, i64 %55
  br label %65

._crit_edge27:                                    ; preds = %99, %._crit_edge.._crit_edge27_crit_edge
  %59 = phi i32 [ %.pre29, %._crit_edge.._crit_edge27_crit_edge ], [ %100, %99 ]
  %60 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %59)
  ret i32 0

.lr.ph23:                                         ; preds = %65
  %61 = load i32, ptr %56, align 16, !tbaa !11
  %62 = getelementptr inbounds [100002 x %struct.Event], ptr @e, i64 0, i64 %indvars.iv.next
  %63 = load i32, ptr %62, align 16, !tbaa !11
  %64 = icmp eq i32 %61, %63
  br i1 %64, label %65, label %.critedge.loopexit, !llvm.loop !13

65:                                               ; preds = %.lr.ph33, %.lr.ph23
  %66 = phi ptr [ %58, %.lr.ph33 ], [ %62, %.lr.ph23 ]
  %indvars.iv32 = phi i64 [ %55, %.lr.ph33 ], [ %indvars.iv.next, %.lr.ph23 ]
  %67 = load i32, ptr @tot, align 4, !tbaa !5
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds i32, ptr @que, i64 %68
  %70 = getelementptr inbounds i8, ptr %66, i64 4
  %71 = call noundef ptr @_ZSt11lower_boundIPiiET_S1_S1_RKT0_(ptr noundef nonnull @que, ptr noundef nonnull %69, ptr noundef nonnull align 4 dereferenceable(4) %70)
  %72 = ptrtoint ptr %71 to i64
  %73 = sub i64 %72, ptrtoint (ptr @que to i64)
  %74 = lshr exact i64 %73, 2
  %75 = trunc i64 %74 to i32
  store i32 %75, ptr %70, align 4, !tbaa !14
  %76 = load i32, ptr @tot, align 4, !tbaa !5
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds i32, ptr @que, i64 %77
  %79 = getelementptr inbounds i8, ptr %66, i64 8
  %80 = call noundef ptr @_ZSt11lower_boundIPiiET_S1_S1_RKT0_(ptr noundef nonnull @que, ptr noundef nonnull %78, ptr noundef nonnull align 4 dereferenceable(4) %79)
  %81 = ptrtoint ptr %80 to i64
  %82 = sub i64 %81, ptrtoint (ptr @que to i64)
  %83 = lshr exact i64 %82, 2
  %84 = trunc i64 %83 to i32
  store i32 %84, ptr %79, align 8, !tbaa !15
  %85 = load i32, ptr @tot, align 4, !tbaa !5
  %86 = add nsw i32 %85, -1
  %87 = load i32, ptr %70, align 4, !tbaa !14
  %88 = add nsw i32 %84, -1
  %89 = getelementptr inbounds i8, ptr %66, i64 12
  %90 = load i32, ptr %89, align 4, !tbaa !16
  call void @_Z3updiiiii(i32 noundef 0, i32 noundef %86, i32 noundef %87, i32 noundef %88, i32 noundef %90)
  %indvars.iv.next = add nsw i64 %indvars.iv32, 1
  %91 = load i32, ptr @m, align 4, !tbaa !5
  %92 = sext i32 %91 to i64
  %93 = icmp slt i64 %indvars.iv.next, %92
  br i1 %93, label %.lr.ph23, label %.critedge.loopexit, !llvm.loop !13

.critedge.loopexit:                               ; preds = %.lr.ph23, %65
  %.1.lcssa.ph = trunc i64 %indvars.iv.next to i32
  br label %.critedge

.critedge:                                        ; preds = %.critedge.loopexit, %.preheader
  %94 = phi i32 [ %54, %.preheader ], [ %91, %.critedge.loopexit ]
  %.1.lcssa = phi i32 [ %.026, %.preheader ], [ %.1.lcssa.ph, %.critedge.loopexit ]
  %95 = load i32, ptr @ans, align 4, !tbaa !5
  %96 = load i32, ptr %53, align 8, !tbaa !17
  %97 = icmp slt i32 %95, %96
  br i1 %97, label %98, label %99

98:                                               ; preds = %.critedge
  store i32 %96, ptr @ans, align 4, !tbaa !5
  br label %99

99:                                               ; preds = %.critedge, %98
  %100 = phi i32 [ %95, %.critedge ], [ %96, %98 ]
  %101 = icmp slt i32 %.1.lcssa, %94
  br i1 %101, label %.preheader, label %._crit_edge27, !llvm.loop !19
}

; 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 @_ZSt4sortIP5EventEvT_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: 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 = { 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 = !{!"_ZTS5Event", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12}
!13 = distinct !{!13, !10}
!14 = !{!12, !6, i64 4}
!15 = !{!12, !6, i64 8}
!16 = !{!12, !6, i64 12}
!17 = !{!18, !6, i64 0}
!18 = !{!"_ZTS7Segment", !6, i64 0, !6, i64 4}
!19 = distinct !{!19, !10}


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