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

; 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, [200001 x i32], i32, [200001 x i32], [200001 x i32] }
%struct.Query = type { [2 x i8], i32, i64 }

@row = external dso_local global i32, align 4
@col = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@rs = external dso_local global %struct.Node, align 4
@cs = external dso_local global %struct.Node, align 4
@que = external dso_local global [200001 x %struct.Query], 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

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

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

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

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

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

13:                                               ; preds = %8
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [200001 x %struct.Query], ptr @que, i64 0, i64 %15
  call void @_ZN5Query5parseEv(ptr noundef nonnull align 8 dereferenceable(16) %16)
  br label %17

17:                                               ; preds = %13
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = add nsw i32 %18, 1
  store i32 %19, ptr %2, align 4, !tbaa !5
  br label %8, !llvm.loop !9

20:                                               ; preds = %12
  call void @_ZN4Node9constructEv(ptr noundef nonnull align 4 dereferenceable(2400020) @rs)
  call void @_ZN4Node9constructEv(ptr noundef nonnull align 4 dereferenceable(2400020) @cs)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  %21 = load i32, ptr @n, align 4, !tbaa !5
  %22 = sub nsw i32 %21, 1
  store i32 %22, ptr %3, align 4, !tbaa !5
  br label %23

23:                                               ; preds = %31, %20
  %24 = load i32, ptr %3, align 4, !tbaa !5
  %25 = icmp sge i32 %24, 0
  br i1 %25, label %27, label %26

26:                                               ; preds = %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  br label %34

27:                                               ; preds = %23
  %28 = load i32, ptr %3, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [200001 x %struct.Query], ptr @que, i64 0, i64 %29
  call void @_ZN5Query5queryEv(ptr noundef nonnull align 8 dereferenceable(16) %30)
  br label %31

31:                                               ; preds = %27
  %32 = load i32, ptr %3, align 4, !tbaa !5
  %33 = add nsw i32 %32, -1
  store i32 %33, ptr %3, align 4, !tbaa !5
  br label %23, !llvm.loop !11

34:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %35

35:                                               ; preds = %47, %34
  %36 = load i32, ptr %4, align 4, !tbaa !5
  %37 = load i32, ptr @n, align 4, !tbaa !5
  %38 = icmp slt i32 %36, %37
  br i1 %38, label %40, label %39

39:                                               ; preds = %35
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  br label %50

40:                                               ; preds = %35
  %41 = load i32, ptr %4, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [200001 x %struct.Query], ptr @que, i64 0, i64 %42
  %44 = getelementptr inbounds %struct.Query, ptr %43, i32 0, i32 2
  %45 = load i64, ptr %44, align 8, !tbaa !12
  %46 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %45)
  br label %47

47:                                               ; preds = %40
  %48 = load i32, ptr %4, align 4, !tbaa !5
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %4, align 4, !tbaa !5
  br label %35, !llvm.loop !15

50:                                               ; preds = %39
  ret i32 0
}

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

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

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

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

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

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { mustprogress nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #4 = { mustprogress 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 = { 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 = distinct !{!11, !10}
!12 = !{!13, !14, i64 8}
!13 = !{!"_ZTS5Query", !7, i64 0, !6, i64 4, !14, i64 8}
!14 = !{!"long long", !7, i64 0}
!15 = distinct !{!15, !10}


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

%struct.Node = type { i32, [200001 x i32], i32, [200001 x i32], [200001 x i32] }
%struct.Query = type { [2 x i8], i32, i64 }

@row = external dso_local global i32, align 4
@col = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@rs = external dso_local global %struct.Node, align 4
@cs = external dso_local global %struct.Node, align 4
@que = external dso_local global [200001 x %struct.Query], 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

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

._crit_edge:                                      ; preds = %.lr.ph, %0
  tail call void @_ZN4Node9constructEv(ptr noundef nonnull align 4 dereferenceable(2400020) @rs)
  tail call void @_ZN4Node9constructEv(ptr noundef nonnull align 4 dereferenceable(2400020) @cs)
  %6 = load i32, ptr @n, align 4, !tbaa !5
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %.lr.ph14.preheader, label %._crit_edge17

.lr.ph14.preheader:                               ; preds = %._crit_edge
  %8 = zext nneg i32 %6 to i64
  br label %.lr.ph14

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %0 ]
  %9 = getelementptr inbounds [200001 x %struct.Query], ptr @que, i64 0, i64 %indvars.iv
  tail call void @_ZN5Query5parseEv(ptr noundef nonnull align 8 dereferenceable(16) %9)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %10 = load i32, ptr @n, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = icmp slt i64 %indvars.iv.next, %11
  br i1 %12, label %.lr.ph, label %._crit_edge, !llvm.loop !9

.preheader:                                       ; preds = %.lr.ph14
  %.pre = load i32, ptr @n, align 4, !tbaa !5
  %13 = icmp sgt i32 %.pre, 0
  br i1 %13, label %.lr.ph16, label %._crit_edge17

.lr.ph14:                                         ; preds = %.lr.ph14.preheader, %.lr.ph14
  %indvars.iv19 = phi i64 [ %8, %.lr.ph14.preheader ], [ %indvars.iv.next20, %.lr.ph14 ]
  %indvars.iv.next20 = add nsw i64 %indvars.iv19, -1
  %14 = getelementptr inbounds [200001 x %struct.Query], ptr @que, i64 0, i64 %indvars.iv.next20
  tail call void @_ZN5Query5queryEv(ptr noundef nonnull align 8 dereferenceable(16) %14)
  %15 = icmp ugt i64 %indvars.iv19, 1
  br i1 %15, label %.lr.ph14, label %.preheader, !llvm.loop !11

._crit_edge17:                                    ; preds = %.lr.ph16, %._crit_edge, %.preheader
  ret i32 0

.lr.ph16:                                         ; preds = %.preheader, %.lr.ph16
  %indvars.iv22 = phi i64 [ %indvars.iv.next23, %.lr.ph16 ], [ 0, %.preheader ]
  %16 = getelementptr inbounds [200001 x %struct.Query], ptr @que, i64 0, i64 %indvars.iv22, i32 2
  %17 = load i64, ptr %16, align 8, !tbaa !12
  %18 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %17)
  %indvars.iv.next23 = add nuw nsw i64 %indvars.iv22, 1
  %19 = load i32, ptr @n, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = icmp slt i64 %indvars.iv.next23, %20
  br i1 %21, label %.lr.ph16, label %._crit_edge17, !llvm.loop !15
}

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN5Query5parseEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4Node9constructEv(ptr noundef nonnull align 4 dereferenceable(2400020)) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN5Query5queryEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #3 align 2

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

attributes #0 = { 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 #1 = { 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 #2 = { mustprogress nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { mustprogress uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }

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

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


; Effective O3 passes: CorrelatedValuePropagationPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass