; LLVM IR from lzyrapx/Competitive-Programming :: ACdream/1081（组合数学）.ll (Z4initv)

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

@C = external dso_local global [2020 x [2020 x i64]], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z4initv() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  store i64 1, ptr @C, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  store i32 1, ptr %1, align 4, !tbaa !9
  br label %4

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

7:                                                ; preds = %4
  store i32 2, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  br label %74

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

19:                                               ; preds = %67, %8
  %20 = load i32, ptr %3, align 4, !tbaa !9
  %21 = load i32, ptr %1, align 4, !tbaa !9
  %22 = icmp slt i32 %20, %21
  br i1 %22, label %24, label %23

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

24:                                               ; preds = %19
  %25 = load i32, ptr %1, align 4, !tbaa !9
  %26 = sub nsw i32 %25, 1
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [2020 x [2020 x i64]], ptr @C, i64 0, i64 %27
  %29 = load i32, ptr %3, align 4, !tbaa !9
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [2020 x i64], ptr %28, i64 0, i64 %30
  %32 = load i64, ptr %31, align 8, !tbaa !5
  %33 = load i32, ptr %1, align 4, !tbaa !9
  %34 = sub nsw i32 %33, 1
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [2020 x [2020 x i64]], ptr @C, i64 0, i64 %35
  %37 = load i32, ptr %3, align 4, !tbaa !9
  %38 = sub nsw i32 %37, 1
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [2020 x i64], ptr %36, i64 0, i64 %39
  %41 = load i64, ptr %40, align 8, !tbaa !5
  %42 = add nsw i64 %32, %41
  %43 = load i32, ptr %1, align 4, !tbaa !9
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [2020 x [2020 x i64]], ptr @C, i64 0, i64 %44
  %46 = load i32, ptr %3, align 4, !tbaa !9
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [2020 x i64], ptr %45, i64 0, i64 %47
  store i64 %42, ptr %48, align 8, !tbaa !5
  %49 = load i32, ptr %1, align 4, !tbaa !9
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [2020 x [2020 x i64]], ptr @C, i64 0, i64 %50
  %52 = load i32, ptr %3, align 4, !tbaa !9
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [2020 x i64], ptr %51, i64 0, i64 %53
  %55 = load i64, ptr %54, align 8, !tbaa !5
  %56 = icmp sge i64 %55, 1000000006
  br i1 %56, label %57, label %66

57:                                               ; preds = %24
  %58 = load i32, ptr %1, align 4, !tbaa !9
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [2020 x [2020 x i64]], ptr @C, i64 0, i64 %59
  %61 = load i32, ptr %3, align 4, !tbaa !9
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [2020 x i64], ptr %60, i64 0, i64 %62
  %64 = load i64, ptr %63, align 8, !tbaa !5
  %65 = sub nsw i64 %64, 1000000006
  store i64 %65, ptr %63, align 8, !tbaa !5
  br label %66

66:                                               ; preds = %57, %24
  br label %67

67:                                               ; preds = %66
  %68 = load i32, ptr %3, align 4, !tbaa !9
  %69 = add nsw i32 %68, 1
  store i32 %69, ptr %3, align 4, !tbaa !9
  br label %19, !llvm.loop !11

70:                                               ; preds = %23
  br label %71

71:                                               ; preds = %70
  %72 = load i32, ptr %1, align 4, !tbaa !9
  %73 = add nsw i32 %72, 1
  store i32 %73, ptr %1, align 4, !tbaa !9
  br label %4, !llvm.loop !13

74:                                               ; preds = %7
  ret void
}

; 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

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 = { 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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

@C = external dso_local local_unnamed_addr global [2020 x [2020 x i64]], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z4initv() local_unnamed_addr #0 {
  store i64 1, ptr @C, align 16, !tbaa !5
  br label %2

1:                                                ; preds = %._crit_edge
  ret void

2:                                                ; preds = %0, %._crit_edge
  %indvar = phi i64 [ 0, %0 ], [ %indvar.next, %._crit_edge ]
  %indvars.iv23 = phi i64 [ 1, %0 ], [ %indvars.iv.next24, %._crit_edge ]
  %3 = getelementptr inbounds [2020 x [2020 x i64]], ptr @C, i64 0, i64 %indvars.iv23
  %4 = getelementptr inbounds [2020 x [2020 x i64]], ptr @C, i64 0, i64 %indvars.iv23, i64 %indvars.iv23
  store i64 1, ptr %4, align 8, !tbaa !5
  store i64 1, ptr %3, align 16, !tbaa !5
  %5 = icmp ugt i64 %indvars.iv23, 1
  br i1 %5, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %2
  %6 = add nsw i64 %indvars.iv23, -1
  %.phi.trans.insert = getelementptr inbounds [2020 x [2020 x i64]], ptr @C, i64 0, i64 %6, i64 0
  %.pre = load i64, ptr %.phi.trans.insert, align 16, !tbaa !5
  %min.iters.check = icmp ult i64 %indvar, 4
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

scalar.ph.preheader:                              ; preds = %middle.block, %.lr.ph
  %.ph = phi i64 [ %.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 %indvar, -4
  %ind.end = or disjoint i64 %n.vec, 1
  %vector.recur.init = insertelement <2 x i64> poison, i64 %.pre, i64 1
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vector.recur = phi <2 x i64> [ %vector.recur.init, %vector.ph ], [ %wide.load27, %vector.body ]
  %offset.idx = or disjoint i64 %index, 1
  %7 = getelementptr inbounds [2020 x [2020 x i64]], ptr @C, i64 0, i64 %6, i64 %offset.idx
  %8 = getelementptr inbounds i8, ptr %7, i64 16
  %wide.load = load <2 x i64>, ptr %7, align 8, !tbaa !5
  %wide.load27 = load <2 x i64>, ptr %8, align 8, !tbaa !5
  %9 = shufflevector <2 x i64> %vector.recur, <2 x i64> %wide.load, <2 x i32> <i32 1, i32 2>
  %10 = shufflevector <2 x i64> %wide.load, <2 x i64> %wide.load27, <2 x i32> <i32 1, i32 2>
  %11 = add nsw <2 x i64> %9, %wide.load
  %12 = add nsw <2 x i64> %10, %wide.load27
  %13 = getelementptr inbounds [2020 x [2020 x i64]], ptr @C, i64 0, i64 %indvars.iv23, i64 %offset.idx
  %14 = icmp sgt <2 x i64> %11, <i64 1000000005, i64 1000000005>
  %15 = icmp sgt <2 x i64> %12, <i64 1000000005, i64 1000000005>
  %16 = add nsw <2 x i64> %11, <i64 -1000000006, i64 -1000000006>
  %17 = add nsw <2 x i64> %12, <i64 -1000000006, i64 -1000000006>
  %18 = select <2 x i1> %14, <2 x i64> %16, <2 x i64> %11
  %19 = select <2 x i1> %15, <2 x i64> %17, <2 x i64> %12
  %20 = getelementptr inbounds i8, ptr %13, i64 16
  store <2 x i64> %18, ptr %13, align 8, !tbaa !5
  store <2 x i64> %19, ptr %20, align 8, !tbaa !5
  %index.next = add nuw i64 %index, 4
  %21 = icmp eq i64 %index.next, %n.vec
  br i1 %21, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %vector.recur.extract = extractelement <2 x i64> %wide.load27, i64 1
  %cmp.n = icmp eq i64 %indvar, %n.vec
  br i1 %cmp.n, label %._crit_edge, label %scalar.ph.preheader

._crit_edge:                                      ; preds = %scalar.ph, %middle.block, %2
  %indvars.iv.next24 = add nuw nsw i64 %indvars.iv23, 1
  %exitcond26.not = icmp eq i64 %indvars.iv.next24, 2020
  %indvar.next = add i64 %indvar, 1
  br i1 %exitcond26.not, label %1, label %2, !llvm.loop !13

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %22 = phi i64 [ %24, %scalar.ph ], [ %.ph, %scalar.ph.preheader ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %scalar.ph ], [ %indvars.iv.ph, %scalar.ph.preheader ]
  %23 = getelementptr inbounds [2020 x [2020 x i64]], ptr @C, i64 0, i64 %6, i64 %indvars.iv
  %24 = load i64, ptr %23, align 8, !tbaa !5
  %25 = add nsw i64 %22, %24
  %26 = getelementptr inbounds [2020 x [2020 x i64]], ptr @C, i64 0, i64 %indvars.iv23, i64 %indvars.iv
  %27 = icmp sgt i64 %25, 1000000005
  %28 = add nsw i64 %25, -1000000006
  %spec.select = select i1 %27, i64 %28, i64 %25
  store i64 %spec.select, ptr %26, align 8, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %indvars.iv23
  br i1 %exitcond.not, label %._crit_edge, label %scalar.ph, !llvm.loop !14
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) 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 = !{!"long long", !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}


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