; LLVM IR from lzyrapx/Competitive-Programming :: HDUOJ/5799.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"

@s = external dso_local global [35 x i8], align 16

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

5:                                                ; preds = %16, %1
  %6 = load i64, ptr %2, align 8, !tbaa !5
  %7 = srem i64 %6, 10
  %8 = add nsw i64 %7, 48
  %9 = trunc i64 %8 to i8
  %10 = load i32, ptr %3, align 4, !tbaa !9
  %11 = add nsw i32 %10, 1
  store i32 %11, ptr %3, align 4, !tbaa !9
  %12 = sext i32 %10 to i64
  %13 = getelementptr inbounds [35 x i8], ptr @s, i64 0, i64 %12
  store i8 %9, ptr %13, align 1, !tbaa !11
  %14 = load i64, ptr %2, align 8, !tbaa !5
  %15 = sdiv i64 %14, 10
  store i64 %15, ptr %2, align 8, !tbaa !5
  br label %16

16:                                               ; preds = %5
  %17 = load i64, ptr %2, align 8, !tbaa !5
  %18 = icmp ne i64 %17, 0
  br i1 %18, label %5, label %19, !llvm.loop !12

19:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %20 = load i32, ptr %3, align 4, !tbaa !9
  %21 = sub nsw i32 %20, 1
  store i32 %21, ptr %4, align 4, !tbaa !9
  br label %22

22:                                               ; preds = %33, %19
  %23 = load i32, ptr %4, align 4, !tbaa !9
  %24 = icmp sge i32 %23, 0
  br i1 %24, label %26, label %25

25:                                               ; preds = %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %36

26:                                               ; preds = %22
  %27 = load i32, ptr %4, align 4, !tbaa !9
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [35 x i8], ptr @s, i64 0, i64 %28
  %30 = load i8, ptr %29, align 1, !tbaa !11
  %31 = sext i8 %30 to i32
  %32 = call i32 @putchar(i32 noundef %31)
  br label %33

33:                                               ; preds = %26
  %34 = load i32, ptr %4, align 4, !tbaa !9
  %35 = add nsw i32 %34, -1
  store i32 %35, ptr %4, align 4, !tbaa !9
  br label %22, !llvm.loop !14

36:                                               ; preds = %25
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret void
}

; Function Attrs: inlinehint mustprogress uwtable
declare i32 @putchar(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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


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

@s = external dso_local local_unnamed_addr global [35 x i8], align 16

; Function Attrs: mustprogress nofree nounwind uwtable
define dso_local void @_Z5printx(i64 noundef %0) local_unnamed_addr #0 {
  br label %2

2:                                                ; preds = %2, %1
  %indvars.iv = phi i64 [ %indvars.iv.next, %2 ], [ 0, %1 ]
  %.09 = phi i64 [ %7, %2 ], [ %0, %1 ]
  %3 = srem i64 %.09, 10
  %4 = trunc nsw i64 %3 to i8
  %5 = add nsw i8 %4, 48
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %6 = getelementptr inbounds [35 x i8], ptr @s, i64 0, i64 %indvars.iv
  store i8 %5, ptr %6, align 1, !tbaa !5
  %7 = sdiv i64 %.09, 10
  %.09.off = add i64 %.09, 9
  %.not = icmp ult i64 %.09.off, 19
  br i1 %.not, label %.lr.ph, label %2, !llvm.loop !8

._crit_edge:                                      ; preds = %.lr.ph
  ret void

.lr.ph:                                           ; preds = %2, %.lr.ph
  %indvars.iv12 = phi i64 [ %indvars.iv.next13, %.lr.ph ], [ %indvars.iv, %2 ]
  %8 = getelementptr inbounds [35 x i8], ptr @s, i64 0, i64 %indvars.iv12
  %9 = load i8, ptr %8, align 1, !tbaa !5
  %10 = sext i8 %9 to i32
  %11 = tail call i32 @putchar(i32 noundef %10)
  %indvars.iv.next13 = add nsw i64 %indvars.iv12, -1
  %12 = icmp sgt i64 %indvars.iv12, 0
  br i1 %12, label %.lr.ph, label %._crit_edge, !llvm.loop !10
}

; Function Attrs: inlinehint mustprogress nofree nounwind uwtable
declare noundef i32 @putchar(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 = !{!6, !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = distinct !{!10, !9}


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