; LLVM IR from upupming/algorithm :: acwing/日常刷题/数位DP/1081. 度的数量.ll (Z3cbpv)

; 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 [35 x [35 x i32]], align 16

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

4:                                                ; preds = %54, %0
  %5 = load i32, ptr %1, align 4, !tbaa !5
  %6 = icmp slt i32 %5, 35
  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 %57

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

9:                                                ; preds = %50, %8
  %10 = load i32, ptr %3, align 4, !tbaa !5
  %11 = load i32, ptr %1, align 4, !tbaa !5
  %12 = icmp sle i32 %10, %11
  br i1 %12, label %14, label %13

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

14:                                               ; preds = %9
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %17, label %24

17:                                               ; preds = %14
  %18 = load i32, ptr %1, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [35 x [35 x i32]], ptr @c, i64 0, i64 %19
  %21 = load i32, ptr %3, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [35 x i32], ptr %20, i64 0, i64 %22
  store i32 1, ptr %23, align 4, !tbaa !5
  br label %49

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

49:                                               ; preds = %24, %17
  br label %50

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

53:                                               ; preds = %13
  br label %54

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

57:                                               ; 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 = !{!"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"

@c = external dso_local local_unnamed_addr global [35 x [35 x i32]], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z3cbpv() local_unnamed_addr #0 {
  br label %1

1:                                                ; preds = %0, %.loopexit
  %indvars.iv23 = phi i64 [ 0, %0 ], [ %indvars.iv.next24, %.loopexit ]
  %indvars.iv21 = phi i64 [ 1, %0 ], [ %indvars.iv.next22, %.loopexit ]
  %2 = add nsw i64 %indvars.iv23, -1
  %3 = getelementptr inbounds [35 x [35 x i32]], ptr @c, i64 0, i64 %indvars.iv23
  store i32 1, ptr %3, align 4, !tbaa !5
  %exitcond.peel.not = icmp eq i64 %indvars.iv21, 1
  br i1 %exitcond.peel.not, label %.loopexit, label %.peel.next.preheader

.peel.next.preheader:                             ; preds = %1
  %min.iters.check = icmp ult i64 %indvars.iv23, 8
  br i1 %min.iters.check, label %.peel.next.preheader32, label %vector.ph

.peel.next.preheader32:                           ; preds = %middle.block, %.peel.next.preheader
  %indvars.iv.ph = phi i64 [ 1, %.peel.next.preheader ], [ %ind.end, %middle.block ]
  br label %.peel.next

vector.ph:                                        ; preds = %.peel.next.preheader
  %n.vec = and i64 %indvars.iv23, 9223372036854775800
  %ind.end = or disjoint i64 %n.vec, 1
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %offset.idx = or disjoint i64 %index, 1
  %4 = getelementptr inbounds [35 x [35 x i32]], ptr @c, i64 0, i64 %2, i64 %offset.idx
  %5 = getelementptr inbounds i8, ptr %4, i64 16
  %wide.load = load <4 x i32>, ptr %4, align 4, !tbaa !5
  %wide.load29 = load <4 x i32>, ptr %5, align 4, !tbaa !5
  %6 = getelementptr inbounds [35 x [35 x i32]], ptr @c, i64 0, i64 %2, i64 %index
  %7 = getelementptr inbounds i8, ptr %6, i64 16
  %wide.load30 = load <4 x i32>, ptr %6, align 4, !tbaa !5
  %wide.load31 = load <4 x i32>, ptr %7, align 4, !tbaa !5
  %8 = add nsw <4 x i32> %wide.load30, %wide.load
  %9 = add nsw <4 x i32> %wide.load31, %wide.load29
  %10 = getelementptr inbounds [35 x [35 x i32]], ptr @c, i64 0, i64 %indvars.iv23, i64 %offset.idx
  %11 = getelementptr inbounds i8, ptr %10, i64 16
  store <4 x i32> %8, ptr %10, align 4, !tbaa !5
  store <4 x i32> %9, ptr %11, align 4, !tbaa !5
  %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
  %cmp.n = icmp eq i64 %indvars.iv23, %n.vec
  br i1 %cmp.n, label %.loopexit, label %.peel.next.preheader32

13:                                               ; preds = %.loopexit
  ret void

.loopexit:                                        ; preds = %.peel.next, %middle.block, %1
  %indvars.iv.next24 = add nuw nsw i64 %indvars.iv23, 1
  %indvars.iv.next22 = add nuw nsw i64 %indvars.iv21, 1
  %exitcond28.not = icmp eq i64 %indvars.iv.next24, 35
  br i1 %exitcond28.not, label %13, label %1, !llvm.loop !14

.peel.next:                                       ; preds = %.peel.next.preheader32, %.peel.next
  %indvars.iv = phi i64 [ %indvars.iv.next, %.peel.next ], [ %indvars.iv.ph, %.peel.next.preheader32 ]
  %14 = getelementptr inbounds [35 x [35 x i32]], ptr @c, i64 0, i64 %2, i64 %indvars.iv
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = add nsw i64 %indvars.iv, -1
  %17 = getelementptr inbounds [35 x [35 x i32]], ptr @c, i64 0, i64 %2, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %19 = add nsw i32 %18, %15
  %20 = getelementptr inbounds [35 x [35 x i32]], ptr @c, i64 0, i64 %indvars.iv23, i64 %indvars.iv
  store i32 %19, ptr %20, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %indvars.iv21
  br i1 %exitcond.not, label %.loopexit, label %.peel.next, !llvm.loop !15
}

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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10, !11, !12, !13}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.peeled.count", i32 1}
!12 = !{!"llvm.loop.isvectorized", i32 1}
!13 = !{!"llvm.loop.unroll.runtime.disable"}
!14 = distinct !{!14, !10}
!15 = distinct !{!15, !10, !11, !13, !12}


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