; LLVM IR from Shah-Shishir/Codeforces-Solutions :: 999C. Alphabetic Removals (main)

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

6:                                                ; preds = %43, %0
  %7 = load i8, ptr %4, align 1, !tbaa !5
  %8 = sext i8 %7 to i32
  %9 = icmp sle i32 %8, 122
  br i1 %9, label %10, label %46

10:                                               ; preds = %6
  %11 = load i32, ptr @k, align 4, !tbaa !8
  %12 = icmp eq i32 %11, 0
  br i1 %12, label %13, label %14

13:                                               ; preds = %10
  br label %46

14:                                               ; preds = %10
  store i32 0, ptr %3, align 4, !tbaa !8
  br label %15

15:                                               ; preds = %39, %14
  %16 = load i32, ptr %3, align 4, !tbaa !8
  %17 = load i32, ptr %2, align 4, !tbaa !8
  %18 = icmp slt i32 %16, %17
  br i1 %18, label %19, label %42

19:                                               ; preds = %15
  %20 = load i32, ptr @k, align 4, !tbaa !8
  %21 = icmp eq i32 %20, 0
  br i1 %21, label %22, label %23

22:                                               ; preds = %19
  br label %42

23:                                               ; preds = %19
  %24 = load i32, ptr %3, align 4, !tbaa !8
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [400001 x i8], ptr @str, i64 0, i64 %25
  %27 = load i8, ptr %26, align 1, !tbaa !5
  %28 = sext i8 %27 to i32
  %29 = load i8, ptr %4, align 1, !tbaa !5
  %30 = sext i8 %29 to i32
  %31 = icmp eq i32 %28, %30
  br i1 %31, label %32, label %38

32:                                               ; preds = %23
  %33 = load i32, ptr %3, align 4, !tbaa !8
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [400001 x i8], ptr @str, i64 0, i64 %34
  store i8 32, ptr %35, align 1, !tbaa !5
  %36 = load i32, ptr @k, align 4, !tbaa !8
  %37 = add nsw i32 %36, -1
  store i32 %37, ptr @k, align 4, !tbaa !8
  br label %38

38:                                               ; preds = %32, %23
  br label %39

39:                                               ; preds = %38
  %40 = load i32, ptr %3, align 4, !tbaa !8
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr %3, align 4, !tbaa !8
  br label %15, !llvm.loop !10

42:                                               ; preds = %22, %15
  br label %43

43:                                               ; preds = %42
  %44 = load i8, ptr %4, align 1, !tbaa !5
  %45 = add i8 %44, 1
  store i8 %45, ptr %4, align 1, !tbaa !5
  br label %6, !llvm.loop !12

46:                                               ; preds = %13, %6
  store i32 0, ptr %3, align 4, !tbaa !8
  br label %47

47:                                               ; preds = %67, %46
  %48 = load i32, ptr %3, align 4, !tbaa !8
  %49 = load i32, ptr %2, align 4, !tbaa !8
  %50 = icmp slt i32 %48, %49
  br i1 %50, label %51, label %70

51:                                               ; preds = %47
  %52 = load i32, ptr %3, align 4, !tbaa !8
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [400001 x i8], ptr @str, i64 0, i64 %53
  %55 = load i8, ptr %54, align 1, !tbaa !5
  %56 = sext i8 %55 to i32
  %57 = call i32 @isspace(i32 noundef %56) #5
  %58 = icmp ne i32 %57, 0
  br i1 %58, label %59, label %60

59:                                               ; preds = %51
  br label %67

60:                                               ; preds = %51
  %61 = load i32, ptr %3, align 4, !tbaa !8
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [400001 x i8], ptr @str, i64 0, i64 %62
  %64 = load i8, ptr %63, align 1, !tbaa !5
  %65 = sext i8 %64 to i32
  %66 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %65)
  br label %67

67:                                               ; preds = %60, %59
  %68 = load i32, ptr %3, align 4, !tbaa !8
  %69 = add nsw i32 %68, 1
  store i32 %69, ptr %3, align 4, !tbaa !8
  br label %47, !llvm.loop !13

70:                                               ; preds = %47
  %71 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  ret i32 0
}

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

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

; Function Attrs: nounwind willreturn memory(read)
declare i32 @isspace(i32 noundef) #3

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nounwind willreturn memory(read) "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 }
attributes #5 = { nounwind willreturn memory(read) }

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


; 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 dso_local global [400001 x i8], align 16
@k = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [9 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  %2 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1, ptr noundef nonnull @k, ptr noundef nonnull @str)
  %k.promoted19 = load i32, ptr @k, align 4
  %3 = icmp eq i32 %k.promoted19, 0
  %.pre = load i32, ptr %1, align 4, !tbaa !5
  %.fr29 = freeze i32 %.pre
  br i1 %3, label %.preheader, label %.preheader16.lr.ph

.preheader16.lr.ph:                               ; preds = %0
  %4 = icmp slt i32 %.fr29, 1
  br i1 %4, label %._crit_edge28, label %.preheader16.preheader

.preheader16.preheader:                           ; preds = %.preheader16.lr.ph
  %5 = zext nneg i32 %.fr29 to i64
  br label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %._crit_edge, %.preheader16.preheader
  %.025 = phi i8 [ %17, %._crit_edge ], [ 97, %.preheader16.preheader ]
  %k.promoted2324 = phi i32 [ %k.promoted20, %._crit_edge ], [ %k.promoted19, %.preheader16.preheader ]
  br label %.lr.ph

.preheader:                                       ; preds = %._crit_edge, %0
  %6 = icmp sgt i32 %.fr29, 0
  br i1 %6, label %.lr.ph27, label %._crit_edge28

.lr.ph:                                           ; preds = %.lr.ph.preheader, %13
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %13 ]
  %k.promoted21 = phi i32 [ %k.promoted2324, %.lr.ph.preheader ], [ %k.promoted20, %13 ]
  %7 = phi i32 [ %k.promoted2324, %.lr.ph.preheader ], [ %14, %13 ]
  %8 = getelementptr inbounds [400001 x i8], ptr @str, i64 0, i64 %indvars.iv
  %9 = load i8, ptr %8, align 1, !tbaa !9
  %10 = icmp eq i8 %9, %.025
  br i1 %10, label %11, label %13

11:                                               ; preds = %.lr.ph
  store i8 32, ptr %8, align 1, !tbaa !9
  %12 = add nsw i32 %7, -1
  store i32 %12, ptr @k, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %.lr.ph, %11
  %k.promoted20 = phi i32 [ %k.promoted21, %.lr.ph ], [ %12, %11 ]
  %14 = phi i32 [ %7, %.lr.ph ], [ %12, %11 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %15 = icmp uge i64 %indvars.iv.next, %5
  %16 = icmp eq i32 %14, 0
  %or.cond3 = select i1 %15, i1 true, i1 %16
  br i1 %or.cond3, label %._crit_edge, label %.lr.ph, !llvm.loop !10

._crit_edge:                                      ; preds = %13
  %17 = add nuw nsw i8 %.025, 1
  %18 = icmp ugt i8 %.025, 121
  %19 = icmp eq i32 %k.promoted20, 0
  %or.cond = select i1 %18, i1 true, i1 %19
  br i1 %or.cond, label %.preheader, label %.lr.ph.preheader, !llvm.loop !12

.lr.ph27:                                         ; preds = %.preheader, %27
  %20 = phi i32 [ %28, %27 ], [ %.fr29, %.preheader ]
  %indvars.iv32 = phi i64 [ %indvars.iv.next33, %27 ], [ 0, %.preheader ]
  %21 = getelementptr inbounds [400001 x i8], ptr @str, i64 0, i64 %indvars.iv32
  %22 = load i8, ptr %21, align 1, !tbaa !9
  %23 = sext i8 %22 to i32
  %24 = call i32 @isspace(i32 noundef %23) #5
  %.not = icmp eq i32 %24, 0
  br i1 %.not, label %25, label %27

25:                                               ; preds = %.lr.ph27
  %26 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %23)
  %.pre35 = load i32, ptr %1, align 4, !tbaa !5
  br label %27

27:                                               ; preds = %.lr.ph27, %25
  %28 = phi i32 [ %20, %.lr.ph27 ], [ %.pre35, %25 ]
  %indvars.iv.next33 = add nuw nsw i64 %indvars.iv32, 1
  %29 = sext i32 %28 to i64
  %30 = icmp slt i64 %indvars.iv.next33, %29
  br i1 %30, label %.lr.ph27, label %._crit_edge28, !llvm.loop !13

._crit_edge28:                                    ; preds = %27, %.preheader16.lr.ph, %.preheader
  %31 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #4
  ret i32 0
}

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

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(read)
declare i32 @isspace(i32 noundef) local_unnamed_addr #3

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { mustprogress nofree nounwind willreturn memory(read) "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 }
attributes #5 = { nounwind willreturn memory(read) }

!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}
!13 = distinct !{!13, !11}


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