; LLVM IR from tangjz/acm-icpc :: luogu (1106)

; 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 i32, align 4
@ch = external dso_local global [256 x i8], align 16
@.str = external hidden unnamed_addr constant [5 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

; 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
  store i32 0, ptr %1, align 4
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @ch, ptr noundef @s)
  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
  %6 = call i64 @strlen(ptr noundef @ch) #5
  %7 = trunc i64 %6 to i32
  store i32 %7, ptr %4, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %53, %0
  %9 = load i32, ptr @s, align 4, !tbaa !5
  %10 = add nsw i32 %9, -1
  store i32 %10, ptr @s, align 4, !tbaa !5
  %11 = icmp ne i32 %9, 0
  br i1 %11, label %12, label %56

12:                                               ; preds = %8
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %33, %12
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = icmp slt i32 %14, %15
  br i1 %16, label %17, label %36

17:                                               ; preds = %13
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [256 x i8], ptr @ch, i64 0, i64 %19
  %21 = load i8, ptr %20, align 1, !tbaa !9
  %22 = sext i8 %21 to i32
  %23 = load i32, ptr %2, align 4, !tbaa !5
  %24 = add nsw i32 %23, 1
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [256 x i8], ptr @ch, i64 0, i64 %25
  %27 = load i8, ptr %26, align 1, !tbaa !9
  %28 = sext i8 %27 to i32
  %29 = icmp sgt i32 %22, %28
  br i1 %29, label %30, label %32

30:                                               ; preds = %17
  %31 = load i32, ptr %2, align 4, !tbaa !5
  store i32 %31, ptr %3, align 4, !tbaa !5
  br label %36

32:                                               ; preds = %17
  br label %33

33:                                               ; preds = %32
  %34 = load i32, ptr %2, align 4, !tbaa !5
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr %2, align 4, !tbaa !5
  br label %13, !llvm.loop !10

36:                                               ; preds = %30, %13
  br label %37

37:                                               ; preds = %50, %36
  %38 = load i32, ptr %3, align 4, !tbaa !5
  %39 = load i32, ptr %4, align 4, !tbaa !5
  %40 = icmp slt i32 %38, %39
  br i1 %40, label %41, label %53

41:                                               ; preds = %37
  %42 = load i32, ptr %3, align 4, !tbaa !5
  %43 = add nsw i32 %42, 1
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [256 x i8], ptr @ch, i64 0, i64 %44
  %46 = load i8, ptr %45, align 1, !tbaa !9
  %47 = load i32, ptr %3, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [256 x i8], ptr @ch, i64 0, i64 %48
  store i8 %46, ptr %49, align 1, !tbaa !9
  br label %50

50:                                               ; preds = %41
  %51 = load i32, ptr %3, align 4, !tbaa !5
  %52 = add nsw i32 %51, 1
  store i32 %52, ptr %3, align 4, !tbaa !5
  br label %37, !llvm.loop !12

53:                                               ; preds = %37
  %54 = load i32, ptr %4, align 4, !tbaa !5
  %55 = add nsw i32 %54, -1
  store i32 %55, ptr %4, align 4, !tbaa !5
  br label %8, !llvm.loop !13

56:                                               ; preds = %8
  br label %57

57:                                               ; preds = %78, %56
  %58 = load i8, ptr @ch, align 16, !tbaa !9
  %59 = sext i8 %58 to i32
  %60 = icmp eq i32 %59, 48
  br i1 %60, label %61, label %81

61:                                               ; preds = %57
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %62

62:                                               ; preds = %75, %61
  %63 = load i32, ptr %2, align 4, !tbaa !5
  %64 = load i32, ptr %4, align 4, !tbaa !5
  %65 = icmp slt i32 %63, %64
  br i1 %65, label %66, label %78

66:                                               ; preds = %62
  %67 = load i32, ptr %2, align 4, !tbaa !5
  %68 = add nsw i32 %67, 1
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [256 x i8], ptr @ch, i64 0, i64 %69
  %71 = load i8, ptr %70, align 1, !tbaa !9
  %72 = load i32, ptr %2, align 4, !tbaa !5
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [256 x i8], ptr @ch, i64 0, i64 %73
  store i8 %71, ptr %74, align 1, !tbaa !9
  br label %75

75:                                               ; preds = %66
  %76 = load i32, ptr %2, align 4, !tbaa !5
  %77 = add nsw i32 %76, 1
  store i32 %77, ptr %2, align 4, !tbaa !5
  br label %62, !llvm.loop !14

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

81:                                               ; preds = %57
  %82 = load i8, ptr @ch, align 16, !tbaa !9
  %83 = sext i8 %82 to i32
  %84 = icmp eq i32 %83, 0
  br i1 %84, label %85, label %87

85:                                               ; preds = %81
  %86 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  br label %89

87:                                               ; preds = %81
  %88 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, ptr noundef @ch)
  br label %89

89:                                               ; preds = %87, %85
  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
}

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

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

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

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}
!13 = distinct !{!13, !11}
!14 = distinct !{!14, !11}
!15 = distinct !{!15, !11}


; 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 i32, align 4
@ch = external dso_local global [256 x i8], align 16
@.str = external hidden unnamed_addr constant [5 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

; 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 @ch, ptr noundef nonnull @s)
  %2 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) @ch) #4
  %s.promoted = load i32, ptr @s, align 4, !tbaa !5
  %.not26 = icmp eq i32 %s.promoted, 0
  br i1 %.not26, label %.preheader23, label %.preheader24.preheader

.preheader24.preheader:                           ; preds = %0
  %3 = add i32 %s.promoted, -1
  %sext = shl i64 %2, 32
  %4 = ashr exact i64 %sext, 32
  %5 = zext i32 %3 to i64
  br label %.preheader24

.preheader24:                                     ; preds = %.preheader24.preheader, %._crit_edge
  %indvars.iv42 = phi i64 [ %4, %.preheader24.preheader ], [ %indvars.iv.next43, %._crit_edge ]
  %6 = phi i32 [ %3, %.preheader24.preheader ], [ %32, %._crit_edge ]
  %.01827 = phi i32 [ undef, %.preheader24.preheader ], [ %.2.lcssa, %._crit_edge ]
  br label %9

.preheader23.loopexit:                            ; preds = %._crit_edge
  %7 = xor i64 %5, -1
  %8 = add i64 %2, %7
  br label %.preheader23

.preheader23:                                     ; preds = %.preheader23.loopexit, %0
  %.0.lcssa.in = phi i64 [ %2, %0 ], [ %8, %.preheader23.loopexit ]
  %.0.lcssa = trunc i64 %.0.lcssa.in to i32
  store i32 -1, ptr @s, align 4, !tbaa !5
  %.pre48 = load i8, ptr @ch, align 16, !tbaa !9
  br label %33

9:                                                ; preds = %.preheader24, %11
  %indvars.iv = phi i64 [ 0, %.preheader24 ], [ %indvars.iv.next, %11 ]
  %10 = icmp slt i64 %indvars.iv, %indvars.iv42
  br i1 %10, label %11, label %.split.loop.exit49

11:                                               ; preds = %9
  %12 = getelementptr inbounds [256 x i8], ptr @ch, i64 0, i64 %indvars.iv
  %13 = load i8, ptr %12, align 1, !tbaa !9
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %14 = getelementptr inbounds [256 x i8], ptr @ch, i64 0, i64 %indvars.iv.next
  %15 = load i8, ptr %14, align 1, !tbaa !9
  %16 = icmp sgt i8 %13, %15
  br i1 %16, label %.split.loop.exit, label %9, !llvm.loop !10

.split.loop.exit:                                 ; preds = %11
  %17 = trunc nuw nsw i64 %indvars.iv to i32
  br label %.split.loop.exit49

.split.loop.exit49:                               ; preds = %9, %.split.loop.exit
  %.119 = phi i32 [ %17, %.split.loop.exit ], [ %.01827, %9 ]
  %18 = sext i32 %.119 to i64
  %19 = icmp sgt i64 %indvars.iv42, %18
  br i1 %19, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %.split.loop.exit49
  %20 = sub i64 %indvars.iv42, %18
  %min.iters.check = icmp ult i64 %20, 32
  br i1 %min.iters.check, label %.lr.ph.preheader53, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph.preheader
  %n.vec = and i64 %20, -32
  %ind.end = add i64 %n.vec, %18
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %offset.idx = add i64 %index, %18
  %21 = add nsw i64 %offset.idx, 1
  %22 = getelementptr inbounds [256 x i8], ptr @ch, i64 0, i64 %21
  %23 = getelementptr inbounds i8, ptr %22, i64 16
  %wide.load = load <16 x i8>, ptr %22, align 1, !tbaa !9
  %wide.load52 = load <16 x i8>, ptr %23, align 1, !tbaa !9
  %24 = getelementptr inbounds [256 x i8], ptr @ch, i64 0, i64 %offset.idx
  %25 = getelementptr inbounds i8, ptr %24, i64 16
  store <16 x i8> %wide.load, ptr %24, align 1, !tbaa !9
  store <16 x i8> %wide.load52, ptr %25, align 1, !tbaa !9
  %index.next = add nuw i64 %index, 32
  %26 = icmp eq i64 %index.next, %n.vec
  br i1 %26, label %middle.block, label %vector.body, !llvm.loop !12

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %20, %n.vec
  br i1 %cmp.n, label %._crit_edge.loopexit, label %.lr.ph.preheader53

.lr.ph.preheader53:                               ; preds = %middle.block, %.lr.ph.preheader
  %indvars.iv39.ph = phi i64 [ %18, %.lr.ph.preheader ], [ %ind.end, %middle.block ]
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader53, %.lr.ph
  %indvars.iv39 = phi i64 [ %indvars.iv.next40, %.lr.ph ], [ %indvars.iv39.ph, %.lr.ph.preheader53 ]
  %indvars.iv.next40 = add nsw i64 %indvars.iv39, 1
  %27 = getelementptr inbounds [256 x i8], ptr @ch, i64 0, i64 %indvars.iv.next40
  %28 = load i8, ptr %27, align 1, !tbaa !9
  %29 = getelementptr inbounds [256 x i8], ptr @ch, i64 0, i64 %indvars.iv39
  store i8 %28, ptr %29, align 1, !tbaa !9
  %30 = icmp slt i64 %indvars.iv.next40, %indvars.iv42
  br i1 %30, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !15

._crit_edge.loopexit:                             ; preds = %.lr.ph, %middle.block
  %indvars.iv.next40.lcssa = phi i64 [ %ind.end, %middle.block ], [ %indvars.iv.next40, %.lr.ph ]
  %31 = trunc nsw i64 %indvars.iv.next40.lcssa to i32
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.split.loop.exit49
  %.2.lcssa = phi i32 [ %.119, %.split.loop.exit49 ], [ %31, %._crit_edge.loopexit ]
  %indvars.iv.next43 = add nsw i64 %indvars.iv42, -1
  %32 = add nsw i32 %6, -1
  %.not = icmp eq i32 %6, 0
  br i1 %.not, label %.preheader23.loopexit, label %.preheader24, !llvm.loop !16

33:                                               ; preds = %.preheader23, %._crit_edge33
  %34 = phi i8 [ %37, %._crit_edge33 ], [ %.pre48, %.preheader23 ]
  %.1 = phi i32 [ %38, %._crit_edge33 ], [ %.0.lcssa, %.preheader23 ]
  %35 = zext i32 %.1 to i64
  switch i8 %34, label %41 [
    i8 48, label %.preheader
    i8 0, label %39
  ]

.preheader:                                       ; preds = %33
  %36 = icmp sgt i32 %.1, 0
  br i1 %36, label %.lr.ph32.preheader, label %._crit_edge33

.lr.ph32.preheader:                               ; preds = %.preheader
  tail call void @llvm.memmove.p0.p0.i64(ptr nonnull align 16 @ch, ptr nonnull align 1 getelementptr inbounds (i8, ptr @ch, i64 1), i64 %35, i1 false), !tbaa !9
  %.pre = load i8, ptr @ch, align 16, !tbaa !9
  br label %._crit_edge33

._crit_edge33:                                    ; preds = %.lr.ph32.preheader, %.preheader
  %37 = phi i8 [ %.pre, %.lr.ph32.preheader ], [ 48, %.preheader ]
  %38 = add i32 %.1, -1
  br label %33, !llvm.loop !17

39:                                               ; preds = %33
  %40 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1)
  br label %43

41:                                               ; preds = %33
  %42 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, ptr noundef nonnull @ch)
  br label %43

43:                                               ; preds = %41, %39
  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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memmove.p0.p0.i64(ptr nocapture writeonly, ptr nocapture readonly, i64, i1 immarg) #3

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11, !13, !14}
!13 = !{!"llvm.loop.isvectorized", i32 1}
!14 = !{!"llvm.loop.unroll.runtime.disable"}
!15 = distinct !{!15, !11, !14, !13}
!16 = distinct !{!16, !11}
!17 = distinct !{!17, !11}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopIdiomRecognizePass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass