; LLVM IR from eyangch/competitive-programming :: CSES/Additional_Problems/network_breakdown_fast.ll (Z5printi)

; 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: 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
define dso_local void @_Z5printi(i32 noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 100000, ptr %3, align 4, !tbaa !5
  br label %5

5:                                                ; preds = %12, %1
  br label %6

6:                                                ; preds = %5
  %7 = load i32, ptr %2, align 4, !tbaa !5
  %8 = load i32, ptr %3, align 4, !tbaa !5
  %9 = sdiv i32 %7, %8
  %10 = icmp sgt i32 %9, 0
  br i1 %10, label %11, label %12

11:                                               ; preds = %6
  br label %15

12:                                               ; preds = %6
  %13 = load i32, ptr %3, align 4, !tbaa !5
  %14 = sdiv i32 %13, 10
  store i32 %14, ptr %3, align 4, !tbaa !5
  br label %5, !llvm.loop !9

15:                                               ; preds = %11
  br label %16

16:                                               ; preds = %19, %15
  %17 = load i32, ptr %3, align 4, !tbaa !5
  %18 = icmp sgt i32 %17, 0
  br i1 %18, label %19, label %31

19:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %20 = load i32, ptr %2, align 4, !tbaa !5
  %21 = load i32, ptr %3, align 4, !tbaa !5
  %22 = sdiv i32 %20, %21
  store i32 %22, ptr %4, align 4, !tbaa !5
  %23 = load i32, ptr %3, align 4, !tbaa !5
  %24 = load i32, ptr %2, align 4, !tbaa !5
  %25 = srem i32 %24, %23
  store i32 %25, ptr %2, align 4, !tbaa !5
  %26 = load i32, ptr %3, align 4, !tbaa !5
  %27 = sdiv i32 %26, 10
  store i32 %27, ptr %3, align 4, !tbaa !5
  %28 = load i32, ptr %4, align 4, !tbaa !5
  %29 = add nsw i32 %28, 48
  %30 = call i32 @putchar_unlocked(i32 noundef %29)
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %16, !llvm.loop !11

31:                                               ; preds = %16
  %32 = call i32 @putchar_unlocked(i32 noundef 32)
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret void
}

; Function Attrs: inlinehint mustprogress uwtable
declare i32 @putchar_unlocked(i32 noundef) #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 = { inlinehint 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 #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 = !{!"int", !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}


; 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 nounwind uwtable
define dso_local void @_Z5printi(i32 noundef %0) local_unnamed_addr #0 {
  %2 = icmp sgt i32 %0, 99999
  br i1 %2, label %.lr.ph14.preheader, label %.lr.ph

.preheader:                                       ; preds = %.lr.ph
  %3 = icmp sgt i32 %.01011, 9
  br i1 %3, label %.lr.ph14.preheader, label %._crit_edge

.lr.ph14.preheader:                               ; preds = %1, %.preheader
  %.112.ph = phi i32 [ %4, %.preheader ], [ 100000, %1 ]
  br label %.lr.ph14

.lr.ph:                                           ; preds = %1, %.lr.ph
  %.01011 = phi i32 [ %4, %.lr.ph ], [ 100000, %1 ]
  %4 = sdiv i32 %.01011, 10
  %5 = sdiv i32 %0, %4
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %.preheader, label %.lr.ph, !llvm.loop !5

.lr.ph14:                                         ; preds = %.lr.ph14.preheader, %.lr.ph14
  %.013 = phi i32 [ %8, %.lr.ph14 ], [ %0, %.lr.ph14.preheader ]
  %.112 = phi i32 [ %9, %.lr.ph14 ], [ %.112.ph, %.lr.ph14.preheader ]
  %7 = sdiv i32 %.013, %.112
  %8 = srem i32 %.013, %.112
  %9 = udiv i32 %.112, 10
  %10 = add nsw i32 %7, 48
  %11 = tail call i32 @putchar_unlocked(i32 noundef %10)
  %.not = icmp ult i32 %.112, 10
  br i1 %.not, label %._crit_edge, label %.lr.ph14, !llvm.loop !7

._crit_edge:                                      ; preds = %.lr.ph14, %.preheader
  %12 = tail call i32 @putchar_unlocked(i32 noundef 32)
  ret void
}

; Function Attrs: inlinehint mustprogress nofree nounwind uwtable
declare noundef i32 @putchar_unlocked(i32 noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nofree 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 = { inlinehint mustprogress nofree 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" }

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}


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