; LLVM IR from tangjz/acm-icpc :: buaa/oj3rd (724)

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

@t = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@q = external dso_local global [524288 x [3 x i32]], align 16
@seg = external dso_local global [1048809 x i32], align 16
@tot = external dso_local global i32, align 4
@num = external dso_local global [1048576 x %struct.Node], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1

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

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

9:                                                ; preds = %204, %0
  %10 = load i32, ptr @t, align 4, !tbaa !5
  %11 = add nsw i32 %10, -1
  store i32 %11, ptr @t, align 4, !tbaa !5
  %12 = icmp ne i32 %10, 0
  br i1 %12, label %13, label %205

13:                                               ; preds = %9
  %14 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  call void @llvm.memset.p0.i64(ptr align 16 @seg, i8 0, i64 4195236, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #8
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %15

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

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

20:                                               ; preds = %15
  %21 = load i32, ptr %2, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [524288 x [3 x i32]], ptr @q, i64 0, i64 %22
  %24 = getelementptr inbounds [3 x i32], ptr %23, i64 0, i64 2
  %25 = load i32, ptr %2, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [524288 x [3 x i32]], ptr @q, i64 0, i64 %26
  %28 = getelementptr inbounds [3 x i32], ptr %27, i64 0, i64 0
  %29 = load i32, ptr %2, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [524288 x [3 x i32]], ptr @q, i64 0, i64 %30
  %32 = getelementptr inbounds [3 x i32], ptr %31, i64 0, i64 1
  %33 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %24, ptr noundef %28, ptr noundef %32)
  %34 = load i32, ptr %2, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [524288 x [3 x i32]], ptr @q, i64 0, i64 %35
  %37 = getelementptr inbounds [3 x i32], ptr %36, i64 0, i64 0
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %39 = load i32, ptr %2, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [524288 x [3 x i32]], ptr @q, i64 0, i64 %40
  %42 = getelementptr inbounds [3 x i32], ptr %41, i64 0, i64 1
  %43 = load i32, ptr %42, align 4, !tbaa !5
  %44 = icmp sgt i32 %38, %43
  br i1 %44, label %45, label %54

45:                                               ; preds = %20
  %46 = load i32, ptr %2, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [524288 x [3 x i32]], ptr @q, i64 0, i64 %47
  %49 = getelementptr inbounds [3 x i32], ptr %48, i64 0, i64 0
  %50 = load i32, ptr %2, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [524288 x [3 x i32]], ptr @q, i64 0, i64 %51
  %53 = getelementptr inbounds [3 x i32], ptr %52, i64 0, i64 1
  call void @_ZSt4swapIiENSt9enable_ifIXsr6__and_ISt6__not_ISt15__is_tuple_likeIT_EESt21is_move_constructibleIS3_ESt18is_move_assignableIS3_EEE5valueEvE4typeERS3_SC_(ptr noundef nonnull align 4 dereferenceable(4) %49, ptr noundef nonnull align 4 dereferenceable(4) %53) #8
  br label %54

54:                                               ; preds = %45, %20
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #8
  %55 = getelementptr inbounds %struct.Node, ptr %3, i32 0, i32 0
  %56 = load i32, ptr %2, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [524288 x [3 x i32]], ptr @q, i64 0, i64 %57
  %59 = getelementptr inbounds [3 x i32], ptr %58, i64 0, i64 0
  %60 = load i32, ptr %59, align 4, !tbaa !5
  store i32 %60, ptr %55, align 4, !tbaa !9
  %61 = getelementptr inbounds %struct.Node, ptr %3, i32 0, i32 1
  %62 = load i32, ptr %2, align 4, !tbaa !5
  %63 = load i32, ptr %2, align 4, !tbaa !5
  %64 = add nsw i32 %62, %63
  store i32 %64, ptr %61, align 4, !tbaa !11
  %65 = load i32, ptr %2, align 4, !tbaa !5
  %66 = load i32, ptr %2, align 4, !tbaa !5
  %67 = add nsw i32 %65, %66
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds [1048576 x %struct.Node], ptr @num, i64 0, i64 %68
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %69, ptr align 4 %3, i64 8, i1 false), !tbaa.struct !12
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #8
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #8
  %70 = getelementptr inbounds %struct.Node, ptr %4, i32 0, i32 0
  %71 = load i32, ptr %2, align 4, !tbaa !5
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds [524288 x [3 x i32]], ptr @q, i64 0, i64 %72
  %74 = getelementptr inbounds [3 x i32], ptr %73, i64 0, i64 1
  %75 = load i32, ptr %74, align 4, !tbaa !5
  store i32 %75, ptr %70, align 4, !tbaa !9
  %76 = getelementptr inbounds %struct.Node, ptr %4, i32 0, i32 1
  %77 = load i32, ptr %2, align 4, !tbaa !5
  %78 = load i32, ptr %2, align 4, !tbaa !5
  %79 = add nsw i32 %77, %78
  %80 = add nsw i32 %79, 1
  store i32 %80, ptr %76, align 4, !tbaa !11
  %81 = load i32, ptr %2, align 4, !tbaa !5
  %82 = load i32, ptr %2, align 4, !tbaa !5
  %83 = add nsw i32 %81, %82
  %84 = add nsw i32 %83, 1
  %85 = sext i32 %84 to i64
  %86 = getelementptr inbounds [1048576 x %struct.Node], ptr @num, i64 0, i64 %85
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %86, ptr align 4 %4, i64 8, i1 false), !tbaa.struct !12
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #8
  br label %87

87:                                               ; preds = %54
  %88 = load i32, ptr %2, align 4, !tbaa !5
  %89 = add nsw i32 %88, 1
  store i32 %89, ptr %2, align 4, !tbaa !5
  br label %15, !llvm.loop !13

90:                                               ; preds = %19
  %91 = load i32, ptr @n, align 4, !tbaa !5
  %92 = sext i32 %91 to i64
  %93 = getelementptr inbounds %struct.Node, ptr @num, i64 %92
  %94 = load i32, ptr @n, align 4, !tbaa !5
  %95 = sext i32 %94 to i64
  %96 = getelementptr inbounds %struct.Node, ptr %93, i64 %95
  call void @_ZSt4sortIP4NodeEvT_S2_(ptr noundef @num, ptr noundef %96)
  %97 = load i32, ptr @tot, align 4, !tbaa !5
  %98 = add nsw i32 %97, 1
  store i32 %98, ptr @tot, align 4, !tbaa !5
  %99 = load i32, ptr getelementptr inbounds (%struct.Node, ptr @num, i32 0, i32 1), align 4, !tbaa !11
  %100 = ashr i32 %99, 1
  %101 = sext i32 %100 to i64
  %102 = getelementptr inbounds [524288 x [3 x i32]], ptr @q, i64 0, i64 %101
  %103 = load i32, ptr getelementptr inbounds (%struct.Node, ptr @num, i32 0, i32 1), align 4, !tbaa !11
  %104 = and i32 %103, 1
  %105 = sext i32 %104 to i64
  %106 = getelementptr inbounds [3 x i32], ptr %102, i64 0, i64 %105
  store i32 %98, ptr %106, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #8
  store i32 1, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #8
  store i32 1, ptr %6, align 4, !tbaa !5
  br label %107

107:                                              ; preds = %150, %90
  %108 = load i32, ptr %5, align 4, !tbaa !5
  %109 = load i32, ptr @n, align 4, !tbaa !5
  %110 = load i32, ptr @n, align 4, !tbaa !5
  %111 = add nsw i32 %109, %110
  %112 = icmp slt i32 %108, %111
  br i1 %112, label %114, label %113

113:                                              ; preds = %107
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #8
  br label %153

114:                                              ; preds = %107
  %115 = load i32, ptr %5, align 4, !tbaa !5
  %116 = sub nsw i32 %115, 1
  %117 = sext i32 %116 to i64
  %118 = getelementptr inbounds [1048576 x %struct.Node], ptr @num, i64 0, i64 %117
  %119 = getelementptr inbounds %struct.Node, ptr %118, i32 0, i32 0
  %120 = load i32, ptr %119, align 8, !tbaa !9
  %121 = load i32, ptr %5, align 4, !tbaa !5
  %122 = sext i32 %121 to i64
  %123 = getelementptr inbounds [1048576 x %struct.Node], ptr @num, i64 0, i64 %122
  %124 = getelementptr inbounds %struct.Node, ptr %123, i32 0, i32 0
  %125 = load i32, ptr %124, align 8, !tbaa !9
  %126 = icmp eq i32 %120, %125
  br i1 %126, label %127, label %129

127:                                              ; preds = %114
  %128 = load i32, ptr @tot, align 4, !tbaa !5
  br label %132

129:                                              ; preds = %114
  %130 = load i32, ptr @tot, align 4, !tbaa !5
  %131 = add nsw i32 %130, 1
  store i32 %131, ptr @tot, align 4, !tbaa !5
  br label %132

132:                                              ; preds = %129, %127
  %133 = phi i32 [ %128, %127 ], [ %131, %129 ]
  %134 = load i32, ptr %5, align 4, !tbaa !5
  %135 = sext i32 %134 to i64
  %136 = getelementptr inbounds [1048576 x %struct.Node], ptr @num, i64 0, i64 %135
  %137 = getelementptr inbounds %struct.Node, ptr %136, i32 0, i32 1
  %138 = load i32, ptr %137, align 4, !tbaa !11
  %139 = ashr i32 %138, 1
  %140 = sext i32 %139 to i64
  %141 = getelementptr inbounds [524288 x [3 x i32]], ptr @q, i64 0, i64 %140
  %142 = load i32, ptr %5, align 4, !tbaa !5
  %143 = sext i32 %142 to i64
  %144 = getelementptr inbounds [1048576 x %struct.Node], ptr @num, i64 0, i64 %143
  %145 = getelementptr inbounds %struct.Node, ptr %144, i32 0, i32 1
  %146 = load i32, ptr %145, align 4, !tbaa !11
  %147 = and i32 %146, 1
  %148 = sext i32 %147 to i64
  %149 = getelementptr inbounds [3 x i32], ptr %141, i64 0, i64 %148
  store i32 %133, ptr %149, align 4, !tbaa !5
  br label %150

150:                                              ; preds = %132
  %151 = load i32, ptr %5, align 4, !tbaa !5
  %152 = add nsw i32 %151, 1
  store i32 %152, ptr %5, align 4, !tbaa !5
  br label %107, !llvm.loop !15

153:                                              ; preds = %113
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #8
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %154

154:                                              ; preds = %201, %153
  %155 = load i32, ptr %7, align 4, !tbaa !5
  %156 = load i32, ptr @n, align 4, !tbaa !5
  %157 = icmp slt i32 %155, %156
  br i1 %157, label %159, label %158

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

159:                                              ; preds = %154
  %160 = load i32, ptr %7, align 4, !tbaa !5
  %161 = sext i32 %160 to i64
  %162 = getelementptr inbounds [524288 x [3 x i32]], ptr @q, i64 0, i64 %161
  %163 = getelementptr inbounds [3 x i32], ptr %162, i64 0, i64 2
  %164 = load i32, ptr %163, align 4, !tbaa !5
  %165 = icmp eq i32 %164, 1
  br i1 %165, label %166, label %183

166:                                              ; preds = %159
  %167 = load i32, ptr @tot, align 4, !tbaa !5
  %168 = load i32, ptr %7, align 4, !tbaa !5
  %169 = sext i32 %168 to i64
  %170 = getelementptr inbounds [524288 x [3 x i32]], ptr @q, i64 0, i64 %169
  %171 = getelementptr inbounds [3 x i32], ptr %170, i64 0, i64 0
  %172 = load i32, ptr %171, align 4, !tbaa !5
  %173 = load i32, ptr %7, align 4, !tbaa !5
  %174 = sext i32 %173 to i64
  %175 = getelementptr inbounds [524288 x [3 x i32]], ptr @q, i64 0, i64 %174
  %176 = getelementptr inbounds [3 x i32], ptr %175, i64 0, i64 1
  %177 = load i32, ptr %176, align 4, !tbaa !5
  %178 = load i32, ptr %7, align 4, !tbaa !5
  %179 = sext i32 %178 to i64
  %180 = getelementptr inbounds [524288 x [3 x i32]], ptr @q, i64 0, i64 %179
  %181 = getelementptr inbounds [3 x i32], ptr %180, i64 0, i64 1
  %182 = load i32, ptr %181, align 4, !tbaa !5
  call void @_Z6updateiiiiii(i32 noundef 1, i32 noundef 1, i32 noundef %167, i32 noundef %172, i32 noundef %177, i32 noundef %182)
  br label %200

