; LLVM IR from DionysiosB/CodeForces :: 1100-1199 (1177A-DigitsSequenceEasyEdition)

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

@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1

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

11:                                               ; preds = %52, %0
  br label %12

12:                                               ; preds = %11
  %13 = load i64, ptr %2, align 8, !tbaa !5
  %14 = load i64, ptr %5, align 8, !tbaa !5
  %15 = load i64, ptr %3, align 8, !tbaa !5
  %16 = mul nsw i64 %14, %15
  %17 = icmp sle i64 %13, %16
  br i1 %17, label %18, label %52

18:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %19 = load i64, ptr %4, align 8, !tbaa !5
  %20 = sub nsw i64 %19, 1
  %21 = load i64, ptr %2, align 8, !tbaa !5
  %22 = load i64, ptr %5, align 8, !tbaa !5
  %23 = add nsw i64 %21, %22
  %24 = sub nsw i64 %23, 1
  %25 = load i64, ptr %5, align 8, !tbaa !5
  %26 = sdiv i64 %24, %25
  %27 = add nsw i64 %20, %26
  store i64 %27, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %28 = load i64, ptr %2, align 8, !tbaa !5
  %29 = load i64, ptr %5, align 8, !tbaa !5
  %30 = srem i64 %28, %29
  store i64 %30, ptr %8, align 8, !tbaa !5
  %31 = load i64, ptr %8, align 8, !tbaa !5
  %32 = icmp eq i64 %31, 0
  br i1 %32, label %33, label %35

33:                                               ; preds = %18
  %34 = load i64, ptr %5, align 8, !tbaa !5
  store i64 %34, ptr %8, align 8, !tbaa !5
  br label %35

35:                                               ; preds = %33, %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %36 = load i64, ptr %8, align 8, !tbaa !5
  store i64 %36, ptr %9, align 8, !tbaa !5
  br label %37

37:                                               ; preds = %45, %35
  %38 = load i64, ptr %9, align 8, !tbaa !5
  %39 = load i64, ptr %5, align 8, !tbaa !5
  %40 = icmp slt i64 %38, %39
  br i1 %40, label %42, label %41

41:                                               ; preds = %37
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  br label %48

42:                                               ; preds = %37
  %43 = load i64, ptr %7, align 8, !tbaa !5
  %44 = sdiv i64 %43, 10
  store i64 %44, ptr %7, align 8, !tbaa !5
  br label %45

45:                                               ; preds = %42
  %46 = load i64, ptr %9, align 8, !tbaa !5
  %47 = add nsw i64 %46, 1
  store i64 %47, ptr %9, align 8, !tbaa !5
  br label %37, !llvm.loop !11

48:                                               ; preds = %41
  %49 = load i64, ptr %7, align 8, !tbaa !5
  %50 = srem i64 %49, 10
  %51 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %50)
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  br label %64

52:                                               ; preds = %12
  %53 = load i64, ptr %5, align 8, !tbaa !5
  %54 = load i64, ptr %3, align 8, !tbaa !5
  %55 = mul nsw i64 %53, %54
  %56 = load i64, ptr %2, align 8, !tbaa !5
  %57 = sub nsw i64 %56, %55
  store i64 %57, ptr %2, align 8, !tbaa !5
  %58 = load i64, ptr %5, align 8, !tbaa !5
  %59 = add nsw i64 %58, 1
  store i64 %59, ptr %5, align 8, !tbaa !5
  %60 = load i64, ptr %4, align 8, !tbaa !5
  %61 = mul nsw i64 %60, 10
  store i64 %61, ptr %4, align 8, !tbaa !5
  %62 = load i64, ptr %3, align 8, !tbaa !5
  %63 = mul nsw i64 %62, 10
  store i64 %63, ptr %3, align 8, !tbaa !5
  br label %11, !llvm.loop !13

64:                                               ; preds = %48
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  ret i32 0
}

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

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

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

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

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

@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #3
  %2 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %.promoted = load i64, ptr %1, align 8, !tbaa !5
  %.not27 = icmp sgt i64 %.promoted, 9
  br i1 %.not27, label %.lr.ph, label %4

._crit_edge:                                      ; preds = %.lr.ph
  store i64 %23, ptr %1, align 8, !tbaa !5
  %3 = add nsw i64 %25, -1
  br label %4

4:                                                ; preds = %._crit_edge, %0
  %.023.lcssa = phi i64 [ %3, %._crit_edge ], [ 0, %0 ]
  %.022.lcssa = phi i64 [ %24, %._crit_edge ], [ 1, %0 ]
  %.lcssa = phi i64 [ %23, %._crit_edge ], [ %.promoted, %0 ]
  %5 = add i64 %.022.lcssa, -1
  %6 = add i64 %5, %.lcssa
  %7 = sdiv i64 %6, %.022.lcssa
  %8 = add nsw i64 %.023.lcssa, %7
  %9 = srem i64 %.lcssa, %.022.lcssa
  %10 = icmp eq i64 %9, 0
  %spec.select = select i1 %10, i64 %.022.lcssa, i64 %9
  %11 = icmp slt i64 %spec.select, %.022.lcssa
  br i1 %11, label %.lr.ph37.preheader, label %._crit_edge38

.lr.ph37.preheader:                               ; preds = %4
  %12 = sub i64 %.022.lcssa, %spec.select
  %xtraiter = and i64 %12, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph37.prol.loopexit, label %.lr.ph37.prol

.lr.ph37.prol:                                    ; preds = %.lr.ph37.preheader, %.lr.ph37.prol
  %.035.prol = phi i64 [ %14, %.lr.ph37.prol ], [ %spec.select, %.lr.ph37.preheader ]
  %.02034.prol = phi i64 [ %13, %.lr.ph37.prol ], [ %8, %.lr.ph37.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %.lr.ph37.prol ], [ 0, %.lr.ph37.preheader ]
  %13 = sdiv i64 %.02034.prol, 10
  %14 = add nsw i64 %.035.prol, 1
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %.lr.ph37.prol.loopexit, label %.lr.ph37.prol, !llvm.loop !9

.lr.ph37.prol.loopexit:                           ; preds = %.lr.ph37.prol, %.lr.ph37.preheader
  %.lcssa52.unr = phi i64 [ poison, %.lr.ph37.preheader ], [ %13, %.lr.ph37.prol ]
  %.035.unr = phi i64 [ %spec.select, %.lr.ph37.preheader ], [ %14, %.lr.ph37.prol ]
  %.02034.unr = phi i64 [ %8, %.lr.ph37.preheader ], [ %13, %.lr.ph37.prol ]
  %15 = sub i64 %spec.select, %.022.lcssa
  %16 = icmp ugt i64 %15, -4
  br i1 %16, label %._crit_edge38, label %.lr.ph37

._crit_edge38:                                    ; preds = %.lr.ph37.prol.loopexit, %.lr.ph37, %4
  %.020.lcssa = phi i64 [ %8, %4 ], [ %.lcssa52.unr, %.lr.ph37.prol.loopexit ], [ %19, %.lr.ph37 ]
  %17 = srem i64 %.020.lcssa, 10
  %18 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %17)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #3
  ret i32 0

.lr.ph37:                                         ; preds = %.lr.ph37.prol.loopexit, %.lr.ph37
  %.035 = phi i64 [ %20, %.lr.ph37 ], [ %.035.unr, %.lr.ph37.prol.loopexit ]
  %.02034 = phi i64 [ %19, %.lr.ph37 ], [ %.02034.unr, %.lr.ph37.prol.loopexit ]
  %19 = sdiv i64 %.02034, 10000
  %20 = add nsw i64 %.035, 4
  %exitcond.not.3 = icmp eq i64 %20, %.022.lcssa
  br i1 %exitcond.not.3, label %._crit_edge38, label %.lr.ph37, !llvm.loop !11

.lr.ph:                                           ; preds = %0, %.lr.ph
  %21 = phi i64 [ %27, %.lr.ph ], [ 9, %0 ]
  %.02130 = phi i64 [ %26, %.lr.ph ], [ 9, %0 ]
  %.02229 = phi i64 [ %24, %.lr.ph ], [ 1, %0 ]
  %.02328 = phi i64 [ %25, %.lr.ph ], [ 1, %0 ]
  %22 = phi i64 [ %23, %.lr.ph ], [ %.promoted, %0 ]
  %23 = sub nsw i64 %22, %21
  %24 = add nuw nsw i64 %.02229, 1
  %25 = mul nuw nsw i64 %.02328, 10
  %26 = mul nuw nsw i64 %.02130, 10
  %27 = mul nuw nsw i64 %26, %24
  %.not = icmp sgt i64 %23, %27
  br i1 %.not, label %.lr.ph, label %._crit_edge, !llvm.loop !13
}

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

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

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

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

attributes #0 = { mustprogress nofree norecurse 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.unroll.disable"}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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