; LLVM IR from tangjz/acm-icpc :: lydsy (1662)

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

@sta = external dso_local global i32, align 4
@end = external dso_local global i32, align 4
@c = external dso_local global [32 x [32 x i32]], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z3cnti(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 norecurse uwtable
define dso_local noundef i32 @main() #2 {
  %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
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %5

5:                                                ; preds = %54, %0
  %6 = load i32, ptr %2, align 4, !tbaa !5
  %7 = icmp slt i32 %6, 32
  br i1 %7, label %9, label %8

8:                                                ; preds = %5
  store i32 2, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %57

9:                                                ; preds = %5
  %10 = load i32, ptr %2, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [32 x [32 x i32]], ptr @c, i64 0, i64 %11
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [32 x i32], ptr %12, i64 0, i64 %14
  store i32 1, ptr %15, align 4, !tbaa !5
  %16 = load i32, ptr %2, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [32 x [32 x i32]], ptr @c, i64 0, i64 %17
  %19 = getelementptr inbounds [32 x i32], ptr %18, i64 0, i64 0
  store i32 1, ptr %19, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 1, ptr %4, align 4, !tbaa !5
  br label %20

20:                                               ; preds = %50, %9
  %21 = load i32, ptr %4, align 4, !tbaa !5
  %22 = load i32, ptr %2, align 4, !tbaa !5
  %23 = icmp slt i32 %21, %22
  br i1 %23, label %25, label %24

24:                                               ; preds = %20
  store i32 5, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %53

25:                                               ; preds = %20
  %26 = load i32, ptr %2, align 4, !tbaa !5
  %27 = sub nsw i32 %26, 1
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [32 x [32 x i32]], ptr @c, i64 0, i64 %28
  %30 = load i32, ptr %4, align 4, !tbaa !5
  %31 = sub nsw i32 %30, 1
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [32 x i32], ptr %29, i64 0, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = load i32, ptr %2, align 4, !tbaa !5
  %36 = sub nsw i32 %35, 1
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [32 x [32 x i32]], ptr @c, i64 0, i64 %37
  %39 = load i32, ptr %4, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [32 x i32], ptr %38, i64 0, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = add nsw i32 %34, %42
  %44 = load i32, ptr %2, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [32 x [32 x i32]], ptr @c, i64 0, i64 %45
  %47 = load i32, ptr %4, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [32 x i32], ptr %46, i64 0, i64 %48
  store i32 %43, ptr %49, align 4, !tbaa !5
  br label %50

50:                                               ; preds = %25
  %51 = load i32, ptr %4, align 4, !tbaa !5
  %52 = add nsw i32 %51, 1
  store i32 %52, ptr %4, align 4, !tbaa !5
  br label %20, !llvm.loop !9

53:                                               ; preds = %24
  br label %54

54:                                               ; preds = %53
  %55 = load i32, ptr %2, align 4, !tbaa !5
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr %2, align 4, !tbaa !5
  br label %5, !llvm.loop !11

57:                                               ; preds = %8
  br label %58

58:                                               ; preds = %61, %57
  %59 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @sta, ptr noundef @end)
  %60 = icmp eq i32 %59, 2
  br i1 %60, label %61, label %69

61:                                               ; preds = %58
  %62 = load i32, ptr @end, align 4, !tbaa !5
  %63 = add nsw i32 %62, 1
  %64 = call noundef i32 @_Z3cnti(i32 noundef %63)
  %65 = load i32, ptr @sta, align 4, !tbaa !5
  %66 = call noundef i32 @_Z3cnti(i32 noundef %65)
  %67 = sub nsw i32 %64, %66
  %68 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %67)
  br label %58, !llvm.loop !12

69:                                               ; preds = %58
  ret i32 0
}

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

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

attributes #0 = { 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 #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 = { 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 = distinct !{!12, !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"

@sta = external dso_local global i32, align 4
@end = external dso_local global i32, align 4
@c = external dso_local local_unnamed_addr global [32 x [32 x i32]], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

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

; Function Attrs: mustprogress norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  br label %3

.preheader:                                       ; preds = %._crit_edge
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @sta, ptr noundef nonnull @end)
  %2 = icmp eq i32 %1, 2
  br i1 %2, label %.lr.ph17, label %._crit_edge18

3:                                                ; preds = %0, %._crit_edge
  %indvars.iv20 = phi i64 [ 0, %0 ], [ %indvars.iv.next21, %._crit_edge ]
  %4 = add nsw i64 %indvars.iv20, -1
  %5 = getelementptr inbounds [32 x [32 x i32]], ptr @c, i64 0, i64 %indvars.iv20
  %6 = getelementptr inbounds [32 x [32 x i32]], ptr @c, i64 0, i64 %indvars.iv20, i64 %indvars.iv20
  store i32 1, ptr %6, align 4, !tbaa !5
  store i32 1, ptr %5, align 16, !tbaa !5
  %7 = icmp ugt i64 %indvars.iv20, 1
  br i1 %7, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %3
  %8 = add nsw i64 %indvars.iv20, -1
  %.phi.trans.insert = getelementptr inbounds [32 x [32 x i32]], ptr @c, i64 0, i64 %8, i64 0
  %.pre = load i32, ptr %.phi.trans.insert, align 16, !tbaa !5
  %min.iters.check = icmp ult i64 %indvars.iv20, 9
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

scalar.ph.preheader:                              ; preds = %middle.block, %.lr.ph
  %.ph = phi i32 [ %.pre, %.lr.ph ], [ %vector.recur.extract, %middle.block ]
  %indvars.iv.ph = phi i64 [ 1, %.lr.ph ], [ %ind.end, %middle.block ]
  br label %scalar.ph

vector.ph:                                        ; preds = %.lr.ph
  %n.vec = and i64 %4, -8
  %ind.end = or disjoint i64 %n.vec, 1
  %vector.recur.init = insertelement <4 x i32> poison, i32 %.pre, i64 3
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vector.recur = phi <4 x i32> [ %vector.recur.init, %vector.ph ], [ %wide.load24, %vector.body ]
  %offset.idx = or disjoint i64 %index, 1
  %9 = getelementptr inbounds [32 x [32 x i32]], ptr @c, i64 0, i64 %8, i64 %offset.idx
  %10 = getelementptr inbounds i8, ptr %9, i64 16
  %wide.load = load <4 x i32>, ptr %9, align 4, !tbaa !5
  %wide.load24 = load <4 x i32>, ptr %10, align 4, !tbaa !5
  %11 = shufflevector <4 x i32> %vector.recur, <4 x i32> %wide.load, <4 x i32> <i32 3, i32 4, i32 5, i32 6>
  %12 = shufflevector <4 x i32> %wide.load, <4 x i32> %wide.load24, <4 x i32> <i32 3, i32 4, i32 5, i32 6>
  %13 = add nsw <4 x i32> %wide.load, %11
  %14 = add nsw <4 x i32> %wide.load24, %12
  %15 = getelementptr inbounds [32 x [32 x i32]], ptr @c, i64 0, i64 %indvars.iv20, i64 %offset.idx
  %16 = getelementptr inbounds i8, ptr %15, i64 16
  store <4 x i32> %13, ptr %15, align 4, !tbaa !5
  store <4 x i32> %14, ptr %16, align 4, !tbaa !5
  %index.next = add nuw i64 %index, 8
  %17 = icmp eq i64 %index.next, %n.vec
  br i1 %17, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %vector.recur.extract = extractelement <4 x i32> %wide.load24, i64 3
  %cmp.n = icmp eq i64 %4, %n.vec
  br i1 %cmp.n, label %._crit_edge, label %scalar.ph.preheader

._crit_edge:                                      ; preds = %scalar.ph, %middle.block, %3
  %indvars.iv.next21 = add nuw nsw i64 %indvars.iv20, 1
  %exitcond23.not = icmp eq i64 %indvars.iv.next21, 32
  br i1 %exitcond23.not, label %.preheader, label %3, !llvm.loop !13

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %18 = phi i32 [ %20, %scalar.ph ], [ %.ph, %scalar.ph.preheader ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %scalar.ph ], [ %indvars.iv.ph, %scalar.ph.preheader ]
  %19 = getelementptr inbounds [32 x [32 x i32]], ptr @c, i64 0, i64 %8, i64 %indvars.iv
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %21 = add nsw i32 %20, %18
  %22 = getelementptr inbounds [32 x [32 x i32]], ptr @c, i64 0, i64 %indvars.iv20, i64 %indvars.iv
  store i32 %21, ptr %22, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %indvars.iv20
  br i1 %exitcond.not, label %._crit_edge, label %scalar.ph, !llvm.loop !14

.lr.ph17:                                         ; preds = %.preheader, %.lr.ph17
  %23 = load i32, ptr @end, align 4, !tbaa !5
  %24 = add nsw i32 %23, 1
  %25 = tail call noundef i32 @_Z3cnti(i32 noundef %24)
  %26 = load i32, ptr @sta, align 4, !tbaa !5
  %27 = tail call noundef i32 @_Z3cnti(i32 noundef %26)
  %28 = sub nsw i32 %25, %27
  %29 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %28)
  %30 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @sta, ptr noundef nonnull @end)
  %31 = icmp eq i32 %30, 2
  br i1 %31, label %.lr.ph17, label %._crit_edge18, !llvm.loop !15

._crit_edge18:                                    ; preds = %.lr.ph17, %.preheader
  ret i32 0
}

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

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

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

!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}
!14 = distinct !{!14, !10, !12, !11}
!15 = distinct !{!15, !10}


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