183:                                              ; preds = %159
  %184 = load i32, ptr @tot, align 4, !tbaa !5
  %185 = load i32, ptr %7, align 4, !tbaa !5
  %186 = sext i32 %185 to i64
  %187 = getelementptr inbounds [524288 x [3 x i32]], ptr @q, i64 0, i64 %186
  %188 = getelementptr inbounds [3 x i32], ptr %187, i64 0, i64 0
  %189 = load i32, ptr %188, align 4, !tbaa !5
  %190 = call noundef i32 @_Z5queryiiii(i32 noundef 1, i32 noundef 1, i32 noundef %184, i32 noundef %189)
  %191 = load i32, ptr %7, align 4, !tbaa !5
  %192 = sext i32 %191 to i64
  %193 = getelementptr inbounds [524288 x [3 x i32]], ptr @q, i64 0, i64 %192
  %194 = getelementptr inbounds [3 x i32], ptr %193, i64 0, i64 1
  %195 = load i32, ptr %194, align 4, !tbaa !5
  %196 = icmp sge i32 %190, %195
  %197 = zext i1 %196 to i64
  %198 = select i1 %196, ptr @.str.2, ptr @.str.3
  %199 = call i32 @puts(ptr noundef %198)
  br label %200

200:                                              ; preds = %183, %166
  br label %201

201:                                              ; preds = %200
  %202 = load i32, ptr %7, align 4, !tbaa !5
  %203 = add nsw i32 %202, 1
  store i32 %203, ptr %7, align 4, !tbaa !5
  br label %154, !llvm.loop !16

204:                                              ; preds = %158
  br label %9, !llvm.loop !17

205:                                              ; preds = %9
  ret i32 0
}

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

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

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

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

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

declare i32 @puts(ptr noundef) #3

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 = { 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 #3 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #4 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { 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 #6 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #7 = { 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 #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, !6, i64 0}
!10 = !{!"_ZTS4Node", !6, i64 0, !6, i64 4}
!11 = !{!10, !6, i64 4}
!12 = !{i64 0, i64 4, !5, i64 4, i64 4, !5}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}
!17 = distinct !{!17, !14}


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

@t = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@q = external dso_local global [524288 x [3 x i32]], align 16
@seg = external dso_local local_unnamed_addr global [1048809 x i32], align 16
@tot = external dso_local local_unnamed_addr global i32, align 4
@num = external dso_local global [1048576 x %struct.Node], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1

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

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @t)
  %2 = load i32, ptr @t, align 4, !tbaa !5
  %3 = add nsw i32 %2, -1
  store i32 %3, ptr @t, align 4, !tbaa !5
  %.not45 = icmp eq i32 %2, 0
  br i1 %.not45, label %._crit_edge48, label %.lr.ph47

.loopexit:                                        ; preds = %73, %._crit_edge, %.preheader
  %4 = load i32, ptr @t, align 4, !tbaa !5
  %5 = add nsw i32 %4, -1
  store i32 %5, ptr @t, align 4, !tbaa !5
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %._crit_edge48, label %.lr.ph47, !llvm.loop !9

.lr.ph47:                                         ; preds = %0, %.loopexit
  %6 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(4195236) @seg, i8 0, i64 4195236, i1 false)
  %7 = load i32, ptr @n, align 4, !tbaa !5
  %8 = icmp sgt i32 %7, 0
  br i1 %8, label %.lr.ph, label %.lr.ph47.._crit_edge_crit_edge

.lr.ph47.._crit_edge_crit_edge:                   ; preds = %.lr.ph47
  %.pre59 = sext i32 %7 to i64
  br label %._crit_edge

._crit_edge:                                      ; preds = %30, %.lr.ph47.._crit_edge_crit_edge
  %.pre-phi = phi i64 [ %.pre59, %.lr.ph47.._crit_edge_crit_edge ], [ %40, %30 ]
  %9 = getelementptr inbounds %struct.Node, ptr @num, i64 %.pre-phi
  %10 = getelementptr inbounds %struct.Node, ptr %9, i64 %.pre-phi
  tail call void @_ZSt4sortIP4NodeEvT_S2_(ptr noundef nonnull @num, ptr noundef nonnull %10)
  %11 = load i32, ptr @tot, align 4, !tbaa !5
  %12 = add nsw i32 %11, 1
  store i32 %12, ptr @tot, align 4, !tbaa !5
  %13 = load i32, ptr getelementptr inbounds (i8, ptr @num, i64 4), align 4, !tbaa !11
  %14 = ashr i32 %13, 1
  %15 = sext i32 %14 to i64
  %16 = and i32 %13, 1
  %17 = zext nneg i32 %16 to i64
  %18 = getelementptr inbounds [524288 x [3 x i32]], ptr @q, i64 0, i64 %15, i64 %17
  store i32 %12, ptr %18, align 4, !tbaa !5
  %19 = load i32, ptr @n, align 4, !tbaa !5
  %20 = icmp sgt i32 %19, 0
  br i1 %20, label %.lr.ph42.preheader, label %.loopexit

.lr.ph42.preheader:                               ; preds = %._crit_edge
  %21 = shl nuw i32 %19, 1
  %smax = tail call i32 @llvm.smax.i32(i32 %21, i32 2)
  %wide.trip.count = zext nneg i32 %smax to i64
  %.pre58 = load i32, ptr @num, align 16, !tbaa !13
  br label %.lr.ph42

.lr.ph:                                           ; preds = %.lr.ph47, %30
  %indvars.iv = phi i64 [ %indvars.iv.next, %30 ], [ 0, %.lr.ph47 ]
  %22 = getelementptr inbounds [524288 x [3 x i32]], ptr @q, i64 0, i64 %indvars.iv
  %23 = getelementptr inbounds i8, ptr %22, i64 8
  %24 = getelementptr inbounds i8, ptr %22, i64 4
  %25 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %23, ptr noundef nonnull %22, ptr noundef nonnull %24)
  %26 = load i32, ptr %22, align 4, !tbaa !5
  %27 = load i32, ptr %24, align 4, !tbaa !5
  %28 = icmp sgt i32 %26, %27
  br i1 %28, label %29, label %30

29:                                               ; preds = %.lr.ph
  tail call void @_ZSt4swapIiENSt9enable_ifIXsr6__and_ISt6__not_ISt15__is_tuple_likeIT_EESt21is_move_constructibleIS3_ESt18is_move_assignableIS3_EEE5valueEvE4typeERS3_SC_(ptr noundef nonnull align 4 dereferenceable(4) %22, ptr noundef nonnull align 4 dereferenceable(4) %24) #7
  %.pre = load i32, ptr %22, align 4, !tbaa !5
  %.pre57 = load i32, ptr %24, align 4, !tbaa !5
  br label %30

30:                                               ; preds = %29, %.lr.ph
  %31 = phi i32 [ %.pre57, %29 ], [ %27, %.lr.ph ]
  %32 = phi i32 [ %.pre, %29 ], [ %26, %.lr.ph ]
  %33 = shl nuw nsw i64 %indvars.iv, 1
  %34 = getelementptr inbounds [1048576 x %struct.Node], ptr @num, i64 0, i64 %33
  store i32 %32, ptr %34, align 16, !tbaa !5
  %.sroa.415.0..sroa_idx = getelementptr inbounds i8, ptr %34, i64 4
  %35 = trunc nuw i64 %33 to i32
  store i32 %35, ptr %.sroa.415.0..sroa_idx, align 4, !tbaa !5
  %36 = or disjoint i64 %33, 1
  %37 = getelementptr inbounds [1048576 x %struct.Node], ptr @num, i64 0, i64 %36
  store i32 %31, ptr %37, align 8, !tbaa !5
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %37, i64 4
  %38 = trunc nuw i64 %36 to i32
  store i32 %38, ptr %.sroa.4.0..sroa_idx, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %39 = load i32, ptr @n, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = icmp slt i64 %indvars.iv.next, %40
  br i1 %41, label %.lr.ph, label %._crit_edge, !llvm.loop !14

.preheader:                                       ; preds = %49
  br i1 %20, label %.lr.ph44, label %.loopexit

.lr.ph42:                                         ; preds = %.lr.ph42.preheader, %49
  %42 = phi i32 [ %.pre58, %.lr.ph42.preheader ], [ %45, %49 ]
  %indvars.iv51 = phi i64 [ 1, %.lr.ph42.preheader ], [ %indvars.iv.next52, %49 ]
  %43 = phi i32 [ %12, %.lr.ph42.preheader ], [ %50, %49 ]
  %44 = getelementptr inbounds [1048576 x %struct.Node], ptr @num, i64 0, i64 %indvars.iv51
  %45 = load i32, ptr %44, align 8, !tbaa !13
  %46 = icmp eq i32 %42, %45
  br i1 %46, label %49, label %47

47:                                               ; preds = %.lr.ph42
  %48 = add nsw i32 %43, 1
  store i32 %48, ptr @tot, align 4, !tbaa !5
  br label %49

49:                                               ; preds = %.lr.ph42, %47
  %50 = phi i32 [ %48, %47 ], [ %43, %.lr.ph42 ]
  %51 = getelementptr inbounds i8, ptr %44, i64 4
  %52 = load i32, ptr %51, align 4, !tbaa !11
  %53 = ashr i32 %52, 1
  %54 = sext i32 %53 to i64
  %55 = and i32 %52, 1
  %56 = zext nneg i32 %55 to i64
  %57 = getelementptr inbounds [524288 x [3 x i32]], ptr @q, i64 0, i64 %54, i64 %56
  store i32 %50, ptr %57, align 4, !tbaa !5
  %indvars.iv.next52 = add nuw nsw i64 %indvars.iv51, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next52, %wide.trip.count
  br i1 %exitcond.not, label %.preheader, label %.lr.ph42, !llvm.loop !15

.lr.ph44:                                         ; preds = %.preheader, %73
  %indvars.iv54 = phi i64 [ %indvars.iv.next55, %73 ], [ 0, %.preheader ]
  %58 = getelementptr inbounds [524288 x [3 x i32]], ptr @q, i64 0, i64 %indvars.iv54
  %59 = getelementptr inbounds i8, ptr %58, i64 8
  %60 = load i32, ptr %59, align 4, !tbaa !5
  %61 = icmp eq i32 %60, 1
  %62 = load i32, ptr @tot, align 4, !tbaa !5
  %63 = load i32, ptr %58, align 4, !tbaa !5
  br i1 %61, label %64, label %67

64:                                               ; preds = %.lr.ph44
  %65 = getelementptr inbounds i8, ptr %58, i64 4
  %66 = load i32, ptr %65, align 4, !tbaa !5
  tail call void @_Z6updateiiiiii(i32 noundef 1, i32 noundef 1, i32 noundef %62, i32 noundef %63, i32 noundef %66, i32 noundef %66)
  br label %73

67:                                               ; preds = %.lr.ph44
  %68 = tail call noundef i32 @_Z5queryiiii(i32 noundef 1, i32 noundef 1, i32 noundef %62, i32 noundef %63)
  %69 = getelementptr inbounds i8, ptr %58, i64 4
  %70 = load i32, ptr %69, align 4, !tbaa !5
  %.not38 = icmp slt i32 %68, %70
  %71 = select i1 %.not38, ptr @.str.3, ptr @.str.2
  %72 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) %71)
  br label %73

73:                                               ; preds = %64, %67
  %indvars.iv.next55 = add nuw nsw i64 %indvars.iv54, 1
  %74 = load i32, ptr @n, align 4, !tbaa !5
  %75 = sext i32 %74 to i64
  %76 = icmp slt i64 %indvars.iv.next55, %75
  br i1 %76, label %.lr.ph44, label %.loopexit, !llvm.loop !16

._crit_edge48:                                    ; preds = %.loopexit, %0
  ret i32 0
}

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) 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 nounwind uwtable
declare dso_local void @_ZSt4swapIiENSt9enable_ifIXsr6__and_ISt6__not_ISt15__is_tuple_likeIT_EESt21is_move_constructibleIS3_ESt18is_move_assignableIS3_EEE5valueEvE4typeERS3_SC_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) 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: nofree nounwind
declare noundef i32 @puts(ptr nocapture noundef readonly) local_unnamed_addr #2

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

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 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 #2 = { 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 #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { 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 #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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 4}
!12 = !{!"_ZTS4Node", !6, i64 0, !6, i64 4}
!13 = !{!12, !6, i64 0}
!14 = distinct !{!14, !10}
!15 = distinct !{!15, !10}
!16 = distinct !{!16, !10}


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