; LLVM IR from tangjz/acm-icpc :: lydsy (2748)

; 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
@sta = external dso_local global i32, align 4
@lim = external dso_local global i32, align 4
@c = external dso_local global i32, align 4
@f = external dso_local global [51 x [1010 x i8]], align 16
@.str = external hidden unnamed_addr constant [7 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
@.str.3 = external hidden unnamed_addr constant [3 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
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @sta, ptr noundef @lim)
  %7 = load i32, ptr @sta, align 4, !tbaa !5
  %8 = sext i32 %7 to i64
  %9 = getelementptr inbounds [1010 x i8], ptr @f, i64 0, i64 %8
  store i8 1, ptr %9, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %10

10:                                               ; preds = %67, %0
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = load i32, ptr @n, align 4, !tbaa !5
  %13 = icmp slt i32 %11, %12
  br i1 %13, label %15, label %14

14:                                               ; preds = %10
  store i32 2, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  br label %70

15:                                               ; preds = %10
  %16 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @c)
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %17

17:                                               ; preds = %63, %15
  %18 = load i32, ptr %4, align 4, !tbaa !5
  %19 = load i32, ptr @lim, align 4, !tbaa !5
  %20 = icmp sle i32 %18, %19
  br i1 %20, label %22, label %21

21:                                               ; preds = %17
  store i32 5, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %66

22:                                               ; preds = %17
  %23 = load i32, ptr %2, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [51 x [1010 x i8]], ptr @f, i64 0, i64 %24
  %26 = load i32, ptr %4, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [1010 x i8], ptr %25, i64 0, i64 %27
  %29 = load i8, ptr %28, align 1, !tbaa !9, !range !11, !noundef !12
  %30 = trunc i8 %29 to i1
  br i1 %30, label %31, label %62

31:                                               ; preds = %22
  %32 = load i32, ptr %4, align 4, !tbaa !5
  %33 = load i32, ptr @c, align 4, !tbaa !5
  %34 = add nsw i32 %32, %33
  %35 = load i32, ptr @lim, align 4, !tbaa !5
  %36 = icmp sle i32 %34, %35
  br i1 %36, label %37, label %47

37:                                               ; preds = %31
  %38 = load i32, ptr %2, align 4, !tbaa !5
  %39 = add nsw i32 %38, 1
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [51 x [1010 x i8]], ptr @f, i64 0, i64 %40
  %42 = load i32, ptr %4, align 4, !tbaa !5
  %43 = load i32, ptr @c, align 4, !tbaa !5
  %44 = add nsw i32 %42, %43
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [1010 x i8], ptr %41, i64 0, i64 %45
  store i8 1, ptr %46, align 1, !tbaa !9
  br label %47

47:                                               ; preds = %37, %31
  %48 = load i32, ptr %4, align 4, !tbaa !5
  %49 = load i32, ptr @c, align 4, !tbaa !5
  %50 = icmp sge i32 %48, %49
  br i1 %50, label %51, label %61

51:                                               ; preds = %47
  %52 = load i32, ptr %2, align 4, !tbaa !5
  %53 = add nsw i32 %52, 1
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [51 x [1010 x i8]], ptr @f, i64 0, i64 %54
  %56 = load i32, ptr %4, align 4, !tbaa !5
  %57 = load i32, ptr @c, align 4, !tbaa !5
  %58 = sub nsw i32 %56, %57
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [1010 x i8], ptr %55, i64 0, i64 %59
  store i8 1, ptr %60, align 1, !tbaa !9
  br label %61

61:                                               ; preds = %51, %47
  br label %62

62:                                               ; preds = %61, %22
  br label %63

63:                                               ; preds = %62
  %64 = load i32, ptr %4, align 4, !tbaa !5
  %65 = add nsw i32 %64, 1
  store i32 %65, ptr %4, align 4, !tbaa !5
  br label %17, !llvm.loop !13

66:                                               ; preds = %21
  br label %67

67:                                               ; preds = %66
  %68 = load i32, ptr %2, align 4, !tbaa !5
  %69 = add nsw i32 %68, 1
  store i32 %69, ptr %2, align 4, !tbaa !5
  br label %10, !llvm.loop !15

70:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %71 = load i32, ptr @lim, align 4, !tbaa !5
  store i32 %71, ptr %5, align 4, !tbaa !5
  br label %72

72:                                               ; preds = %89, %70
  %73 = load i32, ptr %5, align 4, !tbaa !5
  %74 = icmp sge i32 %73, 0
  br i1 %74, label %76, label %75

75:                                               ; preds = %72
  store i32 8, ptr %3, align 4
  br label %92

76:                                               ; preds = %72
  %77 = load i32, ptr @n, align 4, !tbaa !5
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds [51 x [1010 x i8]], ptr @f, i64 0, i64 %78
  %80 = load i32, ptr %5, align 4, !tbaa !5
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds [1010 x i8], ptr %79, i64 0, i64 %81
  %83 = load i8, ptr %82, align 1, !tbaa !9, !range !11, !noundef !12
  %84 = trunc i8 %83 to i1
  br i1 %84, label %85, label %88

85:                                               ; preds = %76
  %86 = load i32, ptr %5, align 4, !tbaa !5
  %87 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %86)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %3, align 4
  br label %92

88:                                               ; preds = %76
  br label %89

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

92:                                               ; preds = %85, %75
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  %93 = load i32, ptr %3, align 4
  switch i32 %93, label %98 [
    i32 8, label %94
    i32 1, label %96
  ]

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

96:                                               ; preds = %94, %92
  %97 = load i32, ptr %1, align 4
  ret i32 %97

98:                                               ; preds = %92
  unreachable
}

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

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}


; 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
@sta = external dso_local global i32, align 4
@lim = external dso_local global i32, align 4
@c = external dso_local global i32, align 4
@f = external dso_local local_unnamed_addr global [51 x [1010 x i8]], align 16
@.str = external hidden unnamed_addr constant [7 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
@.str.3 = external hidden unnamed_addr constant [3 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 @sta, ptr noundef nonnull @lim)
  %2 = load i32, ptr @sta, align 4, !tbaa !5
  %3 = sext i32 %2 to i64
  %4 = getelementptr inbounds [1010 x i8], ptr @f, i64 0, i64 %3
  store i8 1, ptr %4, align 1, !tbaa !9
  %5 = load i32, ptr @n, align 4, !tbaa !5
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %.lr.ph35, label %.._crit_edge36_crit_edge

.._crit_edge36_crit_edge:                         ; preds = %0
  %.pre = load i32, ptr @lim, align 4, !tbaa !5
  br label %._crit_edge36

._crit_edge36:                                    ; preds = %._crit_edge, %.._crit_edge36_crit_edge
  %7 = phi i32 [ %.pre, %.._crit_edge36_crit_edge ], [ %12, %._crit_edge ]
  %.lcssa = phi i32 [ %5, %.._crit_edge36_crit_edge ], [ %18, %._crit_edge ]
  %8 = icmp sgt i32 %7, -1
  br i1 %8, label %.lr.ph39, label %._crit_edge40

.lr.ph39:                                         ; preds = %._crit_edge36
  %9 = sext i32 %.lcssa to i64
  %10 = zext nneg i32 %7 to i64
  br label %34

.lr.ph35:                                         ; preds = %0, %._crit_edge
  %indvars.iv44 = phi i64 [ %indvars.iv.next45.pre-phi, %._crit_edge ], [ 0, %0 ]
  %11 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @c)
  %12 = load i32, ptr @lim, align 4, !tbaa !5
  %.not31 = icmp slt i32 %12, 0
  br i1 %.not31, label %.lr.ph35.._crit_edge_crit_edge, label %.lr.ph

.lr.ph35.._crit_edge_crit_edge:                   ; preds = %.lr.ph35
  %.pre50 = add nuw nsw i64 %indvars.iv44, 1
  br label %._crit_edge

.lr.ph:                                           ; preds = %.lr.ph35
  %13 = load i32, ptr @c, align 4
  %14 = add nuw nsw i64 %indvars.iv44, 1
  %15 = sext i32 %13 to i64
  %16 = zext nneg i32 %12 to i64
  %17 = add nuw i32 %12, 1
  %wide.trip.count = zext i32 %17 to i64
  br label %21

._crit_edge:                                      ; preds = %33, %.lr.ph35.._crit_edge_crit_edge
  %indvars.iv.next45.pre-phi = phi i64 [ %.pre50, %.lr.ph35.._crit_edge_crit_edge ], [ %14, %33 ]
  %18 = load i32, ptr @n, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = icmp slt i64 %indvars.iv.next45.pre-phi, %19
  br i1 %20, label %.lr.ph35, label %._crit_edge36, !llvm.loop !11

21:                                               ; preds = %.lr.ph, %33
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %33 ]
  %22 = getelementptr inbounds [51 x [1010 x i8]], ptr @f, i64 0, i64 %indvars.iv44, i64 %indvars.iv
  %23 = load i8, ptr %22, align 1, !tbaa !9, !range !13, !noundef !14
  %24 = trunc nuw i8 %23 to i1
  br i1 %24, label %25, label %33

25:                                               ; preds = %21
  %26 = add nsw i64 %indvars.iv, %15
  %.not25 = icmp sgt i64 %26, %16
  br i1 %.not25, label %29, label %27

27:                                               ; preds = %25
  %28 = getelementptr inbounds [51 x [1010 x i8]], ptr @f, i64 0, i64 %14, i64 %26
  store i8 1, ptr %28, align 1, !tbaa !9
  br label %29

29:                                               ; preds = %27, %25
  %.not26 = icmp slt i64 %indvars.iv, %15
  br i1 %.not26, label %33, label %30

30:                                               ; preds = %29
  %31 = sub nsw i64 %indvars.iv, %15
  %32 = getelementptr inbounds [51 x [1010 x i8]], ptr @f, i64 0, i64 %14, i64 %31
  store i8 1, ptr %32, align 1, !tbaa !9
  br label %33

33:                                               ; preds = %21, %30, %29
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %21, !llvm.loop !15

34:                                               ; preds = %.lr.ph39, %38
  %indvars.iv47 = phi i64 [ %10, %.lr.ph39 ], [ %indvars.iv.next48, %38 ]
  %35 = getelementptr inbounds [51 x [1010 x i8]], ptr @f, i64 0, i64 %9, i64 %indvars.iv47
  %36 = load i8, ptr %35, align 1, !tbaa !9, !range !13, !noundef !14
  %37 = trunc nuw i8 %36 to i1
  br i1 %37, label %40, label %38

38:                                               ; preds = %34
  %indvars.iv.next48 = add nsw i64 %indvars.iv47, -1
  %39 = icmp sgt i64 %indvars.iv47, 0
  br i1 %39, label %34, label %._crit_edge40, !llvm.loop !16

40:                                               ; preds = %34
  %41 = trunc nuw nsw i64 %indvars.iv47 to i32
  %42 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %41)
  br label %44

._crit_edge40:                                    ; preds = %38, %._crit_edge36
  %43 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.3)
  br label %44

44:                                               ; preds = %40, %._crit_edge40
  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

; 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = distinct !{!15, !12}
!16 = distinct !{!16, !12}


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