; LLVM IR from tangjz/acm-icpc :: luogu (1270)

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

@limit_time = external dso_local global i32, align 4
@f = external dso_local global [101 x [121 x i32]], align 16
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z9make_treev() #0

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

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

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

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #3 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  %3 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @limit_time)
  call void @llvm.memset.p0.i64(ptr align 16 @f, i8 15, i64 48884, i1 false)
  call void @_Z9make_treev()
  call void @_Z2dpi(i32 noundef 1)
  store i32 120, ptr %2, align 4, !tbaa !5
  br label %4

4:                                                ; preds = %16, %0
  %5 = load i32, ptr %2, align 4, !tbaa !5
  %6 = icmp ne i32 %5, 0
  br i1 %6, label %7, label %19

7:                                                ; preds = %4
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [121 x i32], ptr getelementptr inbounds ([101 x [121 x i32]], ptr @f, i64 0, i64 1), i64 0, i64 %9
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = load i32, ptr @limit_time, align 4, !tbaa !5
  %13 = icmp slt i32 %11, %12
  br i1 %13, label %14, label %15

14:                                               ; preds = %7
  br label %19

15:                                               ; preds = %7
  br label %16

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

19:                                               ; preds = %14, %4
  %20 = load i32, ptr %2, align 4, !tbaa !5
  %21 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %20)
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  ret i32 0
}

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

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

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 = { "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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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"}


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

@limit_time = external dso_local global i32, align 4
@f = external dso_local local_unnamed_addr global [101 x [121 x i32]], align 16
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z9make_treev() local_unnamed_addr #0

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

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #2 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @limit_time)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(48884) @f, i8 15, i64 48884, i1 false)
  tail call void @_Z9make_treev()
  tail call void @_Z2dpi(i32 noundef 1)
  %2 = load i32, ptr @limit_time, align 4, !tbaa !5
  br label %3

3:                                                ; preds = %27, %0
  %indvars.iv = phi i64 [ 120, %0 ], [ %indvars.iv.next.5, %27 ]
  %4 = getelementptr inbounds [121 x i32], ptr getelementptr inbounds (i8, ptr @f, i64 484), i64 0, i64 %indvars.iv
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = icmp slt i32 %5, %2
  br i1 %6, label %.split.loop.exit, label %7

7:                                                ; preds = %3
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %8 = getelementptr inbounds [121 x i32], ptr getelementptr inbounds (i8, ptr @f, i64 484), i64 0, i64 %indvars.iv.next
  %9 = load i32, ptr %8, align 8, !tbaa !5
  %10 = icmp slt i32 %9, %2
  br i1 %10, label %.split.loop.exit, label %11

11:                                               ; preds = %7
  %indvars.iv.next.1 = add nsw i64 %indvars.iv, -2
  %12 = getelementptr inbounds [121 x i32], ptr getelementptr inbounds (i8, ptr @f, i64 484), i64 0, i64 %indvars.iv.next.1
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = icmp slt i32 %13, %2
  br i1 %14, label %.split.loop.exit, label %15

15:                                               ; preds = %11
  %indvars.iv.next.2 = add nsw i64 %indvars.iv, -3
  %16 = getelementptr inbounds [121 x i32], ptr getelementptr inbounds (i8, ptr @f, i64 484), i64 0, i64 %indvars.iv.next.2
  %17 = load i32, ptr %16, align 8, !tbaa !5
  %18 = icmp slt i32 %17, %2
  br i1 %18, label %.split.loop.exit, label %19

19:                                               ; preds = %15
  %indvars.iv.next.3 = add nsw i64 %indvars.iv, -4
  %20 = getelementptr inbounds [121 x i32], ptr getelementptr inbounds (i8, ptr @f, i64 484), i64 0, i64 %indvars.iv.next.3
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = icmp slt i32 %21, %2
  br i1 %22, label %.split.loop.exit, label %23

23:                                               ; preds = %19
  %indvars.iv.next.4 = add nsw i64 %indvars.iv, -5
  %24 = getelementptr inbounds [121 x i32], ptr getelementptr inbounds (i8, ptr @f, i64 484), i64 0, i64 %indvars.iv.next.4
  %25 = load i32, ptr %24, align 8, !tbaa !5
  %26 = icmp slt i32 %25, %2
  br i1 %26, label %.split.loop.exit, label %27

27:                                               ; preds = %23
  %indvars.iv.next.5 = add nsw i64 %indvars.iv, -6
  %.not.5 = icmp eq i64 %indvars.iv.next.5, 0
  br i1 %.not.5, label %.split.loop.exit6, label %3, !llvm.loop !9

.split.loop.exit:                                 ; preds = %23, %19, %15, %11, %7, %3
  %indvars.iv.lcssa = phi i64 [ %indvars.iv, %3 ], [ %indvars.iv.next, %7 ], [ %indvars.iv.next.1, %11 ], [ %indvars.iv.next.2, %15 ], [ %indvars.iv.next.3, %19 ], [ %indvars.iv.next.4, %23 ]
  %28 = trunc nuw nsw i64 %indvars.iv.lcssa to i32
  br label %.split.loop.exit6

.split.loop.exit6:                                ; preds = %27, %.split.loop.exit
  %.0.lcssa = phi i32 [ %28, %.split.loop.exit ], [ 0, %27 ]
  %29 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %.0.lcssa)
  ret i32 0
}

; 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: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

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 = { 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 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }

!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"}


; Effective O3 passes: GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass