; LLVM IR from tangjz/acm-icpc :: lydsy/1103.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"

@_ZZ5printiE3len = external hidden global i32, align 4
@_ZZ5printiE3num = external hidden global [6 x i32], align 16

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

3:                                                ; preds = %13, %1
  %4 = load i32, ptr %2, align 4, !tbaa !5
  %5 = icmp ne i32 %4, 0
  br i1 %5, label %6, label %16

6:                                                ; preds = %3
  %7 = load i32, ptr %2, align 4, !tbaa !5
  %8 = srem i32 %7, 10
  %9 = load i32, ptr @_ZZ5printiE3len, align 4, !tbaa !5
  %10 = add nsw i32 %9, 1
  store i32 %10, ptr @_ZZ5printiE3len, align 4, !tbaa !5
  %11 = sext i32 %9 to i64
  %12 = getelementptr inbounds [6 x i32], ptr @_ZZ5printiE3num, i64 0, i64 %11
  store i32 %8, ptr %12, align 4, !tbaa !5
  br label %13

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

16:                                               ; preds = %3
  %17 = load i32, ptr @_ZZ5printiE3len, align 4, !tbaa !5
  %18 = icmp ne i32 %17, 0
  br i1 %18, label %24, label %19

19:                                               ; preds = %16
  %20 = load i32, ptr @_ZZ5printiE3len, align 4, !tbaa !5
  %21 = add nsw i32 %20, 1
  store i32 %21, ptr @_ZZ5printiE3len, align 4, !tbaa !5
  %22 = sext i32 %20 to i64
  %23 = getelementptr inbounds [6 x i32], ptr @_ZZ5printiE3num, i64 0, i64 %22
  store i32 0, ptr %23, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %19, %16
  br label %25

25:                                               ; preds = %28, %24
  %26 = load i32, ptr @_ZZ5printiE3len, align 4, !tbaa !5
  %27 = icmp ne i32 %26, 0
  br i1 %27, label %28, label %36

28:                                               ; preds = %25
  %29 = load i32, ptr @_ZZ5printiE3len, align 4, !tbaa !5
  %30 = add nsw i32 %29, -1
  store i32 %30, ptr @_ZZ5printiE3len, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [6 x i32], ptr @_ZZ5printiE3num, i64 0, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = add nsw i32 48, %33
  %35 = call i32 @putchar(i32 noundef %34)
  br label %25, !llvm.loop !11

36:                                               ; preds = %25
  %37 = call i32 @putchar(i32 noundef 10)
  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"

@_ZZ5printiE3len = external hidden local_unnamed_addr global i32, align 4
@_ZZ5printiE3num = external hidden local_unnamed_addr global [6 x i32], align 16

; Function Attrs: mustprogress nofree nounwind uwtable
define dso_local void @_Z5printi(i32 noundef %0) local_unnamed_addr #0 {
  %.not7 = icmp eq i32 %0, 0
  br i1 %.not7, label %.thread, label %.lr.ph

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

5:                                                ; preds = %.lr.ph
  %6 = trunc nuw i64 %indvars.iv.next to i32
  br label %.lr.ph11.preheader

.thread:                                          ; preds = %1
  store i32 0, ptr @_ZZ5printiE3num, align 16, !tbaa !5
  br label %.lr.ph11.preheader

.lr.ph11.preheader:                               ; preds = %5, %.thread
  %.ph = phi i32 [ %6, %5 ], [ 1, %.thread ]
  br label %.lr.ph11

.lr.ph11:                                         ; preds = %.lr.ph11.preheader, %.lr.ph11
  %7 = phi i32 [ %14, %.lr.ph11 ], [ %.ph, %.lr.ph11.preheader ]
  %8 = add nsw i32 %7, -1
  store i32 %8, ptr @_ZZ5printiE3len, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [6 x i32], ptr @_ZZ5printiE3num, i64 0, i64 %9
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = add nsw i32 %11, 48
  %13 = tail call i32 @putchar(i32 noundef %12)
  %14 = load i32, ptr @_ZZ5printiE3len, align 4, !tbaa !5
  %.not6 = icmp eq i32 %14, 0
  br i1 %.not6, label %._crit_edge12, label %.lr.ph11, !llvm.loop !11

._crit_edge12:                                    ; preds = %.lr.ph11
  %15 = tail call i32 @putchar(i32 noundef 10)
  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,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass