; LLVM IR from lzyrapx/Competitive-Programming :: 百度之星/2016复赛/1004.ll (Z5checki)

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

@tot = external dso_local global i32, align 4
@rt = external dso_local global [10 x i32], align 16
@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@l = external dso_local global i32, align 4
@a = external dso_local global [10005 x i32], align 16
@f = external dso_local global [11 x [10005 x i32]], align 16

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z3addRiiii(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef, i32 noundef, i32 noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z5checki(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  store i32 0, ptr @tot, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %17, %1
  %9 = load i32, ptr %3, align 4, !tbaa !5
  %10 = load i32, ptr @m, 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 %3) #3
  br label %20

13:                                               ; preds = %8
  %14 = load i32, ptr %3, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [10 x i32], ptr @rt, i64 0, i64 %15
  store i32 0, ptr %16, align 4, !tbaa !5
  br label %17

17:                                               ; preds = %13
  %18 = load i32, ptr %3, align 4, !tbaa !5
  %19 = add nsw i32 %18, 1
  store i32 %19, ptr %3, align 4, !tbaa !5
  br label %8, !llvm.loop !9

20:                                               ; preds = %12
  call void @_Z3addRiiii(ptr noundef nonnull align 4 dereferenceable(4) @rt, i32 noundef 29, i32 noundef 0, i32 noundef 1)
  store i32 1, ptr @f, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 1, ptr %4, align 4, !tbaa !5
  br label %21

21:                                               ; preds = %120, %20
  %22 = load i32, ptr %4, align 4, !tbaa !5
  %23 = load i32, ptr @n, align 4, !tbaa !5
  %24 = icmp sle i32 %22, %23
  br i1 %24, label %26, label %25

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

26:                                               ; preds = %21
  %27 = load i32, ptr %4, align 4, !tbaa !5
  %28 = load i32, ptr @l, align 4, !tbaa !5
  %29 = sub nsw i32 %27, %28
  %30 = sub nsw i32 %29, 1
  %31 = icmp sge i32 %30, 0
  br i1 %31, label %32, label %66

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

33:                                               ; preds = %62, %32
  %34 = load i32, ptr %6, align 4, !tbaa !5
  %35 = load i32, ptr @m, align 4, !tbaa !5
  %36 = icmp slt i32 %34, %35
  br i1 %36, label %38, label %37

37:                                               ; preds = %33
  store i32 8, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %65

38:                                               ; preds = %33
  %39 = load i32, ptr %6, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [11 x [10005 x i32]], ptr @f, i64 0, i64 %40
  %42 = load i32, ptr %4, align 4, !tbaa !5
  %43 = load i32, ptr @l, align 4, !tbaa !5
  %44 = sub nsw i32 %42, %43
  %45 = sub nsw i32 %44, 1
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [10005 x i32], ptr %41, i64 0, i64 %46
  %48 = load i32, ptr %47, align 4, !tbaa !5
  %49 = icmp ne i32 %48, 0
  br i1 %49, label %50, label %61

50:                                               ; preds = %38
  %51 = load i32, ptr %6, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [10 x i32], ptr @rt, i64 0, i64 %52
  %54 = load i32, ptr %4, align 4, !tbaa !5
  %55 = load i32, ptr @l, align 4, !tbaa !5
  %56 = sub nsw i32 %54, %55
  %57 = sub nsw i32 %56, 1
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [10005 x i32], ptr @a, i64 0, i64 %58
  %60 = load i32, ptr %59, align 4, !tbaa !5
  call void @_Z3addRiiii(ptr noundef nonnull align 4 dereferenceable(4) %53, i32 noundef 29, i32 noundef %60, i32 noundef -1)
  br label %61

61:                                               ; preds = %50, %38
  br label %62

62:                                               ; preds = %61
  %63 = load i32, ptr %6, align 4, !tbaa !5
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr %6, align 4, !tbaa !5
  br label %33, !llvm.loop !11

65:                                               ; preds = %37
  br label %66

66:                                               ; preds = %65, %26
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %67 = load i32, ptr @m, align 4, !tbaa !5
  %68 = sub nsw i32 %67, 1
  store i32 %68, ptr %7, align 4, !tbaa !5
  br label %69

69:                                               ; preds = %116, %66
  %70 = load i32, ptr %7, align 4, !tbaa !5
  %71 = xor i32 %70, -1
  %72 = icmp ne i32 %71, 0
  br i1 %72, label %74, label %73

73:                                               ; preds = %69
  store i32 11, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %119

74:                                               ; preds = %69
  %75 = load i32, ptr %7, align 4, !tbaa !5
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds [10 x i32], ptr @rt, i64 0, i64 %76
  %78 = load i32, ptr %4, align 4, !tbaa !5
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds [10005 x i32], ptr @a, i64 0, i64 %79
  %81 = load i32, ptr %80, align 4, !tbaa !5
  %82 = load i32, ptr %2, align 4, !tbaa !5
  %83 = call noundef zeroext i1 @_Z4findRiiii(ptr noundef nonnull align 4 dereferenceable(4) %77, i32 noundef 29, i32 noundef %81, i32 noundef %82)
  %84 = zext i1 %83 to i32
  %85 = load i32, ptr %7, align 4, !tbaa !5
  %86 = add nsw i32 %85, 1
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds [11 x [10005 x i32]], ptr @f, i64 0, i64 %87
  %89 = load i32, ptr %4, align 4, !tbaa !5
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds [10005 x i32], ptr %88, i64 0, i64 %90
  store i32 %84, ptr %91, align 4, !tbaa !5
  %92 = load i32, ptr %7, align 4, !tbaa !5
  %93 = load i32, ptr @m, align 4, !tbaa !5
  %94 = sub nsw i32 %93, 1
  %95 = icmp ne i32 %92, %94
  br i1 %95, label %96, label %115

96:                                               ; preds = %74
  %97 = load i32, ptr %7, align 4, !tbaa !5
  %98 = add nsw i32 %97, 1
  %99 = sext i32 %98 to i64
  %100 = getelementptr inbounds [11 x [10005 x i32]], ptr @f, i64 0, i64 %99
  %101 = load i32, ptr %4, align 4, !tbaa !5
  %102 = sext i32 %101 to i64
  %103 = getelementptr inbounds [10005 x i32], ptr %100, i64 0, i64 %102
  %104 = load i32, ptr %103, align 4, !tbaa !5
  %105 = icmp ne i32 %104, 0
  br i1 %105, label %106, label %115

106:                                              ; preds = %96
  %107 = load i32, ptr %7, align 4, !tbaa !5
  %108 = add nsw i32 %107, 1
  %109 = sext i32 %108 to i64
  %110 = getelementptr inbounds [10 x i32], ptr @rt, i64 0, i64 %109
  %111 = load i32, ptr %4, align 4, !tbaa !5
  %112 = sext i32 %111 to i64
  %113 = getelementptr inbounds [10005 x i32], ptr @a, i64 0, i64 %112
  %114 = load i32, ptr %113, align 4, !tbaa !5
  call void @_Z3addRiiii(ptr noundef nonnull align 4 dereferenceable(4) %110, i32 noundef 29, i32 noundef %114, i32 noundef 1)
  br label %115

115:                                              ; preds = %106, %96, %74
  br label %116

116:                                              ; preds = %115
  %117 = load i32, ptr %7, align 4, !tbaa !5
  %118 = add nsw i32 %117, -1
  store i32 %118, ptr %7, align 4, !tbaa !5
  br label %69, !llvm.loop !12

119:                                              ; preds = %73
  br label %120

120:                                              ; preds = %119
  %121 = load i32, ptr %4, align 4, !tbaa !5
  %122 = add nsw i32 %121, 1
  store i32 %122, ptr %4, align 4, !tbaa !5
  br label %21, !llvm.loop !13

123:                                              ; preds = %25
  %124 = load i32, ptr @m, align 4, !tbaa !5
  %125 = sext i32 %124 to i64
  %126 = getelementptr inbounds [11 x [10005 x i32]], ptr @f, i64 0, i64 %125
  %127 = load i32, ptr @n, align 4, !tbaa !5
  %128 = sext i32 %127 to i64
  %129 = getelementptr inbounds [10005 x i32], ptr %126, i64 0, i64 %128
  %130 = load i32, ptr %129, align 4, !tbaa !5
  %131 = icmp ne i32 %130, 0
  ret i1 %131
}

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef zeroext i1 @_Z4findRiiii(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef, i32 noundef, i32 noundef) #2

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !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"

@tot = external dso_local local_unnamed_addr global i32, align 4
@rt = external dso_local global [10 x i32], align 16
@n = external dso_local local_unnamed_addr global i32, align 4
@m = external dso_local local_unnamed_addr global i32, align 4
@l = external dso_local local_unnamed_addr global i32, align 4
@a = external dso_local local_unnamed_addr global [10005 x i32], align 16
@f = external dso_local local_unnamed_addr global [11 x [10005 x i32]], align 16

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z3addRiiii(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z5checki(i32 noundef %0) local_unnamed_addr #0 {
  store i32 0, ptr @tot, align 4, !tbaa !5
  %2 = load i32, ptr @m, align 4, !tbaa !5
  %3 = icmp sgt i32 %2, 0
  br i1 %3, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %1
  %4 = zext nneg i32 %2 to i64
  %5 = shl nuw nsw i64 %4, 2
  tail call void @llvm.memset.p0.i64(ptr nonnull align 16 @rt, i8 0, i64 %5, i1 false), !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph.preheader, %1
  tail call void @_Z3addRiiii(ptr noundef nonnull align 4 dereferenceable(4) @rt, i32 noundef 29, i32 noundef 0, i32 noundef 1)
  store i32 1, ptr @f, align 16, !tbaa !5
  %6 = load i32, ptr @n, align 4, !tbaa !5
  %.not42 = icmp slt i32 %6, 1
  br i1 %.not42, label %._crit_edge.._crit_edge47_crit_edge, label %.lr.ph46

._crit_edge.._crit_edge47_crit_edge:              ; preds = %._crit_edge
  %.pre60 = sext i32 %6 to i64
  br label %._crit_edge47

._crit_edge47:                                    ; preds = %._crit_edge41, %._crit_edge.._crit_edge47_crit_edge
  %.pre-phi = phi i64 [ %.pre60, %._crit_edge.._crit_edge47_crit_edge ], [ %38, %._crit_edge41 ]
  %7 = load i32, ptr @m, align 4, !tbaa !5
  %8 = sext i32 %7 to i64
  %9 = getelementptr inbounds [11 x [10005 x i32]], ptr @f, i64 0, i64 %8, i64 %.pre-phi
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = icmp ne i32 %10, 0
  ret i1 %11

.lr.ph46:                                         ; preds = %._crit_edge, %._crit_edge41
  %indvars.iv55 = phi i64 [ %indvars.iv.next56, %._crit_edge41 ], [ 1, %._crit_edge ]
  %12 = load i32, ptr @l, align 4, !tbaa !5
  %13 = trunc nuw nsw i64 %indvars.iv55 to i32
  %14 = sub i32 %12, %13
  %15 = icmp slt i32 %14, 0
  %16 = load i32, ptr @m, align 4
  %17 = icmp sgt i32 %16, 0
  %or.cond = select i1 %15, i1 %17, i1 false
  br i1 %or.cond, label %.lr.ph34, label %.loopexit

.lr.ph34:                                         ; preds = %.lr.ph46, %29
  %18 = phi i32 [ %30, %29 ], [ %16, %.lr.ph46 ]
  %19 = phi i32 [ %31, %29 ], [ %12, %.lr.ph46 ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %29 ], [ 0, %.lr.ph46 ]
  %20 = xor i32 %19, -1
  %21 = add i32 %13, %20
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [11 x [10005 x i32]], ptr @f, i64 0, i64 %indvars.iv, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %.not30 = icmp eq i32 %24, 0
  br i1 %.not30, label %29, label %25

25:                                               ; preds = %.lr.ph34
  %26 = getelementptr inbounds [10 x i32], ptr @rt, i64 0, i64 %indvars.iv
  %27 = getelementptr inbounds [10005 x i32], ptr @a, i64 0, i64 %22
  %28 = load i32, ptr %27, align 4, !tbaa !5
  tail call void @_Z3addRiiii(ptr noundef nonnull align 4 dereferenceable(4) %26, i32 noundef 29, i32 noundef %28, i32 noundef -1)
  %.pre = load i32, ptr @l, align 4, !tbaa !5
  %.pre59 = load i32, ptr @m, align 4, !tbaa !5
  br label %29

29:                                               ; preds = %.lr.ph34, %25
  %30 = phi i32 [ %18, %.lr.ph34 ], [ %.pre59, %25 ]
  %31 = phi i32 [ %19, %.lr.ph34 ], [ %.pre, %25 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %32 = sext i32 %30 to i64
  %33 = icmp slt i64 %indvars.iv.next, %32
  br i1 %33, label %.lr.ph34, label %.loopexit, !llvm.loop !9

.loopexit:                                        ; preds = %29, %.lr.ph46
  %34 = phi i32 [ %16, %.lr.ph46 ], [ %30, %29 ]
  %.not2836 = icmp eq i32 %34, 0
  br i1 %.not2836, label %._crit_edge41, label %.lr.ph40

.lr.ph40:                                         ; preds = %.loopexit
  %35 = getelementptr inbounds [10005 x i32], ptr @a, i64 0, i64 %indvars.iv55
  %36 = sext i32 %34 to i64
  br label %39

._crit_edge41:                                    ; preds = %50, %.loopexit
  %indvars.iv.next56 = add nuw nsw i64 %indvars.iv55, 1
  %37 = load i32, ptr @n, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %.not.not = icmp slt i64 %indvars.iv55, %38
  br i1 %.not.not, label %.lr.ph46, label %._crit_edge47, !llvm.loop !11

39:                                               ; preds = %.lr.ph40, %50
  %indvars.iv52 = phi i64 [ %36, %.lr.ph40 ], [ %indvars.iv.next53, %50 ]
  %indvars.iv.next53 = add nsw i64 %indvars.iv52, -1
  %40 = getelementptr inbounds [10 x i32], ptr @rt, i64 0, i64 %indvars.iv.next53
  %41 = load i32, ptr %35, align 4, !tbaa !5
  %42 = tail call noundef zeroext i1 @_Z4findRiiii(ptr noundef nonnull align 4 dereferenceable(4) %40, i32 noundef 29, i32 noundef %41, i32 noundef %0)
  %43 = zext i1 %42 to i32
  %44 = getelementptr inbounds [11 x [10005 x i32]], ptr @f, i64 0, i64 %indvars.iv52, i64 %indvars.iv55
  store i32 %43, ptr %44, align 4, !tbaa !5
  %45 = load i32, ptr @m, align 4, !tbaa !5
  %46 = trunc nsw i64 %indvars.iv52 to i32
  %.not29 = icmp ne i32 %45, %46
  %brmerge.not = and i1 %42, %.not29
  br i1 %brmerge.not, label %47, label %50

47:                                               ; preds = %39
  %48 = getelementptr inbounds [10 x i32], ptr @rt, i64 0, i64 %indvars.iv52
  %49 = load i32, ptr %35, align 4, !tbaa !5
  tail call void @_Z3addRiiii(ptr noundef nonnull align 4 dereferenceable(4) %48, i32 noundef 29, i32 noundef %49, i32 noundef 1)
  br label %50

50:                                               ; preds = %39, %47
  %.not28 = icmp eq i64 %indvars.iv.next53, 0
  br i1 %.not28, label %._crit_edge41, label %39, !llvm.loop !12
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef zeroext i1 @_Z4findRiiii(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

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

attributes #0 = { 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 #1 = { 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 #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }

!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}


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