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

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

@n = external dso_local global i32, align 4
@a = external dso_local global [10001 x [4 x i32]], align 16
@x = external dso_local global i32, align 4
@y = external dso_local global i32, align 4
@i = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %2 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  store i32 1, ptr @i, align 4, !tbaa !5
  br label %3

3:                                                ; preds = %47, %0
  %4 = load i32, ptr @i, align 4, !tbaa !5
  %5 = load i32, ptr @n, align 4, !tbaa !5
  %6 = icmp sle i32 %4, %5
  br i1 %6, label %7, label %50

7:                                                ; preds = %3
  %8 = load i32, ptr @i, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [10001 x [4 x i32]], ptr @a, i64 0, i64 %9
  %11 = getelementptr inbounds [4 x i32], ptr %10, i64 0, i64 0
  %12 = load i32, ptr @i, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [10001 x [4 x i32]], ptr @a, i64 0, i64 %13
  %15 = getelementptr inbounds [4 x i32], ptr %14, i64 0, i64 1
  %16 = load i32, ptr @i, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [10001 x [4 x i32]], ptr @a, i64 0, i64 %17
  %19 = getelementptr inbounds [4 x i32], ptr %18, i64 0, i64 2
  %20 = load i32, ptr @i, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [10001 x [4 x i32]], ptr @a, i64 0, i64 %21
  %23 = getelementptr inbounds [4 x i32], ptr %22, i64 0, i64 3
  %24 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %11, ptr noundef %15, ptr noundef %19, ptr noundef %23)
  %25 = load i32, ptr @i, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [10001 x [4 x i32]], ptr @a, i64 0, i64 %26
  %28 = getelementptr inbounds [4 x i32], ptr %27, i64 0, i64 0
  %29 = load i32, ptr %28, align 16, !tbaa !5
  %30 = load i32, ptr @i, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [10001 x [4 x i32]], ptr @a, i64 0, i64 %31
  %33 = getelementptr inbounds [4 x i32], ptr %32, i64 0, i64 2
  %34 = load i32, ptr %33, align 8, !tbaa !5
  %35 = add nsw i32 %34, %29
  store i32 %35, ptr %33, align 8, !tbaa !5
  %36 = load i32, ptr @i, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [10001 x [4 x i32]], ptr @a, i64 0, i64 %37
  %39 = getelementptr inbounds [4 x i32], ptr %38, i64 0, i64 1
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %41 = load i32, ptr @i, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [10001 x [4 x i32]], ptr @a, i64 0, i64 %42
  %44 = getelementptr inbounds [4 x i32], ptr %43, i64 0, i64 3
  %45 = load i32, ptr %44, align 4, !tbaa !5
  %46 = add nsw i32 %45, %40
  store i32 %46, ptr %44, align 4, !tbaa !5
  br label %47

47:                                               ; preds = %7
  %48 = load i32, ptr @i, align 4, !tbaa !5
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr @i, align 4, !tbaa !5
  br label %3, !llvm.loop !9

50:                                               ; preds = %3
  %51 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.2, ptr noundef @x, ptr noundef @y)
  %52 = load i32, ptr @n, align 4, !tbaa !5
  store i32 %52, ptr @i, align 4, !tbaa !5
  br label %53

53:                                               ; preds = %90, %50
  %54 = load i32, ptr @i, align 4, !tbaa !5
  %55 = icmp ne i32 %54, 0
  br i1 %55, label %56, label %93

56:                                               ; preds = %53
  %57 = load i32, ptr @i, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [10001 x [4 x i32]], ptr @a, i64 0, i64 %58
  %60 = getelementptr inbounds [4 x i32], ptr %59, i64 0, i64 0
  %61 = load i32, ptr %60, align 16, !tbaa !5
  %62 = load i32, ptr @x, align 4, !tbaa !5
  %63 = icmp sle i32 %61, %62
  br i1 %63, label %64, label %89

64:                                               ; preds = %56
  %65 = load i32, ptr @x, align 4, !tbaa !5
  %66 = load i32, ptr @i, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [10001 x [4 x i32]], ptr @a, i64 0, i64 %67
  %69 = getelementptr inbounds [4 x i32], ptr %68, i64 0, i64 2
  %70 = load i32, ptr %69, align 8, !tbaa !5
  %71 = icmp sle i32 %65, %70
  br i1 %71, label %72, label %89

72:                                               ; preds = %64
  %73 = load i32, ptr @i, align 4, !tbaa !5
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [10001 x [4 x i32]], ptr @a, i64 0, i64 %74
  %76 = getelementptr inbounds [4 x i32], ptr %75, i64 0, i64 1
  %77 = load i32, ptr %76, align 4, !tbaa !5
  %78 = load i32, ptr @y, align 4, !tbaa !5
  %79 = icmp sle i32 %77, %78
  br i1 %79, label %80, label %89

80:                                               ; preds = %72
  %81 = load i32, ptr @y, align 4, !tbaa !5
  %82 = load i32, ptr @i, align 4, !tbaa !5
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds [10001 x [4 x i32]], ptr @a, i64 0, i64 %83
  %85 = getelementptr inbounds [4 x i32], ptr %84, i64 0, i64 3
  %86 = load i32, ptr %85, align 4, !tbaa !5
  %87 = icmp sle i32 %81, %86
  br i1 %87, label %88, label %89

88:                                               ; preds = %80
  br label %93

89:                                               ; preds = %80, %72, %64, %56
  br label %90

90:                                               ; preds = %89
  %91 = load i32, ptr @i, align 4, !tbaa !5
  %92 = add nsw i32 %91, -1
  store i32 %92, ptr @i, align 4, !tbaa !5
  br label %53, !llvm.loop !11

93:                                               ; preds = %88, %53
  %94 = load i32, ptr @i, align 4, !tbaa !5
  %95 = icmp ne i32 %94, 0
  br i1 %95, label %96, label %98

96:                                               ; preds = %93
  %97 = load i32, ptr @i, align 4, !tbaa !5
  br label %99

98:                                               ; preds = %93
  br label %99

99:                                               ; preds = %98, %96
  %100 = phi i32 [ %97, %96 ], [ -1, %98 ]
  %101 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i32 noundef %100)
  ret i32 0
}

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

declare i32 @printf(ptr noundef, ...) #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 = { "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}


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

@n = external dso_local global i32, align 4
@a = external dso_local global [10001 x [4 x i32]], align 16
@x = external dso_local global i32, align 4
@y = external dso_local global i32, align 4
@i = external dso_local local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind 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 @n)
  store i32 1, ptr @i, align 4, !tbaa !5
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %.not11 = icmp slt i32 %2, 1
  br i1 %.not11, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %0, %.lr.ph
  %storemerge12 = phi i32 [ %16, %.lr.ph ], [ 1, %0 ]
  %3 = sext i32 %storemerge12 to i64
  %4 = getelementptr inbounds [10001 x [4 x i32]], ptr @a, i64 0, i64 %3
  %5 = getelementptr inbounds i8, ptr %4, i64 4
  %6 = getelementptr inbounds i8, ptr %4, i64 8
  %7 = getelementptr inbounds i8, ptr %4, i64 12
  %8 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %4, ptr noundef nonnull %5, ptr noundef nonnull %6, ptr noundef nonnull %7)
  %9 = load i32, ptr @i, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [10001 x [4 x i32]], ptr @a, i64 0, i64 %10
  %12 = getelementptr inbounds i8, ptr %11, i64 8
  %13 = load <2 x i32>, ptr %11, align 16, !tbaa !5
  %14 = load <2 x i32>, ptr %12, align 8, !tbaa !5
  %15 = add nsw <2 x i32> %14, %13
  store <2 x i32> %15, ptr %12, align 8, !tbaa !5
  %16 = add nsw i32 %9, 1
  store i32 %16, ptr @i, align 4, !tbaa !5
  %17 = load i32, ptr @n, align 4, !tbaa !5
  %.not.not = icmp slt i32 %9, %17
  br i1 %.not.not, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %0
  %18 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.2, ptr noundef nonnull @x, ptr noundef nonnull @y)
  %19 = load i32, ptr @n, align 4, !tbaa !5
  %.not513 = icmp eq i32 %19, 0
  br i1 %.not513, label %._crit_edge17, label %.lr.ph16

.lr.ph16:                                         ; preds = %._crit_edge
  %20 = load i32, ptr @x, align 4, !tbaa !5
  %21 = load i32, ptr @y, align 4
  %22 = sext i32 %19 to i64
  br label %23

23:                                               ; preds = %.lr.ph16, %35
  %indvars.iv = phi i64 [ %22, %.lr.ph16 ], [ %indvars.iv.next, %35 ]
  %24 = getelementptr inbounds [10001 x [4 x i32]], ptr @a, i64 0, i64 %indvars.iv
  %25 = load i32, ptr %24, align 16, !tbaa !5
  %.not6 = icmp sgt i32 %25, %20
  br i1 %.not6, label %35, label %26

26:                                               ; preds = %23
  %27 = getelementptr inbounds i8, ptr %24, i64 8
  %28 = load i32, ptr %27, align 8, !tbaa !5
  %.not7 = icmp sgt i32 %20, %28
  br i1 %.not7, label %35, label %29

29:                                               ; preds = %26
  %30 = getelementptr inbounds i8, ptr %24, i64 4
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %.not8 = icmp sgt i32 %31, %21
  br i1 %.not8, label %35, label %32

32:                                               ; preds = %29
  %33 = getelementptr inbounds i8, ptr %24, i64 12
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %.not9 = icmp sgt i32 %21, %34
  br i1 %.not9, label %35, label %._crit_edge17.loopexit.split.loop.exit

35:                                               ; preds = %23, %26, %29, %32
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %.not5 = icmp eq i64 %indvars.iv.next, 0
  br i1 %.not5, label %._crit_edge17, label %23, !llvm.loop !11

._crit_edge17.loopexit.split.loop.exit:           ; preds = %32
  %36 = trunc nsw i64 %indvars.iv to i32
  br label %._crit_edge17

._crit_edge17:                                    ; preds = %35, %._crit_edge17.loopexit.split.loop.exit, %._crit_edge
  %storemerge4.lcssa = phi i32 [ 0, %._crit_edge ], [ %36, %._crit_edge17.loopexit.split.loop.exit ], [ 0, %35 ]
  %37 = phi i32 [ -1, %._crit_edge ], [ %36, %._crit_edge17.loopexit.split.loop.exit ], [ -1, %35 ]
  store i32 %storemerge4.lcssa, ptr @i, align 4, !tbaa !5
  %38 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %37)
  ret i32 0
}

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

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

attributes #0 = { mustprogress nofree norecurse 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 #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" }

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


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