; LLVM IR from tangjz/acm-icpc :: lydsy/1669.ll (Z8PrintInti)

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

@p = external dso_local global i32, align 4
@buf = external dso_local global [10 x i32], align 16

; Function Attrs: mustprogress uwtable
define dso_local void @_Z8PrintInti(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  %3 = load i32, ptr %2, align 4, !tbaa !5
  %4 = icmp ne i32 %3, 0
  br i1 %4, label %8, label %5

5:                                                ; preds = %1
  %6 = load i32, ptr @p, align 4, !tbaa !5
  %7 = add nsw i32 %6, 1
  store i32 %7, ptr @p, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %5, %1
  br label %9

9:                                                ; preds = %12, %8
  %10 = load i32, ptr %2, align 4, !tbaa !5
  %11 = icmp ne i32 %10, 0
  br i1 %11, label %12, label %21

12:                                               ; preds = %9
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = srem i32 %13, 10
  %15 = load i32, ptr @p, align 4, !tbaa !5
  %16 = add nsw i32 %15, 1
  store i32 %16, ptr @p, align 4, !tbaa !5
  %17 = sext i32 %15 to i64
  %18 = getelementptr inbounds [10 x i32], ptr @buf, i64 0, i64 %17
  store i32 %14, ptr %18, align 4, !tbaa !5
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = sdiv i32 %19, 10
  store i32 %20, ptr %2, align 4, !tbaa !5
  br label %9, !llvm.loop !9

21:                                               ; preds = %9
  br label %22

22:                                               ; preds = %26, %21
  %23 = load i32, ptr @p, align 4, !tbaa !5
  %24 = add nsw i32 %23, -1
  store i32 %24, ptr @p, align 4, !tbaa !5
  %25 = icmp ne i32 %23, 0
  br i1 %25, label %26, label %33

26:                                               ; preds = %22
  %27 = load i32, ptr @p, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [10 x i32], ptr @buf, i64 0, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = add nsw i32 48, %30
  %32 = call i32 @putchar(i32 noundef %31)
  br label %22, !llvm.loop !11

33:                                               ; preds = %22
  ret void
}

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

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

@p = external dso_local local_unnamed_addr global i32, align 4
@buf = external dso_local local_unnamed_addr global [10 x i32], align 16

; Function Attrs: mustprogress nofree nounwind uwtable
define dso_local void @_Z8PrintInti(i32 noundef %0) local_unnamed_addr #0 {
  %.not = icmp eq i32 %0, 0
  %2 = load i32, ptr @p, align 4, !tbaa !5
  br i1 %.not, label %.thread, label %.lr.ph.preheader

.thread:                                          ; preds = %1
  %3 = add nsw i32 %2, 1
  br label %.preheader

.lr.ph.preheader:                                 ; preds = %1
  %4 = sext i32 %2 to i64
  br label %.lr.ph

..preheader_crit_edge:                            ; preds = %.lr.ph
  %5 = trunc nsw i64 %indvars.iv.next to i32
  br label %.preheader

.preheader:                                       ; preds = %.thread, %..preheader_crit_edge
  %6 = phi i32 [ %5, %..preheader_crit_edge ], [ %3, %.thread ]
  %7 = add nsw i32 %6, -1
  store i32 %7, ptr @p, align 4, !tbaa !5
  %.not58 = icmp eq i32 %6, 0
  br i1 %.not58, label %._crit_edge, label %.lr.ph9

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ %4, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %.07 = phi i32 [ %0, %.lr.ph.preheader ], [ %10, %.lr.ph ]
  %8 = srem i32 %.07, 10
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %9 = getelementptr inbounds [10 x i32], ptr @buf, i64 0, i64 %indvars.iv
  store i32 %8, ptr %9, align 4, !tbaa !5
  %10 = sdiv i32 %.07, 10
  %.07.off = add i32 %.07, 9
  %.not4 = icmp ult i32 %.07.off, 19
  br i1 %.not4, label %..preheader_crit_edge, label %.lr.ph, !llvm.loop !9

.lr.ph9:                                          ; preds = %.preheader, %.lr.ph9
  %11 = phi i32 [ %18, %.lr.ph9 ], [ %7, %.preheader ]
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [10 x i32], ptr @buf, i64 0, i64 %12
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %15 = add nsw i32 %14, 48
  %16 = tail call i32 @putchar(i32 noundef %15)
  %17 = load i32, ptr @p, align 4, !tbaa !5
  %18 = add nsw i32 %17, -1
  store i32 %18, ptr @p, align 4, !tbaa !5
  %.not5 = icmp eq i32 %17, 0
  br i1 %.not5, label %._crit_edge, label %.lr.ph9, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph9, %.preheader
  ret void
}

; 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 = !{!"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}


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