; LLVM IR from tangjz/acm-icpc :: buaa/oj3rd/1240.ll (Z5solvev)

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

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@p = external dso_local global i32, align 4
@q_tot = external dso_local global i32, align 4
@que = external dso_local global [200020 x i32], align 16
@p_tot = external dso_local global i32, align 4
@a = external dso_local global [100010 x %struct.Square], align 16
@pp = external dso_local global [200020 x %struct.Segment], align 16
@seg = external dso_local global [400040 x %struct.SegTree], align 16

; 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 @_Z3idxii(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
define dso_local noundef i64 @_Z5solvev() #0 {
  %1 = alloca i64, align 8
  %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 %struct.Segment, align 4
  %9 = alloca %struct.Segment, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #6
  store i64 0, ptr %1, align 8, !tbaa !5
  store i32 0, ptr @p_tot, align 4, !tbaa !9
  store i32 0, ptr @q_tot, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #6
  store i32 0, ptr %2, align 4, !tbaa !9
  br label %13

13:                                               ; preds = %107, %0
  %14 = load i32, ptr %2, align 4, !tbaa !9
  %15 = load i32, ptr @p, align 4, !tbaa !9
  %16 = icmp sle i32 %14, %15
  br i1 %16, label %18, label %17

17:                                               ; preds = %13
  store i32 2, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #6
  br label %110

18:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #6
  %19 = load i32, ptr %2, align 4, !tbaa !9
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [100010 x %struct.Square], ptr @a, i64 0, i64 %20
  %22 = getelementptr inbounds %struct.Square, ptr %21, i32 0, i32 0
  %23 = load i32, ptr %22, align 16, !tbaa !11
  store i32 %23, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #6
  %24 = load i32, ptr %2, align 4, !tbaa !9
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [100010 x %struct.Square], ptr @a, i64 0, i64 %25
  %27 = getelementptr inbounds %struct.Square, ptr %26, i32 0, i32 1
  %28 = load i32, ptr %27, align 4, !tbaa !13
  store i32 %28, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  %29 = load i32, ptr %2, align 4, !tbaa !9
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [100010 x %struct.Square], ptr @a, i64 0, i64 %30
  %32 = getelementptr inbounds %struct.Square, ptr %31, i32 0, i32 2
  %33 = load i32, ptr %32, align 8, !tbaa !14
  store i32 %33, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #6
  %34 = load i32, ptr %2, align 4, !tbaa !9
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [100010 x %struct.Square], ptr @a, i64 0, i64 %35
  %37 = getelementptr inbounds %struct.Square, ptr %36, i32 0, i32 3
  %38 = load i32, ptr %37, align 4, !tbaa !15
  store i32 %38, ptr %7, align 4, !tbaa !9
  %39 = load i32, ptr %4, align 4, !tbaa !9
  %40 = icmp sle i32 %39, 0
  br i1 %40, label %41, label %42

41:                                               ; preds = %18
  store i32 1, ptr %4, align 4, !tbaa !9
  br label %42

42:                                               ; preds = %41, %18
  %43 = load i32, ptr %5, align 4, !tbaa !9
  %44 = icmp sle i32 %43, 0
  br i1 %44, label %45, label %46

45:                                               ; preds = %42
  store i32 1, ptr %5, align 4, !tbaa !9
  br label %46

46:                                               ; preds = %45, %42
  %47 = load i32, ptr %6, align 4, !tbaa !9
  %48 = load i32, ptr @n, align 4, !tbaa !9
  %49 = icmp sgt i32 %47, %48
  br i1 %49, label %50, label %52

50:                                               ; preds = %46
  %51 = load i32, ptr @n, align 4, !tbaa !9
  store i32 %51, ptr %6, align 4, !tbaa !9
  br label %52

52:                                               ; preds = %50, %46
  %53 = load i32, ptr %7, align 4, !tbaa !9
  %54 = load i32, ptr @m, align 4, !tbaa !9
  %55 = icmp sgt i32 %53, %54
  br i1 %55, label %56, label %58

56:                                               ; preds = %52
  %57 = load i32, ptr @m, align 4, !tbaa !9
  store i32 %57, ptr %7, align 4, !tbaa !9
  br label %58

58:                                               ; preds = %56, %52
  %59 = load i32, ptr %4, align 4, !tbaa !9
  %60 = load i32, ptr %6, align 4, !tbaa !9
  %61 = icmp sgt i32 %59, %60
  br i1 %61, label %66, label %62

62:                                               ; preds = %58
  %63 = load i32, ptr %5, align 4, !tbaa !9
  %64 = load i32, ptr %7, align 4, !tbaa !9
  %65 = icmp sgt i32 %63, %64
  br i1 %65, label %66, label %67

66:                                               ; preds = %62, %58
  store i32 4, ptr %3, align 4
  br label %104

67:                                               ; preds = %62
  %68 = load i32, ptr %4, align 4, !tbaa !9
  %69 = load i32, ptr @q_tot, align 4, !tbaa !9
  %70 = add nsw i32 %69, 1
  store i32 %70, ptr @q_tot, align 4, !tbaa !9
  %71 = sext i32 %69 to i64
  %72 = getelementptr inbounds [200020 x i32], ptr @que, i64 0, i64 %71
  store i32 %68, ptr %72, align 4, !tbaa !9
  %73 = load i32, ptr %6, align 4, !tbaa !9
  %74 = add nsw i32 %73, 1
  %75 = load i32, ptr @q_tot, align 4, !tbaa !9
  %76 = add nsw i32 %75, 1
  store i32 %76, ptr @q_tot, align 4, !tbaa !9
  %77 = sext i32 %75 to i64
  %78 = getelementptr inbounds [200020 x i32], ptr @que, i64 0, i64 %77
  store i32 %74, ptr %78, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 16, ptr %8) #6
  %79 = getelementptr inbounds %struct.Segment, ptr %8, i32 0, i32 0
  store i32 1, ptr %79, align 4, !tbaa !16
  %80 = getelementptr inbounds %struct.Segment, ptr %8, i32 0, i32 1
  %81 = load i32, ptr %5, align 4, !tbaa !9
  store i32 %81, ptr %80, align 4, !tbaa !18
  %82 = getelementptr inbounds %struct.Segment, ptr %8, i32 0, i32 2
  %83 = load i32, ptr %4, align 4, !tbaa !9
  store i32 %83, ptr %82, align 4, !tbaa !19
  %84 = getelementptr inbounds %struct.Segment, ptr %8, i32 0, i32 3
  %85 = load i32, ptr %6, align 4, !tbaa !9
  %86 = add nsw i32 %85, 1
  store i32 %86, ptr %84, align 4, !tbaa !20
  %87 = load i32, ptr @p_tot, align 4, !tbaa !9
  %88 = add nsw i32 %87, 1
  store i32 %88, ptr @p_tot, align 4, !tbaa !9
  %89 = sext i32 %87 to i64
  %90 = getelementptr inbounds [200020 x %struct.Segment], ptr @pp, i64 0, i64 %89
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %90, ptr align 4 %8, i64 16, i1 false), !tbaa.struct !21
  call void @llvm.lifetime.end.p0(i64 16, ptr %8) #6
  call void @llvm.lifetime.start.p0(i64 16, ptr %9) #6
  %91 = getelementptr inbounds %struct.Segment, ptr %9, i32 0, i32 0
  store i32 -1, ptr %91, align 4, !tbaa !16
  %92 = getelementptr inbounds %struct.Segment, ptr %9, i32 0, i32 1
  %93 = load i32, ptr %7, align 4, !tbaa !9
  %94 = add nsw i32 %93, 1
  store i32 %94, ptr %92, align 4, !tbaa !18
  %95 = getelementptr inbounds %struct.Segment, ptr %9, i32 0, i32 2
  %96 = load i32, ptr %4, align 4, !tbaa !9
  store i32 %96, ptr %95, align 4, !tbaa !19
  %97 = getelementptr inbounds %struct.Segment, ptr %9, i32 0, i32 3
  %98 = load i32, ptr %6, align 4, !tbaa !9
  %99 = add nsw i32 %98, 1
  store i32 %99, ptr %97, align 4, !tbaa !20
  %100 = load i32, ptr @p_tot, align 4, !tbaa !9
  %101 = add nsw i32 %100, 1
  store i32 %101, ptr @p_tot, align 4, !tbaa !9
  %102 = sext i32 %100 to i64
  %103 = getelementptr inbounds [200020 x %struct.Segment], ptr @pp, i64 0, i64 %102
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %103, ptr align 4 %9, i64 16, i1 false), !tbaa.struct !21
  call void @llvm.lifetime.end.p0(i64 16, ptr %9) #6
  store i32 0, ptr %3, align 4
  br label %104

104:                                              ; preds = %67, %66
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #6
  %105 = load i32, ptr %3, align 4
  switch i32 %105, label %195 [
    i32 0, label %106
    i32 4, label %107
  ]

106:                                              ; preds = %104
  br label %107

107:                                              ; preds = %106, %104
  %108 = load i32, ptr %2, align 4, !tbaa !9
  %109 = add nsw i32 %108, 1
  store i32 %109, ptr %2, align 4, !tbaa !9
  br label %13, !llvm.loop !22

110:                                              ; preds = %17
  %111 = load i32, ptr @q_tot, align 4, !tbaa !9
  %112 = sext i32 %111 to i64
  %113 = getelementptr inbounds i32, ptr @que, i64 %112
  call void @_ZSt4sortIPiEvT_S1_(ptr noundef @que, ptr noundef %113)
  %114 = load i32, ptr @q_tot, align 4, !tbaa !9
  %115 = sext i32 %114 to i64
  %116 = getelementptr inbounds i32, ptr @que, i64 %115
  %117 = call noundef ptr @_ZSt6uniqueIPiET_S1_S1_(ptr noundef @que, ptr noundef %116)
  %118 = ptrtoint ptr %117 to i64
  %119 = sub i64 %118, ptrtoint (ptr @que to i64)
  %120 = sdiv exact i64 %119, 4
  %121 = trunc i64 %120 to i32
  store i32 %121, ptr @q_tot, align 4, !tbaa !9
  %122 = load i32, ptr @p_tot, align 4, !tbaa !9
  %123 = sext i32 %122 to i64
  %124 = getelementptr inbounds %struct.Segment, ptr @pp, i64 %123
  call void @_ZSt4sortIP7SegmentEvT_S2_(ptr noundef @pp, ptr noundef %124)
  call void @llvm.memset.p0.i64(ptr align 16 @seg, i8 0, i64 3200320, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #6
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %125

125:                                              ; preds = %190, %110
  %126 = load i32, ptr %10, align 4, !tbaa !9
  %127 = load i32, ptr @p_tot, align 4, !tbaa !9
  %128 = sub nsw i32 %127, 1
  %129 = icmp slt i32 %126, %128
  br i1 %129, label %131, label %130

130:                                              ; preds = %125
  store i32 5, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #6
  br label %193

131:                                              ; preds = %125
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #6
  %132 = load i32, ptr @q_tot, align 4, !tbaa !9
  %133 = sext i32 %132 to i64
  %134 = getelementptr inbounds i32, ptr @que, i64 %133
  %135 = load i32, ptr %10, align 4, !tbaa !9
  %136 = sext i32 %135 to i64
  %137 = getelementptr inbounds [200020 x %struct.Segment], ptr @pp, i64 0, i64 %136
  %138 = getelementptr inbounds %struct.Segment, ptr %137, i32 0, i32 2
  %139 = call noundef ptr @_ZSt11lower_boundIPiiET_S1_S1_RKT0_(ptr noundef @que, ptr noundef %134, ptr noundef nonnull align 4 dereferenceable(4) %138)
  %140 = ptrtoint ptr %139 to i64
  %141 = sub i64 %140, ptrtoint (ptr @que to i64)
  %142 = sdiv exact i64 %141, 4
  %143 = trunc i64 %142 to i32
  store i32 %143, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #6
  %144 = load i32, ptr @q_tot, align 4, !tbaa !9
  %145 = sext i32 %144 to i64
  %146 = getelementptr inbounds i32, ptr @que, i64 %145
  %147 = load i32, ptr %10, align 4, !tbaa !9
  %148 = sext i32 %147 to i64
  %149 = getelementptr inbounds [200020 x %struct.Segment], ptr @pp, i64 0, i64 %148
  %150 = getelementptr inbounds %struct.Segment, ptr %149, i32 0, i32 3
  %151 = call noundef ptr @_ZSt11lower_boundIPiiET_S1_S1_RKT0_(ptr noundef @que, ptr noundef %146, ptr noundef nonnull align 4 dereferenceable(4) %150)
  %152 = ptrtoint ptr %151 to i64
  %153 = sub i64 %152, ptrtoint (ptr @que to i64)
  %154 = sdiv exact i64 %153, 4
  %155 = trunc i64 %154 to i32
  store i32 %155, ptr %12, align 4, !tbaa !9
  %156 = load i32, ptr @q_tot, align 4, !tbaa !9
  %157 = sub nsw i32 %156, 2
  %158 = load i32, ptr %11, align 4, !tbaa !9
  %159 = load i32, ptr %12, align 4, !tbaa !9
  %160 = sub nsw i32 %159, 1
  %161 = load i32, ptr %10, align 4, !tbaa !9
  %162 = sext i32 %161 to i64
  %163 = getelementptr inbounds [200020 x %struct.Segment], ptr @pp, i64 0, i64 %162
  %164 = getelementptr inbounds %struct.Segment, ptr %163, i32 0, i32 0
  %165 = load i32, ptr %164, align 16, !tbaa !16
  call void @_Z3updiiiii(i32 noundef 0, i32 noundef %157, i32 noundef %158, i32 noundef %160, i32 noundef %165)
  %166 = load i32, ptr %10, align 4, !tbaa !9
  %167 = add nsw i32 %166, 1
  %168 = sext i32 %167 to i64
  %169 = getelementptr inbounds [200020 x %struct.Segment], ptr @pp, i64 0, i64 %168
  %170 = getelementptr inbounds %struct.Segment, ptr %169, i32 0, i32 1
  %171 = load i32, ptr %170, align 4, !tbaa !18
  %172 = load i32, ptr %10, align 4, !tbaa !9
  %173 = sext i32 %172 to i64
  %174 = getelementptr inbounds [200020 x %struct.Segment], ptr @pp, i64 0, i64 %173
  %175 = getelementptr inbounds %struct.Segment, ptr %174, i32 0, i32 1
  %176 = load i32, ptr %175, align 4, !tbaa !18
  %177 = sub nsw i32 %171, %176
  %178 = sext i32 %177 to i64
  %179 = load i32, ptr @q_tot, align 4, !tbaa !9
  %180 = sub nsw i32 %179, 2
  %181 = call noundef i32 @_Z3idxii(i32 noundef 0, i32 noundef %180)
  %182 = sext i32 %181 to i64
  %183 = getelementptr inbounds [400040 x %struct.SegTree], ptr @seg, i64 0, i64 %182
  %184 = getelementptr inbounds %struct.SegTree, ptr %183, i32 0, i32 1
  %185 = load i32, ptr %184, align 4, !tbaa !24
  %186 = sext i32 %185 to i64
  %187 = mul nsw i64 %178, %186
  %188 = load i64, ptr %1, align 8, !tbaa !5
  %189 = add nsw i64 %188, %187
  store i64 %189, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #6
  br label %190

190:                                              ; preds = %131
  %191 = load i32, ptr %10, align 4, !tbaa !9
  %192 = add nsw i32 %191, 1
  store i32 %192, ptr %10, align 4, !tbaa !9
  br label %125, !llvm.loop !26

193:                                              ; preds = %130
  %194 = load i64, ptr %1, align 8, !tbaa !5
  store i32 1, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #6
  ret i64 %194

195:                                              ; preds = %104
  unreachable
}

; 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) #3

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

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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)) #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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 #5 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"_ZTS6Square", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12}
!13 = !{!12, !10, i64 4}
!14 = !{!12, !10, i64 8}
!15 = !{!12, !10, i64 12}
!16 = !{!17, !10, i64 0}
!17 = !{!"_ZTS7Segment", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12}
!18 = !{!17, !10, i64 4}
!19 = !{!17, !10, i64 8}
!20 = !{!17, !10, i64 12}
!21 = !{i64 0, i64 4, !9, i64 4, i64 4, !9, i64 8, i64 4, !9, i64 12, i64 4, !9}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}
!24 = !{!25, !10, i64 4}
!25 = !{!"_ZTS7SegTree", !10, i64 0, !10, i64 4}
!26 = distinct !{!26, !23}


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

@n = external dso_local local_unnamed_addr global i32, align 4
@m = external dso_local local_unnamed_addr global i32, align 4
@p = external dso_local local_unnamed_addr global i32, align 4
@q_tot = external dso_local local_unnamed_addr global i32, align 4
@que = external dso_local global [200020 x i32], align 16
@p_tot = external dso_local local_unnamed_addr global i32, align 4
@a = external dso_local local_unnamed_addr global [100010 x %struct.Square], align 16
@pp = external dso_local global [200020 x %struct.Segment], align 16
@seg = external dso_local local_unnamed_addr global [400040 x %struct.SegTree], align 16

; 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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z3idxii(i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z5solvev() local_unnamed_addr #0 {
  store i32 0, ptr @p_tot, align 4, !tbaa !5
  store i32 0, ptr @q_tot, align 4, !tbaa !5
  %1 = load i32, ptr @p, align 4, !tbaa !5
  %.not46 = icmp slt i32 %1, 0
  br i1 %.not46, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %0
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %3 = load i32, ptr @m, align 4, !tbaa !5
  %4 = add nuw i32 %1, 1
  %wide.trip.count = zext i32 %4 to i64
  br label %21

._crit_edge.loopexit:                             ; preds = %49
  %5 = sext i32 %51 to i64
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %0
  %6 = phi i64 [ %5, %._crit_edge.loopexit ], [ 0, %0 ]
  %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 @q_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 @q_tot, align 4, !tbaa !5
  %16 = load i32, ptr @p_tot, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds %struct.Segment, ptr @pp, i64 %17
  tail call void @_ZSt4sortIP7SegmentEvT_S2_(ptr noundef nonnull @pp, ptr noundef nonnull %18)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(3200320) @seg, i8 0, i64 3200320, i1 false)
  %19 = load i32, ptr @p_tot, align 4, !tbaa !5
  %20 = icmp sgt i32 %19, 1
  br i1 %20, label %.lr.ph51, label %._crit_edge52

21:                                               ; preds = %.lr.ph, %49
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %49 ]
  %22 = phi i32 [ 0, %.lr.ph ], [ %51, %49 ]
  %23 = phi i32 [ 0, %.lr.ph ], [ %50, %49 ]
  %24 = getelementptr inbounds [100010 x %struct.Square], ptr @a, i64 0, i64 %indvars.iv
  %25 = load i32, ptr %24, align 16, !tbaa !9
  %26 = getelementptr inbounds i8, ptr %24, i64 4
  %27 = load i32, ptr %26, align 4, !tbaa !11
  %28 = getelementptr inbounds i8, ptr %24, i64 8
  %29 = load i32, ptr %28, align 8, !tbaa !12
  %30 = getelementptr inbounds i8, ptr %24, i64 12
  %31 = load i32, ptr %30, align 4, !tbaa !13
  %spec.store.select = tail call i32 @llvm.smax.i32(i32 %25, i32 1)
  %spec.store.select1 = tail call i32 @llvm.smax.i32(i32 %27, i32 1)
  %spec.select = tail call i32 @llvm.smin.i32(i32 %29, i32 %2)
  %.041 = tail call i32 @llvm.smin.i32(i32 %31, i32 %3)
  %32 = icmp sgt i32 %spec.store.select, %spec.select
  %33 = icmp sgt i32 %spec.store.select1, %.041
  %or.cond = select i1 %32, i1 true, i1 %33
  br i1 %or.cond, label %49, label %34

34:                                               ; preds = %21
  %35 = add nsw i32 %22, 1
  %36 = sext i32 %22 to i64
  %37 = getelementptr inbounds [200020 x i32], ptr @que, i64 0, i64 %36
  store i32 %spec.store.select, ptr %37, align 4, !tbaa !5
  %38 = add nuw nsw i32 %spec.select, 1
  %39 = add nsw i32 %22, 2
  store i32 %39, ptr @q_tot, align 4, !tbaa !5
  %40 = sext i32 %35 to i64
  %41 = getelementptr inbounds [200020 x i32], ptr @que, i64 0, i64 %40
  store i32 %38, ptr %41, align 4, !tbaa !5
  %42 = add nsw i32 %23, 1
  %43 = sext i32 %23 to i64
  %44 = getelementptr inbounds [200020 x %struct.Segment], ptr @pp, i64 0, i64 %43
  store i32 1, ptr %44, align 16, !tbaa !5
  %.sroa.411.0..sroa_idx = getelementptr inbounds i8, ptr %44, i64 4
  store i32 %spec.store.select1, ptr %.sroa.411.0..sroa_idx, align 4, !tbaa !5
  %.sroa.512.0..sroa_idx = getelementptr inbounds i8, ptr %44, i64 8
  store i32 %spec.store.select, ptr %.sroa.512.0..sroa_idx, align 8, !tbaa !5
  %.sroa.613.0..sroa_idx = getelementptr inbounds i8, ptr %44, i64 12
  store i32 %38, ptr %.sroa.613.0..sroa_idx, align 4, !tbaa !5
  %45 = add nuw nsw i32 %.041, 1
  %46 = add nsw i32 %23, 2
  store i32 %46, ptr @p_tot, align 4, !tbaa !5
  %47 = sext i32 %42 to i64
  %48 = getelementptr inbounds [200020 x %struct.Segment], ptr @pp, i64 0, i64 %47
  store i32 -1, ptr %48, align 16, !tbaa !5
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %48, i64 4
  store i32 %45, ptr %.sroa.4.0..sroa_idx, align 4, !tbaa !5
  %.sroa.5.0..sroa_idx = getelementptr inbounds i8, ptr %48, i64 8
  store i32 %spec.store.select, ptr %.sroa.5.0..sroa_idx, align 8, !tbaa !5
  %.sroa.6.0..sroa_idx = getelementptr inbounds i8, ptr %48, i64 12
  store i32 %38, ptr %.sroa.6.0..sroa_idx, align 4, !tbaa !5
  br label %49

49:                                               ; preds = %21, %34
  %50 = phi i32 [ %23, %21 ], [ %46, %34 ]
  %51 = phi i32 [ %22, %21 ], [ %39, %34 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge.loopexit, label %21, !llvm.loop !14

._crit_edge52:                                    ; preds = %.lr.ph51, %._crit_edge
  %.0.lcssa = phi i64 [ 0, %._crit_edge ], [ %89, %.lr.ph51 ]
  ret i64 %.0.lcssa

.lr.ph51:                                         ; preds = %._crit_edge, %.lr.ph51
  %indvars.iv54 = phi i64 [ %indvars.iv.next55, %.lr.ph51 ], [ 0, %._crit_edge ]
  %.049 = phi i64 [ %89, %.lr.ph51 ], [ 0, %._crit_edge ]
  %52 = load i32, ptr @q_tot, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds i32, ptr @que, i64 %53
  %55 = getelementptr inbounds [200020 x %struct.Segment], ptr @pp, i64 0, i64 %indvars.iv54
  %56 = getelementptr inbounds i8, ptr %55, i64 8
  %57 = tail call noundef ptr @_ZSt11lower_boundIPiiET_S1_S1_RKT0_(ptr noundef nonnull @que, ptr noundef nonnull %54, ptr noundef nonnull align 4 dereferenceable(4) %56)
  %58 = ptrtoint ptr %57 to i64
  %59 = sub i64 %58, ptrtoint (ptr @que to i64)
  %60 = lshr exact i64 %59, 2
  %61 = trunc i64 %60 to i32
  %62 = load i32, ptr @q_tot, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds i32, ptr @que, i64 %63
  %65 = getelementptr inbounds i8, ptr %55, i64 12
  %66 = tail call noundef ptr @_ZSt11lower_boundIPiiET_S1_S1_RKT0_(ptr noundef nonnull @que, ptr noundef nonnull %64, ptr noundef nonnull align 4 dereferenceable(4) %65)
  %67 = ptrtoint ptr %66 to i64
  %68 = sub i64 %67, ptrtoint (ptr @que to i64)
  %69 = lshr exact i64 %68, 2
  %70 = trunc i64 %69 to i32
  %71 = load i32, ptr @q_tot, align 4, !tbaa !5
  %72 = add nsw i32 %71, -2
  %73 = add nsw i32 %70, -1
  %74 = load i32, ptr %55, align 16, !tbaa !16
  tail call void @_Z3updiiiii(i32 noundef 0, i32 noundef %72, i32 noundef %61, i32 noundef %73, i32 noundef %74)
  %indvars.iv.next55 = add nuw nsw i64 %indvars.iv54, 1
  %75 = getelementptr inbounds [200020 x %struct.Segment], ptr @pp, i64 0, i64 %indvars.iv.next55, i32 1
  %76 = load i32, ptr %75, align 4, !tbaa !18
  %77 = getelementptr inbounds i8, ptr %55, i64 4
  %78 = load i32, ptr %77, align 4, !tbaa !18
  %79 = sub nsw i32 %76, %78
  %80 = sext i32 %79 to i64
  %81 = load i32, ptr @q_tot, align 4, !tbaa !5
  %82 = add nsw i32 %81, -2
  %83 = tail call noundef i32 @_Z3idxii(i32 noundef 0, i32 noundef %82)
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds [400040 x %struct.SegTree], ptr @seg, i64 0, i64 %84, i32 1
  %86 = load i32, ptr %85, align 4, !tbaa !19
  %87 = sext i32 %86 to i64
  %88 = mul nsw i64 %87, %80
  %89 = add nsw i64 %88, %.049
  %90 = load i32, ptr @p_tot, align 4, !tbaa !5
  %91 = add nsw i32 %90, -1
  %92 = sext i32 %91 to i64
  %93 = icmp slt i64 %indvars.iv.next55, %92
  br i1 %93, label %.lr.ph51, label %._crit_edge52, !llvm.loop !21
}

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

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

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

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #4

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, i32) #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 = { 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 #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

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


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