; LLVM IR from tangjz/acm-icpc :: codeforces/complete (5C)

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

@ch = external dso_local global i32, align 4
@f = external dso_local global [1000010 x i32], align 16
@top = external dso_local global i32, align 4
@ans = external dso_local global i32, align 4
@cnt = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [7 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
  br label %2

2:                                                ; preds = %71, %0
  %3 = call i32 @getchar()
  store i32 %3, ptr @ch, align 4, !tbaa !5
  %4 = icmp ne i32 %3, -1
  br i1 %4, label %5, label %8

5:                                                ; preds = %2
  %6 = load i32, ptr @ch, align 4, !tbaa !5
  %7 = icmp sge i32 %6, 40
  br label %8

8:                                                ; preds = %5, %2
  %9 = phi i1 [ false, %2 ], [ %7, %5 ]
  br i1 %9, label %10, label %72

10:                                               ; preds = %8
  %11 = load i32, ptr @ch, align 4, !tbaa !5
  %12 = icmp eq i32 %11, 40
  br i1 %12, label %13, label %23

13:                                               ; preds = %10
  %14 = load i32, ptr @top, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [1000010 x i32], ptr @f, i64 0, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = add nsw i32 %17, 1
  store i32 %18, ptr %16, align 4, !tbaa !5
  %19 = load i32, ptr @top, align 4, !tbaa !5
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr @top, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [1000010 x i32], ptr @f, i64 0, i64 %21
  store i32 0, ptr %22, align 4, !tbaa !5
  br label %45

23:                                               ; preds = %10
  %24 = load i32, ptr @top, align 4, !tbaa !5
  %25 = icmp ne i32 %24, 0
  br i1 %25, label %26, label %40

26:                                               ; preds = %23
  %27 = load i32, ptr @top, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [1000010 x i32], ptr @f, i64 0, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = add nsw i32 %30, 1
  %32 = load i32, ptr @top, align 4, !tbaa !5
  %33 = sub nsw i32 %32, 1
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [1000010 x i32], ptr @f, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = add nsw i32 %36, %31
  store i32 %37, ptr %35, align 4, !tbaa !5
  %38 = load i32, ptr @top, align 4, !tbaa !5
  %39 = add nsw i32 %38, -1
  store i32 %39, ptr @top, align 4, !tbaa !5
  br label %44

40:                                               ; preds = %23
  %41 = load i32, ptr @top, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [1000010 x i32], ptr @f, i64 0, i64 %42
  store i32 0, ptr %43, align 4, !tbaa !5
  br label %44

44:                                               ; preds = %40, %26
  br label %45

45:                                               ; preds = %44, %13
  %46 = load i32, ptr @ans, align 4, !tbaa !5
  %47 = load i32, ptr @top, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [1000010 x i32], ptr @f, i64 0, i64 %48
  %50 = load i32, ptr %49, align 4, !tbaa !5
  %51 = icmp slt i32 %46, %50
  br i1 %51, label %52, label %57

52:                                               ; preds = %45
  %53 = load i32, ptr @top, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [1000010 x i32], ptr @f, i64 0, i64 %54
  %56 = load i32, ptr %55, align 4, !tbaa !5
  store i32 %56, ptr @ans, align 4, !tbaa !5
  store i32 1, ptr @cnt, align 4, !tbaa !5
  br label %71

57:                                               ; preds = %45
  %58 = load i32, ptr @ans, align 4, !tbaa !5
  %59 = icmp ne i32 %58, 0
  br i1 %59, label %60, label %70

60:                                               ; preds = %57
  %61 = load i32, ptr @ans, align 4, !tbaa !5
  %62 = load i32, ptr @top, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [1000010 x i32], ptr @f, i64 0, i64 %63
  %65 = load i32, ptr %64, align 4, !tbaa !5
  %66 = icmp eq i32 %61, %65
  br i1 %66, label %67, label %70

67:                                               ; preds = %60
  %68 = load i32, ptr @cnt, align 4, !tbaa !5
  %69 = add nsw i32 %68, 1
  store i32 %69, ptr @cnt, align 4, !tbaa !5
  br label %70

70:                                               ; preds = %67, %60, %57
  br label %71

71:                                               ; preds = %70, %52
  br label %2, !llvm.loop !9

72:                                               ; preds = %8
  %73 = load i32, ptr @ans, align 4, !tbaa !5
  %74 = load i32, ptr @cnt, align 4, !tbaa !5
  %75 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %73, i32 noundef %74)
  ret i32 0
}

; Function Attrs: inlinehint mustprogress uwtable
declare i32 @getchar() #1

declare i32 @printf(ptr noundef, ...) #2

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

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


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

@ch = external dso_local local_unnamed_addr global i32, align 4
@f = external dso_local local_unnamed_addr global [1000010 x i32], align 16
@top = external dso_local local_unnamed_addr global i32, align 4
@ans = external dso_local local_unnamed_addr global i32, align 4
@cnt = external dso_local local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [7 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 @getchar()
  store i32 %1, ptr @ch, align 4, !tbaa !5
  %2 = icmp sgt i32 %1, 39
  br i1 %2, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %0, %36
  %3 = phi i32 [ %37, %36 ], [ %1, %0 ]
  %4 = icmp eq i32 %3, 40
  %5 = load i32, ptr @top, align 4, !tbaa !5
  br i1 %4, label %6, label %14

6:                                                ; preds = %.lr.ph
  %7 = sext i32 %5 to i64
  %8 = getelementptr inbounds [1000010 x i32], ptr @f, i64 0, i64 %7
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %10 = add nsw i32 %9, 1
  store i32 %10, ptr %8, align 4, !tbaa !5
  %11 = add nsw i32 %5, 1
  store i32 %11, ptr @top, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [1000010 x i32], ptr @f, i64 0, i64 %12
  store i32 0, ptr %13, align 4, !tbaa !5
  br label %26

14:                                               ; preds = %.lr.ph
  %.not = icmp eq i32 %5, 0
  br i1 %.not, label %25, label %15

15:                                               ; preds = %14
  %16 = sext i32 %5 to i64
  %17 = getelementptr inbounds [1000010 x i32], ptr @f, i64 0, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %19 = add nsw i32 %18, 1
  %20 = add nsw i32 %5, -1
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [1000010 x i32], ptr @f, i64 0, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = add nsw i32 %19, %23
  store i32 %24, ptr %22, align 4, !tbaa !5
  store i32 %20, ptr @top, align 4, !tbaa !5
  br label %26

25:                                               ; preds = %14
  store i32 0, ptr @f, align 16, !tbaa !5
  br label %26

26:                                               ; preds = %15, %25, %6
  %27 = phi i32 [ %24, %15 ], [ 0, %25 ], [ 0, %6 ]
  %28 = load i32, ptr @ans, align 4, !tbaa !5
  %29 = icmp slt i32 %28, %27
  br i1 %29, label %30, label %31

30:                                               ; preds = %26
  store i32 %27, ptr @ans, align 4, !tbaa !5
  br label %.sink.split

31:                                               ; preds = %26
  %.not5 = icmp ne i32 %28, 0
  %32 = icmp eq i32 %28, %27
  %or.cond = and i1 %.not5, %32
  br i1 %or.cond, label %33, label %36

33:                                               ; preds = %31
  %34 = load i32, ptr @cnt, align 4, !tbaa !5
  %35 = add nsw i32 %34, 1
  br label %.sink.split

.sink.split:                                      ; preds = %30, %33
  %.sink = phi i32 [ %35, %33 ], [ 1, %30 ]
  store i32 %.sink, ptr @cnt, align 4, !tbaa !5
  br label %36

36:                                               ; preds = %.sink.split, %31
  %37 = tail call i32 @getchar()
  store i32 %37, ptr @ch, align 4, !tbaa !5
  %38 = icmp sgt i32 %37, 39
  br i1 %38, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %36, %0
  %39 = load i32, ptr @ans, align 4, !tbaa !5
  %40 = load i32, ptr @cnt, align 4, !tbaa !5
  %41 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %39, i32 noundef %40)
  ret i32 0
}

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

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #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 = { 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 #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" }

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


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass