; LLVM IR from tangjz/acm-icpc :: leetcode/extra (espressif_04-猴子打字)

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

@_ZZ4mainE2st = external hidden global i32, align 4
@_ZZ4mainE3tim = external hidden global [257 x i32], align 16
@_ZZ4mainE3buf = external hidden global [5 x [1001 x i8]], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [12 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 i8, align 1
  %6 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %7

7:                                                ; preds = %17, %0
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %9 = icmp slt i32 %8, 4
  br i1 %9, label %11, label %10

10:                                               ; preds = %7
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  br label %20

11:                                               ; preds = %7
  %12 = load i32, ptr %2, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [5 x [1001 x i8]], ptr @_ZZ4mainE3buf, i64 0, i64 %13
  %15 = getelementptr inbounds [1001 x i8], ptr %14, i64 0, i64 0
  %16 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %15)
  br label %17

17:                                               ; preds = %11
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = add nsw i32 %18, 1
  store i32 %19, ptr %2, align 4, !tbaa !5
  br label %7, !llvm.loop !9

20:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %21

21:                                               ; preds = %104, %20
  %22 = load i32, ptr %3, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [1001 x i8], ptr @_ZZ4mainE3buf, i64 0, i64 %23
  %25 = load i8, ptr %24, align 1, !tbaa !11
  %26 = icmp ne i8 %25, 0
  br i1 %26, label %28, label %27

27:                                               ; preds = %21
  store i32 5, ptr %4, align 4
  br label %107

28:                                               ; preds = %21
  %29 = load i32, ptr @_ZZ4mainE2st, align 4, !tbaa !5
  %30 = add nsw i32 %29, 1
  store i32 %30, ptr @_ZZ4mainE2st, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %5) #3
  store i8 0, ptr %5, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %31

31:                                               ; preds = %86, %28
  %32 = load i32, ptr %6, align 4, !tbaa !5
  %33 = icmp slt i32 %32, 4
  br i1 %33, label %35, label %34

34:                                               ; preds = %31
  store i32 8, ptr %4, align 4
  br label %89

35:                                               ; preds = %31
  %36 = load i32, ptr %6, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [5 x [1001 x i8]], ptr @_ZZ4mainE3buf, i64 0, i64 %37
  %39 = load i32, ptr %3, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [1001 x i8], ptr %38, i64 0, i64 %40
  %42 = load i8, ptr %41, align 1, !tbaa !11
  %43 = sext i8 %42 to i64
  %44 = getelementptr inbounds [257 x i32], ptr @_ZZ4mainE3tim, i64 0, i64 %43
  %45 = load i32, ptr %44, align 4, !tbaa !5
  %46 = load i32, ptr @_ZZ4mainE2st, align 4, !tbaa !5
  %47 = icmp eq i32 %45, %46
  br i1 %47, label %48, label %75

48:                                               ; preds = %35
  %49 = load i8, ptr %5, align 1, !tbaa !11
  %50 = sext i8 %49 to i32
  %51 = icmp eq i32 %50, 0
  br i1 %51, label %52, label %60

52:                                               ; preds = %48
  %53 = load i32, ptr %6, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [5 x [1001 x i8]], ptr @_ZZ4mainE3buf, i64 0, i64 %54
  %56 = load i32, ptr %3, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [1001 x i8], ptr %55, i64 0, i64 %57
  %59 = load i8, ptr %58, align 1, !tbaa !11
  store i8 %59, ptr %5, align 1, !tbaa !11
  br label %74

60:                                               ; preds = %48
  %61 = load i8, ptr %5, align 1, !tbaa !11
  %62 = sext i8 %61 to i32
  %63 = load i32, ptr %6, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [5 x [1001 x i8]], ptr @_ZZ4mainE3buf, i64 0, i64 %64
  %66 = load i32, ptr %3, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [1001 x i8], ptr %65, i64 0, i64 %67
  %69 = load i8, ptr %68, align 1, !tbaa !11
  %70 = sext i8 %69 to i32
  %71 = icmp ne i32 %62, %70
  br i1 %71, label %72, label %73

72:                                               ; preds = %60
  store i8 0, ptr %5, align 1, !tbaa !11
  store i32 8, ptr %4, align 4
  br label %89

73:                                               ; preds = %60
  br label %74

74:                                               ; preds = %73, %52
  br label %75

75:                                               ; preds = %74, %35
  %76 = load i32, ptr @_ZZ4mainE2st, align 4, !tbaa !5
  %77 = load i32, ptr %6, align 4, !tbaa !5
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds [5 x [1001 x i8]], ptr @_ZZ4mainE3buf, i64 0, i64 %78
  %80 = load i32, ptr %3, align 4, !tbaa !5
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds [1001 x i8], ptr %79, i64 0, i64 %81
  %83 = load i8, ptr %82, align 1, !tbaa !11
  %84 = sext i8 %83 to i64
  %85 = getelementptr inbounds [257 x i32], ptr @_ZZ4mainE3tim, i64 0, i64 %84
  store i32 %76, ptr %85, align 4, !tbaa !5
  br label %86

86:                                               ; preds = %75
  %87 = load i32, ptr %6, align 4, !tbaa !5
  %88 = add nsw i32 %87, 1
  store i32 %88, ptr %6, align 4, !tbaa !5
  br label %31, !llvm.loop !12

89:                                               ; preds = %72, %34
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %90

90:                                               ; preds = %89
  %91 = load i8, ptr %5, align 1, !tbaa !11
  %92 = sext i8 %91 to i32
  %93 = icmp eq i32 %92, 0
  br i1 %93, label %94, label %96

94:                                               ; preds = %90
  %95 = call i32 @puts(ptr noundef @.str.1)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %4, align 4
  br label %101

96:                                               ; preds = %90
  %97 = load i8, ptr %5, align 1, !tbaa !11
  %98 = load i32, ptr %3, align 4, !tbaa !5
  %99 = sext i32 %98 to i64
  %100 = getelementptr inbounds [1001 x i8], ptr @_ZZ4mainE3buf, i64 0, i64 %99
  store i8 %97, ptr %100, align 1, !tbaa !11
  store i32 0, ptr %4, align 4
  br label %101

101:                                              ; preds = %96, %94
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #3
  %102 = load i32, ptr %4, align 4
  switch i32 %102, label %107 [
    i32 0, label %103
  ]

103:                                              ; preds = %101
  br label %104

104:                                              ; preds = %103
  %105 = load i32, ptr %3, align 4, !tbaa !5
  %106 = add nsw i32 %105, 1
  store i32 %106, ptr %3, align 4, !tbaa !5
  br label %21, !llvm.loop !13

107:                                              ; preds = %101, %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  %108 = load i32, ptr %4, align 4
  switch i32 %108, label %113 [
    i32 5, label %109
    i32 1, label %111
  ]

109:                                              ; preds = %107
  %110 = call i32 @puts(ptr noundef @_ZZ4mainE3buf)
  store i32 0, ptr %1, align 4
  br label %111

111:                                              ; preds = %109, %107
  %112 = load i32, ptr %1, align 4
  ret i32 %112

113:                                              ; preds = %107
  unreachable
}

; 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

declare i32 @puts(ptr noundef) #2

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 }

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

@_ZZ4mainE2st = external hidden local_unnamed_addr global i32, align 4
@_ZZ4mainE3tim = external hidden local_unnamed_addr global [257 x i32], align 16
@_ZZ4mainE3buf = external hidden global [5 x [1001 x i8]], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [12 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
.preheader:
  %0 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @_ZZ4mainE3buf)
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull getelementptr inbounds (i8, ptr @_ZZ4mainE3buf, i64 1001))
  %2 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull getelementptr inbounds (i8, ptr @_ZZ4mainE3buf, i64 2002))
  %3 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull getelementptr inbounds (i8, ptr @_ZZ4mainE3buf, i64 3003))
  %4 = load i8, ptr @_ZZ4mainE3buf, align 16, !tbaa !5
  %.not49 = icmp eq i8 %4, 0
  br i1 %.not49, label %66, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.preheader
  %_ZZ4mainE2st.promoted = load i32, ptr @_ZZ4mainE2st, align 4, !tbaa !8
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %63
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %63 ]
  %5 = phi ptr [ @_ZZ4mainE3buf, %.lr.ph.preheader ], [ %64, %63 ]
  %6 = phi i32 [ %_ZZ4mainE2st.promoted, %.lr.ph.preheader ], [ %7, %63 ]
  %7 = add nsw i32 %6, 1
  %8 = getelementptr inbounds [5 x [1001 x i8]], ptr @_ZZ4mainE3buf, i64 0, i64 0, i64 %indvars.iv
  %9 = load i8, ptr %8, align 1, !tbaa !5
  %10 = sext i8 %9 to i64
  %11 = getelementptr inbounds [257 x i32], ptr @_ZZ4mainE3tim, i64 0, i64 %10
  %12 = load i32, ptr %11, align 4, !tbaa !8
  %13 = icmp eq i32 %12, %7
  br i1 %13, label %14, label %.thread58

14:                                               ; preds = %.lr.ph
  %15 = getelementptr inbounds [5 x [1001 x i8]], ptr @_ZZ4mainE3buf, i64 0, i64 1, i64 %indvars.iv
  %16 = load i8, ptr %15, align 1, !tbaa !5
  %17 = sext i8 %16 to i64
  %18 = getelementptr inbounds [257 x i32], ptr @_ZZ4mainE3tim, i64 0, i64 %17
  %19 = load i32, ptr %18, align 4, !tbaa !8
  %20 = icmp eq i32 %19, %7
  br i1 %20, label %27, label %.thread61

.thread58:                                        ; preds = %.lr.ph
  store i32 %7, ptr %11, align 4, !tbaa !8
  %21 = getelementptr inbounds [5 x [1001 x i8]], ptr @_ZZ4mainE3buf, i64 0, i64 1, i64 %indvars.iv
  %22 = load i8, ptr %21, align 1, !tbaa !5
  %23 = sext i8 %22 to i64
  %24 = getelementptr inbounds [257 x i32], ptr @_ZZ4mainE3tim, i64 0, i64 %23
  %25 = load i32, ptr %24, align 4, !tbaa !8
  %26 = icmp eq i32 %25, %7
  br i1 %26, label %.thread61, label %.thread63

27:                                               ; preds = %14
  %28 = icmp eq i8 %9, 0
  br i1 %28, label %.thread61, label %29

29:                                               ; preds = %27
  %.not32.1 = icmp eq i8 %9, %16
  br i1 %.not32.1, label %.thread61, label %.sink.split

.thread61:                                        ; preds = %.thread58, %29, %27, %14
  %30 = phi ptr [ %18, %29 ], [ %18, %14 ], [ %18, %27 ], [ %24, %.thread58 ]
  %.1.1 = phi i8 [ %9, %29 ], [ %9, %14 ], [ %16, %27 ], [ %22, %.thread58 ]
  store i32 %7, ptr %30, align 4, !tbaa !8
  %31 = getelementptr inbounds [5 x [1001 x i8]], ptr @_ZZ4mainE3buf, i64 0, i64 2, i64 %indvars.iv
  %32 = load i8, ptr %31, align 1, !tbaa !5
  %33 = sext i8 %32 to i64
  %34 = getelementptr inbounds [257 x i32], ptr @_ZZ4mainE3tim, i64 0, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !8
  %36 = icmp eq i32 %35, %7
  br i1 %36, label %43, label %.thread66

.thread63:                                        ; preds = %.thread58
  store i32 %7, ptr %24, align 4, !tbaa !8
  %37 = getelementptr inbounds [5 x [1001 x i8]], ptr @_ZZ4mainE3buf, i64 0, i64 2, i64 %indvars.iv
  %38 = load i8, ptr %37, align 1, !tbaa !5
  %39 = sext i8 %38 to i64
  %40 = getelementptr inbounds [257 x i32], ptr @_ZZ4mainE3tim, i64 0, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !8
  %42 = icmp eq i32 %41, %7
  br i1 %42, label %.thread66, label %.thread68

43:                                               ; preds = %.thread61
  %44 = icmp eq i8 %.1.1, 0
  br i1 %44, label %.thread66, label %45

45:                                               ; preds = %43
  %.not32.2 = icmp eq i8 %.1.1, %32
  br i1 %.not32.2, label %.thread66, label %.sink.split

.thread66:                                        ; preds = %.thread63, %45, %43, %.thread61
  %46 = phi ptr [ %34, %45 ], [ %34, %.thread61 ], [ %34, %43 ], [ %40, %.thread63 ]
  %.1.2 = phi i8 [ %.1.1, %45 ], [ %.1.1, %.thread61 ], [ %32, %43 ], [ %38, %.thread63 ]
  store i32 %7, ptr %46, align 4, !tbaa !8
  %47 = getelementptr inbounds [5 x [1001 x i8]], ptr @_ZZ4mainE3buf, i64 0, i64 3, i64 %indvars.iv
  %48 = load i8, ptr %47, align 1, !tbaa !5
  %49 = sext i8 %48 to i64
  %50 = getelementptr inbounds [257 x i32], ptr @_ZZ4mainE3tim, i64 0, i64 %49
  %51 = load i32, ptr %50, align 4, !tbaa !8
  %52 = icmp eq i32 %51, %7
  br i1 %52, label %59, label %.thread71

.thread68:                                        ; preds = %.thread63
  store i32 %7, ptr %40, align 4, !tbaa !8
  %53 = getelementptr inbounds [5 x [1001 x i8]], ptr @_ZZ4mainE3buf, i64 0, i64 3, i64 %indvars.iv
  %54 = load i8, ptr %53, align 1, !tbaa !5
  %55 = sext i8 %54 to i64
  %56 = getelementptr inbounds [257 x i32], ptr @_ZZ4mainE3tim, i64 0, i64 %55
  %57 = load i32, ptr %56, align 4, !tbaa !8
  %58 = icmp eq i32 %57, %7
  br i1 %58, label %.thread71, label %.thread73

.thread73:                                        ; preds = %.thread68
  store i32 %7, ptr %56, align 4, !tbaa !8
  br label %.sink.split

59:                                               ; preds = %.thread66
  %60 = icmp eq i8 %.1.2, 0
  br i1 %60, label %.thread71, label %61

61:                                               ; preds = %59
  %.not32.3 = icmp eq i8 %.1.2, %48
  br i1 %.not32.3, label %.thread76, label %.sink.split

.thread76:                                        ; preds = %61
  store i32 %7, ptr %50, align 4, !tbaa !8
  br label %63

.thread71:                                        ; preds = %.thread68, %59, %.thread66
  %62 = phi ptr [ %50, %.thread66 ], [ %50, %59 ], [ %56, %.thread68 ]
  %.1.3 = phi i8 [ %.1.2, %.thread66 ], [ %48, %59 ], [ %54, %.thread68 ]
  store i32 %7, ptr %62, align 4, !tbaa !8
  %.not33 = icmp eq i8 %.1.3, 0
  br i1 %.not33, label %.sink.split, label %63

63:                                               ; preds = %.thread76, %.thread71
  %.1.379 = phi i8 [ %.1.2, %.thread76 ], [ %.1.3, %.thread71 ]
  store i8 %.1.379, ptr %5, align 1, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %64 = getelementptr inbounds [1001 x i8], ptr @_ZZ4mainE3buf, i64 0, i64 %indvars.iv.next
  %65 = load i8, ptr %64, align 1, !tbaa !5
  %.not = icmp eq i8 %65, 0
  br i1 %.not, label %.sink.split, label %.lr.ph, !llvm.loop !10

.sink.split:                                      ; preds = %63, %61, %45, %29, %.thread71, %.thread73
  %.str.1.sink.ph = phi ptr [ @.str.1, %.thread73 ], [ @.str.1, %.thread71 ], [ @.str.1, %29 ], [ @.str.1, %45 ], [ @.str.1, %61 ], [ @_ZZ4mainE3buf, %63 ]
  store i32 %7, ptr @_ZZ4mainE2st, align 4, !tbaa !8
  br label %66

66:                                               ; preds = %.sink.split, %.preheader
  %.str.1.sink = phi ptr [ @_ZZ4mainE3buf, %.preheader ], [ %.str.1.sink.ph, %.sink.split ]
  %67 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) %.str.1.sink)
  ret i32 0
}

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

; Function Attrs: nofree nounwind
declare noundef i32 @puts(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" }

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


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