; LLVM IR from lzyrapx/Competitive-Programming :: HDUOJ (1491)

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

@a = external dso_local global [12 x i32], align 16
@i = external dso_local global i32, align 4
@k = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@x = external dso_local global i32, align 4
@y = 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 [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.4 = 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 @k)
  br label %3

3:                                                ; preds = %44, %0
  %4 = load i32, ptr @k, align 4, !tbaa !5
  %5 = add nsw i32 %4, -1
  store i32 %5, ptr @k, align 4, !tbaa !5
  %6 = icmp ne i32 %4, 0
  br i1 %6, label %7, label %45

7:                                                ; preds = %3
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @x, ptr noundef @y)
  store i32 0, ptr @m, align 4, !tbaa !5
  store i32 0, ptr @i, align 4, !tbaa !5
  br label %9

9:                                                ; preds = %21, %7
  %10 = load i32, ptr @i, align 4, !tbaa !5
  %11 = load i32, ptr @x, align 4, !tbaa !5
  %12 = sub nsw i32 %11, 1
  %13 = icmp slt i32 %10, %12
  br i1 %13, label %14, label %24

14:                                               ; preds = %9
  %15 = load i32, ptr @i, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [12 x i32], ptr @a, i64 0, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %19 = load i32, ptr @m, align 4, !tbaa !5
  %20 = add nsw i32 %19, %18
  store i32 %20, ptr @m, align 4, !tbaa !5
  br label %21

21:                                               ; preds = %14
  %22 = load i32, ptr @i, align 4, !tbaa !5
  %23 = add nsw i32 %22, 1
  store i32 %23, ptr @i, align 4, !tbaa !5
  br label %9, !llvm.loop !9

24:                                               ; preds = %9
  %25 = load i32, ptr @y, align 4, !tbaa !5
  %26 = load i32, ptr @m, align 4, !tbaa !5
  %27 = add nsw i32 %26, %25
  store i32 %27, ptr @m, align 4, !tbaa !5
  %28 = load i32, ptr @m, align 4, !tbaa !5
  %29 = icmp eq i32 %28, 294
  br i1 %29, label %30, label %32

30:                                               ; preds = %24
  %31 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  br label %32

32:                                               ; preds = %30, %24
  %33 = load i32, ptr @m, align 4, !tbaa !5
  %34 = icmp sgt i32 %33, 294
  br i1 %34, label %35, label %37

35:                                               ; preds = %32
  %36 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  br label %37

37:                                               ; preds = %35, %32
  %38 = load i32, ptr @m, align 4, !tbaa !5
  %39 = icmp slt i32 %38, 294
  br i1 %39, label %40, label %44

40:                                               ; preds = %37
  %41 = load i32, ptr @m, align 4, !tbaa !5
  %42 = sub nsw i32 294, %41
  %43 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, i32 noundef %42)
  br label %44

44:                                               ; preds = %40, %37
  br label %3, !llvm.loop !11

45:                                               ; preds = %3
  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"

@a = external dso_local local_unnamed_addr global [12 x i32], align 16
@i = external dso_local local_unnamed_addr global i32, align 4
@k = external dso_local global i32, align 4
@m = external dso_local local_unnamed_addr global i32, align 4
@x = external dso_local global i32, align 4
@y = 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 [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.4 = 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 @k)
  %2 = load i32, ptr @k, align 4, !tbaa !5
  %3 = add nsw i32 %2, -1
  store i32 %3, ptr @k, align 4, !tbaa !5
  %.not3 = icmp eq i32 %2, 0
  br i1 %.not3, label %._crit_edge6, label %.lr.ph5

.lr.ph5:                                          ; preds = %0, %37
  %4 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @x, ptr noundef nonnull @y)
  %5 = load i32, ptr @x, align 4, !tbaa !5
  %6 = icmp sgt i32 %5, 1
  br i1 %6, label %.lr.ph.preheader, label %19

.lr.ph.preheader:                                 ; preds = %.lr.ph5
  %7 = add nsw i32 %5, -1
  %wide.trip.count = zext nneg i32 %7 to i64
  %min.iters.check = icmp ult i32 %5, 9
  br i1 %min.iters.check, label %.lr.ph.preheader11, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph.preheader
  %n.vec = and i64 %wide.trip.count, 2147483640
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.phi = phi <4 x i32> [ zeroinitializer, %vector.ph ], [ %10, %vector.body ]
  %vec.phi9 = phi <4 x i32> [ zeroinitializer, %vector.ph ], [ %11, %vector.body ]
  %8 = getelementptr inbounds [12 x i32], ptr @a, i64 0, i64 %index
  %9 = getelementptr inbounds i8, ptr %8, i64 16
  %wide.load = load <4 x i32>, ptr %8, align 16, !tbaa !5
  %wide.load10 = load <4 x i32>, ptr %9, align 16, !tbaa !5
  %10 = add <4 x i32> %vec.phi, %wide.load
  %11 = add <4 x i32> %vec.phi9, %wide.load10
  %index.next = add nuw i64 %index, 8
  %12 = icmp eq i64 %index.next, %n.vec
  br i1 %12, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %bin.rdx = add <4 x i32> %11, %10
  %13 = tail call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %bin.rdx)
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  br i1 %cmp.n, label %._crit_edge, label %.lr.ph.preheader11

.lr.ph.preheader11:                               ; preds = %middle.block, %.lr.ph.preheader
  %indvars.iv.ph = phi i64 [ 0, %.lr.ph.preheader ], [ %n.vec, %middle.block ]
  %.ph = phi i32 [ 0, %.lr.ph.preheader ], [ %13, %middle.block ]
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader11, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ %indvars.iv.ph, %.lr.ph.preheader11 ]
  %14 = phi i32 [ %17, %.lr.ph ], [ %.ph, %.lr.ph.preheader11 ]
  %15 = getelementptr inbounds [12 x i32], ptr @a, i64 0, i64 %indvars.iv
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %17 = add nsw i32 %14, %16
  %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, label %.lr.ph, !llvm.loop !13

._crit_edge:                                      ; preds = %.lr.ph, %middle.block
  %.lcssa = phi i32 [ %13, %middle.block ], [ %17, %.lr.ph ]
  %18 = add nsw i32 %5, -1
  br label %19

19:                                               ; preds = %._crit_edge, %.lr.ph5
  %20 = phi i32 [ %.lcssa, %._crit_edge ], [ 0, %.lr.ph5 ]
  %storemerge.lcssa = phi i32 [ %18, %._crit_edge ], [ 0, %.lr.ph5 ]
  store i32 %storemerge.lcssa, ptr @i, align 4, !tbaa !5
  %21 = load i32, ptr @y, align 4, !tbaa !5
  %22 = add nsw i32 %20, %21
  store i32 %22, ptr @m, align 4, !tbaa !5
  %23 = icmp eq i32 %22, 294
  br i1 %23, label %24, label %26

24:                                               ; preds = %19
  %25 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  %.pr = load i32, ptr @m, align 4, !tbaa !5
  br label %26

26:                                               ; preds = %24, %19
  %27 = phi i32 [ %.pr, %24 ], [ %22, %19 ]
  %28 = icmp sgt i32 %27, 294
  br i1 %28, label %29, label %31

29:                                               ; preds = %26
  %30 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  %.pre = load i32, ptr @m, align 4, !tbaa !5
  br label %31

31:                                               ; preds = %29, %26
  %32 = phi i32 [ %.pre, %29 ], [ %27, %26 ]
  %33 = icmp slt i32 %32, 294
  br i1 %33, label %34, label %37

34:                                               ; preds = %31
  %35 = sub nsw i32 294, %32
  %36 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, i32 noundef %35)
  br label %37

37:                                               ; preds = %34, %31
  %38 = load i32, ptr @k, align 4, !tbaa !5
  %39 = add nsw i32 %38, -1
  store i32 %39, ptr @k, align 4, !tbaa !5
  %.not = icmp eq i32 %38, 0
  br i1 %.not, label %._crit_edge6, label %.lr.ph5, !llvm.loop !14

._crit_edge6:                                     ; preds = %37, %0
  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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.vector.reduce.add.v4i32(<4 x i32>) #2

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" }
attributes #2 = { 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 = distinct !{!9, !10, !11, !12}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = distinct !{!13, !10, !12, !11}
!14 = distinct !{!14, !10}


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