; LLVM IR from upupming/algorithm :: acwing/算法竞赛进阶指南/0x59D-数位统计DP/310. 启示录.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"

@f = external dso_local global [21 x [4 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
  %4 = alloca i32, align 4
  store i64 1, ptr @f, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  store i32 0, ptr %1, align 4, !tbaa !9
  br label %5

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

8:                                                ; preds = %5
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  br label %19

9:                                                ; preds = %5
  %10 = load i32, ptr %1, align 4, !tbaa !9
  %11 = icmp eq i32 %10, 6
  %12 = zext i1 %11 to i64
  %13 = getelementptr inbounds [4 x i64], ptr getelementptr inbounds ([21 x [4 x i64]], ptr @f, i64 0, i64 1), i64 0, i64 %12
  %14 = load i64, ptr %13, align 8, !tbaa !5
  %15 = add nsw i64 %14, 1
  store i64 %15, ptr %13, align 8, !tbaa !5
  br label %16

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

19:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #2
  store i32 1, ptr %2, align 4, !tbaa !9
  br label %20

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

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

24:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %25

25:                                               ; preds = %62, %24
  %26 = load i32, ptr %4, align 4, !tbaa !9
  %27 = icmp slt i32 %26, 3
  br i1 %27, label %29, label %28

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

29:                                               ; preds = %25
  %30 = load i32, ptr %2, align 4, !tbaa !9
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [21 x [4 x i64]], ptr @f, i64 0, i64 %31
  %33 = load i32, ptr %4, align 4, !tbaa !9
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [4 x i64], ptr %32, i64 0, i64 %34
  %36 = load i64, ptr %35, align 8, !tbaa !5
  %37 = load i32, ptr %2, align 4, !tbaa !9
  %38 = add nsw i32 %37, 1
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [21 x [4 x i64]], ptr @f, i64 0, i64 %39
  %41 = load i32, ptr %4, align 4, !tbaa !9
  %42 = add nsw i32 %41, 1
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [4 x i64], ptr %40, i64 0, i64 %43
  %45 = load i64, ptr %44, align 8, !tbaa !5
  %46 = add nsw i64 %45, %36
  store i64 %46, ptr %44, align 8, !tbaa !5
  %47 = load i32, ptr %2, align 4, !tbaa !9
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [21 x [4 x i64]], ptr @f, i64 0, i64 %48
  %50 = load i32, ptr %4, align 4, !tbaa !9
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [4 x i64], ptr %49, i64 0, i64 %51
  %53 = load i64, ptr %52, align 8, !tbaa !5
  %54 = mul nsw i64 %53, 9
  %55 = load i32, ptr %2, align 4, !tbaa !9
  %56 = add nsw i32 %55, 1
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [21 x [4 x i64]], ptr @f, i64 0, i64 %57
  %59 = getelementptr inbounds [4 x i64], ptr %58, i64 0, i64 0
  %60 = load i64, ptr %59, align 16, !tbaa !5
  %61 = add nsw i64 %60, %54
  store i64 %61, ptr %59, align 16, !tbaa !5
  br label %62

62:                                               ; preds = %29
  %63 = load i32, ptr %4, align 4, !tbaa !9
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr %4, align 4, !tbaa !9
  br label %25, !llvm.loop !13

65:                                               ; preds = %28
  %66 = load i32, ptr %2, align 4, !tbaa !9
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [21 x [4 x i64]], ptr @f, i64 0, i64 %67
  %69 = getelementptr inbounds [4 x i64], ptr %68, i64 0, i64 3
  %70 = load i64, ptr %69, align 8, !tbaa !5
  %71 = mul nsw i64 %70, 10
  %72 = load i32, ptr %2, align 4, !tbaa !9
  %73 = add nsw i32 %72, 1
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [21 x [4 x i64]], ptr @f, i64 0, i64 %74
  %76 = getelementptr inbounds [4 x i64], ptr %75, i64 0, i64 3
  %77 = load i64, ptr %76, align 8, !tbaa !5
  %78 = add nsw i64 %77, %71
  store i64 %78, ptr %76, align 8, !tbaa !5
  br label %79

79:                                               ; preds = %65
  %80 = load i32, ptr %2, align 4, !tbaa !9
  %81 = add nsw i32 %80, 1
  store i32 %81, ptr %2, align 4, !tbaa !9
  br label %20, !llvm.loop !14

82:                                               ; preds = %23
  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}
!14 = distinct !{!14, !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"

@f = external dso_local local_unnamed_addr global [21 x [4 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 {
.preheader.preheader:
  store i64 1, ptr @f, align 16, !tbaa !5
  %0 = load <2 x i64>, ptr getelementptr inbounds (i8, ptr @f, i64 32), align 16, !tbaa !5
  %1 = add nsw <2 x i64> %0, <i64 9, i64 1>
  store <2 x i64> %1, ptr getelementptr inbounds (i8, ptr @f, i64 32), align 16, !tbaa !5
  %.pre = load i64, ptr getelementptr inbounds (i8, ptr @f, i64 48), align 16, !tbaa !5
  %.pre24 = load i64, ptr getelementptr inbounds (i8, ptr @f, i64 56), align 8, !tbaa !5
  %2 = extractelement <2 x i64> %1, i64 1
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %.preheader
  %3 = phi i64 [ %.pre24, %.preheader.preheader ], [ %25, %.preheader ]
  %4 = phi i64 [ %.pre, %.preheader.preheader ], [ %16, %.preheader ]
  %5 = phi i64 [ %2, %.preheader.preheader ], [ %11, %.preheader ]
  %indvars.iv = phi i64 [ 1, %.preheader.preheader ], [ %indvars.iv.next, %.preheader ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %6 = getelementptr inbounds [21 x [4 x i64]], ptr @f, i64 0, i64 %indvars.iv.next
  %.promoted = load i64, ptr %6, align 16, !tbaa !5
  %7 = getelementptr inbounds [21 x [4 x i64]], ptr @f, i64 0, i64 %indvars.iv, i64 0
  %8 = load i64, ptr %7, align 16, !tbaa !5
  %9 = getelementptr inbounds [21 x [4 x i64]], ptr @f, i64 0, i64 %indvars.iv.next, i64 1
  %10 = load i64, ptr %9, align 8, !tbaa !5
  %11 = add nsw i64 %10, %8
  store i64 %11, ptr %9, align 8, !tbaa !5
  %12 = mul nsw i64 %8, 9
  %13 = add nsw i64 %.promoted, %12
  %14 = getelementptr inbounds [21 x [4 x i64]], ptr @f, i64 0, i64 %indvars.iv.next, i64 2
  %15 = load i64, ptr %14, align 16, !tbaa !5
  %16 = add nsw i64 %15, %5
  store i64 %16, ptr %14, align 16, !tbaa !5
  %17 = mul nsw i64 %5, 9
  %18 = add nsw i64 %13, %17
  %19 = getelementptr inbounds [21 x [4 x i64]], ptr @f, i64 0, i64 %indvars.iv.next, i64 3
  %20 = load i64, ptr %19, align 8, !tbaa !5
  %21 = add nsw i64 %20, %4
  %22 = mul nsw i64 %4, 9
  %23 = add nsw i64 %18, %22
  store i64 %23, ptr %6, align 16, !tbaa !5
  %24 = mul nsw i64 %3, 10
  %25 = add nsw i64 %21, %24
  store i64 %25, ptr %19, align 8, !tbaa !5
  %exitcond.not = icmp eq i64 %indvars.iv.next, 21
  br i1 %exitcond.not, label %26, label %.preheader, !llvm.loop !9

26:                                               ; preds = %.preheader
  ret void
}

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}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: BDCEPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass