; LLVM IR from eyangch/competitive-programming :: CSES/Sorting_and_Searching/missing_coin_sum.ll (Z5printx)

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

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

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

11:                                               ; preds = %6
  br label %15

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

15:                                               ; preds = %11
  br label %16

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

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

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare i32 @putchar_unlocked(i32 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 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 = { 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 = !{!"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 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !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 @_Z5printx(i64 noundef %0) local_unnamed_addr #0 {
  %2 = icmp sgt i64 %0, 99999999999999999
  br i1 %2, label %.lr.ph14.preheader, label %.lr.ph

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

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

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

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

._crit_edge:                                      ; preds = %.lr.ph14, %.preheader
  %13 = tail call i32 @putchar_unlocked(i32 noundef 10)
  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