; LLVM IR from tangjz/acm-icpc :: codeforces (887A)

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

@i = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@buf = external dso_local global [111 x i8], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

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

3:                                                ; preds = %19, %0
  %4 = load i32, ptr @i, align 4, !tbaa !5
  %5 = sext i32 %4 to i64
  %6 = getelementptr inbounds [111 x i8], ptr @buf, i64 0, i64 %5
  %7 = load i8, ptr %6, align 1, !tbaa !9
  %8 = icmp ne i8 %7, 0
  br i1 %8, label %9, label %16

9:                                                ; preds = %3
  %10 = load i32, ptr @i, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [111 x i8], ptr @buf, i64 0, i64 %11
  %13 = load i8, ptr %12, align 1, !tbaa !9
  %14 = sext i8 %13 to i32
  %15 = icmp ne i32 %14, 49
  br label %16

16:                                               ; preds = %9, %3
  %17 = phi i1 [ false, %3 ], [ %15, %9 ]
  br i1 %17, label %18, label %22

18:                                               ; preds = %16
  br label %19

19:                                               ; preds = %18
  %20 = load i32, ptr @i, align 4, !tbaa !5
  %21 = add nsw i32 %20, 1
  store i32 %21, ptr @i, align 4, !tbaa !5
  br label %3, !llvm.loop !10

22:                                               ; preds = %16
  br label %23

23:                                               ; preds = %30, %22
  %24 = load i32, ptr @i, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [111 x i8], ptr @buf, i64 0, i64 %25
  %27 = load i8, ptr %26, align 1, !tbaa !9
  %28 = icmp ne i8 %27, 0
  br i1 %28, label %29, label %41

29:                                               ; preds = %23
  br label %30

30:                                               ; preds = %29
  %31 = load i32, ptr @i, align 4, !tbaa !5
  %32 = add nsw i32 %31, 1
  store i32 %32, ptr @i, align 4, !tbaa !5
  %33 = sext i32 %31 to i64
  %34 = getelementptr inbounds [111 x i8], ptr @buf, i64 0, i64 %33
  %35 = load i8, ptr %34, align 1, !tbaa !9
  %36 = sext i8 %35 to i32
  %37 = icmp eq i32 %36, 48
  %38 = zext i1 %37 to i32
  %39 = load i32, ptr @n, align 4, !tbaa !5
  %40 = add nsw i32 %39, %38
  store i32 %40, ptr @n, align 4, !tbaa !5
  br label %23, !llvm.loop !12

41:                                               ; preds = %23
  %42 = load i32, ptr @n, align 4, !tbaa !5
  %43 = icmp slt i32 %42, 6
  %44 = zext i1 %43 to i64
  %45 = select i1 %43, ptr @.str.1, ptr @.str.2
  %46 = call i32 @puts(ptr noundef %45)
  ret i32 0
}

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

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

!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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}


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

@i = external dso_local local_unnamed_addr global i32, align 4
@n = external dso_local local_unnamed_addr global i32, align 4
@buf = external dso_local global [111 x i8], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 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 @buf)
  %i.promoted = load i32, ptr @i, align 4, !tbaa !5
  %2 = sext i32 %i.promoted to i64
  br label %3

3:                                                ; preds = %6, %0
  %i.promoted3 = phi i32 [ %7, %6 ], [ %i.promoted, %0 ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %6 ], [ %2, %0 ]
  %4 = getelementptr inbounds [111 x i8], ptr @buf, i64 0, i64 %indvars.iv
  %5 = load i8, ptr %4, align 1, !tbaa !9
  switch i8 %5, label %6 [
    i8 0, label %.critedge
    i8 49, label %.critedge
  ]

6:                                                ; preds = %3
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %7 = trunc nsw i64 %indvars.iv.next to i32
  store i32 %7, ptr @i, align 4, !tbaa !5
  br label %3, !llvm.loop !10

.critedge:                                        ; preds = %3, %3
  %n.promoted = load i32, ptr @n, align 4, !tbaa !5
  %8 = sext i32 %i.promoted3 to i64
  %9 = getelementptr inbounds [111 x i8], ptr @buf, i64 0, i64 %8
  %10 = load i8, ptr %9, align 1, !tbaa !9
  %.not24 = icmp eq i8 %10, 0
  br i1 %.not24, label %19, label %.lr.ph

.lr.ph:                                           ; preds = %.critedge, %.lr.ph
  %indvars.iv8 = phi i64 [ %indvars.iv.next9, %.lr.ph ], [ %8, %.critedge ]
  %11 = phi i8 [ %17, %.lr.ph ], [ %10, %.critedge ]
  %12 = phi i32 [ %15, %.lr.ph ], [ %n.promoted, %.critedge ]
  %indvars.iv.next9 = add nsw i64 %indvars.iv8, 1
  %13 = icmp eq i8 %11, 48
  %14 = zext i1 %13 to i32
  %15 = add nsw i32 %12, %14
  %16 = getelementptr inbounds [111 x i8], ptr @buf, i64 0, i64 %indvars.iv.next9
  %17 = load i8, ptr %16, align 1, !tbaa !9
  %.not2 = icmp eq i8 %17, 0
  br i1 %.not2, label %._crit_edge, label %.lr.ph, !llvm.loop !12

._crit_edge:                                      ; preds = %.lr.ph
  %18 = trunc nsw i64 %indvars.iv.next9 to i32
  store i32 %18, ptr @i, align 4, !tbaa !5
  store i32 %15, ptr @n, align 4, !tbaa !5
  br label %19

19:                                               ; preds = %._crit_edge, %.critedge
  %20 = phi i32 [ %15, %._crit_edge ], [ %n.promoted, %.critedge ]
  %21 = icmp slt i32 %20, 6
  %22 = select i1 %21, ptr @.str.1, ptr @.str.2
  %23 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) %22)
  ret i32 0
}

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

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

!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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}


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