; LLVM IR from Shah-Shishir/Codeforces-Solutions :: 978C. Letters (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"

@arr = external dso_local global [200001 x i64], align 16
@.str = external hidden unnamed_addr constant [10 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [11 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 i64, align 8
  %9 = alloca i64, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  br label %10

10:                                               ; preds = %72, %0
  %11 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2, ptr noundef %3)
  %12 = icmp ne i32 %11, -1
  br i1 %12, label %13, label %73

13:                                               ; preds = %10
  %14 = load i64, ptr %2, align 8, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 16 @arr, i8 0, i64 %14, i1 false)
  store i64 0, ptr %4, align 8, !tbaa !5
  br label %15

15:                                               ; preds = %37, %13
  %16 = load i64, ptr %4, align 8, !tbaa !5
  %17 = load i64, ptr %2, align 8, !tbaa !5
  %18 = icmp ult i64 %16, %17
  br i1 %18, label %19, label %40

19:                                               ; preds = %15
  %20 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %8)
  %21 = load i64, ptr %4, align 8, !tbaa !5
  %22 = icmp eq i64 %21, 0
  br i1 %22, label %23, label %27

23:                                               ; preds = %19
  %24 = load i64, ptr %8, align 8, !tbaa !5
  %25 = load i64, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds [200001 x i64], ptr @arr, i64 0, i64 %25
  store i64 %24, ptr %26, align 8, !tbaa !5
  br label %36

27:                                               ; preds = %19
  %28 = load i64, ptr %4, align 8, !tbaa !5
  %29 = sub i64 %28, 1
  %30 = getelementptr inbounds [200001 x i64], ptr @arr, i64 0, i64 %29
  %31 = load i64, ptr %30, align 8, !tbaa !5
  %32 = load i64, ptr %8, align 8, !tbaa !5
  %33 = add i64 %31, %32
  %34 = load i64, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds [200001 x i64], ptr @arr, i64 0, i64 %34
  store i64 %33, ptr %35, align 8, !tbaa !5
  br label %36

36:                                               ; preds = %27, %23
  br label %37

37:                                               ; preds = %36
  %38 = load i64, ptr %4, align 8, !tbaa !5
  %39 = add i64 %38, 1
  store i64 %39, ptr %4, align 8, !tbaa !5
  br label %15, !llvm.loop !9

40:                                               ; preds = %15
  store i64 0, ptr %4, align 8, !tbaa !5
  br label %41

41:                                               ; preds = %69, %40
  %42 = load i64, ptr %4, align 8, !tbaa !5
  %43 = load i64, ptr %3, align 8, !tbaa !5
  %44 = icmp ult i64 %42, %43
  br i1 %44, label %45, label %72

45:                                               ; preds = %41
  %46 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %9)
  %47 = load i64, ptr %2, align 8, !tbaa !5
  %48 = getelementptr inbounds i64, ptr @arr, i64 %47
  %49 = call noundef ptr @_ZSt11lower_boundIPyyET_S1_S1_RKT0_(ptr noundef @arr, ptr noundef %48, ptr noundef nonnull align 8 dereferenceable(8) %9)
  %50 = ptrtoint ptr %49 to i64
  %51 = sub i64 %50, ptrtoint (ptr @arr to i64)
  %52 = sdiv exact i64 %51, 8
  store i64 %52, ptr %6, align 8, !tbaa !5
  %53 = load i64, ptr %6, align 8, !tbaa !5
  %54 = icmp eq i64 %53, 0
  br i1 %54, label %55, label %57

55:                                               ; preds = %45
  %56 = load i64, ptr %9, align 8, !tbaa !5
  store i64 %56, ptr %7, align 8, !tbaa !5
  br label %64

57:                                               ; preds = %45
  %58 = load i64, ptr %9, align 8, !tbaa !5
  %59 = load i64, ptr %6, align 8, !tbaa !5
  %60 = sub i64 %59, 1
  %61 = getelementptr inbounds [200001 x i64], ptr @arr, i64 0, i64 %60
  %62 = load i64, ptr %61, align 8, !tbaa !5
  %63 = sub i64 %58, %62
  store i64 %63, ptr %7, align 8, !tbaa !5
  br label %64

64:                                               ; preds = %57, %55
  %65 = load i64, ptr %6, align 8, !tbaa !5
  %66 = add i64 %65, 1
  %67 = load i64, ptr %7, align 8, !tbaa !5
  %68 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %66, i64 noundef %67)
  br label %69

69:                                               ; preds = %64
  %70 = load i64, ptr %4, align 8, !tbaa !5
  %71 = add i64 %70, 1
  store i64 %71, ptr %4, align 8, !tbaa !5
  br label %41, !llvm.loop !11

72:                                               ; preds = %41
  br label %10, !llvm.loop !12

73:                                               ; preds = %10
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #5
  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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZSt11lower_boundIPyyET_S1_S1_RKT0_(ptr noundef, ptr noundef, ptr noundef nonnull align 8 dereferenceable(8)) #4

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


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

@arr = external dso_local global [200001 x i64], align 16
@.str = external hidden unnamed_addr constant [10 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [11 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i64, align 8
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #5
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1, ptr noundef nonnull %2)
  %.not17 = icmp eq i32 %5, -1
  br i1 %.not17, label %._crit_edge, label %.lr.ph18

.loopexit:                                        ; preds = %38, %.preheader
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1, ptr noundef nonnull %2)
  %.not = icmp eq i32 %6, -1
  br i1 %.not, label %._crit_edge, label %.lr.ph18, !llvm.loop !5

.lr.ph18:                                         ; preds = %0, %.loopexit
  %7 = load i64, ptr %1, align 8, !tbaa !7
  call void @llvm.memset.p0.i64(ptr nonnull align 16 @arr, i8 0, i64 %7, i1 false)
  %.not19 = icmp eq i64 %7, 0
  br i1 %.not19, label %.preheader, label %8

8:                                                ; preds = %.lr.ph18
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %3)
  %10 = load i64, ptr %3, align 8, !tbaa !7
  store i64 %10, ptr @arr, align 16, !tbaa !7
  %11 = load i64, ptr %1, align 8, !tbaa !7
  %12 = icmp ugt i64 %11, 1
  br i1 %12, label %.lr.ph.peel.next, label %.preheader

.preheader:                                       ; preds = %.lr.ph.peel.next, %8, %.lr.ph18
  %13 = load i64, ptr %2, align 8, !tbaa !7
  %.not20 = icmp eq i64 %13, 0
  br i1 %.not20, label %.loopexit, label %.lr.ph16

.lr.ph.peel.next:                                 ; preds = %8, %.lr.ph.peel.next
  %.01214 = phi i64 [ %21, %.lr.ph.peel.next ], [ 1, %8 ]
  %14 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %3)
  %15 = add i64 %.01214, -1
  %16 = getelementptr inbounds [200001 x i64], ptr @arr, i64 0, i64 %15
  %17 = load i64, ptr %16, align 8, !tbaa !7
  %18 = load i64, ptr %3, align 8, !tbaa !7
  %19 = add i64 %18, %17
  %20 = getelementptr inbounds [200001 x i64], ptr @arr, i64 0, i64 %.01214
  store i64 %19, ptr %20, align 8, !tbaa !7
  %21 = add nuw i64 %.01214, 1
  %22 = load i64, ptr %1, align 8, !tbaa !7
  %23 = icmp ult i64 %21, %22
  br i1 %23, label %.lr.ph.peel.next, label %.preheader, !llvm.loop !11

.lr.ph16:                                         ; preds = %.preheader, %38
  %.115 = phi i64 [ %41, %38 ], [ 0, %.preheader ]
  %24 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %4)
  %25 = load i64, ptr %1, align 8, !tbaa !7
  %26 = getelementptr inbounds i64, ptr @arr, i64 %25
  %27 = call noundef ptr @_ZSt11lower_boundIPyyET_S1_S1_RKT0_(ptr noundef nonnull @arr, ptr noundef nonnull %26, ptr noundef nonnull align 8 dereferenceable(8) %4)
  %28 = ptrtoint ptr %27 to i64
  %29 = sub i64 %28, ptrtoint (ptr @arr to i64)
  %30 = ashr exact i64 %29, 3
  %31 = icmp eq ptr %27, @arr
  %32 = load i64, ptr %4, align 8, !tbaa !7
  br i1 %31, label %38, label %33

33:                                               ; preds = %.lr.ph16
  %34 = add nsw i64 %30, -1
  %35 = getelementptr inbounds [200001 x i64], ptr @arr, i64 0, i64 %34
  %36 = load i64, ptr %35, align 8, !tbaa !7
  %37 = sub i64 %32, %36
  br label %38

38:                                               ; preds = %.lr.ph16, %33
  %.0 = phi i64 [ %37, %33 ], [ %32, %.lr.ph16 ]
  %39 = add nsw i64 %30, 1
  %40 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %39, i64 noundef %.0)
  %41 = add nuw i64 %.115, 1
  %42 = load i64, ptr %2, align 8, !tbaa !7
  %43 = icmp ult i64 %41, %42
  br i1 %43, label %.lr.ph16, label %.loopexit, !llvm.loop !13

._crit_edge:                                      ; preds = %.loopexit, %0
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #5
  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: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZSt11lower_boundIPyyET_S1_S1_RKT0_(ptr noundef, ptr noundef, ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #4

; 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 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 = { 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 = { 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 #5 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"long long", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = distinct !{!11, !6, !12}
!12 = !{!"llvm.loop.peeled.count", i32 1}
!13 = distinct !{!13, !6}


; Effective O3 passes: CorrelatedValuePropagationPass,GVNPass,GlobalOptPass,IPSCCPPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopFullUnrollPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass