; LLVM IR from tangjz/acm-icpc :: 51nod/1188.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: 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 [20 x i32], align 16
  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
  call void @llvm.lifetime.start.p0(i64 80, ptr %4) #3
  br label %5

5:                                                ; preds = %16, %1
  %6 = load i64, ptr %2, align 8, !tbaa !5
  %7 = icmp ne i64 %6, 0
  br i1 %7, label %8, label %19

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

16:                                               ; preds = %8
  %17 = load i64, ptr %2, align 8, !tbaa !5
  %18 = sdiv i64 %17, 10
  store i64 %18, ptr %2, align 8, !tbaa !5
  br label %5, !llvm.loop !11

19:                                               ; preds = %5
  %20 = load i32, ptr %3, align 4, !tbaa !9
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %27, label %22

22:                                               ; preds = %19
  %23 = load i32, ptr %3, align 4, !tbaa !9
  %24 = add nsw i32 %23, 1
  store i32 %24, ptr %3, align 4, !tbaa !9
  %25 = sext i32 %23 to i64
  %26 = getelementptr inbounds [20 x i32], ptr %4, i64 0, i64 %25
  store i32 0, ptr %26, align 4, !tbaa !9
  br label %27

27:                                               ; preds = %22, %19
  br label %28

28:                                               ; preds = %31, %27
  %29 = load i32, ptr %3, align 4, !tbaa !9
  %30 = icmp ne i32 %29, 0
  br i1 %30, label %31, label %39

31:                                               ; preds = %28
  %32 = load i32, ptr %3, align 4, !tbaa !9
  %33 = add nsw i32 %32, -1
  store i32 %33, ptr %3, align 4, !tbaa !9
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [20 x i32], ptr %4, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !9
  %37 = add nsw i32 48, %36
  %38 = call i32 @putchar(i32 noundef %37)
  br label %28, !llvm.loop !13

39:                                               ; preds = %28
  %40 = call i32 @putchar(i32 noundef 10)
  call void @llvm.lifetime.end.p0(i64 80, ptr %4) #3
  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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: mustprogress nofree nounwind uwtable
define dso_local void @_Z5printx(i64 noundef %0) local_unnamed_addr #1 {
  %2 = alloca [20 x i32], align 16
  call void @llvm.lifetime.start.p0(i64 80, ptr nonnull %2) #3
  %.not11 = icmp eq i64 %0, 0
  br i1 %.not11, label %._crit_edge.thread, label %.lr.ph

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

._crit_edge:                                      ; preds = %.lr.ph
  %7 = shl i64 %indvars.iv.next, 32
  %8 = ashr exact i64 %7, 32
  br label %.preheader

._crit_edge.thread:                               ; preds = %1
  store i32 0, ptr %2, align 16, !tbaa !5
  br label %.preheader

.preheader:                                       ; preds = %._crit_edge, %._crit_edge.thread
  %indvars.iv16.ph = phi i64 [ 1, %._crit_edge.thread ], [ %8, %._crit_edge ]
  br label %9

9:                                                ; preds = %.preheader, %9
  %indvars.iv16 = phi i64 [ %indvars.iv.next17, %9 ], [ %indvars.iv16.ph, %.preheader ]
  %indvars.iv.next17 = add nsw i64 %indvars.iv16, -1
  %10 = getelementptr inbounds [20 x i32], ptr %2, i64 0, i64 %indvars.iv.next17
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = add nsw i32 %11, 48
  %13 = tail call i32 @putchar(i32 noundef %12)
  %.not10 = icmp eq i64 %indvars.iv.next17, 0
  br i1 %.not10, label %14, label %9, !llvm.loop !11

14:                                               ; preds = %9
  %15 = tail call i32 @putchar(i32 noundef 10)
  call void @llvm.lifetime.end.p0(i64 80, ptr nonnull %2) #3
  ret void
}

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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" }
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}


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