; LLVM IR from reyadussalahin/problem-solving :: hashing/string_hashing/codeforces/F126B (Solution)

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

@s = external dso_local global [1000010 x i8], align 16
@n = external dso_local global i32, align 4
@l = external dso_local global [1000010 x i32], align 16
@mc = external dso_local global i32, align 4
@m = external dso_local global [1000010 x i64], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z8containsxi(i64 noundef, i32 noundef) #0

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

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #2 {
  %1 = alloca i32, align 4
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %11 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @s)
  %12 = call i64 @strlen(ptr noundef @s) #5
  %13 = trunc i64 %12 to i32
  store i32 %13, ptr @n, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #6
  store i64 0, ptr %2, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #6
  store i64 0, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #6
  store i64 1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #6
  store i32 0, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  %14 = load i32, ptr @n, align 4, !tbaa !5
  %15 = sub nsw i32 %14, 1
  store i32 %15, ptr %6, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %61, %0
  %17 = load i32, ptr %6, align 4, !tbaa !5
  %18 = icmp sgt i32 %17, 0
  br i1 %18, label %20, label %19

19:                                               ; preds = %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  br label %66

20:                                               ; preds = %16
  %21 = load i64, ptr %2, align 8, !tbaa !9
  %22 = mul nsw i64 %21, 47
  %23 = load i32, ptr %5, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [1000010 x i8], ptr @s, i64 0, i64 %24
  %26 = load i8, ptr %25, align 1, !tbaa !11
  %27 = sext i8 %26 to i32
  %28 = sub nsw i32 %27, 97
  %29 = add nsw i32 %28, 1
  %30 = sext i32 %29 to i64
  %31 = add nsw i64 %22, %30
  store i64 %31, ptr %2, align 8, !tbaa !9
  %32 = load i64, ptr %3, align 8, !tbaa !9
  %33 = load i32, ptr %6, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [1000010 x i8], ptr @s, i64 0, i64 %34
  %36 = load i8, ptr %35, align 1, !tbaa !11
  %37 = sext i8 %36 to i32
  %38 = sub nsw i32 %37, 97
  %39 = add nsw i32 %38, 1
  %40 = sext i32 %39 to i64
  %41 = load i64, ptr %4, align 8, !tbaa !9
  %42 = mul nsw i64 %40, %41
  %43 = add nsw i64 %32, %42
  store i64 %43, ptr %3, align 8, !tbaa !9
  %44 = load i64, ptr %4, align 8, !tbaa !9
  %45 = mul nsw i64 %44, 47
  store i64 %45, ptr %4, align 8, !tbaa !9
  %46 = load i64, ptr %2, align 8, !tbaa !9
  %47 = load i64, ptr %3, align 8, !tbaa !9
  %48 = icmp eq i64 %46, %47
  br i1 %48, label %49, label %60

49:                                               ; preds = %20
  %50 = load i64, ptr %2, align 8, !tbaa !9
  %51 = load i32, ptr @mc, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [1000010 x i64], ptr @m, i64 0, i64 %52
  store i64 %50, ptr %53, align 8, !tbaa !9
  %54 = load i32, ptr %5, align 4, !tbaa !5
  %55 = add nsw i32 %54, 1
  %56 = load i32, ptr @mc, align 4, !tbaa !5
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr @mc, align 4, !tbaa !5
  %58 = sext i32 %56 to i64
  %59 = getelementptr inbounds [1000010 x i32], ptr @l, i64 0, i64 %58
  store i32 %55, ptr %59, align 4, !tbaa !5
  br label %60

60:                                               ; preds = %49, %20
  br label %61

61:                                               ; preds = %60
  %62 = load i32, ptr %6, align 4, !tbaa !5
  %63 = add nsw i32 %62, -1
  store i32 %63, ptr %6, align 4, !tbaa !5
  %64 = load i32, ptr %5, align 4, !tbaa !5
  %65 = add nsw i32 %64, 1
  store i32 %65, ptr %5, align 4, !tbaa !5
  br label %16, !llvm.loop !12

66:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #6
  store i32 0, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  %67 = load i32, ptr @mc, align 4, !tbaa !5
  %68 = sub nsw i32 %67, 1
  store i32 %68, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #6
  store i32 -1, ptr %9, align 4, !tbaa !5
  br label %69

69:                                               ; preds = %94, %66
  %70 = load i32, ptr %7, align 4, !tbaa !5
  %71 = load i32, ptr %8, align 4, !tbaa !5
  %72 = icmp sle i32 %70, %71
  br i1 %72, label %73, label %95

73:                                               ; preds = %69
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #6
  %74 = load i32, ptr %7, align 4, !tbaa !5
  %75 = load i32, ptr %8, align 4, !tbaa !5
  %76 = add nsw i32 %74, %75
  %77 = sdiv i32 %76, 2
  store i32 %77, ptr %10, align 4, !tbaa !5
  %78 = load i32, ptr %10, align 4, !tbaa !5
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds [1000010 x i64], ptr @m, i64 0, i64 %79
  %81 = load i64, ptr %80, align 8, !tbaa !9
  %82 = load i32, ptr %10, align 4, !tbaa !5
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds [1000010 x i32], ptr @l, i64 0, i64 %83
  %85 = load i32, ptr %84, align 4, !tbaa !5
  %86 = call noundef zeroext i1 @_Z8containsxi(i64 noundef %81, i32 noundef %85)
  br i1 %86, label %87, label %91

87:                                               ; preds = %73
  %88 = load i32, ptr %10, align 4, !tbaa !5
  store i32 %88, ptr %9, align 4, !tbaa !5
  %89 = load i32, ptr %10, align 4, !tbaa !5
  %90 = add nsw i32 %89, 1
  store i32 %90, ptr %7, align 4, !tbaa !5
  br label %94

91:                                               ; preds = %73
  %92 = load i32, ptr %10, align 4, !tbaa !5
  %93 = sub nsw i32 %92, 1
  store i32 %93, ptr %8, align 4, !tbaa !5
  br label %94

94:                                               ; preds = %91, %87
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #6
  br label %69, !llvm.loop !14

95:                                               ; preds = %69
  %96 = load i32, ptr %9, align 4, !tbaa !5
  %97 = icmp eq i32 %96, -1
  br i1 %97, label %98, label %100

98:                                               ; preds = %95
  %99 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  br label %108

100:                                              ; preds = %95
  %101 = load i32, ptr %9, align 4, !tbaa !5
  %102 = sext i32 %101 to i64
  %103 = getelementptr inbounds [1000010 x i32], ptr @l, i64 0, i64 %102
  %104 = load i32, ptr %103, align 4, !tbaa !5
  %105 = sext i32 %104 to i64
  %106 = getelementptr inbounds [1000010 x i8], ptr @s, i64 0, i64 %105
  store i8 0, ptr %106, align 1, !tbaa !11
  %107 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, ptr noundef @s)
  br label %108

108:                                              ; preds = %100, %98
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #6
  ret i32 0
}

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

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #4

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

attributes #0 = { mustprogress 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { "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 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 #5 = { nounwind willreturn memory(read) }
attributes #6 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !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"

@s = external dso_local global [1000010 x i8], align 16
@n = external dso_local local_unnamed_addr global i32, align 4
@l = external dso_local local_unnamed_addr global [1000010 x i32], align 16
@mc = external dso_local local_unnamed_addr global i32, align 4
@m = external dso_local local_unnamed_addr global [1000010 x i64], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z8containsxi(i64 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @s)
  %2 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) @s) #4
  %3 = trunc i64 %2 to i32
  store i32 %3, ptr @n, align 4, !tbaa !5
  %mc.promoted = load i32, ptr @mc, align 4, !tbaa !5
  %4 = icmp sgt i32 %3, 1
  br i1 %4, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %0
  %5 = and i64 %2, 2147483647
  %6 = add i64 %2, 4294967295
  %wide.trip.count = and i64 %6, 4294967295
  br label %.lr.ph

._crit_edge:                                      ; preds = %31, %0
  %7 = phi i32 [ %mc.promoted, %0 ], [ %32, %31 ]
  %.not40 = icmp slt i32 %7, 1
  br i1 %.not40, label %._crit_edge46.thread, label %.lr.ph45.preheader

.lr.ph45.preheader:                               ; preds = %._crit_edge
  %8 = add nsw i32 %7, -1
  br label %.lr.ph45

.lr.ph:                                           ; preds = %.lr.ph.preheader, %31
  %indvars.iv47 = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next48.pre-phi, %31 ]
  %indvars.iv = phi i64 [ %5, %.lr.ph.preheader ], [ %indvars.iv.next, %31 ]
  %.038 = phi i64 [ 0, %.lr.ph.preheader ], [ %15, %31 ]
  %.03136 = phi i64 [ 1, %.lr.ph.preheader ], [ %22, %31 ]
  %.03235 = phi i64 [ 0, %.lr.ph.preheader ], [ %21, %31 ]
  %9 = phi i32 [ %mc.promoted, %.lr.ph.preheader ], [ %32, %31 ]
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %10 = mul nsw i64 %.038, 47
  %11 = getelementptr inbounds [1000010 x i8], ptr @s, i64 0, i64 %indvars.iv47
  %12 = load i8, ptr %11, align 1, !tbaa !9
  %13 = sext i8 %12 to i64
  %14 = add i64 %10, -96
  %15 = add i64 %14, %13
  %16 = getelementptr inbounds [1000010 x i8], ptr @s, i64 0, i64 %indvars.iv.next
  %17 = load i8, ptr %16, align 1, !tbaa !9
  %18 = sext i8 %17 to i64
  %19 = add nsw i64 %18, -96
  %20 = mul nsw i64 %19, %.03136
  %21 = add nsw i64 %20, %.03235
  %22 = mul nuw nsw i64 %.03136, 47
  %23 = icmp eq i64 %15, %21
  br i1 %23, label %24, label %.lr.ph._crit_edge

.lr.ph._crit_edge:                                ; preds = %.lr.ph
  %.pre = add nuw nsw i64 %indvars.iv47, 1
  br label %31

24:                                               ; preds = %.lr.ph
  %25 = sext i32 %9 to i64
  %26 = getelementptr inbounds [1000010 x i64], ptr @m, i64 0, i64 %25
  store i64 %15, ptr %26, align 8, !tbaa !10
  %27 = add nuw nsw i64 %indvars.iv47, 1
  %28 = add nsw i32 %9, 1
  store i32 %28, ptr @mc, align 4, !tbaa !5
  %29 = getelementptr inbounds [1000010 x i32], ptr @l, i64 0, i64 %25
  %30 = trunc nuw nsw i64 %27 to i32
  store i32 %30, ptr %29, align 4, !tbaa !5
  br label %31

31:                                               ; preds = %.lr.ph._crit_edge, %24
  %indvars.iv.next48.pre-phi = phi i64 [ %.pre, %.lr.ph._crit_edge ], [ %27, %24 ]
  %32 = phi i32 [ %9, %.lr.ph._crit_edge ], [ %28, %24 ]
  %exitcond.not = icmp eq i64 %indvars.iv.next48.pre-phi, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !12

.lr.ph45:                                         ; preds = %.lr.ph45.preheader, %.lr.ph45
  %.02443 = phi i32 [ %.1, %.lr.ph45 ], [ -1, %.lr.ph45.preheader ]
  %.02542 = phi i32 [ %.126, %.lr.ph45 ], [ %8, %.lr.ph45.preheader ]
  %.02741 = phi i32 [ %.128, %.lr.ph45 ], [ 0, %.lr.ph45.preheader ]
  %33 = add nuw nsw i32 %.02542, %.02741
  %34 = lshr i32 %33, 1
  %35 = zext nneg i32 %34 to i64
  %36 = getelementptr inbounds [1000010 x i64], ptr @m, i64 0, i64 %35
  %37 = load i64, ptr %36, align 8, !tbaa !10
  %38 = getelementptr inbounds [1000010 x i32], ptr @l, i64 0, i64 %35
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %40 = tail call noundef zeroext i1 @_Z8containsxi(i64 noundef %37, i32 noundef %39)
  %41 = add nuw nsw i32 %34, 1
  %42 = add nsw i32 %34, -1
  %.128 = select i1 %40, i32 %41, i32 %.02741
  %.126 = select i1 %40, i32 %.02542, i32 %42
  %.1 = select i1 %40, i32 %34, i32 %.02443
  %.not = icmp sgt i32 %.128, %.126
  br i1 %.not, label %._crit_edge46, label %.lr.ph45, !llvm.loop !14

._crit_edge46:                                    ; preds = %.lr.ph45
  %43 = icmp eq i32 %.1, -1
  br i1 %43, label %._crit_edge46.thread, label %45

._crit_edge46.thread:                             ; preds = %._crit_edge, %._crit_edge46
  %44 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1)
  br label %52

45:                                               ; preds = %._crit_edge46
  %46 = zext nneg i32 %.1 to i64
  %47 = getelementptr inbounds [1000010 x i32], ptr @l, i64 0, i64 %46
  %48 = load i32, ptr %47, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [1000010 x i8], ptr @s, i64 0, i64 %49
  store i8 0, ptr %50, align 1, !tbaa !9
  %51 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, ptr noundef nonnull @s)
  br label %52

52:                                               ; preds = %45, %._crit_edge46.thread
  ret i32 0
}

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #3

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

attributes #0 = { mustprogress 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 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 #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(argmem: 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 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 = !{!11, !11, i64 0}
!11 = !{!"long long", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


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