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

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

@n = external dso_local global i32, align 4
@len = external dso_local global i32, align 4
@tot = external dso_local global i32, align 4
@pos = external dso_local global [101 x i32], align 16
@str = external dso_local global [101 x i8], align 16
@vis = 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 i8, align 1
  store i32 0, ptr %1, align 4
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @str)
  %6 = call i64 @strlen(ptr noundef @str) #4
  %7 = trunc i64 %6 to i32
  store i32 %7, ptr @len, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %37, %0
  %9 = load i32, ptr %2, align 4, !tbaa !5
  %10 = load i32, ptr @len, align 4, !tbaa !5
  %11 = icmp slt i32 %9, %10
  br i1 %11, label %13, label %12

12:                                               ; preds = %8
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  br label %40

13:                                               ; preds = %8
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [101 x i8], ptr @str, i64 0, i64 %15
  %17 = load i8, ptr %16, align 1, !tbaa !9
  %18 = sext i8 %17 to i32
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [256 x i8], ptr @vis, i64 0, i64 %19
  %21 = load i8, ptr %20, align 1, !tbaa !10, !range !12, !noundef !13
  %22 = trunc i8 %21 to i1
  br i1 %22, label %36, label %23

23:                                               ; preds = %13
  %24 = load i32, ptr %2, align 4, !tbaa !5
  %25 = load i32, ptr @tot, align 4, !tbaa !5
  %26 = add nsw i32 %25, 1
  store i32 %26, ptr @tot, align 4, !tbaa !5
  %27 = sext i32 %25 to i64
  %28 = getelementptr inbounds [101 x i32], ptr @pos, i64 0, i64 %27
  store i32 %24, ptr %28, align 4, !tbaa !5
  %29 = load i32, ptr %2, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [101 x i8], ptr @str, i64 0, i64 %30
  %32 = load i8, ptr %31, align 1, !tbaa !9
  %33 = sext i8 %32 to i32
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [256 x i8], ptr @vis, i64 0, i64 %34
  store i8 1, ptr %35, align 1, !tbaa !10
  br label %36

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

37:                                               ; preds = %36
  %38 = load i32, ptr %2, align 4, !tbaa !5
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr %2, align 4, !tbaa !5
  br label %8, !llvm.loop !14

40:                                               ; preds = %12
  %41 = load i32, ptr @tot, align 4, !tbaa !5
  %42 = load i32, ptr @n, align 4, !tbaa !5
  %43 = icmp slt i32 %41, %42
  br i1 %43, label %44, label %46

44:                                               ; preds = %40
  %45 = call i32 @puts(ptr noundef @.str.1)
  store i32 0, ptr %1, align 4
  br label %92

46:                                               ; preds = %40
  %47 = call i32 @puts(ptr noundef @.str.2)
  %48 = load i32, ptr @len, align 4, !tbaa !5
  %49 = load i32, ptr @n, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [101 x i32], ptr @pos, i64 0, i64 %50
  store i32 %48, ptr %51, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %52

52:                                               ; preds = %88, %46
  %53 = load i32, ptr %3, align 4, !tbaa !5
  %54 = load i32, ptr @n, align 4, !tbaa !5
  %55 = icmp slt i32 %53, %54
  br i1 %55, label %57, label %56

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

57:                                               ; preds = %52
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #5
  %58 = load i32, ptr %3, align 4, !tbaa !5
  %59 = add nsw i32 %58, 1
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [101 x i32], ptr @pos, i64 0, i64 %60
  %62 = load i32, ptr %61, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [101 x i8], ptr @str, i64 0, i64 %63
  %65 = load i8, ptr %64, align 1, !tbaa !9
  store i8 %65, ptr %4, align 1, !tbaa !9
  %66 = load i32, ptr %3, align 4, !tbaa !5
  %67 = add nsw i32 %66, 1
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds [101 x i32], ptr @pos, i64 0, i64 %68
  %70 = load i32, ptr %69, align 4, !tbaa !5
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [101 x i8], ptr @str, i64 0, i64 %71
  store i8 0, ptr %72, align 1, !tbaa !9
  %73 = load i32, ptr %3, align 4, !tbaa !5
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [101 x i32], ptr @pos, i64 0, i64 %74
  %76 = load i32, ptr %75, align 4, !tbaa !5
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds i8, ptr @str, i64 %77
  %79 = call i32 @puts(ptr noundef %78)
  %80 = load i8, ptr %4, align 1, !tbaa !9
  %81 = load i32, ptr %3, align 4, !tbaa !5
  %82 = add nsw i32 %81, 1
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds [101 x i32], ptr @pos, i64 0, i64 %83
  %85 = load i32, ptr %84, align 4, !tbaa !5
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds [101 x i8], ptr @str, i64 0, i64 %86
  store i8 %80, ptr %87, align 1, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #5
  br label %88

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

91:                                               ; preds = %56
  store i32 0, ptr %1, align 4
  br label %92

92:                                               ; preds = %91, %44
  %93 = load i32, ptr %1, align 4
  ret i32 %93
}

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

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

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

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

declare i32 @puts(ptr noundef) #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 = { "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 = { 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 #3 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { nounwind willreturn memory(read) }
attributes #5 = { 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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"bool", !7, i64 0}
!12 = !{i8 0, i8 2}
!13 = !{}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


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

@n = external dso_local global i32, align 4
@len = external dso_local local_unnamed_addr global i32, align 4
@tot = external dso_local local_unnamed_addr global i32, align 4
@pos = external dso_local local_unnamed_addr global [101 x i32], align 16
@str = external dso_local global [101 x i8], align 16
@vis = external dso_local local_unnamed_addr 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 @n, ptr noundef nonnull @str)
  %2 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) @str) #3
  %3 = trunc i64 %2 to i32
  store i32 %3, ptr @len, align 4, !tbaa !5
  %tot.promoted = load i32, ptr @tot, align 4, !tbaa !5
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %0
  %wide.trip.count = and i64 %2, 2147483647
  %xtraiter = and i64 %2, 1
  %5 = icmp eq i64 %wide.trip.count, 1
  br i1 %5, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = sub nsw i64 %wide.trip.count, %xtraiter
  br label %.lr.ph

._crit_edge.loopexit.unr-lcssa:                   ; preds = %44, %.lr.ph.preheader
  %.lcssa.ph = phi i32 [ poison, %.lr.ph.preheader ], [ %45, %44 ]
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next.1, %44 ]
  %.unr = phi i32 [ %tot.promoted, %.lr.ph.preheader ], [ %45, %44 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa
  %6 = getelementptr inbounds [101 x i8], ptr @str, i64 0, i64 %indvars.iv.unr
  %7 = load i8, ptr %6, align 1, !tbaa !9
  %8 = sext i8 %7 to i64
  %9 = getelementptr inbounds [256 x i8], ptr @vis, i64 0, i64 %8
  %10 = load i8, ptr %9, align 1, !tbaa !10, !range !12, !noundef !13
  %11 = trunc nuw i8 %10 to i1
  br i1 %11, label %._crit_edge, label %12

12:                                               ; preds = %.lr.ph.epil
  %13 = add nsw i32 %.unr, 1
  store i32 %13, ptr @tot, align 4, !tbaa !5
  %14 = sext i32 %.unr to i64
  %15 = getelementptr inbounds [101 x i32], ptr @pos, i64 0, i64 %14
  %16 = trunc nuw nsw i64 %indvars.iv.unr to i32
  store i32 %16, ptr %15, align 4, !tbaa !5
  store i8 1, ptr %9, align 1, !tbaa !10
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %12, %.lr.ph.epil, %0
  %17 = phi i32 [ %tot.promoted, %0 ], [ %.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %.unr, %.lr.ph.epil ], [ %13, %12 ]
  %18 = load i32, ptr @n, align 4, !tbaa !5
  %19 = icmp slt i32 %17, %18
  br i1 %19, label %46, label %48

.lr.ph:                                           ; preds = %44, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader.new ], [ %indvars.iv.next.1, %44 ]
  %20 = phi i32 [ %tot.promoted, %.lr.ph.preheader.new ], [ %45, %44 ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %44 ]
  %21 = getelementptr inbounds [101 x i8], ptr @str, i64 0, i64 %indvars.iv
  %22 = load i8, ptr %21, align 2, !tbaa !9
  %23 = sext i8 %22 to i64
  %24 = getelementptr inbounds [256 x i8], ptr @vis, i64 0, i64 %23
  %25 = load i8, ptr %24, align 1, !tbaa !10, !range !12, !noundef !13
  %26 = trunc nuw i8 %25 to i1
  br i1 %26, label %.lr.ph.1, label %27

27:                                               ; preds = %.lr.ph
  %28 = add nsw i32 %20, 1
  store i32 %28, ptr @tot, align 4, !tbaa !5
  %29 = sext i32 %20 to i64
  %30 = getelementptr inbounds [101 x i32], ptr @pos, i64 0, i64 %29
  %31 = trunc nuw nsw i64 %indvars.iv to i32
  store i32 %31, ptr %30, align 4, !tbaa !5
  store i8 1, ptr %24, align 1, !tbaa !10
  br label %.lr.ph.1

.lr.ph.1:                                         ; preds = %.lr.ph, %27
  %32 = phi i32 [ %20, %.lr.ph ], [ %28, %27 ]
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %33 = getelementptr inbounds [101 x i8], ptr @str, i64 0, i64 %indvars.iv.next
  %34 = load i8, ptr %33, align 1, !tbaa !9
  %35 = sext i8 %34 to i64
  %36 = getelementptr inbounds [256 x i8], ptr @vis, i64 0, i64 %35
  %37 = load i8, ptr %36, align 1, !tbaa !10, !range !12, !noundef !13
  %38 = trunc nuw i8 %37 to i1
  br i1 %38, label %44, label %39

39:                                               ; preds = %.lr.ph.1
  %40 = add nsw i32 %32, 1
  store i32 %40, ptr @tot, align 4, !tbaa !5
  %41 = sext i32 %32 to i64
  %42 = getelementptr inbounds [101 x i32], ptr @pos, i64 0, i64 %41
  %43 = trunc nuw nsw i64 %indvars.iv.next to i32
  store i32 %43, ptr %42, align 4, !tbaa !5
  store i8 1, ptr %36, align 1, !tbaa !10
  br label %44

44:                                               ; preds = %39, %.lr.ph.1
  %45 = phi i32 [ %32, %.lr.ph.1 ], [ %40, %39 ]
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !14

46:                                               ; preds = %._crit_edge
  %47 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.1)
  br label %.loopexit

48:                                               ; preds = %._crit_edge
  %49 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.2)
  %50 = load i32, ptr @len, align 4, !tbaa !5
  %51 = load i32, ptr @n, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [101 x i32], ptr @pos, i64 0, i64 %52
  store i32 %50, ptr %53, align 4, !tbaa !5
  %54 = icmp sgt i32 %51, 0
  br i1 %54, label %.lr.ph18.preheader, label %.loopexit

.lr.ph18.preheader:                               ; preds = %48
  %.pre = load i32, ptr @pos, align 16, !tbaa !5
  br label %.lr.ph18

.lr.ph18:                                         ; preds = %.lr.ph18.preheader, %.lr.ph18
  %55 = phi i32 [ %.pre, %.lr.ph18.preheader ], [ %64, %.lr.ph18 ]
  %indvars.iv20 = phi i64 [ 0, %.lr.ph18.preheader ], [ %indvars.iv.next21, %.lr.ph18 ]
  %indvars.iv.next21 = add nuw nsw i64 %indvars.iv20, 1
  %56 = getelementptr inbounds [101 x i32], ptr @pos, i64 0, i64 %indvars.iv.next21
  %57 = load i32, ptr %56, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [101 x i8], ptr @str, i64 0, i64 %58
  %60 = load i8, ptr %59, align 1, !tbaa !9
  store i8 0, ptr %59, align 1, !tbaa !9
  %61 = sext i32 %55 to i64
  %62 = getelementptr inbounds i8, ptr @str, i64 %61
  %63 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) %62)
  %64 = load i32, ptr %56, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [101 x i8], ptr @str, i64 0, i64 %65
  store i8 %60, ptr %66, align 1, !tbaa !9
  %67 = load i32, ptr @n, align 4, !tbaa !5
  %68 = sext i32 %67 to i64
  %69 = icmp slt i64 %indvars.iv.next21, %68
  br i1 %69, label %.lr.ph18, label %.loopexit, !llvm.loop !16

.loopexit:                                        ; preds = %.lr.ph18, %48, %46
  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 @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" }
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 = !{!"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 = !{!"bool", !7, i64 0}
!12 = !{i8 0, i8 2}
!13 = !{}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


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