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

; 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
@cnt = external dso_local global i32, align 4
@a = external dso_local global [101 x i32], align 16
@str = external dso_local global [101 x i8], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.3 = 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
  store i32 0, ptr %1, align 4
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef getelementptr inbounds (i8, ptr @str, i64 1))
  store i8 87, ptr @str, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 0, ptr %2, align 4, !tbaa !8
  br label %5

5:                                                ; preds = %62, %0
  %6 = load i32, ptr %2, align 4, !tbaa !8
  %7 = load i32, ptr @n, align 4, !tbaa !8
  %8 = icmp sle i32 %6, %7
  br i1 %8, label %10, label %9

9:                                                ; preds = %5
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  br label %65

10:                                               ; preds = %5
  br label %11

11:                                               ; preds = %25, %10
  %12 = load i32, ptr %2, align 4, !tbaa !8
  %13 = load i32, ptr @n, align 4, !tbaa !8
  %14 = icmp sle i32 %12, %13
  br i1 %14, label %15, label %22

15:                                               ; preds = %11
  %16 = load i32, ptr %2, align 4, !tbaa !8
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [101 x i8], ptr @str, i64 0, i64 %17
  %19 = load i8, ptr %18, align 1, !tbaa !5
  %20 = sext i8 %19 to i32
  %21 = icmp eq i32 %20, 87
  br label %22

22:                                               ; preds = %15, %11
  %23 = phi i1 [ false, %11 ], [ %21, %15 ]
  br i1 %23, label %24, label %28

24:                                               ; preds = %22
  br label %25

25:                                               ; preds = %24
  %26 = load i32, ptr %2, align 4, !tbaa !8
  %27 = add nsw i32 %26, 1
  store i32 %27, ptr %2, align 4, !tbaa !8
  br label %11, !llvm.loop !10

28:                                               ; preds = %22
  %29 = load i32, ptr %2, align 4, !tbaa !8
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [101 x i8], ptr @str, i64 0, i64 %30
  %32 = load i8, ptr %31, align 1, !tbaa !5
  %33 = sext i8 %32 to i32
  %34 = icmp eq i32 %33, 66
  br i1 %34, label %35, label %61

35:                                               ; preds = %28
  %36 = load i32, ptr @cnt, align 4, !tbaa !8
  %37 = add nsw i32 %36, 1
  store i32 %37, ptr @cnt, align 4, !tbaa !8
  br label %38

38:                                               ; preds = %52, %35
  %39 = load i32, ptr %2, align 4, !tbaa !8
  %40 = load i32, ptr @n, align 4, !tbaa !8
  %41 = icmp sle i32 %39, %40
  br i1 %41, label %42, label %49

42:                                               ; preds = %38
  %43 = load i32, ptr %2, align 4, !tbaa !8
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [101 x i8], ptr @str, i64 0, i64 %44
  %46 = load i8, ptr %45, align 1, !tbaa !5
  %47 = sext i8 %46 to i32
  %48 = icmp eq i32 %47, 66
  br label %49

49:                                               ; preds = %42, %38
  %50 = phi i1 [ false, %38 ], [ %48, %42 ]
  br i1 %50, label %51, label %60

51:                                               ; preds = %49
  br label %52

52:                                               ; preds = %51
  %53 = load i32, ptr %2, align 4, !tbaa !8
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %2, align 4, !tbaa !8
  %55 = load i32, ptr @cnt, align 4, !tbaa !8
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [101 x i32], ptr @a, i64 0, i64 %56
  %58 = load i32, ptr %57, align 4, !tbaa !8
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %57, align 4, !tbaa !8
  br label %38, !llvm.loop !12

60:                                               ; preds = %49
  br label %61

61:                                               ; preds = %60, %28
  br label %62

62:                                               ; preds = %61
  %63 = load i32, ptr %2, align 4, !tbaa !8
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr %2, align 4, !tbaa !8
  br label %5, !llvm.loop !13

65:                                               ; preds = %9
  %66 = load i32, ptr @cnt, align 4, !tbaa !8
  %67 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %66)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 1, ptr %3, align 4, !tbaa !8
  br label %68

68:                                               ; preds = %86, %65
  %69 = load i32, ptr %3, align 4, !tbaa !8
  %70 = load i32, ptr @cnt, align 4, !tbaa !8
  %71 = icmp sle i32 %69, %70
  br i1 %71, label %73, label %72

72:                                               ; preds = %68
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %89

73:                                               ; preds = %68
  %74 = load i32, ptr %3, align 4, !tbaa !8
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds [101 x i32], ptr @a, i64 0, i64 %75
  %77 = load i32, ptr %76, align 4, !tbaa !8
  %78 = load i32, ptr %3, align 4, !tbaa !8
  %79 = load i32, ptr @cnt, align 4, !tbaa !8
  %80 = icmp eq i32 %78, %79
  %81 = zext i1 %80 to i64
  %82 = getelementptr inbounds [3 x i8], ptr @.str.3, i64 0, i64 %81
  %83 = load i8, ptr %82, align 1, !tbaa !5
  %84 = sext i8 %83 to i32
  %85 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %77, i32 noundef %84)
  br label %86

86:                                               ; preds = %73
  %87 = load i32, ptr %3, align 4, !tbaa !8
  %88 = add nsw i32 %87, 1
  store i32 %88, ptr %3, align 4, !tbaa !8
  br label %68, !llvm.loop !14

89:                                               ; preds = %72
  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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2

declare i32 @printf(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 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !6, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}
!13 = distinct !{!13, !11}
!14 = distinct !{!14, !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"

@n = external dso_local global i32, align 4
@cnt = external dso_local local_unnamed_addr global i32, align 4
@a = external dso_local local_unnamed_addr global [101 x i32], align 16
@str = external dso_local global [101 x i8], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.3 = 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, ptr noundef nonnull getelementptr inbounds (i8, ptr @str, i64 1))
  store i8 87, ptr @str, align 16, !tbaa !5
  %2 = load i32, ptr @n, align 4, !tbaa !8
  %cnt.promoted = load i32, ptr @cnt, align 4, !tbaa !8
  %.not25 = icmp slt i32 %2, 0
  br i1 %.not25, label %._crit_edge, label %.preheader.preheader

.preheader.preheader:                             ; preds = %0
  %3 = zext nneg i32 %2 to i64
  %4 = add nuw i32 %2, 1
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %.critedge2
  %.01526 = phi i32 [ %34, %.critedge2 ], [ 0, %.preheader.preheader ]
  %5 = phi i32 [ %33, %.critedge2 ], [ %cnt.promoted, %.preheader.preheader ]
  %6 = sext i32 %.01526 to i64
  %smax = tail call i32 @llvm.smax.i32(i32 %.01526, i32 %2)
  %7 = add nuw i32 %smax, 1
  br label %11

._crit_edge:                                      ; preds = %.critedge2, %0
  %8 = phi i32 [ %cnt.promoted, %0 ], [ %33, %.critedge2 ]
  %9 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %8)
  %10 = load i32, ptr @cnt, align 4, !tbaa !8
  %.not1727 = icmp slt i32 %10, 1
  br i1 %.not1727, label %._crit_edge31, label %.lr.ph30

11:                                               ; preds = %.preheader, %15
  %indvars.iv = phi i64 [ %6, %.preheader ], [ %indvars.iv.next, %15 ]
  %12 = getelementptr inbounds [101 x i8], ptr @str, i64 0, i64 %indvars.iv
  %13 = load i8, ptr %12, align 1, !tbaa !5
  %14 = icmp eq i8 %13, 87
  br i1 %14, label %15, label %.critedge.split.loop.exit39

15:                                               ; preds = %11
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %.not18.not = icmp slt i64 %indvars.iv, %3
  br i1 %.not18.not, label %11, label %.critedge, !llvm.loop !10

.critedge.split.loop.exit39:                      ; preds = %11
  %16 = trunc nsw i64 %indvars.iv to i32
  br label %.critedge

.critedge:                                        ; preds = %15, %.critedge.split.loop.exit39
  %.1.lcssa = phi i32 [ %16, %.critedge.split.loop.exit39 ], [ %7, %15 ]
  %17 = sext i32 %.1.lcssa to i64
  %18 = getelementptr inbounds [101 x i8], ptr @str, i64 0, i64 %17
  %19 = load i8, ptr %18, align 1, !tbaa !5
  %20 = icmp eq i8 %19, 66
  br i1 %20, label %21, label %.critedge2

21:                                               ; preds = %.critedge
  %22 = add nsw i32 %5, 1
  store i32 %22, ptr @cnt, align 4, !tbaa !8
  %.not1921 = icmp sgt i32 %.1.lcssa, %2
  br i1 %.not1921, label %.critedge2, label %.lr.ph

.lr.ph:                                           ; preds = %21
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [101 x i32], ptr @a, i64 0, i64 %23
  br label %25

25:                                               ; preds = %.lr.ph, %29
  %indvars.iv33 = phi i64 [ %17, %.lr.ph ], [ %indvars.iv.next34, %29 ]
  %26 = getelementptr inbounds [101 x i8], ptr @str, i64 0, i64 %indvars.iv33
  %27 = load i8, ptr %26, align 1, !tbaa !5
  %28 = icmp eq i8 %27, 66
  br i1 %28, label %29, label %.critedge2.loopexit.split.loop.exit41

29:                                               ; preds = %25
  %indvars.iv.next34 = add nsw i64 %indvars.iv33, 1
  %30 = load i32, ptr %24, align 4, !tbaa !8
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr %24, align 4, !tbaa !8
  %.not19.not = icmp slt i64 %indvars.iv33, %3
  br i1 %.not19.not, label %25, label %.critedge2, !llvm.loop !12

.critedge2.loopexit.split.loop.exit41:            ; preds = %25
  %32 = trunc nsw i64 %indvars.iv33 to i32
  br label %.critedge2

.critedge2:                                       ; preds = %29, %.critedge2.loopexit.split.loop.exit41, %21, %.critedge
  %33 = phi i32 [ %5, %.critedge ], [ %22, %21 ], [ %22, %.critedge2.loopexit.split.loop.exit41 ], [ %22, %29 ]
  %.3 = phi i32 [ %.1.lcssa, %.critedge ], [ %.1.lcssa, %21 ], [ %32, %.critedge2.loopexit.split.loop.exit41 ], [ %4, %29 ]
  %34 = add nsw i32 %.3, 1
  %.not.not = icmp slt i32 %.3, %2
  br i1 %.not.not, label %.preheader, label %._crit_edge, !llvm.loop !13

._crit_edge31:                                    ; preds = %.lr.ph30, %._crit_edge
  ret i32 0

.lr.ph30:                                         ; preds = %._crit_edge, %.lr.ph30
  %indvars.iv36 = phi i64 [ %indvars.iv.next37, %.lr.ph30 ], [ 1, %._crit_edge ]
  %35 = phi i32 [ %45, %.lr.ph30 ], [ %10, %._crit_edge ]
  %36 = getelementptr inbounds [101 x i32], ptr @a, i64 0, i64 %indvars.iv36
  %37 = load i32, ptr %36, align 4, !tbaa !8
  %38 = zext i32 %35 to i64
  %39 = icmp eq i64 %indvars.iv36, %38
  %40 = zext i1 %39 to i64
  %41 = getelementptr inbounds [3 x i8], ptr @.str.3, i64 0, i64 %40
  %42 = load i8, ptr %41, align 1, !tbaa !5
  %43 = sext i8 %42 to i32
  %44 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %37, i32 noundef %43)
  %indvars.iv.next37 = add nuw nsw i64 %indvars.iv36, 1
  %45 = load i32, ptr @cnt, align 4, !tbaa !8
  %46 = sext i32 %45 to i64
  %.not17.not = icmp slt i64 %indvars.iv36, %46
  br i1 %.not17.not, label %.lr.ph30, label %._crit_edge31, !llvm.loop !14
}

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #2

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !6, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}
!13 = distinct !{!13, !11}
!14 = distinct !{!14, !11}


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