; LLVM IR from DionysiosB/CodeForces :: 0200-0299/221B-LittleElephantAndNumbers.ll (Z12commonDigitsll)

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_Z12commonDigitsll(i64 noundef %0, i64 noundef %1) #0 {
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca [10 x i8], align 1
  %6 = alloca i8, align 1
  store i64 %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 10, ptr %5) #3
  call void @llvm.memset.p0.i64(ptr align 1 %5, i8 0, i64 10, i1 false)
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #3
  store i8 0, ptr %6, align 1, !tbaa !9
  br label %7

7:                                                ; preds = %10, %2
  %8 = load i64, ptr %3, align 8, !tbaa !5
  %9 = icmp sgt i64 %8, 0
  br i1 %9, label %10, label %16

10:                                               ; preds = %7
  %11 = load i64, ptr %3, align 8, !tbaa !5
  %12 = srem i64 %11, 10
  %13 = getelementptr inbounds [10 x i8], ptr %5, i64 0, i64 %12
  store i8 1, ptr %13, align 1, !tbaa !9
  %14 = load i64, ptr %3, align 8, !tbaa !5
  %15 = sdiv i64 %14, 10
  store i64 %15, ptr %3, align 8, !tbaa !5
  br label %7, !llvm.loop !11

16:                                               ; preds = %7
  br label %17

17:                                               ; preds = %27, %16
  %18 = load i64, ptr %4, align 8, !tbaa !5
  %19 = icmp sgt i64 %18, 0
  br i1 %19, label %20, label %30

20:                                               ; preds = %17
  %21 = load i64, ptr %4, align 8, !tbaa !5
  %22 = srem i64 %21, 10
  %23 = getelementptr inbounds [10 x i8], ptr %5, i64 0, i64 %22
  %24 = load i8, ptr %23, align 1, !tbaa !9, !range !13, !noundef !14
  %25 = trunc i8 %24 to i1
  br i1 %25, label %26, label %27

26:                                               ; preds = %20
  store i8 1, ptr %6, align 1, !tbaa !9
  br label %30

27:                                               ; preds = %20
  %28 = load i64, ptr %4, align 8, !tbaa !5
  %29 = sdiv i64 %28, 10
  store i64 %29, ptr %4, align 8, !tbaa !5
  br label %17, !llvm.loop !15

30:                                               ; preds = %26, %17
  %31 = load i8, ptr %6, align 1, !tbaa !9, !range !13, !noundef !14
  %32 = trunc i8 %31 to i1
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 10, ptr %5) #3
  ret i1 %32
}

; 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; 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 = { 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", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = distinct !{!15, !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"

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none) uwtable
define dso_local noundef zeroext i1 @_Z12commonDigitsll(i64 noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = alloca [10 x i8], align 1
  call void @llvm.lifetime.start.p0(i64 10, ptr nonnull %3) #3
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 1 dereferenceable(10) %3, i8 0, i64 10, i1 false)
  %4 = icmp sgt i64 %0, 0
  br i1 %4, label %.lr.ph, label %.preheader

.preheader:                                       ; preds = %.lr.ph, %2
  %5 = icmp sgt i64 %1, 0
  br i1 %5, label %.lr.ph11, label %._crit_edge

.lr.ph:                                           ; preds = %2, %.lr.ph
  %.089 = phi i64 [ %8, %.lr.ph ], [ %0, %2 ]
  %6 = urem i64 %.089, 10
  %7 = getelementptr inbounds [10 x i8], ptr %3, i64 0, i64 %6
  store i8 1, ptr %7, align 1, !tbaa !5
  %8 = udiv i64 %.089, 10
  %.not = icmp ult i64 %.089, 10
  br i1 %.not, label %.preheader, label %.lr.ph, !llvm.loop !9

.lr.ph11:                                         ; preds = %.preheader, %.lr.ph11
  %.0710 = phi i64 [ %13, %.lr.ph11 ], [ %1, %.preheader ]
  %9 = urem i64 %.0710, 10
  %10 = getelementptr inbounds [10 x i8], ptr %3, i64 0, i64 %9
  %11 = load i8, ptr %10, align 1, !tbaa !5, !range !11, !noundef !12
  %12 = trunc nuw i8 %11 to i1
  %13 = udiv i64 %.0710, 10
  %14 = icmp ult i64 %.0710, 10
  %or.cond.not = or i1 %14, %12
  br i1 %or.cond.not, label %._crit_edge, label %.lr.ph11, !llvm.loop !13

._crit_edge:                                      ; preds = %.lr.ph11, %.preheader
  %.lcssa = phi i1 [ false, %.preheader ], [ %12, %.lr.ph11 ]
  call void @llvm.lifetime.end.p0(i64 10, ptr nonnull %3) #3
  ret i1 %.lcssa
}

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

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

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

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress 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 = !{!"bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = distinct !{!13, !10}


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