; LLVM IR from codee-com/open-catalog :: Checks/PWR020 (example)

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

; Function Attrs: nounwind uwtable
define dso_local void @example() #0 {
  %1 = alloca [1000 x i32], align 16
  %2 = alloca [1000 x i32], align 16
  %3 = alloca [1000 x i32], align 16
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4000, ptr %1) #2
  call void @llvm.lifetime.start.p0(i64 4000, ptr %2) #2
  call void @llvm.lifetime.start.p0(i64 4000, ptr %3) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %6

6:                                                ; preds = %21, %0
  %7 = load i32, ptr %4, align 4, !tbaa !5
  %8 = icmp slt i32 %7, 1000
  br i1 %8, label %10, label %9

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

10:                                               ; preds = %6
  %11 = load i32, ptr %4, align 4, !tbaa !5
  %12 = load i32, ptr %4, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [1000 x i32], ptr %3, i64 0, i64 %13
  store i32 %11, ptr %14, align 4, !tbaa !5
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [1000 x i32], ptr %2, i64 0, i64 %16
  store i32 %11, ptr %17, align 4, !tbaa !5
  %18 = load i32, ptr %4, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [1000 x i32], ptr %1, i64 0, i64 %19
  store i32 %11, ptr %20, align 4, !tbaa !5
  br label %21

21:                                               ; preds = %10
  %22 = load i32, ptr %4, align 4, !tbaa !5
  %23 = add nsw i32 %22, 1
  store i32 %23, ptr %4, align 4, !tbaa !5
  br label %6, !llvm.loop !9

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

25:                                               ; preds = %45, %24
  %26 = load i32, ptr %5, align 4, !tbaa !5
  %27 = icmp slt i32 %26, 1000
  br i1 %27, label %29, label %28

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

29:                                               ; preds = %25
  %30 = load i32, ptr %5, align 4, !tbaa !5
  %31 = load i32, ptr %5, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [1000 x i32], ptr %1, i64 0, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = add nsw i32 %34, %30
  store i32 %35, ptr %33, align 4, !tbaa !5
  %36 = load i32, ptr %5, align 4, !tbaa !5
  %37 = load i32, ptr %5, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [1000 x i32], ptr %3, i64 0, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [1000 x i32], ptr %2, i64 0, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !5
  %44 = add nsw i32 %43, %36
  store i32 %44, ptr %42, align 4, !tbaa !5
  br label %45

45:                                               ; preds = %29
  %46 = load i32, ptr %5, align 4, !tbaa !5
  %47 = add nsw i32 %46, 1
  store i32 %47, ptr %5, align 4, !tbaa !5
  br label %25, !llvm.loop !11

48:                                               ; preds = %28
  call void @llvm.lifetime.end.p0(i64 4000, ptr %3) #2
  call void @llvm.lifetime.end.p0(i64 4000, ptr %2) #2
  call void @llvm.lifetime.end.p0(i64 4000, ptr %1) #2
  ret void
}

; 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

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

; Function Attrs: nofree norecurse nosync nounwind memory(none) uwtable
define dso_local void @example() local_unnamed_addr #0 {
vector.ph:
  %0 = alloca [1000 x i32], align 16
  %1 = alloca [1000 x i32], align 16
  %2 = alloca [1000 x i32], align 16
  call void @llvm.lifetime.start.p0(i64 4000, ptr nonnull %0) #2
  call void @llvm.lifetime.start.p0(i64 4000, ptr nonnull %1) #2
  call void @llvm.lifetime.start.p0(i64 4000, ptr nonnull %2) #2
  br label %vector.body

vector.body:                                      ; preds = %vector.body.1, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next.1, %vector.body.1 ]
  %vec.ind = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, %vector.ph ], [ %vec.ind.next.1, %vector.body.1 ]
  %step.add = add <4 x i32> %vec.ind, <i32 4, i32 4, i32 4, i32 4>
  %3 = getelementptr inbounds [1000 x i32], ptr %2, i64 0, i64 %index
  %4 = getelementptr inbounds i8, ptr %3, i64 16
  store <4 x i32> %vec.ind, ptr %3, align 16, !tbaa !5
  store <4 x i32> %step.add, ptr %4, align 16, !tbaa !5
  %5 = getelementptr inbounds [1000 x i32], ptr %1, i64 0, i64 %index
  %6 = getelementptr inbounds i8, ptr %5, i64 16
  store <4 x i32> %vec.ind, ptr %5, align 16, !tbaa !5
  store <4 x i32> %step.add, ptr %6, align 16, !tbaa !5
  %7 = getelementptr inbounds [1000 x i32], ptr %0, i64 0, i64 %index
  %8 = getelementptr inbounds i8, ptr %7, i64 16
  store <4 x i32> %vec.ind, ptr %7, align 16, !tbaa !5
  store <4 x i32> %step.add, ptr %8, align 16, !tbaa !5
  %9 = icmp eq i64 %index, 992
  br i1 %9, label %.preheader, label %vector.body.1, !llvm.loop !9

vector.body.1:                                    ; preds = %vector.body
  %index.next = or disjoint i64 %index, 8
  %vec.ind.next = add <4 x i32> %vec.ind, <i32 8, i32 8, i32 8, i32 8>
  %step.add.1 = add <4 x i32> %vec.ind, <i32 12, i32 12, i32 12, i32 12>
  %10 = getelementptr inbounds [1000 x i32], ptr %2, i64 0, i64 %index.next
  %11 = getelementptr inbounds i8, ptr %10, i64 16
  store <4 x i32> %vec.ind.next, ptr %10, align 16, !tbaa !5
  store <4 x i32> %step.add.1, ptr %11, align 16, !tbaa !5
  %12 = getelementptr inbounds [1000 x i32], ptr %1, i64 0, i64 %index.next
  %13 = getelementptr inbounds i8, ptr %12, i64 16
  store <4 x i32> %vec.ind.next, ptr %12, align 16, !tbaa !5
  store <4 x i32> %step.add.1, ptr %13, align 16, !tbaa !5
  %14 = getelementptr inbounds [1000 x i32], ptr %0, i64 0, i64 %index.next
  %15 = getelementptr inbounds i8, ptr %14, i64 16
  store <4 x i32> %vec.ind.next, ptr %14, align 16, !tbaa !5
  store <4 x i32> %step.add.1, ptr %15, align 16, !tbaa !5
  %index.next.1 = add nuw nsw i64 %index, 16
  %vec.ind.next.1 = add <4 x i32> %vec.ind, <i32 16, i32 16, i32 16, i32 16>
  br label %vector.body

16:                                               ; preds = %.preheader
  call void @llvm.lifetime.end.p0(i64 4000, ptr nonnull %2) #2
  call void @llvm.lifetime.end.p0(i64 4000, ptr nonnull %1) #2
  call void @llvm.lifetime.end.p0(i64 4000, ptr nonnull %0) #2
  ret void

.preheader:                                       ; preds = %vector.body, %.preheader
  %indvars.iv16 = phi i64 [ %indvars.iv.next17.1, %.preheader ], [ 0, %vector.body ]
  %17 = getelementptr inbounds [1000 x i32], ptr %0, i64 0, i64 %indvars.iv16
  %18 = load i32, ptr %17, align 8, !tbaa !5
  %19 = trunc nuw nsw i64 %indvars.iv16 to i32
  %20 = add nsw i32 %18, %19
  store i32 %20, ptr %17, align 8, !tbaa !5
  %21 = getelementptr inbounds [1000 x i32], ptr %2, i64 0, i64 %indvars.iv16
  %22 = load i32, ptr %21, align 8, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [1000 x i32], ptr %1, i64 0, i64 %23
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = add nsw i32 %25, %19
  store i32 %26, ptr %24, align 4, !tbaa !5
  %indvars.iv.next17 = or disjoint i64 %indvars.iv16, 1
  %27 = getelementptr inbounds [1000 x i32], ptr %0, i64 0, i64 %indvars.iv.next17
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = trunc nuw nsw i64 %indvars.iv.next17 to i32
  %30 = add nsw i32 %28, %29
  store i32 %30, ptr %27, align 4, !tbaa !5
  %31 = getelementptr inbounds [1000 x i32], ptr %2, i64 0, i64 %indvars.iv.next17
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [1000 x i32], ptr %1, i64 0, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %36 = add nsw i32 %35, %29
  store i32 %36, ptr %34, align 4, !tbaa !5
  %indvars.iv.next17.1 = add nuw nsw i64 %indvars.iv16, 2
  %exitcond19.not.1 = icmp eq i64 %indvars.iv.next17.1, 1000
  br i1 %exitcond19.not.1, label %16, label %.preheader, !llvm.loop !13
}

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

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

attributes #0 = { nofree norecurse nosync nounwind memory(none) 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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/C++ TBAA"}
!9 = distinct !{!9, !10, !11, !12}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = distinct !{!13, !10}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass