; LLVM IR from tangjz/acm-icpc :: 51nod/1381.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"

@.str = external hidden unnamed_addr constant [2 x i8], align 1

; 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 [18 x i32], align 16
  store i64 %0, ptr %2, align 8, !tbaa !5
  %5 = load i64, ptr %2, align 8, !tbaa !5
  %6 = icmp ne i64 %5, 0
  br i1 %6, label %9, label %7

7:                                                ; preds = %1
  %8 = call i32 @puts(ptr noundef @.str)
  br label %37

9:                                                ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 0, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 72, ptr %4) #4
  br label %10

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

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

23:                                               ; preds = %10
  br label %24

24:                                               ; preds = %27, %23
  %25 = load i32, ptr %3, align 4, !tbaa !9
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %27, label %35

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

35:                                               ; preds = %24
  %36 = call i32 @putchar(i32 noundef 10)
  call void @llvm.lifetime.end.p0(i64 72, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %37

37:                                               ; preds = %35, %7
  ret void
}

declare i32 @puts(ptr noundef) #2

; Function Attrs: inlinehint mustprogress uwtable
declare i32 @putchar(i32 noundef) #3

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 = { "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 = { 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 #4 = { 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"

@.str = external hidden unnamed_addr constant [2 x i8], align 1

; 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 [18 x i32], align 16
  %.not = icmp eq i64 %0, 0
  br i1 %.not, label %3, label %5

3:                                                ; preds = %1
  %4 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str)
  br label %18

5:                                                ; preds = %1
  call void @llvm.lifetime.start.p0(i64 72, ptr nonnull %2) #4
  br label %6

6:                                                ; preds = %5, %6
  %indvars.iv15 = phi i32 [ 1, %5 ], [ %indvars.iv.next16, %6 ]
  %indvars.iv = phi i64 [ 0, %5 ], [ %indvars.iv.next, %6 ]
  %.0711 = phi i64 [ %0, %5 ], [ %10, %6 ]
  %7 = srem i64 %.0711, 10
  %8 = trunc nsw i64 %7 to i32
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %9 = getelementptr inbounds [18 x i32], ptr %2, i64 0, i64 %indvars.iv
  store i32 %8, ptr %9, align 4, !tbaa !5
  %10 = sdiv i64 %.0711, 10
  %.0711.off = add i64 %.0711, 9
  %.not9 = icmp ult i64 %.0711.off, 19
  %indvars.iv.next16 = add nuw i32 %indvars.iv15, 1
  br i1 %.not9, label %.preheader.preheader, label %6, !llvm.loop !9

.preheader.preheader:                             ; preds = %6
  %11 = sext i32 %indvars.iv15 to i64
  br label %.preheader

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

16:                                               ; preds = %.preheader
  %17 = tail call i32 @putchar(i32 noundef 10)
  call void @llvm.lifetime.end.p0(i64 72, ptr nonnull %2) #4
  br label %18

18:                                               ; preds = %16, %3
  ret void
}

; Function Attrs: nofree nounwind
declare noundef i32 @puts(ptr nocapture noundef readonly) local_unnamed_addr #2

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

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 = { nofree nounwind "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 = { 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 #4 = { 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,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass