; LLVM IR from lzyrapx/Competitive-Programming :: BZOJ (1026（数位dp）)

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

@a = external dso_local global i32, align 4
@b = external dso_local global i32, align 4
@dp = external dso_local global [10 x [10 x [2 x i32]]], align 16
@vis = external dso_local global [10 x [10 x [2 x i32]]], align 16
@dig = external dso_local global [10 x i32], align 16
@.str = external hidden unnamed_addr constant [6 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z3dfsiii(i32 noundef, i32 noundef, 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
  %5 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  br label %6

6:                                                ; preds = %41, %0
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @a, ptr noundef @b)
  %8 = xor i32 %7, -1
  %9 = icmp ne i32 %8, 0
  br i1 %9, label %10, label %49

10:                                               ; preds = %6
  %11 = load i32, ptr @a, align 4, !tbaa !5
  %12 = add nsw i32 %11, -1
  store i32 %12, ptr @a, align 4, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 16 @dp, i8 0, i64 800, i1 false)
  call void @llvm.memset.p0.i64(ptr align 16 @vis, i8 0, i64 800, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  store i32 0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  store i32 0, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %16, %10
  %14 = load i32, ptr @a, align 4, !tbaa !5
  %15 = icmp ne i32 %14, 0
  br i1 %15, label %16, label %25

16:                                               ; preds = %13
  %17 = load i32, ptr @a, align 4, !tbaa !5
  %18 = srem i32 %17, 10
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr %2, align 4, !tbaa !5
  %21 = sext i32 %19 to i64
  %22 = getelementptr inbounds [10 x i32], ptr @dig, i64 0, i64 %21
  store i32 %18, ptr %22, align 4, !tbaa !5
  %23 = load i32, ptr @a, align 4, !tbaa !5
  %24 = sdiv i32 %23, 10
  store i32 %24, ptr @a, align 4, !tbaa !5
  br label %13, !llvm.loop !9

25:                                               ; preds = %13
  %26 = load i32, ptr %2, align 4, !tbaa !5
  %27 = sub nsw i32 %26, 1
  %28 = call noundef i32 @_Z3dfsiii(i32 noundef %27, i32 noundef -1, i32 noundef 0)
  store i32 %28, ptr %4, align 4, !tbaa !5
  br label %29

29:                                               ; preds = %32, %25
  %30 = load i32, ptr @b, align 4, !tbaa !5
  %31 = icmp ne i32 %30, 0
  br i1 %31, label %32, label %41

32:                                               ; preds = %29
  %33 = load i32, ptr @b, align 4, !tbaa !5
  %34 = srem i32 %33, 10
  %35 = load i32, ptr %3, align 4, !tbaa !5
  %36 = add nsw i32 %35, 1
  store i32 %36, ptr %3, align 4, !tbaa !5
  %37 = sext i32 %35 to i64
  %38 = getelementptr inbounds [10 x i32], ptr @dig, i64 0, i64 %37
  store i32 %34, ptr %38, align 4, !tbaa !5
  %39 = load i32, ptr @b, align 4, !tbaa !5
  %40 = sdiv i32 %39, 10
  store i32 %40, ptr @b, align 4, !tbaa !5
  br label %29, !llvm.loop !11

41:                                               ; preds = %29
  %42 = load i32, ptr %3, align 4, !tbaa !5
  %43 = sub nsw i32 %42, 1
  %44 = call noundef i32 @_Z3dfsiii(i32 noundef %43, i32 noundef -1, i32 noundef 0)
  store i32 %44, ptr %5, align 4, !tbaa !5
  %45 = load i32, ptr %5, align 4, !tbaa !5
  %46 = load i32, ptr %4, align 4, !tbaa !5
  %47 = sub nsw i32 %45, %46
  %48 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %47)
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  br label %6, !llvm.loop !12

49:                                               ; preds = %6
  ret i32 0
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

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

attributes #0 = { mustprogress 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { 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"

@a = external dso_local global i32, align 4
@b = external dso_local global i32, align 4
@dp = external dso_local local_unnamed_addr global [10 x [10 x [2 x i32]]], align 16
@vis = external dso_local local_unnamed_addr global [10 x [10 x [2 x i32]]], align 16
@dig = external dso_local local_unnamed_addr global [10 x i32], align 16
@.str = external hidden unnamed_addr constant [6 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @a, ptr noundef nonnull @b)
  %.not20 = icmp eq i32 %1, -1
  br i1 %.not20, label %._crit_edge23, label %.lr.ph22

.lr.ph22:                                         ; preds = %0, %16
  %2 = load i32, ptr @a, align 4, !tbaa !5
  %3 = add nsw i32 %2, -1
  store i32 %3, ptr @a, align 4, !tbaa !5
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(800) @dp, i8 0, i64 800, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(800) @vis, i8 0, i64 800, i1 false)
  %.not911 = icmp eq i32 %3, 0
  br i1 %.not911, label %9, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph22, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %.lr.ph22 ]
  %4 = phi i32 [ %7, %.lr.ph ], [ %3, %.lr.ph22 ]
  %5 = srem i32 %4, 10
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %6 = getelementptr inbounds [10 x i32], ptr @dig, i64 0, i64 %indvars.iv
  store i32 %5, ptr %6, align 4, !tbaa !5
  %7 = sdiv i32 %4, 10
  %.off = add i32 %4, 9
  %.not9 = icmp ult i32 %.off, 19
  br i1 %.not9, label %._crit_edge, label %.lr.ph, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph
  %8 = trunc nuw nsw i64 %indvars.iv to i32
  store i32 %7, ptr @a, align 4, !tbaa !5
  br label %9

9:                                                ; preds = %._crit_edge, %.lr.ph22
  %.06.lcssa = phi i32 [ %8, %._crit_edge ], [ -1, %.lr.ph22 ]
  %10 = tail call noundef i32 @_Z3dfsiii(i32 noundef %.06.lcssa, i32 noundef -1, i32 noundef 0)
  %.pr = load i32, ptr @b, align 4, !tbaa !5
  %.not1013 = icmp eq i32 %.pr, 0
  br i1 %.not1013, label %16, label %.lr.ph16

.lr.ph16:                                         ; preds = %9, %.lr.ph16
  %indvars.iv27 = phi i64 [ %indvars.iv.next28, %.lr.ph16 ], [ 0, %9 ]
  %11 = phi i32 [ %14, %.lr.ph16 ], [ %.pr, %9 ]
  %12 = srem i32 %11, 10
  %indvars.iv.next28 = add nuw nsw i64 %indvars.iv27, 1
  %13 = getelementptr inbounds [10 x i32], ptr @dig, i64 0, i64 %indvars.iv27
  store i32 %12, ptr %13, align 4, !tbaa !5
  %14 = sdiv i32 %11, 10
  %.off24 = add i32 %11, 9
  %.not10 = icmp ult i32 %.off24, 19
  br i1 %.not10, label %._crit_edge17, label %.lr.ph16, !llvm.loop !11

._crit_edge17:                                    ; preds = %.lr.ph16
  %15 = trunc nuw nsw i64 %indvars.iv27 to i32
  store i32 %14, ptr @b, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %._crit_edge17, %9
  %.0.lcssa = phi i32 [ %15, %._crit_edge17 ], [ -1, %9 ]
  %17 = tail call noundef i32 @_Z3dfsiii(i32 noundef %.0.lcssa, i32 noundef -1, i32 noundef 0)
  %18 = sub nsw i32 %17, %10
  %19 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %18)
  %20 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @a, ptr noundef nonnull @b)
  %.not = icmp eq i32 %20, -1
  br i1 %.not, label %._crit_edge23, label %.lr.ph22, !llvm.loop !12

._crit_edge23:                                    ; preds = %16, %0
  ret i32 0
}

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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

attributes #0 = { mustprogress 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 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" }
attributes #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }

!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}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass