; LLVM IR from lzyrapx/Competitive-Programming :: BZOJ/3209（数位dp）.ll (Z5solvex)

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

@ans = external dso_local global [66 x i64], align 16
@dig = external dso_local global [60 x i64], align 16
@dp = external dso_local global [60 x [60 x [2 x i64]]], align 16
@vis = external dso_local global [60 x [60 x [2 x i32]]], align 16

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z5solvex(i64 noundef %0) #1 {
  %2 = alloca i64, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store i64 %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !9
  call void @llvm.memset.p0.i64(ptr align 16 @dp, i8 0, i64 57600, i1 false)
  call void @llvm.memset.p0.i64(ptr align 16 @vis, i8 0, i64 28800, i1 false)
  br label %5

5:                                                ; preds = %8, %1
  %6 = load i64, ptr %2, align 8, !tbaa !5
  %7 = icmp ne i64 %6, 0
  br i1 %7, label %8, label %17

8:                                                ; preds = %5
  %9 = load i64, ptr %2, align 8, !tbaa !5
  %10 = and i64 %9, 1
  %11 = load i32, ptr %3, align 4, !tbaa !9
  %12 = add nsw i32 %11, 1
  store i32 %12, ptr %3, align 4, !tbaa !9
  %13 = sext i32 %11 to i64
  %14 = getelementptr inbounds [60 x i64], ptr @dig, i64 0, i64 %13
  store i64 %10, ptr %14, align 8, !tbaa !5
  %15 = load i64, ptr %2, align 8, !tbaa !5
  %16 = ashr i64 %15, 1
  store i64 %16, ptr %2, align 8, !tbaa !5
  br label %5, !llvm.loop !11

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

18:                                               ; preds = %31, %17
  %19 = load i32, ptr %4, align 4, !tbaa !9
  %20 = load i32, ptr %3, align 4, !tbaa !9
  %21 = icmp sle i32 %19, %20
  br i1 %21, label %23, label %22

22:                                               ; preds = %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %34

23:                                               ; preds = %18
  %24 = load i32, ptr %3, align 4, !tbaa !9
  %25 = sub nsw i32 %24, 1
  %26 = load i32, ptr %4, align 4, !tbaa !9
  %27 = call noundef i64 @_Z3dfsiii(i32 noundef %25, i32 noundef %26, i32 noundef 0)
  %28 = load i32, ptr %4, align 4, !tbaa !9
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [66 x i64], ptr @ans, i64 0, i64 %29
  store i64 %27, ptr %30, align 8, !tbaa !5
  br label %31

31:                                               ; preds = %23
  %32 = load i32, ptr %4, align 4, !tbaa !9
  %33 = add nsw i32 %32, 1
  store i32 %33, ptr %4, align 4, !tbaa !9
  br label %18, !llvm.loop !13

34:                                               ; preds = %22
  %35 = load i32, ptr %3, align 4, !tbaa !9
  %36 = sext i32 %35 to i64
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret i64 %36
}

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

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

@ans = external dso_local local_unnamed_addr global [66 x i64], align 16
@dig = external dso_local local_unnamed_addr global [60 x i64], align 16
@dp = external dso_local local_unnamed_addr global [60 x [60 x [2 x i64]]], align 16
@vis = external dso_local local_unnamed_addr global [60 x [60 x [2 x i32]]], align 16

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

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i64 -2147483648, 2147483648) i64 @_Z5solvex(i64 noundef %0) local_unnamed_addr #0 {
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(57600) @dp, i8 0, i64 57600, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(28800) @vis, i8 0, i64 28800, i1 false)
  %.not14 = icmp eq i64 %0, 0
  br i1 %.not14, label %._crit_edge, label %.lr.ph

.lr.ph19:                                         ; preds = %.lr.ph
  %2 = trunc nuw i64 %indvars.iv.next to i32
  %3 = add nsw i32 %2, -1
  %4 = add nuw i64 %indvars.iv, 2
  %wide.trip.count = and i64 %4, 4294967295
  br label %9

.lr.ph:                                           ; preds = %1, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %1 ]
  %.01215 = phi i64 [ %7, %.lr.ph ], [ %0, %1 ]
  %5 = and i64 %.01215, 1
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %6 = getelementptr inbounds [60 x i64], ptr @dig, i64 0, i64 %indvars.iv
  store i64 %5, ptr %6, align 8, !tbaa !5
  %7 = ashr i64 %.01215, 1
  %.not = icmp ult i64 %.01215, 2
  br i1 %.not, label %.lr.ph19, label %.lr.ph, !llvm.loop !9

._crit_edge.loopexit:                             ; preds = %9
  %8 = and i64 %indvars.iv.next, 4294967295
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %1
  %.011.lcssa26 = phi i64 [ 0, %1 ], [ %8, %._crit_edge.loopexit ]
  ret i64 %.011.lcssa26

9:                                                ; preds = %.lr.ph19, %9
  %indvars.iv21 = phi i64 [ 1, %.lr.ph19 ], [ %indvars.iv.next22, %9 ]
  %10 = trunc nuw nsw i64 %indvars.iv21 to i32
  %11 = tail call noundef i64 @_Z3dfsiii(i32 noundef %3, i32 noundef %10, i32 noundef 0)
  %12 = getelementptr inbounds [66 x i64], ptr @ans, i64 0, i64 %indvars.iv21
  store i64 %11, ptr %12, align 8, !tbaa !5
  %indvars.iv.next22 = add nuw nsw i64 %indvars.iv21, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next22, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge.loopexit, label %9, !llvm.loop !11
}

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

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 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 = !{!"long long", !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,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass