; LLVM IR from lzyrapx/Competitive-Programming :: ACdream/1086（背包+dp）.ll (Z5checkx)

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

@digit = external dso_local global [20 x i32], align 16

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

7:                                                ; preds = %10, %1
  %8 = load i64, ptr %3, align 8, !tbaa !5
  %9 = icmp ne i64 %8, 0
  br i1 %9, label %10, label %20

10:                                               ; preds = %7
  %11 = load i64, ptr %3, align 8, !tbaa !5
  %12 = srem i64 %11, 10
  %13 = trunc i64 %12 to i32
  %14 = load i32, ptr %4, align 4, !tbaa !9
  %15 = add nsw i32 %14, 1
  store i32 %15, ptr %4, align 4, !tbaa !9
  %16 = sext i32 %14 to i64
  %17 = getelementptr inbounds [20 x i32], ptr @digit, i64 0, i64 %16
  store i32 %13, ptr %17, align 4, !tbaa !9
  %18 = load i64, ptr %3, align 8, !tbaa !5
  %19 = sdiv i64 %18, 10
  store i64 %19, ptr %3, align 8, !tbaa !5
  br label %7, !llvm.loop !11

20:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %21 = load i32, ptr %4, align 4, !tbaa !9
  %22 = sub nsw i32 %21, 1
  store i32 %22, ptr %5, align 4, !tbaa !9
  br label %23

23:                                               ; preds = %42, %20
  %24 = load i32, ptr %5, align 4, !tbaa !9
  %25 = icmp sge i32 %24, 1
  br i1 %25, label %27, label %26

26:                                               ; preds = %23
  store i32 4, ptr %6, align 4
  br label %45

27:                                               ; preds = %23
  %28 = load i32, ptr %5, align 4, !tbaa !9
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [20 x i32], ptr @digit, i64 0, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !9
  %32 = icmp eq i32 %31, 6
  br i1 %32, label %33, label %41

33:                                               ; preds = %27
  %34 = load i32, ptr %5, align 4, !tbaa !9
  %35 = sub nsw i32 %34, 1
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [20 x i32], ptr @digit, i64 0, i64 %36
  %38 = load i32, ptr %37, align 4, !tbaa !9
  %39 = icmp eq i32 %38, 1
  br i1 %39, label %40, label %41

40:                                               ; preds = %33
  store i32 1, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %45

41:                                               ; preds = %33, %27
  br label %42

42:                                               ; preds = %41
  %43 = load i32, ptr %5, align 4, !tbaa !9
  %44 = add nsw i32 %43, -1
  store i32 %44, ptr %5, align 4, !tbaa !9
  br label %23, !llvm.loop !13

45:                                               ; preds = %40, %26
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  %46 = load i32, ptr %6, align 4
  switch i32 %46, label %48 [
    i32 4, label %47
  ]

47:                                               ; preds = %45
  store i32 0, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %48

48:                                               ; preds = %47, %45
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  %49 = load i32, ptr %2, align 4
  ret i32 %49
}

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

@digit = external dso_local local_unnamed_addr global [20 x i32], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef range(i32 0, 2) i32 @_Z5checkx(i64 noundef %0) local_unnamed_addr #0 {
  %.not15 = icmp eq i64 %0, 0
  br i1 %.not15, label %._crit_edge, label %.lr.ph

.preheader:                                       ; preds = %.lr.ph
  %2 = trunc nuw i64 %indvars.iv.next to i32
  %3 = icmp sgt i32 %2, 1
  br i1 %3, label %.lr.ph21.preheader, label %._crit_edge

.lr.ph21.preheader:                               ; preds = %.preheader
  %4 = and i64 %indvars.iv.next, 2147483647
  br label %.lr.ph21

.lr.ph:                                           ; preds = %1, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %1 ]
  %.01316 = phi i64 [ %8, %.lr.ph ], [ %0, %1 ]
  %5 = srem i64 %.01316, 10
  %6 = trunc nsw i64 %5 to i32
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %7 = getelementptr inbounds [20 x i32], ptr @digit, i64 0, i64 %indvars.iv
  store i32 %6, ptr %7, align 4, !tbaa !5
  %8 = sdiv i64 %.01316, 10
  %.01316.off = add i64 %.01316, 9
  %.not = icmp ult i64 %.01316.off, 19
  br i1 %.not, label %.preheader, label %.lr.ph, !llvm.loop !9

.lr.ph21:                                         ; preds = %.lr.ph21.preheader, %17
  %indvars.iv27 = phi i64 [ %4, %.lr.ph21.preheader ], [ %indvars.iv.next28, %17 ]
  %indvars.iv.next28 = add nsw i64 %indvars.iv27, -1
  %9 = getelementptr inbounds [20 x i32], ptr @digit, i64 0, i64 %indvars.iv.next28
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = icmp eq i32 %10, 6
  br i1 %11, label %12, label %17

12:                                               ; preds = %.lr.ph21
  %13 = add nsw i64 %indvars.iv27, -2
  %14 = getelementptr inbounds [20 x i32], ptr @digit, i64 0, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = icmp eq i32 %15, 1
  br i1 %16, label %._crit_edge, label %17

17:                                               ; preds = %.lr.ph21, %12
  %18 = icmp ugt i64 %indvars.iv27, 2
  br i1 %18, label %.lr.ph21, label %._crit_edge, !llvm.loop !11

._crit_edge:                                      ; preds = %17, %12, %1, %.preheader
  %.lcssa = phi i32 [ 0, %.preheader ], [ 0, %1 ], [ 1, %12 ], [ 0, %17 ]
  ret i32 %.lcssa
}

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


; Effective O3 passes: CorrelatedValuePropagationPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass