; LLVM IR from Tudor67/Competitive-Programming :: AtCoder/ABC336/E_sol1_dp_on_digits.ll (Z9resetMemoiii)

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

@memo = external dso_local global [16 x [136 x [135 x i64]]], 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 nounwind uwtable
define dso_local void @_Z9resetMemoiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %46, %3
  %12 = load i32, ptr %7, align 4, !tbaa !5
  %13 = load i32, ptr %4, align 4, !tbaa !5
  %14 = icmp sle i32 %12, %13
  br i1 %14, label %16, label %15

15:                                               ; preds = %11
  store i32 2, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  br label %49

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

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

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

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

23:                                               ; preds = %38, %22
  %24 = load i32, ptr %10, align 4, !tbaa !5
  %25 = load i32, ptr %6, align 4, !tbaa !5
  %26 = icmp sle i32 %24, %25
  br i1 %26, label %28, label %27

27:                                               ; preds = %23
  store i32 8, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  br label %41

28:                                               ; preds = %23
  %29 = load i32, ptr %7, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [16 x [136 x [135 x i64]]], ptr @memo, i64 0, i64 %30
  %32 = load i32, ptr %9, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [136 x [135 x i64]], ptr %31, i64 0, i64 %33
  %35 = load i32, ptr %10, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [135 x i64], ptr %34, i64 0, i64 %36
  store i64 -1, ptr %37, align 8, !tbaa !9
  br label %38

38:                                               ; preds = %28
  %39 = load i32, ptr %10, align 4, !tbaa !5
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %10, align 4, !tbaa !5
  br label %23, !llvm.loop !11

41:                                               ; preds = %27
  br label %42

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

45:                                               ; preds = %21
  br label %46

46:                                               ; preds = %45
  %47 = load i32, ptr %7, align 4, !tbaa !5
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr %7, align 4, !tbaa !5
  br label %11, !llvm.loop !14

49:                                               ; preds = %15
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = !{!10, !10, i64 0}
!10 = !{!"long long", !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"

@memo = external dso_local local_unnamed_addr global [16 x [136 x [135 x i64]]], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(write, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z9resetMemoiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = or i32 %0, %1
  %5 = or i32 %4, %2
  %or.cond37.not = icmp sgt i32 %5, -1
  br i1 %or.cond37.not, label %.preheader16.preheader, label %._crit_edge24

.preheader16.preheader:                           ; preds = %3
  %6 = add nuw i32 %2, 1
  %7 = zext i32 %6 to i64
  %8 = shl nuw nsw i64 %7, 3
  %9 = add nuw i32 %1, 1
  %10 = add nuw i32 %0, 1
  %wide.trip.count35 = zext i32 %10 to i64
  %wide.trip.count = zext i32 %9 to i64
  %xtraiter = and i64 %wide.trip.count, 7
  %11 = icmp ult i32 %1, 7
  %unroll_iter = and i64 %wide.trip.count, 4294967288
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.preheader16

.preheader16:                                     ; preds = %.preheader16.preheader, %._crit_edge21.split
  %indvar = phi i64 [ 0, %.preheader16.preheader ], [ %indvar.next, %._crit_edge21.split ]
  %12 = mul nuw nsw i64 %indvar, 146880
  %13 = getelementptr i8, ptr @memo, i64 %12
  br i1 %11, label %._crit_edge21.split.unr-lcssa, label %.preheader16.new

.preheader16.new:                                 ; preds = %.preheader16
  %invariant.gep = getelementptr i8, ptr %13, i64 1080
  %invariant.gep38 = getelementptr i8, ptr %13, i64 2160
  %invariant.gep40 = getelementptr i8, ptr %13, i64 3240
  %invariant.gep42 = getelementptr i8, ptr %13, i64 4320
  %invariant.gep44 = getelementptr i8, ptr %13, i64 5400
  %invariant.gep46 = getelementptr i8, ptr %13, i64 6480
  %invariant.gep48 = getelementptr i8, ptr %13, i64 7560
  br label %.preheader

._crit_edge24:                                    ; preds = %._crit_edge21.split, %3
  ret void

.preheader:                                       ; preds = %.preheader, %.preheader16.new
  %indvar30 = phi i64 [ 0, %.preheader16.new ], [ %indvar.next31.7, %.preheader ]
  %niter = phi i64 [ 0, %.preheader16.new ], [ %niter.next.7, %.preheader ]
  %14 = mul nuw nsw i64 %indvar30, 1080
  %scevgep = getelementptr i8, ptr %13, i64 %14
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(1) %scevgep, i8 -1, i64 %8, i1 false), !tbaa !5
  %15 = mul nuw i64 %indvar30, 1080
  %gep = getelementptr i8, ptr %invariant.gep, i64 %15
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(1) %gep, i8 -1, i64 %8, i1 false), !tbaa !5
  %16 = mul nuw i64 %indvar30, 1080
  %gep39 = getelementptr i8, ptr %invariant.gep38, i64 %16
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(1) %gep39, i8 -1, i64 %8, i1 false), !tbaa !5
  %17 = mul nuw i64 %indvar30, 1080
  %gep41 = getelementptr i8, ptr %invariant.gep40, i64 %17
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(1) %gep41, i8 -1, i64 %8, i1 false), !tbaa !5
  %18 = mul nuw i64 %indvar30, 1080
  %gep43 = getelementptr i8, ptr %invariant.gep42, i64 %18
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(1) %gep43, i8 -1, i64 %8, i1 false), !tbaa !5
  %19 = mul nuw i64 %indvar30, 1080
  %gep45 = getelementptr i8, ptr %invariant.gep44, i64 %19
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(1) %gep45, i8 -1, i64 %8, i1 false), !tbaa !5
  %20 = mul nuw i64 %indvar30, 1080
  %gep47 = getelementptr i8, ptr %invariant.gep46, i64 %20
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(1) %gep47, i8 -1, i64 %8, i1 false), !tbaa !5
  %21 = mul nuw i64 %indvar30, 1080
  %gep49 = getelementptr i8, ptr %invariant.gep48, i64 %21
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(1) %gep49, i8 -1, i64 %8, i1 false), !tbaa !5
  %indvar.next31.7 = add nuw nsw i64 %indvar30, 8
  %niter.next.7 = add i64 %niter, 8
  %niter.ncmp.7 = icmp eq i64 %niter.next.7, %unroll_iter
  br i1 %niter.ncmp.7, label %._crit_edge21.split.unr-lcssa, label %.preheader, !llvm.loop !9

._crit_edge21.split.unr-lcssa:                    ; preds = %.preheader, %.preheader16
  %indvar30.unr = phi i64 [ 0, %.preheader16 ], [ %indvar.next31.7, %.preheader ]
  br i1 %lcmp.mod.not, label %._crit_edge21.split, label %.preheader.epil

.preheader.epil:                                  ; preds = %._crit_edge21.split.unr-lcssa, %.preheader.epil
  %indvar30.epil = phi i64 [ %indvar.next31.epil, %.preheader.epil ], [ %indvar30.unr, %._crit_edge21.split.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.preheader.epil ], [ 0, %._crit_edge21.split.unr-lcssa ]
  %22 = mul nuw nsw i64 %indvar30.epil, 1080
  %scevgep.epil = getelementptr i8, ptr %13, i64 %22
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(1) %scevgep.epil, i8 -1, i64 %8, i1 false), !tbaa !5
  %indvar.next31.epil = add nuw nsw i64 %indvar30.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge21.split, label %.preheader.epil, !llvm.loop !11

._crit_edge21.split:                              ; preds = %.preheader.epil, %._crit_edge21.split.unr-lcssa
  %indvar.next = add nuw nsw i64 %indvar, 1
  %exitcond36.not = icmp eq i64 %indvar.next, %wide.trip.count35
  br i1 %exitcond36.not, label %._crit_edge24, label %.preheader16, !llvm.loop !13
}

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

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(write, 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" }
attributes #1 = { 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, !12}
!12 = !{!"llvm.loop.unroll.disable"}
!13 = distinct !{!13, !10}


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