; LLVM IR from tangjz/acm-icpc :: uvalive/7217.ll (Z7chkZerov)

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

@low = external dso_local global i32, align 4
@high = external dso_local global i32, align 4
@b = external dso_local global [5 x i32], align 16
@c = external dso_local global [5 x i32], align 16

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #2

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z7chkZerov() #3 {
  %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
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #4
  store i32 0, ptr %1, align 4, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 16 @c, i8 0, i64 20, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  %9 = load i32, ptr @high, align 4, !tbaa !5
  %10 = load i32, ptr %1, align 4, !tbaa !5
  %11 = sub nsw i32 %9, %10
  store i32 %11, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  %12 = load i32, ptr getelementptr inbounds ([5 x i32], ptr @b, i64 0, i64 2), align 8, !tbaa !5
  %13 = load i32, ptr getelementptr inbounds ([5 x i32], ptr @c, i64 0, i64 2), align 8, !tbaa !5
  %14 = sub nsw i32 %12, %13
  store i32 %14, ptr %4, align 4, !tbaa !5
  %15 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %3, ptr noundef nonnull align 4 dereferenceable(4) %4)
  %16 = load i32, ptr %15, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  store i32 %16, ptr %2, align 4, !tbaa !5
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = load i32, ptr getelementptr inbounds ([5 x i32], ptr @c, i64 0, i64 2), align 8, !tbaa !5
  %19 = add nsw i32 %18, %17
  store i32 %19, ptr getelementptr inbounds ([5 x i32], ptr @c, i64 0, i64 2), align 8, !tbaa !5
  %20 = load i32, ptr %2, align 4, !tbaa !5
  %21 = load i32, ptr %1, align 4, !tbaa !5
  %22 = add nsw i32 %21, %20
  store i32 %22, ptr %1, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %23

23:                                               ; preds = %61, %0
  %24 = load i32, ptr %5, align 4, !tbaa !5
  %25 = icmp slt i32 %24, 5
  br i1 %25, label %26, label %30

26:                                               ; preds = %23
  %27 = load i32, ptr %1, align 4, !tbaa !5
  %28 = load i32, ptr @low, align 4, !tbaa !5
  %29 = icmp slt i32 %27, %28
  br label %30

30:                                               ; preds = %26, %23
  %31 = phi i1 [ false, %23 ], [ %29, %26 ]
  br i1 %31, label %33, label %32

32:                                               ; preds = %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %64

33:                                               ; preds = %30
  %34 = load i32, ptr %5, align 4, !tbaa !5
  %35 = icmp eq i32 %34, 2
  br i1 %35, label %36, label %37

36:                                               ; preds = %33
  br label %61

37:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %38 = load i32, ptr @high, align 4, !tbaa !5
  %39 = load i32, ptr %1, align 4, !tbaa !5
  %40 = sub nsw i32 %38, %39
  store i32 %40, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %41 = load i32, ptr %5, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [5 x i32], ptr @b, i64 0, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !5
  %45 = load i32, ptr %5, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [5 x i32], ptr @c, i64 0, i64 %46
  %48 = load i32, ptr %47, align 4, !tbaa !5
  %49 = sub nsw i32 %44, %48
  store i32 %49, ptr %8, align 4, !tbaa !5
  %50 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %7, ptr noundef nonnull align 4 dereferenceable(4) %8)
  %51 = load i32, ptr %50, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  store i32 %51, ptr %6, align 4, !tbaa !5
  %52 = load i32, ptr %6, align 4, !tbaa !5
  %53 = load i32, ptr %5, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [5 x i32], ptr @c, i64 0, i64 %54
  %56 = load i32, ptr %55, align 4, !tbaa !5
  %57 = add nsw i32 %56, %52
  store i32 %57, ptr %55, align 4, !tbaa !5
  %58 = load i32, ptr %6, align 4, !tbaa !5
  %59 = load i32, ptr %1, align 4, !tbaa !5
  %60 = add nsw i32 %59, %58
  store i32 %60, ptr %1, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %61

61:                                               ; preds = %37, %36
  %62 = load i32, ptr %5, align 4, !tbaa !5
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr %5, align 4, !tbaa !5
  br label %23, !llvm.loop !9

64:                                               ; preds = %32
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #4
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { inlinehint mustprogress 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 #3 = { 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 #4 = { 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"}


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

@low = external dso_local local_unnamed_addr global i32, align 4
@high = external dso_local local_unnamed_addr global i32, align 4
@b = external dso_local local_unnamed_addr global [5 x i32], align 16
@c = external dso_local local_unnamed_addr global [5 x i32], align 16

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #2

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z7chkZerov() local_unnamed_addr #3 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(20) @c, i8 0, i64 20, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  %5 = load i32, ptr @high, align 4, !tbaa !5
  store i32 %5, ptr %1, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #4
  %6 = load i32, ptr getelementptr inbounds (i8, ptr @b, i64 8), align 8, !tbaa !5
  store i32 %6, ptr %2, align 4, !tbaa !5
  %7 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %1, ptr noundef nonnull align 4 dereferenceable(4) %2)
  %8 = load i32, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #4
  %9 = load i32, ptr getelementptr inbounds (i8, ptr @c, i64 8), align 8, !tbaa !5
  %10 = add nsw i32 %9, %8
  store i32 %10, ptr getelementptr inbounds (i8, ptr @c, i64 8), align 8, !tbaa !5
  %11 = load i32, ptr @low, align 4
  %12 = icmp slt i32 %8, %11
  br i1 %12, label %13, label %._crit_edge

13:                                               ; preds = %0
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #4
  %14 = load i32, ptr @high, align 4, !tbaa !5
  %15 = sub nsw i32 %14, %8
  store i32 %15, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #4
  %16 = load i32, ptr @b, align 16, !tbaa !5
  %17 = load i32, ptr @c, align 16, !tbaa !5
  %18 = sub nsw i32 %16, %17
  store i32 %18, ptr %4, align 4, !tbaa !5
  %19 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %3, ptr noundef nonnull align 4 dereferenceable(4) %4)
  %20 = load i32, ptr %19, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #4
  %21 = load i32, ptr @c, align 16, !tbaa !5
  %22 = add nsw i32 %21, %20
  store i32 %22, ptr @c, align 16, !tbaa !5
  %23 = add nsw i32 %20, %8
  %.pre = load i32, ptr @low, align 4
  %24 = icmp slt i32 %23, %.pre
  br i1 %24, label %25, label %._crit_edge

25:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #4
  %26 = load i32, ptr @high, align 4, !tbaa !5
  %27 = sub nsw i32 %26, %23
  store i32 %27, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #4
  %28 = load i32, ptr getelementptr inbounds (i8, ptr @b, i64 4), align 4, !tbaa !5
  %29 = load i32, ptr getelementptr inbounds (i8, ptr @c, i64 4), align 4, !tbaa !5
  %30 = sub nsw i32 %28, %29
  store i32 %30, ptr %4, align 4, !tbaa !5
  %31 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %3, ptr noundef nonnull align 4 dereferenceable(4) %4)
  %32 = load i32, ptr %31, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #4
  %33 = load i32, ptr getelementptr inbounds (i8, ptr @c, i64 4), align 4, !tbaa !5
  %34 = add nsw i32 %33, %32
  store i32 %34, ptr getelementptr inbounds (i8, ptr @c, i64 4), align 4, !tbaa !5
  %35 = add nsw i32 %32, %23
  %.pre28 = load i32, ptr @low, align 4
  %36 = icmp slt i32 %35, %.pre28
  br i1 %36, label %.lr.ph.peel.next23, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph.peel.next23, %13, %25, %0
  ret void

.lr.ph.peel.next23:                               ; preds = %25, %.lr.ph.peel.next23
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph.peel.next23 ], [ 3, %25 ]
  %.017 = phi i32 [ %48, %.lr.ph.peel.next23 ], [ %35, %25 ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #4
  %37 = load i32, ptr @high, align 4, !tbaa !5
  %38 = sub nsw i32 %37, %.017
  store i32 %38, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #4
  %39 = getelementptr inbounds [5 x i32], ptr @b, i64 0, i64 %indvars.iv
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %41 = getelementptr inbounds [5 x i32], ptr @c, i64 0, i64 %indvars.iv
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = sub nsw i32 %40, %42
  store i32 %43, ptr %4, align 4, !tbaa !5
  %44 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %3, ptr noundef nonnull align 4 dereferenceable(4) %4)
  %45 = load i32, ptr %44, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #4
  %46 = load i32, ptr %41, align 4, !tbaa !5
  %47 = add nsw i32 %46, %45
  store i32 %47, ptr %41, align 4, !tbaa !5
  %.pre29 = load i32, ptr @low, align 4
  %48 = add nsw i32 %45, %.017
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %49 = icmp ult i64 %indvars.iv, 4
  %50 = icmp slt i32 %48, %.pre29
  %51 = select i1 %49, i1 %50, i1 false
  br i1 %51, label %.lr.ph.peel.next23, label %._crit_edge, !llvm.loop !9
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { inlinehint mustprogress 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 #3 = { mustprogress 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 #4 = { 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, !11}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.peeled.count", i32 3}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopFullUnrollPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass