; LLVM IR from Shah-Shishir/Codeforces-Solutions :: 1272C. Yet Another Broken Keyboard (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 [200005 x i8], align 16
@ch = external dso_local global [5 x i8], align 1
@.str = external hidden unnamed_addr constant [13 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca [26 x i32], align 16
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  br label %9

9:                                                ; preds = %55, %0
  %10 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2, ptr noundef %5, ptr noundef @str)
  %11 = icmp ne i32 %10, -1
  br i1 %11, label %12, label %58

12:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 104, ptr %8) #4
  call void @llvm.memset.p0.i64(ptr align 16 %8, i8 0, i64 104, i1 false)
  store i64 0, ptr %3, align 8, !tbaa !5
  br label %13

13:                                               ; preds = %24, %12
  %14 = load i64, ptr %3, align 8, !tbaa !5
  %15 = load i64, ptr %5, align 8, !tbaa !5
  %16 = icmp slt i64 %14, %15
  br i1 %16, label %17, label %27

17:                                               ; preds = %13
  %18 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.2, ptr noundef @ch)
  %19 = load i8, ptr @ch, align 1, !tbaa !9
  %20 = sext i8 %19 to i32
  %21 = sub nsw i32 %20, 97
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [26 x i32], ptr %8, i64 0, i64 %22
  store i32 1, ptr %23, align 4, !tbaa !10
  br label %24

24:                                               ; preds = %17
  %25 = load i64, ptr %3, align 8, !tbaa !5
  %26 = add nsw i64 %25, 1
  store i64 %26, ptr %3, align 8, !tbaa !5
  br label %13, !llvm.loop !12

27:                                               ; preds = %13
  store i64 0, ptr %4, align 8, !tbaa !5
  store i64 -1, ptr %7, align 8, !tbaa !5
  store i64 0, ptr %3, align 8, !tbaa !5
  br label %28

28:                                               ; preds = %52, %27
  %29 = load i64, ptr %3, align 8, !tbaa !5
  %30 = load i64, ptr %2, align 8, !tbaa !5
  %31 = icmp slt i64 %29, %30
  br i1 %31, label %32, label %55

32:                                               ; preds = %28
  %33 = load i64, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds [200005 x i8], ptr @str, i64 0, i64 %33
  %35 = load i8, ptr %34, align 1, !tbaa !9
  %36 = sext i8 %35 to i32
  %37 = sub nsw i32 %36, 97
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [26 x i32], ptr %8, i64 0, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !10
  %41 = icmp ne i32 %40, 0
  br i1 %41, label %42, label %49

42:                                               ; preds = %32
  %43 = load i64, ptr %3, align 8, !tbaa !5
  %44 = load i64, ptr %7, align 8, !tbaa !5
  %45 = sub nsw i64 %43, %44
  store i64 %45, ptr %6, align 8, !tbaa !5
  %46 = load i64, ptr %6, align 8, !tbaa !5
  %47 = load i64, ptr %4, align 8, !tbaa !5
  %48 = add nsw i64 %47, %46
  store i64 %48, ptr %4, align 8, !tbaa !5
  br label %51

49:                                               ; preds = %32
  %50 = load i64, ptr %3, align 8, !tbaa !5
  store i64 %50, ptr %7, align 8, !tbaa !5
  br label %51

51:                                               ; preds = %49, %42
  br label %52

52:                                               ; preds = %51
  %53 = load i64, ptr %3, align 8, !tbaa !5
  %54 = add nsw i64 %53, 1
  store i64 %54, ptr %3, align 8, !tbaa !5
  br label %28, !llvm.loop !14

55:                                               ; preds = %28
  %56 = load i64, ptr %4, align 8, !tbaa !5
  %57 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i64 noundef %56)
  call void @llvm.lifetime.end.p0(i64 104, ptr %8) #4
  br label %9, !llvm.loop !15

58:                                               ; preds = %9
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 8, 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: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}
!15 = distinct !{!15, !13}


; 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 [200005 x i8], align 16
@ch = external dso_local global [5 x i8], align 1
@.str = external hidden unnamed_addr constant [13 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i64, align 8
  %2 = alloca i64, align 8
  %3 = alloca [26 x i32], align 16
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #4
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1, ptr noundef nonnull %2, ptr noundef nonnull @str)
  %.not21 = icmp eq i32 %4, -1
  br i1 %.not21, label %._crit_edge24, label %.lr.ph23

.lr.ph23:                                         ; preds = %0, %._crit_edge
  call void @llvm.lifetime.start.p0(i64 104, ptr nonnull %3) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(104) %3, i8 0, i64 104, i1 false)
  %5 = load i64, ptr %2, align 8, !tbaa !5
  %6 = icmp sgt i64 %5, 0
  br i1 %6, label %.lr.ph, label %.preheader

.preheader:                                       ; preds = %.lr.ph, %.lr.ph23
  %7 = load i64, ptr %1, align 8, !tbaa !5
  %8 = icmp sgt i64 %7, 0
  br i1 %8, label %.lr.ph20.preheader, label %._crit_edge

.lr.ph20.preheader:                               ; preds = %.preheader
  %xtraiter = and i64 %7, 1
  %9 = icmp eq i64 %7, 1
  br i1 %9, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph20.preheader.new

.lr.ph20.preheader.new:                           ; preds = %.lr.ph20.preheader
  %unroll_iter = and i64 %7, 9223372036854775806
  br label %.lr.ph20

.lr.ph:                                           ; preds = %.lr.ph23, %.lr.ph
  %.01116 = phi i64 [ %15, %.lr.ph ], [ 0, %.lr.ph23 ]
  %10 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.2, ptr noundef nonnull @ch)
  %11 = load i8, ptr @ch, align 1, !tbaa !9
  %12 = sext i8 %11 to i64
  %13 = add nsw i64 %12, -97
  %14 = getelementptr inbounds [26 x i32], ptr %3, i64 0, i64 %13
  store i32 1, ptr %14, align 4, !tbaa !10
  %15 = add nuw nsw i64 %.01116, 1
  %16 = load i64, ptr %2, align 8, !tbaa !5
  %17 = icmp slt i64 %15, %16
  br i1 %17, label %.lr.ph, label %.preheader, !llvm.loop !12

.lr.ph20:                                         ; preds = %.lr.ph20, %.lr.ph20.preheader.new
  %.019 = phi i64 [ -1, %.lr.ph20.preheader.new ], [ %.1.1, %.lr.ph20 ]
  %.11218 = phi i64 [ 0, %.lr.ph20.preheader.new ], [ %35, %.lr.ph20 ]
  %.01317 = phi i64 [ 0, %.lr.ph20.preheader.new ], [ %.114.1, %.lr.ph20 ]
  %niter = phi i64 [ 0, %.lr.ph20.preheader.new ], [ %niter.next.1, %.lr.ph20 ]
  %18 = getelementptr inbounds [200005 x i8], ptr @str, i64 0, i64 %.11218
  %19 = load i8, ptr %18, align 2, !tbaa !9
  %20 = sext i8 %19 to i64
  %21 = add nsw i64 %20, -97
  %22 = getelementptr inbounds [26 x i32], ptr %3, i64 0, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !10
  %.not15 = icmp eq i32 %23, 0
  %24 = sub nsw i64 %.11218, %.019
  %25 = select i1 %.not15, i64 0, i64 %24
  %.114 = add nsw i64 %25, %.01317
  %.1 = select i1 %.not15, i64 %.11218, i64 %.019
  %26 = or disjoint i64 %.11218, 1
  %27 = getelementptr inbounds [200005 x i8], ptr @str, i64 0, i64 %26
  %28 = load i8, ptr %27, align 1, !tbaa !9
  %29 = sext i8 %28 to i64
  %30 = add nsw i64 %29, -97
  %31 = getelementptr inbounds [26 x i32], ptr %3, i64 0, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !10
  %.not15.1 = icmp eq i32 %32, 0
  %33 = sub nsw i64 %26, %.1
  %34 = select i1 %.not15.1, i64 0, i64 %33
  %.114.1 = add nsw i64 %34, %.114
  %.1.1 = select i1 %.not15.1, i64 %26, i64 %.1
  %35 = add nuw nsw i64 %.11218, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph20, !llvm.loop !14

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.lr.ph20, %.lr.ph20.preheader
  %.114.lcssa.ph = phi i64 [ poison, %.lr.ph20.preheader ], [ %.114.1, %.lr.ph20 ]
  %.019.unr = phi i64 [ -1, %.lr.ph20.preheader ], [ %.1.1, %.lr.ph20 ]
  %.11218.unr = phi i64 [ 0, %.lr.ph20.preheader ], [ %35, %.lr.ph20 ]
  %.01317.unr = phi i64 [ 0, %.lr.ph20.preheader ], [ %.114.1, %.lr.ph20 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph20.epil

.lr.ph20.epil:                                    ; preds = %._crit_edge.loopexit.unr-lcssa
  %36 = getelementptr inbounds [200005 x i8], ptr @str, i64 0, i64 %.11218.unr
  %37 = load i8, ptr %36, align 1, !tbaa !9
  %38 = sext i8 %37 to i64
  %39 = add nsw i64 %38, -97
  %40 = getelementptr inbounds [26 x i32], ptr %3, i64 0, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !10
  %.not15.epil = icmp eq i32 %41, 0
  %42 = sub nsw i64 %.11218.unr, %.019.unr
  %43 = select i1 %.not15.epil, i64 0, i64 %42
  %.114.epil = add nsw i64 %43, %.01317.unr
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph20.epil, %._crit_edge.loopexit.unr-lcssa, %.preheader
  %.013.lcssa = phi i64 [ 0, %.preheader ], [ %.114.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %.114.epil, %.lr.ph20.epil ]
  %44 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i64 noundef %.013.lcssa)
  call void @llvm.lifetime.end.p0(i64 104, ptr nonnull %3) #4
  %45 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1, ptr noundef nonnull %2, ptr noundef nonnull @str)
  %.not = icmp eq i32 %45, -1
  br i1 %.not, label %._crit_edge24, label %.lr.ph23, !llvm.loop !15

._crit_edge24:                                    ; preds = %._crit_edge, %0
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #4
  call void @llvm.lifetime.end.p0(i64 8, 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 nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}
!15 = distinct !{!15, !13}


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