; LLVM IR from Shah-Shishir/Codeforces-Solutions :: 960A. Check the string (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 [5005 x i8], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = 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 i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = 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 4, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #4
  br label %8

8:                                                ; preds = %117, %0
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @str)
  %10 = icmp ne i32 %9, -1
  br i1 %10, label %11, label %119

11:                                               ; preds = %8
  %12 = call i64 @strlen(ptr noundef @str) #5
  %13 = trunc i64 %12 to i32
  store i32 %13, ptr %2, align 4, !tbaa !5
  store i32 0, ptr %6, align 4, !tbaa !5
  store i32 0, ptr %5, align 4, !tbaa !5
  store i32 0, ptr %4, align 4, !tbaa !5
  store i8 1, ptr %7, align 1, !tbaa !9
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %89, %11
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = load i32, ptr %2, align 4, !tbaa !5
  %17 = icmp slt i32 %15, %16
  br i1 %17, label %18, label %92

18:                                               ; preds = %14
  %19 = load i32, ptr %3, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [5005 x i8], ptr @str, i64 0, i64 %20
  %22 = load i8, ptr %21, align 1, !tbaa !11
  %23 = sext i8 %22 to i32
  %24 = icmp eq i32 %23, 97
  br i1 %24, label %25, label %28

25:                                               ; preds = %18
  %26 = load i32, ptr %4, align 4, !tbaa !5
  %27 = add nsw i32 %26, 1
  store i32 %27, ptr %4, align 4, !tbaa !5
  br label %42

28:                                               ; preds = %18
  %29 = load i32, ptr %3, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [5005 x i8], ptr @str, i64 0, i64 %30
  %32 = load i8, ptr %31, align 1, !tbaa !11
  %33 = sext i8 %32 to i32
  %34 = icmp eq i32 %33, 98
  br i1 %34, label %35, label %38

35:                                               ; preds = %28
  %36 = load i32, ptr %5, align 4, !tbaa !5
  %37 = add nsw i32 %36, 1
  store i32 %37, ptr %5, align 4, !tbaa !5
  br label %41

38:                                               ; preds = %28
  %39 = load i32, ptr %6, align 4, !tbaa !5
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %6, align 4, !tbaa !5
  br label %41

41:                                               ; preds = %38, %35
  br label %42

42:                                               ; preds = %41, %25
  %43 = load i32, ptr %3, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [5005 x i8], ptr @str, i64 0, i64 %44
  %46 = load i8, ptr %45, align 1, !tbaa !11
  %47 = sext i8 %46 to i32
  %48 = icmp eq i32 %47, 98
  br i1 %48, label %49, label %57

49:                                               ; preds = %42
  %50 = load i32, ptr %3, align 4, !tbaa !5
  %51 = add nsw i32 %50, 1
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [5005 x i8], ptr @str, i64 0, i64 %52
  %54 = load i8, ptr %53, align 1, !tbaa !11
  %55 = sext i8 %54 to i32
  %56 = icmp eq i32 %55, 97
  br i1 %56, label %87, label %57

57:                                               ; preds = %49, %42
  %58 = load i32, ptr %3, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [5005 x i8], ptr @str, i64 0, i64 %59
  %61 = load i8, ptr %60, align 1, !tbaa !11
  %62 = sext i8 %61 to i32
  %63 = icmp eq i32 %62, 99
  br i1 %63, label %64, label %72

64:                                               ; preds = %57
  %65 = load i32, ptr %3, align 4, !tbaa !5
  %66 = add nsw i32 %65, 1
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [5005 x i8], ptr @str, i64 0, i64 %67
  %69 = load i8, ptr %68, align 1, !tbaa !11
  %70 = sext i8 %69 to i32
  %71 = icmp eq i32 %70, 97
  br i1 %71, label %87, label %72

72:                                               ; preds = %64, %57
  %73 = load i32, ptr %3, align 4, !tbaa !5
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [5005 x i8], ptr @str, i64 0, i64 %74
  %76 = load i8, ptr %75, align 1, !tbaa !11
  %77 = sext i8 %76 to i32
  %78 = icmp eq i32 %77, 99
  br i1 %78, label %79, label %88

79:                                               ; preds = %72
  %80 = load i32, ptr %3, align 4, !tbaa !5
  %81 = add nsw i32 %80, 1
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds [5005 x i8], ptr @str, i64 0, i64 %82
  %84 = load i8, ptr %83, align 1, !tbaa !11
  %85 = sext i8 %84 to i32
  %86 = icmp eq i32 %85, 98
  br i1 %86, label %87, label %88

87:                                               ; preds = %79, %64, %49
  store i8 0, ptr %7, align 1, !tbaa !9
  br label %92

88:                                               ; preds = %79, %72
  br label %89

89:                                               ; preds = %88
  %90 = load i32, ptr %3, align 4, !tbaa !5
  %91 = add nsw i32 %90, 1
  store i32 %91, ptr %3, align 4, !tbaa !5
  br label %14, !llvm.loop !12

92:                                               ; preds = %87, %14
  %93 = load i32, ptr %4, align 4, !tbaa !5
  %94 = icmp sge i32 %93, 1
  br i1 %94, label %95, label %109

95:                                               ; preds = %92
  %96 = load i32, ptr %5, align 4, !tbaa !5
  %97 = icmp sge i32 %96, 1
  br i1 %97, label %98, label %109

98:                                               ; preds = %95
  %99 = load i32, ptr %6, align 4, !tbaa !5
  %100 = icmp sge i32 %99, 1
  br i1 %100, label %101, label %109

101:                                              ; preds = %98
  %102 = load i32, ptr %6, align 4, !tbaa !5
  %103 = load i32, ptr %4, align 4, !tbaa !5
  %104 = icmp eq i32 %102, %103
  br i1 %104, label %110, label %105

105:                                              ; preds = %101
  %106 = load i32, ptr %6, align 4, !tbaa !5
  %107 = load i32, ptr %5, align 4, !tbaa !5
  %108 = icmp eq i32 %106, %107
  br i1 %108, label %110, label %109

109:                                              ; preds = %105, %98, %95, %92
  store i8 0, ptr %7, align 1, !tbaa !9
  br label %110

110:                                              ; preds = %109, %105, %101
  %111 = load i8, ptr %7, align 1, !tbaa !9, !range !14, !noundef !15
  %112 = trunc i8 %111 to i1
  br i1 %112, label %115, label %113

113:                                              ; preds = %110
  %114 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  br label %117

115:                                              ; preds = %110
  %116 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  br label %117

117:                                              ; preds = %115, %113
  %118 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  br label %8, !llvm.loop !16

119:                                              ; preds = %8
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, 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 i64 @strlen(ptr 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{i8 0, i8 2}
!15 = !{}
!16 = distinct !{!16, !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 [5005 x i8], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = 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 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @str)
  %.not92 = icmp eq i32 %1, -1
  br i1 %.not92, label %._crit_edge95, label %.lr.ph94

.lr.ph94:                                         ; preds = %0, %.thread66
  %2 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) @str) #3
  %3 = trunc i64 %2 to i32
  %.not6869 = icmp sgt i32 %3, 0
  br i1 %.not6869, label %.lr.ph.preheader, label %.thread66

.lr.ph.preheader:                                 ; preds = %.lr.ph94
  %4 = and i64 %2, 2147483647
  %wide.trip.count = and i64 %2, 2147483647
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.thread42
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %.thread42 ]
  %.not6874 = phi i1 [ true, %.lr.ph.preheader ], [ %.not68, %.thread42 ]
  %.02573 = phi i32 [ 0, %.lr.ph.preheader ], [ %.126414660, %.thread42 ]
  %.02772 = phi i32 [ 0, %.lr.ph.preheader ], [ %.128404758, %.thread42 ]
  %.03071 = phi i32 [ 0, %.lr.ph.preheader ], [ %.131394856, %.thread42 ]
  %5 = getelementptr inbounds [5005 x i8], ptr @str, i64 0, i64 %indvars.iv
  %6 = load i8, ptr %5, align 1, !tbaa !5
  switch i8 %6, label %13 [
    i8 97, label %20
    i8 98, label %7
  ]

7:                                                ; preds = %.lr.ph
  %8 = add nsw i32 %.02772, 1
  %9 = add nuw nsw i64 %indvars.iv, 1
  %10 = getelementptr inbounds [5005 x i8], ptr @str, i64 0, i64 %9
  %11 = load i8, ptr %10, align 1, !tbaa !5
  %12 = icmp eq i8 %11, 97
  br i1 %12, label %._crit_edge, label %.thread42

13:                                               ; preds = %.lr.ph
  %14 = add nsw i32 %.02573, 1
  %15 = icmp eq i8 %6, 99
  br i1 %15, label %16, label %.thread42

16:                                               ; preds = %13
  %17 = add nuw nsw i64 %indvars.iv, 1
  %18 = getelementptr inbounds [5005 x i8], ptr @str, i64 0, i64 %17
  %19 = load i8, ptr %18, align 1, !tbaa !5
  %.off = add i8 %19, -97
  %switch = icmp ult i8 %.off, 2
  br i1 %switch, label %._crit_edge, label %.thread42

20:                                               ; preds = %.lr.ph
  %21 = add nsw i32 %.03071, 1
  br label %.thread42

.thread42:                                        ; preds = %16, %13, %7, %20
  %.126414660 = phi i32 [ %.02573, %20 ], [ %.02573, %7 ], [ %14, %13 ], [ %14, %16 ]
  %.128404758 = phi i32 [ %.02772, %20 ], [ %8, %7 ], [ %.02772, %13 ], [ %.02772, %16 ]
  %.131394856 = phi i32 [ %21, %20 ], [ %.03071, %7 ], [ %.03071, %13 ], [ %.03071, %16 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %.not68 = icmp ult i64 %indvars.iv.next, %4
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !8

._crit_edge:                                      ; preds = %16, %.thread42, %7
  %.030.lcssa = phi i32 [ %.131394856, %.thread42 ], [ %.03071, %7 ], [ %.03071, %16 ]
  %.not68.lcssa = phi i1 [ %.not68, %.thread42 ], [ %.not6874, %7 ], [ %.not6874, %16 ]
  %.229 = phi i32 [ %.128404758, %.thread42 ], [ %8, %7 ], [ %.02772, %16 ]
  %.2 = phi i32 [ %.126414660, %.thread42 ], [ %.02573, %7 ], [ %14, %16 ]
  %22 = icmp sgt i32 %.030.lcssa, 0
  %23 = icmp sgt i32 %.229, 0
  %or.cond = select i1 %22, i1 %23, i1 false
  %24 = icmp sgt i32 %.2, 0
  %or.cond3 = select i1 %or.cond, i1 %24, i1 false
  br i1 %or.cond3, label %25, label %.thread66

25:                                               ; preds = %._crit_edge
  %26 = icmp ne i32 %.2, %.030.lcssa
  %27 = icmp ne i32 %.2, %.229
  %or.cond35.not98 = select i1 %26, i1 %27, i1 false
  %brmerge = or i1 %.not68.lcssa, %or.cond35.not98
  %spec.select = select i1 %brmerge, ptr @.str.1, ptr @.str.2
  br label %.thread66

.thread66:                                        ; preds = %25, %._crit_edge, %.lr.ph94
  %.str.2.sink = phi ptr [ @.str.1, %.lr.ph94 ], [ @.str.1, %._crit_edge ], [ %spec.select, %25 ]
  %28 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) %.str.2.sink)
  %29 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  %30 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @str)
  %.not = icmp eq i32 %30, -1
  br i1 %.not, label %._crit_edge95, label %.lr.ph94, !llvm.loop !10

._crit_edge95:                                    ; preds = %.thread66, %0
  ret i32 0
}

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

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

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #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 = { 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 #2 = { 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 #3 = { 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 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = distinct !{!10, !9}


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