; LLVM IR from tangjz/acm-icpc :: 51nod (1433)

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

@n = external dso_local global i32, align 4
@x = external dso_local global i32, align 4
@c0 = external dso_local global i32, align 4
@c5 = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  br label %7

7:                                                ; preds = %21, %0
  %8 = load i32, ptr @n, align 4, !tbaa !5
  %9 = add nsw i32 %8, -1
  store i32 %9, ptr @n, align 4, !tbaa !5
  %10 = icmp ne i32 %8, 0
  br i1 %10, label %11, label %23

11:                                               ; preds = %7
  %12 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @x)
  %13 = load i32, ptr @x, align 4, !tbaa !5
  %14 = icmp ne i32 %13, 0
  br i1 %14, label %15, label %18

15:                                               ; preds = %11
  %16 = load i32, ptr @c5, align 4, !tbaa !5
  %17 = add nsw i32 %16, 1
  store i32 %17, ptr @c5, align 4, !tbaa !5
  br label %21

18:                                               ; preds = %11
  %19 = load i32, ptr @c0, align 4, !tbaa !5
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr @c0, align 4, !tbaa !5
  br label %21

21:                                               ; preds = %18, %15
  %22 = phi ptr [ @c5, %15 ], [ @c0, %18 ]
  br label %7, !llvm.loop !9

23:                                               ; preds = %7
  %24 = load i32, ptr @c5, align 4, !tbaa !5
  %25 = icmp sge i32 %24, 9
  br i1 %25, label %26, label %62

26:                                               ; preds = %23
  %27 = load i32, ptr @c0, align 4, !tbaa !5
  %28 = icmp ne i32 %27, 0
  br i1 %28, label %29, label %62

29:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 9, ptr %2, align 4, !tbaa !5
  br label %30

30:                                               ; preds = %46, %29
  %31 = load i32, ptr %2, align 4, !tbaa !5
  %32 = load i32, ptr @c5, align 4, !tbaa !5
  %33 = icmp sle i32 %31, %32
  br i1 %33, label %35, label %34

34:                                               ; preds = %30
  store i32 4, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %49

35:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %36

36:                                               ; preds = %42, %35
  %37 = load i32, ptr %4, align 4, !tbaa !5
  %38 = icmp slt i32 %37, 9
  br i1 %38, label %40, label %39

39:                                               ; preds = %36
  store i32 7, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %45

40:                                               ; preds = %36
  %41 = call i32 @putchar(i32 noundef 53)
  br label %42

42:                                               ; preds = %40
  %43 = load i32, ptr %4, align 4, !tbaa !5
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr %4, align 4, !tbaa !5
  br label %36, !llvm.loop !11

45:                                               ; preds = %39
  br label %46

46:                                               ; preds = %45
  %47 = load i32, ptr %2, align 4, !tbaa !5
  %48 = add nsw i32 %47, 9
  store i32 %48, ptr %2, align 4, !tbaa !5
  br label %30, !llvm.loop !12

49:                                               ; preds = %34
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 1, ptr %5, align 4, !tbaa !5
  br label %50

50:                                               ; preds = %57, %49
  %51 = load i32, ptr %5, align 4, !tbaa !5
  %52 = load i32, ptr @c0, align 4, !tbaa !5
  %53 = icmp sle i32 %51, %52
  br i1 %53, label %55, label %54

54:                                               ; preds = %50
  store i32 10, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %60

55:                                               ; preds = %50
  %56 = call i32 @putchar(i32 noundef 48)
  br label %57

57:                                               ; preds = %55
  %58 = load i32, ptr %5, align 4, !tbaa !5
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %5, align 4, !tbaa !5
  br label %50, !llvm.loop !13

60:                                               ; preds = %54
  %61 = call i32 @putchar(i32 noundef 10)
  br label %70

62:                                               ; preds = %26, %23
  %63 = load i32, ptr @c0, align 4, !tbaa !5
  %64 = icmp ne i32 %63, 0
  br i1 %64, label %65, label %67

65:                                               ; preds = %62
  %66 = call i32 @puts(ptr noundef @.str.1)
  br label %69

67:                                               ; preds = %62
  %68 = call i32 @puts(ptr noundef @.str.2)
  br label %69

69:                                               ; preds = %67, %65
  br label %70

70:                                               ; preds = %69, %60
  ret i32 0
}

declare i32 @__isoc99_scanf(ptr noundef, ...) #1

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

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

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

declare i32 @puts(ptr noundef) #1

attributes #0 = { mustprogress norecurse 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 = { "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"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}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !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"

@n = external dso_local global i32, align 4
@x = external dso_local global i32, align 4
@c0 = external dso_local local_unnamed_addr global i32, align 4
@c5 = external dso_local local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %3 = add nsw i32 %2, -1
  store i32 %3, ptr @n, align 4, !tbaa !5
  %.not14 = icmp eq i32 %2, 0
  br i1 %.not14, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %0, %.lr.ph
  %4 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @x)
  %5 = load i32, ptr @x, align 4, !tbaa !5
  %.not11 = icmp eq i32 %5, 0
  %c0.c5 = select i1 %.not11, ptr @c0, ptr @c5
  %6 = load i32, ptr %c0.c5, align 4, !tbaa !5
  %7 = add nsw i32 %6, 1
  store i32 %7, ptr %c0.c5, align 4, !tbaa !5
  %8 = load i32, ptr @n, align 4, !tbaa !5
  %9 = add nsw i32 %8, -1
  store i32 %9, ptr @n, align 4, !tbaa !5
  %.not = icmp eq i32 %8, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %0
  %10 = load i32, ptr @c5, align 4, !tbaa !5
  %11 = icmp sgt i32 %10, 8
  %12 = load i32, ptr @c0, align 4
  %13 = icmp ne i32 %12, 0
  %or.cond = select i1 %11, i1 %13, i1 false
  br i1 %or.cond, label %.preheader12, label %29

.preheader12:                                     ; preds = %._crit_edge, %.preheader12
  %.0817 = phi i32 [ %23, %.preheader12 ], [ 9, %._crit_edge ]
  %14 = tail call i32 @putchar(i32 noundef 53)
  %15 = tail call i32 @putchar(i32 noundef 53)
  %16 = tail call i32 @putchar(i32 noundef 53)
  %17 = tail call i32 @putchar(i32 noundef 53)
  %18 = tail call i32 @putchar(i32 noundef 53)
  %19 = tail call i32 @putchar(i32 noundef 53)
  %20 = tail call i32 @putchar(i32 noundef 53)
  %21 = tail call i32 @putchar(i32 noundef 53)
  %22 = tail call i32 @putchar(i32 noundef 53)
  %23 = add nuw nsw i32 %.0817, 9
  %24 = load i32, ptr @c5, align 4, !tbaa !5
  %.not9 = icmp sgt i32 %23, %24
  br i1 %.not9, label %.preheader, label %.preheader12, !llvm.loop !11

.preheader:                                       ; preds = %.preheader12
  %.pre = load i32, ptr @c0, align 4, !tbaa !5
  %.not1018 = icmp slt i32 %.pre, 1
  br i1 %.not1018, label %._crit_edge21, label %.lr.ph20

._crit_edge21:                                    ; preds = %.lr.ph20, %.preheader
  %25 = tail call i32 @putchar(i32 noundef 10)
  br label %34

.lr.ph20:                                         ; preds = %.preheader, %.lr.ph20
  %.019 = phi i32 [ %27, %.lr.ph20 ], [ 1, %.preheader ]
  %26 = tail call i32 @putchar(i32 noundef 48)
  %27 = add nuw nsw i32 %.019, 1
  %28 = load i32, ptr @c0, align 4, !tbaa !5
  %.not10.not = icmp slt i32 %.019, %28
  br i1 %.not10.not, label %.lr.ph20, label %._crit_edge21, !llvm.loop !12

29:                                               ; preds = %._crit_edge
  br i1 %13, label %30, label %32

30:                                               ; preds = %29
  %31 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.1)
  br label %34

32:                                               ; preds = %29
  %33 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.2)
  br label %34

34:                                               ; preds = %30, %32, %._crit_edge21
  ret i32 0
}

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

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

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

attributes #0 = { mustprogress nofree norecurse 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 = { 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 #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" }

!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}
!12 = distinct !{!12, !10}


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