; LLVM IR from DionysiosB/CodeForces :: 1000-1099 (1060B-MaximumSumOfDigits)

; 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 [5 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 i64, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  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
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2)
  %8 = load i64, ptr %2, align 8, !tbaa !5
  store i64 %8, ptr %3, align 8, !tbaa !5
  br label %9

9:                                                ; preds = %13, %0
  %10 = load i64, ptr %4, align 8, !tbaa !5
  %11 = load i64, ptr %3, align 8, !tbaa !5
  %12 = icmp sle i64 %10, %11
  br i1 %12, label %13, label %16

13:                                               ; preds = %9
  %14 = load i64, ptr %4, align 8, !tbaa !5
  %15 = mul nsw i64 %14, 10
  store i64 %15, ptr %4, align 8, !tbaa !5
  br label %9, !llvm.loop !9

16:                                               ; preds = %9
  %17 = load i64, ptr %4, align 8, !tbaa !5
  %18 = sdiv i64 %17, 10
  store i64 %18, ptr %4, align 8, !tbaa !5
  %19 = load i64, ptr %4, align 8, !tbaa !5
  %20 = sub nsw i64 %19, 1
  store i64 %20, ptr %4, align 8, !tbaa !5
  %21 = load i64, ptr %2, align 8, !tbaa !5
  %22 = load i64, ptr %4, align 8, !tbaa !5
  %23 = sub nsw i64 %21, %22
  store i64 %23, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store i64 0, ptr %6, align 8, !tbaa !11
  br label %24

24:                                               ; preds = %27, %16
  %25 = load i64, ptr %4, align 8, !tbaa !5
  %26 = icmp sgt i64 %25, 0
  br i1 %26, label %27, label %34

27:                                               ; preds = %24
  %28 = load i64, ptr %4, align 8, !tbaa !5
  %29 = srem i64 %28, 10
  %30 = load i64, ptr %6, align 8, !tbaa !11
  %31 = add nsw i64 %30, %29
  store i64 %31, ptr %6, align 8, !tbaa !11
  %32 = load i64, ptr %4, align 8, !tbaa !5
  %33 = sdiv i64 %32, 10
  store i64 %33, ptr %4, align 8, !tbaa !5
  br label %24, !llvm.loop !13

34:                                               ; preds = %24
  br label %35

35:                                               ; preds = %38, %34
  %36 = load i64, ptr %5, align 8, !tbaa !5
  %37 = icmp sgt i64 %36, 0
  br i1 %37, label %38, label %45

38:                                               ; preds = %35
  %39 = load i64, ptr %5, align 8, !tbaa !5
  %40 = srem i64 %39, 10
  %41 = load i64, ptr %6, align 8, !tbaa !11
  %42 = add nsw i64 %41, %40
  store i64 %42, ptr %6, align 8, !tbaa !11
  %43 = load i64, ptr %5, align 8, !tbaa !5
  %44 = sdiv i64 %43, 10
  store i64 %44, ptr %5, align 8, !tbaa !5
  br label %35, !llvm.loop !14

45:                                               ; preds = %35
  %46 = load i64, ptr %6, align 8, !tbaa !11
  %47 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %46)
  call void @llvm.lifetime.end.p0(i64 8, 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

declare i32 @printf(ptr noundef, ...) #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 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !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"

@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 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)
  %3 = load i64, ptr %1, align 8, !tbaa !5
  %.not18 = icmp slt i64 %3, 1
  br i1 %.not18, label %._crit_edge.thread, label %.lr.ph

._crit_edge.thread:                               ; preds = %0
  %4 = add nsw i64 %3, 1
  br label %.preheader

.lr.ph:                                           ; preds = %0, %.lr.ph
  %.01619 = phi i64 [ %5, %.lr.ph ], [ 1, %0 ]
  %5 = mul nuw nsw i64 %.01619, 10
  %.not = icmp sgt i64 %5, %3
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph
  %6 = add nsw i64 %.01619, -1
  %7 = sub nsw i64 %3, %6
  %8 = icmp ugt i64 %.01619, 1
  br i1 %8, label %.lr.ph23, label %.preheader

.preheader:                                       ; preds = %.lr.ph23, %._crit_edge.thread, %._crit_edge
  %9 = phi i64 [ %7, %._crit_edge ], [ %4, %._crit_edge.thread ], [ %7, %.lr.ph23 ]
  %.0.lcssa = phi i64 [ 0, %._crit_edge ], [ 0, %._crit_edge.thread ], [ %12, %.lr.ph23 ]
  %10 = icmp sgt i64 %9, 0
  br i1 %10, label %.lr.ph27, label %._crit_edge28

.lr.ph23:                                         ; preds = %._crit_edge, %.lr.ph23
  %.021 = phi i64 [ %12, %.lr.ph23 ], [ 0, %._crit_edge ]
  %.11720 = phi i64 [ %13, %.lr.ph23 ], [ %6, %._crit_edge ]
  %11 = urem i64 %.11720, 10
  %12 = add nuw nsw i64 %.021, %11
  %13 = udiv i64 %.11720, 10
  %.not30 = icmp ult i64 %.11720, 10
  br i1 %.not30, label %.preheader, label %.lr.ph23, !llvm.loop !11

.lr.ph27:                                         ; preds = %.preheader, %.lr.ph27
  %.126 = phi i64 [ %15, %.lr.ph27 ], [ %.0.lcssa, %.preheader ]
  %.01525 = phi i64 [ %16, %.lr.ph27 ], [ %9, %.preheader ]
  %14 = urem i64 %.01525, 10
  %15 = add nuw nsw i64 %.126, %14
  %16 = udiv i64 %.01525, 10
  %.not31 = icmp ult i64 %.01525, 10
  br i1 %.not31, label %._crit_edge28, label %.lr.ph27, !llvm.loop !12

._crit_edge28:                                    ; preds = %.lr.ph27, %.preheader
  %.1.lcssa = phi i64 [ %.0.lcssa, %.preheader ], [ %15, %.lr.ph27 ]
  %17 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %.1.lcssa)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #3
  ret i32 0
}

; 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: nofree nounwind
declare noundef i32 @printf(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

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.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}


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