; LLVM IR from tangjz/acm-icpc :: codeforces/complete (757A)

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

@pat = external dso_local global ptr, align 8
@cnt = external dso_local global [257 x i32], align 16
@need = external dso_local global [257 x i32], align 16
@ans = external dso_local global i32, align 4
@tex = external dso_local global [100001 x i8], align 16
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 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
  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 %6

6:                                                ; preds = %24, %0
  %7 = load ptr, ptr @pat, align 8, !tbaa !9
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds i8, ptr %7, i64 %9
  %11 = load i8, ptr %10, align 1, !tbaa !11
  %12 = icmp ne i8 %11, 0
  br i1 %12, label %14, label %13

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

14:                                               ; preds = %6
  %15 = load ptr, ptr @pat, align 8, !tbaa !9
  %16 = load i32, ptr %2, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds i8, ptr %15, i64 %17
  %19 = load i8, ptr %18, align 1, !tbaa !11
  %20 = sext i8 %19 to i64
  %21 = getelementptr inbounds [257 x i32], ptr @need, i64 0, i64 %20
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = add nsw i32 %22, 1
  store i32 %23, ptr %21, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %14
  %25 = load i32, ptr %2, align 4, !tbaa !5
  %26 = add nsw i32 %25, 1
  store i32 %26, ptr %2, align 4, !tbaa !5
  br label %6, !llvm.loop !12

27:                                               ; preds = %13
  %28 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @tex)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %29

29:                                               ; preds = %45, %27
  %30 = load i32, ptr %3, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [100001 x i8], ptr @tex, i64 0, i64 %31
  %33 = load i8, ptr %32, align 1, !tbaa !11
  %34 = icmp ne i8 %33, 0
  br i1 %34, label %36, label %35

35:                                               ; preds = %29
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %48

36:                                               ; preds = %29
  %37 = load i32, ptr %3, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [100001 x i8], ptr @tex, i64 0, i64 %38
  %40 = load i8, ptr %39, align 1, !tbaa !11
  %41 = sext i8 %40 to i64
  %42 = getelementptr inbounds [257 x i32], ptr @cnt, i64 0, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !5
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr %42, align 4, !tbaa !5
  br label %45

45:                                               ; preds = %36
  %46 = load i32, ptr %3, align 4, !tbaa !5
  %47 = add nsw i32 %46, 1
  store i32 %47, ptr %3, align 4, !tbaa !5
  br label %29, !llvm.loop !14

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

49:                                               ; preds = %79, %48
  %50 = load i32, ptr %4, align 4, !tbaa !5
  %51 = icmp slt i32 %50, 257
  br i1 %51, label %53, label %52

52:                                               ; preds = %49
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %82

53:                                               ; preds = %49
  %54 = load i32, ptr %4, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [257 x i32], ptr @need, i64 0, i64 %55
  %57 = load i32, ptr %56, align 4, !tbaa !5
  %58 = icmp ne i32 %57, 0
  br i1 %58, label %60, label %59

59:                                               ; preds = %53
  br label %79

60:                                               ; preds = %53
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %61 = load i32, ptr %4, align 4, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [257 x i32], ptr @cnt, i64 0, i64 %62
  %64 = load i32, ptr %63, align 4, !tbaa !5
  %65 = load i32, ptr %4, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [257 x i32], ptr @need, i64 0, i64 %66
  %68 = load i32, ptr %67, align 4, !tbaa !5
  %69 = sdiv i32 %64, %68
  store i32 %69, ptr %5, align 4, !tbaa !5
  %70 = load i32, ptr @ans, align 4, !tbaa !5
  %71 = icmp eq i32 %70, -1
  br i1 %71, label %76, label %72

72:                                               ; preds = %60
  %73 = load i32, ptr @ans, align 4, !tbaa !5
  %74 = load i32, ptr %5, align 4, !tbaa !5
  %75 = icmp sgt i32 %73, %74
  br i1 %75, label %76, label %78

76:                                               ; preds = %72, %60
  %77 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %77, ptr @ans, align 4, !tbaa !5
  br label %78

78:                                               ; preds = %76, %72
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %79

79:                                               ; preds = %78, %59
  %80 = load i32, ptr %4, align 4, !tbaa !5
  %81 = add nsw i32 %80, 1
  store i32 %81, ptr %4, align 4, !tbaa !5
  br label %49, !llvm.loop !15

82:                                               ; preds = %52
  %83 = load i32, ptr @ans, align 4, !tbaa !5
  %84 = icmp eq i32 %83, -1
  br i1 %84, label %85, label %86

85:                                               ; preds = %82
  store i32 0, ptr @ans, align 4, !tbaa !5
  br label %86

86:                                               ; preds = %85, %82
  %87 = load i32, ptr @ans, align 4, !tbaa !5
  %88 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %87)
  ret i32 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

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

declare i32 @printf(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 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!7, !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"

@pat = external dso_local local_unnamed_addr global ptr, align 8
@cnt = external dso_local local_unnamed_addr global [257 x i32], align 16
@need = external dso_local local_unnamed_addr global [257 x i32], align 16
@ans = external dso_local local_unnamed_addr global i32, align 4
@tex = external dso_local global [100001 x i8], align 16
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = load ptr, ptr @pat, align 8, !tbaa !5
  %2 = load i8, ptr %1, align 1, !tbaa !9
  %.not21 = icmp eq i8 %2, 0
  br i1 %.not21, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %0
  %3 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @tex)
  %4 = load i8, ptr @tex, align 16, !tbaa !9
  %.not1923 = icmp eq i8 %4, 0
  br i1 %.not1923, label %.preheader, label %.lr.ph26

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %0 ]
  %5 = phi i8 [ %11, %.lr.ph ], [ %2, %0 ]
  %6 = sext i8 %5 to i64
  %7 = getelementptr inbounds [257 x i32], ptr @need, i64 0, i64 %6
  %8 = load i32, ptr %7, align 4, !tbaa !10
  %9 = add nsw i32 %8, 1
  store i32 %9, ptr %7, align 4, !tbaa !10
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %10 = getelementptr inbounds i8, ptr %1, i64 %indvars.iv.next
  %11 = load i8, ptr %10, align 1, !tbaa !9
  %.not = icmp eq i8 %11, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !12

.preheader:                                       ; preds = %.lr.ph26, %._crit_edge
  %ans.promoted = load i32, ptr @ans, align 4, !tbaa !10
  br label %21

.lr.ph26:                                         ; preds = %._crit_edge, %.lr.ph26
  %indvars.iv28 = phi i64 [ %indvars.iv.next29, %.lr.ph26 ], [ 0, %._crit_edge ]
  %12 = phi i8 [ %18, %.lr.ph26 ], [ %4, %._crit_edge ]
  %13 = sext i8 %12 to i64
  %14 = getelementptr inbounds [257 x i32], ptr @cnt, i64 0, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !10
  %16 = add nsw i32 %15, 1
  store i32 %16, ptr %14, align 4, !tbaa !10
  %indvars.iv.next29 = add nuw nsw i64 %indvars.iv28, 1
  %17 = getelementptr inbounds [100001 x i8], ptr @tex, i64 0, i64 %indvars.iv.next29
  %18 = load i8, ptr %17, align 1, !tbaa !9
  %.not19 = icmp eq i8 %18, 0
  br i1 %.not19, label %.preheader, label %.lr.ph26, !llvm.loop !14

19:                                               ; preds = %32
  %20 = icmp eq i32 %33, -1
  br i1 %20, label %34, label %35

21:                                               ; preds = %.preheader, %32
  %indvars.iv30 = phi i64 [ 0, %.preheader ], [ %indvars.iv.next31, %32 ]
  %22 = phi i32 [ %ans.promoted, %.preheader ], [ %33, %32 ]
  %23 = getelementptr inbounds [257 x i32], ptr @need, i64 0, i64 %indvars.iv30
  %24 = load i32, ptr %23, align 4, !tbaa !10
  %.not20 = icmp eq i32 %24, 0
  br i1 %.not20, label %32, label %25

25:                                               ; preds = %21
  %26 = getelementptr inbounds [257 x i32], ptr @cnt, i64 0, i64 %indvars.iv30
  %27 = load i32, ptr %26, align 4, !tbaa !10
  %28 = sdiv i32 %27, %24
  %29 = icmp eq i32 %22, -1
  %30 = icmp sgt i32 %22, %28
  %or.cond = select i1 %29, i1 true, i1 %30
  br i1 %or.cond, label %31, label %32

31:                                               ; preds = %25
  store i32 %28, ptr @ans, align 4, !tbaa !10
  br label %32

32:                                               ; preds = %31, %25, %21
  %33 = phi i32 [ %28, %31 ], [ %22, %25 ], [ %22, %21 ]
  %indvars.iv.next31 = add nuw nsw i64 %indvars.iv30, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next31, 257
  br i1 %exitcond.not, label %19, label %21, !llvm.loop !15

34:                                               ; preds = %19
  store i32 0, ptr @ans, align 4, !tbaa !10
  br label %35

35:                                               ; preds = %34, %19
  %36 = phi i32 [ 0, %34 ], [ %33, %19 ]
  %37 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %36)
  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 @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" }

!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 = !{!"any pointer", !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: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass