; LLVM IR from tangjz/acm-icpc :: buaa/oj3rd (791)

; 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
@a = external dso_local global [101 x i32], align 16
@x = external dso_local global i32, align 4
@k = external dso_local global i32, align 4
@.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 [5 x i8], align 1
@.str.3 = 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
  br label %5

5:                                                ; preds = %101, %0
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  %7 = icmp eq i32 %6, 1
  br i1 %7, label %8, label %103

8:                                                ; preds = %5
  call void @llvm.memset.p0.i64(ptr align 16 @a, i8 0, i64 404, i1 false)
  br label %9

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

13:                                               ; preds = %9
  %14 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @x)
  %15 = load i32, ptr @x, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [101 x i32], ptr @a, i64 0, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %19 = add nsw i32 %18, 1
  store i32 %19, ptr %17, align 4, !tbaa !5
  br label %9, !llvm.loop !9

20:                                               ; preds = %9
  %21 = load i32, ptr @a, align 16, !tbaa !5
  store i32 %21, ptr @x, 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 %22

22:                                               ; preds = %39, %20
  %23 = load i32, ptr %2, align 4, !tbaa !5
  %24 = icmp sle i32 %23, 100
  br i1 %24, label %26, label %25

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

26:                                               ; preds = %22
  %27 = load i32, ptr @x, align 4, !tbaa !5
  %28 = load i32, ptr %2, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [101 x i32], ptr @a, i64 0, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = icmp slt i32 %27, %31
  br i1 %32, label %33, label %38

33:                                               ; preds = %26
  %34 = load i32, ptr %2, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [101 x i32], ptr @a, i64 0, i64 %35
  %37 = load i32, ptr %36, align 4, !tbaa !5
  store i32 %37, ptr @x, align 4, !tbaa !5
  br label %38

38:                                               ; preds = %33, %26
  br label %39

39:                                               ; preds = %38
  %40 = load i32, ptr %2, align 4, !tbaa !5
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr %2, align 4, !tbaa !5
  br label %22, !llvm.loop !11

42:                                               ; preds = %25
  %43 = load i32, ptr @k, align 4, !tbaa !5
  %44 = icmp ne i32 %43, 0
  br i1 %44, label %45, label %47

45:                                               ; preds = %42
  %46 = call i32 @putchar(i32 noundef 10)
  br label %48

47:                                               ; preds = %42
  store i32 1, ptr @k, align 4, !tbaa !5
  br label %48

48:                                               ; preds = %47, %45
  %49 = phi i32 [ %46, %45 ], [ 1, %47 ]
  br label %50

50:                                               ; preds = %81, %48
  %51 = load i32, ptr @x, align 4, !tbaa !5
  %52 = add nsw i32 %51, -1
  store i32 %52, ptr @x, align 4, !tbaa !5
  %53 = icmp ne i32 %51, 0
  br i1 %53, label %54, label %83

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

55:                                               ; preds = %78, %54
  %56 = load i32, ptr %3, align 4, !tbaa !5
  %57 = icmp sle i32 %56, 100
  br i1 %57, label %59, label %58

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

59:                                               ; preds = %55
  %60 = load i32, ptr %3, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [101 x i32], ptr @a, i64 0, i64 %61
  %63 = load i32, ptr %62, align 4, !tbaa !5
  %64 = load i32, ptr @x, align 4, !tbaa !5
  %65 = icmp sgt i32 %63, %64
  br i1 %65, label %66, label %68

66:                                               ; preds = %59
  %67 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  br label %77

68:                                               ; preds = %59
  %69 = load i32, ptr %3, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [101 x i32], ptr @a, i64 0, i64 %70
  %72 = load i32, ptr %71, align 4, !tbaa !5
  %73 = icmp ne i32 %72, 0
  br i1 %73, label %74, label %76

74:                                               ; preds = %68
  %75 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  br label %76

76:                                               ; preds = %74, %68
  br label %77

77:                                               ; preds = %76, %66
  br label %78

78:                                               ; preds = %77
  %79 = load i32, ptr %3, align 4, !tbaa !5
  %80 = add nsw i32 %79, 1
  store i32 %80, ptr %3, align 4, !tbaa !5
  br label %55, !llvm.loop !12

81:                                               ; preds = %58
  %82 = call i32 @putchar(i32 noundef 10)
  br label %50, !llvm.loop !13

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

84:                                               ; preds = %98, %83
  %85 = load i32, ptr %4, align 4, !tbaa !5
  %86 = icmp sle i32 %85, 100
  br i1 %86, label %88, label %87

87:                                               ; preds = %84
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  br label %101

88:                                               ; preds = %84
  %89 = load i32, ptr %4, align 4, !tbaa !5
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds [101 x i32], ptr @a, i64 0, i64 %90
  %92 = load i32, ptr %91, align 4, !tbaa !5
  %93 = icmp ne i32 %92, 0
  br i1 %93, label %94, label %97

94:                                               ; preds = %88
  %95 = load i32, ptr %4, align 4, !tbaa !5
  %96 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i32 noundef %95)
  br label %97

97:                                               ; preds = %94, %88
  br label %98

98:                                               ; preds = %97
  %99 = load i32, ptr %4, align 4, !tbaa !5
  %100 = add nsw i32 %99, 1
  store i32 %100, ptr %4, align 4, !tbaa !5
  br label %84, !llvm.loop !14

101:                                              ; preds = %87
  %102 = call i32 @putchar(i32 noundef 10)
  br label %5, !llvm.loop !15

103:                                              ; preds = %5
  ret i32 0
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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

; Function Attrs: inlinehint mustprogress uwtable
declare i32 @putchar(i32 noundef) #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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { inlinehint mustprogress 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 #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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10}
!15 = distinct !{!15, !10}


; 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
@a = external dso_local local_unnamed_addr global [101 x i32], align 16
@x = external dso_local global i32, align 4
@k = external dso_local local_unnamed_addr global i32, align 4
@.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 [5 x i8], align 1
@.str.3 = 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)
  %2 = icmp eq i32 %1, 1
  br i1 %2, label %.lr.ph27, label %._crit_edge28

.lr.ph27:                                         ; preds = %0, %60
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(404) @a, i8 0, i64 404, i1 false)
  %3 = load i32, ptr @n, align 4, !tbaa !5
  %4 = add nsw i32 %3, -1
  store i32 %4, ptr @n, align 4, !tbaa !5
  %.not21 = icmp eq i32 %3, 0
  br i1 %.not21, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph27, %.lr.ph
  %5 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @x)
  %6 = load i32, ptr @x, align 4, !tbaa !5
  %7 = sext i32 %6 to i64
  %8 = getelementptr inbounds [101 x i32], ptr @a, i64 0, i64 %7
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %10 = add nsw i32 %9, 1
  store i32 %10, ptr %8, align 4, !tbaa !5
  %11 = load i32, ptr @n, align 4, !tbaa !5
  %12 = add nsw i32 %11, -1
  store i32 %12, ptr @n, align 4, !tbaa !5
  %.not = icmp eq i32 %11, 0
  br i1 %.not, label %._crit_edge.loopexit, label %.lr.ph, !llvm.loop !9

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %.pre = load i32, ptr @a, align 16, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.lr.ph27
  %13 = phi i32 [ %.pre, %._crit_edge.loopexit ], [ 0, %.lr.ph27 ]
  store i32 %13, ptr @x, align 4, !tbaa !5
  br label %16

14:                                               ; preds = %22
  %15 = load i32, ptr @k, align 4, !tbaa !5
  %.not16 = icmp eq i32 %15, 0
  br i1 %.not16, label %45, label %43

16:                                               ; preds = %41, %._crit_edge
  %indvars.iv = phi i64 [ 0, %._crit_edge ], [ %indvars.iv.next.3, %41 ]
  %17 = phi i32 [ %13, %._crit_edge ], [ %42, %41 ]
  %18 = getelementptr inbounds [101 x i32], ptr @a, i64 0, i64 %indvars.iv
  %19 = load i32, ptr %18, align 16, !tbaa !5
  %20 = icmp slt i32 %17, %19
  br i1 %20, label %21, label %22

21:                                               ; preds = %16
  store i32 %19, ptr @x, align 4, !tbaa !5
  br label %22

22:                                               ; preds = %16, %21
  %23 = phi i32 [ %17, %16 ], [ %19, %21 ]
  %exitcond.not = icmp eq i64 %indvars.iv, 100
  br i1 %exitcond.not, label %14, label %24, !llvm.loop !11

24:                                               ; preds = %22
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %25 = getelementptr inbounds [101 x i32], ptr @a, i64 0, i64 %indvars.iv.next
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = icmp slt i32 %23, %26
  br i1 %27, label %28, label %29

28:                                               ; preds = %24
  store i32 %26, ptr @x, align 4, !tbaa !5
  br label %29

29:                                               ; preds = %28, %24
  %30 = phi i32 [ %23, %24 ], [ %26, %28 ]
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %31 = getelementptr inbounds [101 x i32], ptr @a, i64 0, i64 %indvars.iv.next.1
  %32 = load i32, ptr %31, align 8, !tbaa !5
  %33 = icmp slt i32 %30, %32
  br i1 %33, label %34, label %35

34:                                               ; preds = %29
  store i32 %32, ptr @x, align 4, !tbaa !5
  br label %35

35:                                               ; preds = %34, %29
  %36 = phi i32 [ %30, %29 ], [ %32, %34 ]
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %37 = getelementptr inbounds [101 x i32], ptr @a, i64 0, i64 %indvars.iv.next.2
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %39 = icmp slt i32 %36, %38
  br i1 %39, label %40, label %41

40:                                               ; preds = %35
  store i32 %38, ptr @x, align 4, !tbaa !5
  br label %41

41:                                               ; preds = %40, %35
  %42 = phi i32 [ %36, %35 ], [ %38, %40 ]
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  br label %16

43:                                               ; preds = %14
  %44 = tail call i32 @putchar(i32 noundef 10)
  %.pre38 = load i32, ptr @x, align 4, !tbaa !5
  br label %46

45:                                               ; preds = %14
  store i32 1, ptr @k, align 4, !tbaa !5
  br label %46

46:                                               ; preds = %45, %43
  %47 = phi i32 [ %23, %45 ], [ %.pre38, %43 ]
  %48 = add nsw i32 %47, -1
  store i32 %48, ptr @x, align 4, !tbaa !5
  %.not1724 = icmp eq i32 %47, 0
  br i1 %.not1724, label %.preheader20.preheader, label %.preheader

.preheader20.preheader:                           ; preds = %49, %46
  br label %.preheader20

49:                                               ; preds = %59
  %50 = tail call i32 @putchar(i32 noundef 10)
  %51 = load i32, ptr @x, align 4, !tbaa !5
  %52 = add nsw i32 %51, -1
  store i32 %52, ptr @x, align 4, !tbaa !5
  %.not17 = icmp eq i32 %51, 0
  br i1 %.not17, label %.preheader20.preheader, label %.preheader.backedge

.preheader:                                       ; preds = %46, %.preheader.backedge
  %indvars.iv30 = phi i64 [ %indvars.iv30.be, %.preheader.backedge ], [ 0, %46 ]
  %53 = getelementptr inbounds [101 x i32], ptr @a, i64 0, i64 %indvars.iv30
  %54 = load i32, ptr %53, align 4, !tbaa !5
  %55 = load i32, ptr @x, align 4, !tbaa !5
  %56 = icmp sgt i32 %54, %55
  br i1 %56, label %.sink.split, label %57

57:                                               ; preds = %.preheader
  %.not19 = icmp eq i32 %54, 0
  br i1 %.not19, label %59, label %.sink.split

.sink.split:                                      ; preds = %57, %.preheader
  %.str.1.sink = phi ptr [ @.str.1, %.preheader ], [ @.str.2, %57 ]
  %58 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) %.str.1.sink)
  br label %59

59:                                               ; preds = %.sink.split, %57
  %indvars.iv.next31 = add nuw nsw i64 %indvars.iv30, 1
  %exitcond33.not = icmp eq i64 %indvars.iv.next31, 101
  br i1 %exitcond33.not, label %49, label %.preheader.backedge

.preheader.backedge:                              ; preds = %59, %49
  %indvars.iv30.be = phi i64 [ %indvars.iv.next31, %59 ], [ 0, %49 ]
  br label %.preheader, !llvm.loop !12

60:                                               ; preds = %69
  %61 = tail call i32 @putchar(i32 noundef 10)
  %62 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %63 = icmp eq i32 %62, 1
  br i1 %63, label %.lr.ph27, label %._crit_edge28, !llvm.loop !13

.preheader20:                                     ; preds = %.preheader20.preheader, %69
  %indvars.iv34 = phi i64 [ %indvars.iv.next35, %69 ], [ 0, %.preheader20.preheader ]
  %64 = getelementptr inbounds [101 x i32], ptr @a, i64 0, i64 %indvars.iv34
  %65 = load i32, ptr %64, align 4, !tbaa !5
  %.not18 = icmp eq i32 %65, 0
  br i1 %.not18, label %69, label %66

66:                                               ; preds = %.preheader20
  %67 = trunc nuw nsw i64 %indvars.iv34 to i32
  %68 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %67)
  br label %69

69:                                               ; preds = %.preheader20, %66
  %indvars.iv.next35 = add nuw nsw i64 %indvars.iv34, 1
  %exitcond37.not = icmp eq i64 %indvars.iv.next35, 101
  br i1 %exitcond37.not, label %60, label %.preheader20, !llvm.loop !14

._crit_edge28:                                    ; preds = %60, %0
  ret i32 0
}

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: inlinehint mustprogress nofree nounwind uwtable
declare noundef i32 @putchar(i32 noundef) 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 nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { inlinehint mustprogress nofree 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" }

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10}


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