; LLVM IR from tangjz/acm-icpc :: uvalive (5876)

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

@t = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@f = external dso_local global [100020 x i32], align 16
@ans = external dso_local global i32, align 4
@tmp = external dso_local global [50010 x i8], align 16
@str = external dso_local global [100020 x i8], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 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 @t)
  br label %6

6:                                                ; preds = %98, %0
  %7 = load i32, ptr @t, align 4, !tbaa !5
  %8 = add nsw i32 %7, -1
  store i32 %8, ptr @t, align 4, !tbaa !5
  %9 = icmp ne i32 %7, 0
  br i1 %9, label %10, label %101

10:                                               ; preds = %6
  %11 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @tmp, ptr noundef @str)
  %12 = call i64 @strlen(ptr noundef @str) #5
  %13 = add i64 %12, 1
  %14 = trunc i64 %13 to i32
  store i32 %14, ptr @n, align 4, !tbaa !5
  %15 = load i32, ptr @n, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [100020 x i8], ptr @str, i64 0, i64 %16
  store i8 0, ptr %17, align 1, !tbaa !9
  %18 = load i32, ptr @n, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds i8, ptr @str, i64 %19
  %21 = call ptr @strcat(ptr noundef %20, ptr noundef @tmp) #6
  %22 = load i32, ptr @n, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds i8, ptr @str, i64 %23
  %25 = call i64 @strlen(ptr noundef %24) #5
  %26 = load i32, ptr @n, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = add i64 %27, %25
  %29 = trunc i64 %28 to i32
  store i32 %29, ptr @n, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #6
  store i32 1, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #6
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %30

30:                                               ; preds = %81, %10
  %31 = load i32, ptr %2, align 4, !tbaa !5
  %32 = load i32, ptr @n, align 4, !tbaa !5
  %33 = icmp slt i32 %31, %32
  br i1 %33, label %35, label %34

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

35:                                               ; preds = %30
  br label %36

36:                                               ; preds = %54, %35
  %37 = load i32, ptr %3, align 4, !tbaa !5
  %38 = icmp ne i32 %37, 0
  br i1 %38, label %39, label %51

39:                                               ; preds = %36
  %40 = load i32, ptr %2, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [100020 x i8], ptr @str, i64 0, i64 %41
  %43 = load i8, ptr %42, align 1, !tbaa !9
  %44 = sext i8 %43 to i32
  %45 = load i32, ptr %3, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [100020 x i8], ptr @str, i64 0, i64 %46
  %48 = load i8, ptr %47, align 1, !tbaa !9
  %49 = sext i8 %48 to i32
  %50 = icmp ne i32 %44, %49
  br label %51

51:                                               ; preds = %39, %36
  %52 = phi i1 [ false, %36 ], [ %50, %39 ]
  br i1 %52, label %53, label %59

53:                                               ; preds = %51
  br label %54

54:                                               ; preds = %53
  %55 = load i32, ptr %3, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [100020 x i32], ptr @f, i64 0, i64 %56
  %58 = load i32, ptr %57, align 4, !tbaa !5
  store i32 %58, ptr %3, align 4, !tbaa !5
  br label %36, !llvm.loop !10

59:                                               ; preds = %51
  %60 = load i32, ptr %2, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [100020 x i8], ptr @str, i64 0, i64 %61
  %63 = load i8, ptr %62, align 1, !tbaa !9
  %64 = sext i8 %63 to i32
  %65 = load i32, ptr %3, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [100020 x i8], ptr @str, i64 0, i64 %66
  %68 = load i8, ptr %67, align 1, !tbaa !9
  %69 = sext i8 %68 to i32
  %70 = icmp eq i32 %64, %69
  br i1 %70, label %71, label %74

71:                                               ; preds = %59
  %72 = load i32, ptr %3, align 4, !tbaa !5
  %73 = add nsw i32 %72, 1
  store i32 %73, ptr %3, align 4, !tbaa !5
  br label %75

74:                                               ; preds = %59
  br label %75

75:                                               ; preds = %74, %71
  %76 = phi i32 [ %73, %71 ], [ 0, %74 ]
  %77 = load i32, ptr %2, align 4, !tbaa !5
  %78 = add nsw i32 %77, 1
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds [100020 x i32], ptr @f, i64 0, i64 %79
  store i32 %76, ptr %80, align 4, !tbaa !5
  br label %81

81:                                               ; preds = %75
  %82 = load i32, ptr %2, align 4, !tbaa !5
  %83 = add nsw i32 %82, 1
  store i32 %83, ptr %2, align 4, !tbaa !5
  br label %30, !llvm.loop !12

84:                                               ; preds = %34
  store i32 0, ptr @ans, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #6
  %85 = load i32, ptr @n, align 4, !tbaa !5
  store i32 %85, ptr %4, align 4, !tbaa !5
  br label %86

86:                                               ; preds = %93, %84
  %87 = load i32, ptr %4, align 4, !tbaa !5
  %88 = icmp sgt i32 %87, 0
  br i1 %88, label %90, label %89

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

90:                                               ; preds = %86
  %91 = load i32, ptr @ans, align 4, !tbaa !5
  %92 = add nsw i32 %91, 1
  store i32 %92, ptr @ans, align 4, !tbaa !5
  br label %93

93:                                               ; preds = %90
  %94 = load i32, ptr %4, align 4, !tbaa !5
  %95 = sext i32 %94 to i64
  %96 = getelementptr inbounds [100020 x i32], ptr @f, i64 0, i64 %95
  %97 = load i32, ptr %96, align 4, !tbaa !5
  store i32 %97, ptr %4, align 4, !tbaa !5
  br label %86, !llvm.loop !13

98:                                               ; preds = %89
  %99 = load i32, ptr @ans, align 4, !tbaa !5
  %100 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %99)
  br label %6, !llvm.loop !14

101:                                              ; preds = %6
  ret i32 0
}

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

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

; Function Attrs: nounwind
declare ptr @strcat(ptr noundef, ptr noundef) #3

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

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

declare i32 @printf(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 = { 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 #4 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { nounwind willreturn memory(read) }
attributes #6 = { 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 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}
!13 = distinct !{!13, !11}
!14 = distinct !{!14, !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"

@t = external dso_local global i32, align 4
@n = external dso_local local_unnamed_addr global i32, align 4
@f = external dso_local local_unnamed_addr global [100020 x i32], align 16
@ans = external dso_local local_unnamed_addr global i32, align 4
@tmp = external dso_local global [50010 x i8], align 16
@str = external dso_local global [100020 x i8], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 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 @t)
  %2 = load i32, ptr @t, align 4, !tbaa !5
  %3 = add nsw i32 %2, -1
  store i32 %3, ptr @t, align 4, !tbaa !5
  %.not28 = icmp eq i32 %2, 0
  br i1 %.not28, label %._crit_edge31, label %.lr.ph30

.lr.ph30:                                         ; preds = %0, %28
  %4 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @tmp, ptr noundef nonnull @str)
  %5 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) @str) #4
  %6 = trunc i64 %5 to i32
  %7 = add i32 %6, 1
  %8 = sext i32 %7 to i64
  %9 = getelementptr inbounds [100020 x i8], ptr @str, i64 0, i64 %8
  store i8 0, ptr %9, align 1, !tbaa !9
  %10 = tail call ptr @strcat(ptr noundef nonnull dereferenceable(1) %9, ptr noundef nonnull dereferenceable(1) @tmp) #5
  %11 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %9) #4
  %12 = trunc i64 %11 to i32
  %13 = add i32 %7, %12
  store i32 %13, ptr @n, align 4, !tbaa !5
  %14 = icmp sgt i32 %13, 1
  br i1 %14, label %.preheader.preheader, label %._crit_edge

.preheader.preheader:                             ; preds = %.lr.ph30
  %wide.trip.count = zext nneg i32 %13 to i64
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %.critedge
  %indvars.iv = phi i64 [ 1, %.preheader.preheader ], [ %indvars.iv.next, %.critedge ]
  %.01222 = phi i32 [ 0, %.preheader.preheader ], [ %spec.select, %.critedge ]
  %.not1417 = icmp eq i32 %.01222, 0
  %.phi.trans.insert = getelementptr inbounds [100020 x i8], ptr @str, i64 0, i64 %indvars.iv
  %.pre = load i8, ptr %.phi.trans.insert, align 1, !tbaa !9
  br i1 %.not1417, label %.critedge, label %.lr.ph

._crit_edge:                                      ; preds = %.critedge, %.lr.ph30
  store i32 0, ptr @ans, align 4, !tbaa !5
  %15 = icmp sgt i32 %13, 0
  br i1 %15, label %.lr.ph26, label %28

.lr.ph:                                           ; preds = %.preheader, %19
  %.118 = phi i32 [ %21, %19 ], [ %.01222, %.preheader ]
  %16 = sext i32 %.118 to i64
  %17 = getelementptr inbounds [100020 x i8], ptr @str, i64 0, i64 %16
  %18 = load i8, ptr %17, align 1, !tbaa !9
  %.not15 = icmp eq i8 %.pre, %18
  br i1 %.not15, label %.critedge, label %19

19:                                               ; preds = %.lr.ph
  %20 = getelementptr inbounds [100020 x i32], ptr @f, i64 0, i64 %16
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %.not14 = icmp eq i32 %21, 0
  br i1 %.not14, label %.critedge, label %.lr.ph, !llvm.loop !10

.critedge:                                        ; preds = %.lr.ph, %19, %.preheader
  %.1.lcssa = phi i32 [ 0, %.preheader ], [ 0, %19 ], [ %.118, %.lr.ph ]
  %22 = sext i32 %.1.lcssa to i64
  %23 = getelementptr inbounds [100020 x i8], ptr @str, i64 0, i64 %22
  %24 = load i8, ptr %23, align 1, !tbaa !9
  %25 = icmp eq i8 %.pre, %24
  %26 = add nsw i32 %.1.lcssa, 1
  %spec.select = select i1 %25, i32 %26, i32 %.1.lcssa
  %spec.select16 = select i1 %25, i32 %26, i32 0
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %27 = getelementptr inbounds [100020 x i32], ptr @f, i64 0, i64 %indvars.iv.next
  store i32 %spec.select16, ptr %27, align 4, !tbaa !5
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.preheader, !llvm.loop !12

._crit_edge27:                                    ; preds = %.lr.ph26
  store i32 %34, ptr @ans, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %._crit_edge27, %._crit_edge
  %29 = phi i32 [ %34, %._crit_edge27 ], [ 0, %._crit_edge ]
  %30 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %29)
  %31 = load i32, ptr @t, align 4, !tbaa !5
  %32 = add nsw i32 %31, -1
  store i32 %32, ptr @t, align 4, !tbaa !5
  %.not = icmp eq i32 %31, 0
  br i1 %.not, label %._crit_edge31, label %.lr.ph30, !llvm.loop !13

.lr.ph26:                                         ; preds = %._crit_edge, %.lr.ph26
  %.024 = phi i32 [ %.0, %.lr.ph26 ], [ %13, %._crit_edge ]
  %33 = phi i32 [ %34, %.lr.ph26 ], [ 0, %._crit_edge ]
  %34 = add nuw nsw i32 %33, 1
  %35 = zext nneg i32 %.024 to i64
  %36 = getelementptr inbounds [100020 x i32], ptr @f, i64 0, i64 %35
  %.0 = load i32, ptr %36, align 4, !tbaa !5
  %37 = icmp sgt i32 %.0, 0
  br i1 %37, label %.lr.ph26, label %._crit_edge27, !llvm.loop !14

._crit_edge31:                                    ; preds = %28, %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: mustprogress nofree nounwind willreturn memory(argmem: readwrite)
declare ptr @strcat(ptr noalias noundef returned, ptr noalias nocapture noundef readonly) local_unnamed_addr #3

; 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 = { mustprogress nofree nounwind willreturn memory(argmem: readwrite) "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 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 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}
!13 = distinct !{!13, !11}
!14 = distinct !{!14, !11}


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