; LLVM IR from codee-com/open-catalog :: Checks/PWR001 (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"

@A = external dso_local global [100 x i32], align 16
@B = external dso_local global [100 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
define dso_local void @add() #1 {
  %1 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %2

2:                                                ; preds = %15, %0
  %3 = load i32, ptr %1, align 4, !tbaa !5
  %4 = icmp slt i32 %3, 100
  br i1 %4, label %6, label %5

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

6:                                                ; preds = %2
  %7 = load i32, ptr %1, align 4, !tbaa !5
  %8 = sext i32 %7 to i64
  %9 = getelementptr inbounds [100 x i32], ptr @A, i64 0, i64 %8
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = add nsw i32 %10, 1
  %12 = load i32, ptr %1, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [100 x i32], ptr @B, i64 0, i64 %13
  store i32 %11, ptr %14, align 4, !tbaa !5
  br label %15

15:                                               ; preds = %6
  %16 = load i32, ptr %1, align 4, !tbaa !5
  %17 = add nsw i32 %16, 1
  store i32 %17, ptr %1, align 4, !tbaa !5
  br label %2, !llvm.loop !9

18:                                               ; preds = %5
  ret void
}

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


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

@A = external dso_local local_unnamed_addr global [100 x i32], align 16
@B = external dso_local local_unnamed_addr global [100 x i32], align 16

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @add() local_unnamed_addr #0 {
vector.ph:
  %wide.load = load <4 x i32>, ptr @A, align 16, !tbaa !5
  %wide.load6 = load <4 x i32>, ptr getelementptr inbounds (i8, ptr @A, i64 16), align 16, !tbaa !5
  %0 = add nsw <4 x i32> %wide.load, <i32 1, i32 1, i32 1, i32 1>
  %1 = add nsw <4 x i32> %wide.load6, <i32 1, i32 1, i32 1, i32 1>
  store <4 x i32> %0, ptr @B, align 16, !tbaa !5
  store <4 x i32> %1, ptr getelementptr inbounds (i8, ptr @B, i64 16), align 16, !tbaa !5
  %wide.load.1 = load <4 x i32>, ptr getelementptr inbounds (i8, ptr @A, i64 32), align 16, !tbaa !5
  %wide.load6.1 = load <4 x i32>, ptr getelementptr inbounds (i8, ptr @A, i64 48), align 16, !tbaa !5
  %2 = add nsw <4 x i32> %wide.load.1, <i32 1, i32 1, i32 1, i32 1>
  %3 = add nsw <4 x i32> %wide.load6.1, <i32 1, i32 1, i32 1, i32 1>
  store <4 x i32> %2, ptr getelementptr inbounds (i8, ptr @B, i64 32), align 16, !tbaa !5
  store <4 x i32> %3, ptr getelementptr inbounds (i8, ptr @B, i64 48), align 16, !tbaa !5
  %wide.load.2 = load <4 x i32>, ptr getelementptr inbounds (i8, ptr @A, i64 64), align 16, !tbaa !5
  %wide.load6.2 = load <4 x i32>, ptr getelementptr inbounds (i8, ptr @A, i64 80), align 16, !tbaa !5
  %4 = add nsw <4 x i32> %wide.load.2, <i32 1, i32 1, i32 1, i32 1>
  %5 = add nsw <4 x i32> %wide.load6.2, <i32 1, i32 1, i32 1, i32 1>
  store <4 x i32> %4, ptr getelementptr inbounds (i8, ptr @B, i64 64), align 16, !tbaa !5
  store <4 x i32> %5, ptr getelementptr inbounds (i8, ptr @B, i64 80), align 16, !tbaa !5
  %wide.load.3 = load <4 x i32>, ptr getelementptr inbounds (i8, ptr @A, i64 96), align 16, !tbaa !5
  %wide.load6.3 = load <4 x i32>, ptr getelementptr inbounds (i8, ptr @A, i64 112), align 16, !tbaa !5
  %6 = add nsw <4 x i32> %wide.load.3, <i32 1, i32 1, i32 1, i32 1>
  %7 = add nsw <4 x i32> %wide.load6.3, <i32 1, i32 1, i32 1, i32 1>
  store <4 x i32> %6, ptr getelementptr inbounds (i8, ptr @B, i64 96), align 16, !tbaa !5
  store <4 x i32> %7, ptr getelementptr inbounds (i8, ptr @B, i64 112), align 16, !tbaa !5
  %wide.load.4 = load <4 x i32>, ptr getelementptr inbounds (i8, ptr @A, i64 128), align 16, !tbaa !5
  %wide.load6.4 = load <4 x i32>, ptr getelementptr inbounds (i8, ptr @A, i64 144), align 16, !tbaa !5
  %8 = add nsw <4 x i32> %wide.load.4, <i32 1, i32 1, i32 1, i32 1>
  %9 = add nsw <4 x i32> %wide.load6.4, <i32 1, i32 1, i32 1, i32 1>
  store <4 x i32> %8, ptr getelementptr inbounds (i8, ptr @B, i64 128), align 16, !tbaa !5
  store <4 x i32> %9, ptr getelementptr inbounds (i8, ptr @B, i64 144), align 16, !tbaa !5
  %wide.load.5 = load <4 x i32>, ptr getelementptr inbounds (i8, ptr @A, i64 160), align 16, !tbaa !5
  %wide.load6.5 = load <4 x i32>, ptr getelementptr inbounds (i8, ptr @A, i64 176), align 16, !tbaa !5
  %10 = add nsw <4 x i32> %wide.load.5, <i32 1, i32 1, i32 1, i32 1>
  %11 = add nsw <4 x i32> %wide.load6.5, <i32 1, i32 1, i32 1, i32 1>
  store <4 x i32> %10, ptr getelementptr inbounds (i8, ptr @B, i64 160), align 16, !tbaa !5
  store <4 x i32> %11, ptr getelementptr inbounds (i8, ptr @B, i64 176), align 16, !tbaa !5
  %wide.load.6 = load <4 x i32>, ptr getelementptr inbounds (i8, ptr @A, i64 192), align 16, !tbaa !5
  %wide.load6.6 = load <4 x i32>, ptr getelementptr inbounds (i8, ptr @A, i64 208), align 16, !tbaa !5
  %12 = add nsw <4 x i32> %wide.load.6, <i32 1, i32 1, i32 1, i32 1>
  %13 = add nsw <4 x i32> %wide.load6.6, <i32 1, i32 1, i32 1, i32 1>
  store <4 x i32> %12, ptr getelementptr inbounds (i8, ptr @B, i64 192), align 16, !tbaa !5
  store <4 x i32> %13, ptr getelementptr inbounds (i8, ptr @B, i64 208), align 16, !tbaa !5
  %wide.load.7 = load <4 x i32>, ptr getelementptr inbounds (i8, ptr @A, i64 224), align 16, !tbaa !5
  %wide.load6.7 = load <4 x i32>, ptr getelementptr inbounds (i8, ptr @A, i64 240), align 16, !tbaa !5
  %14 = add nsw <4 x i32> %wide.load.7, <i32 1, i32 1, i32 1, i32 1>
  %15 = add nsw <4 x i32> %wide.load6.7, <i32 1, i32 1, i32 1, i32 1>
  store <4 x i32> %14, ptr getelementptr inbounds (i8, ptr @B, i64 224), align 16, !tbaa !5
  store <4 x i32> %15, ptr getelementptr inbounds (i8, ptr @B, i64 240), align 16, !tbaa !5
  %wide.load.8 = load <4 x i32>, ptr getelementptr inbounds (i8, ptr @A, i64 256), align 16, !tbaa !5
  %wide.load6.8 = load <4 x i32>, ptr getelementptr inbounds (i8, ptr @A, i64 272), align 16, !tbaa !5
  %16 = add nsw <4 x i32> %wide.load.8, <i32 1, i32 1, i32 1, i32 1>
  %17 = add nsw <4 x i32> %wide.load6.8, <i32 1, i32 1, i32 1, i32 1>
  store <4 x i32> %16, ptr getelementptr inbounds (i8, ptr @B, i64 256), align 16, !tbaa !5
  store <4 x i32> %17, ptr getelementptr inbounds (i8, ptr @B, i64 272), align 16, !tbaa !5
  %wide.load.9 = load <4 x i32>, ptr getelementptr inbounds (i8, ptr @A, i64 288), align 16, !tbaa !5
  %wide.load6.9 = load <4 x i32>, ptr getelementptr inbounds (i8, ptr @A, i64 304), align 16, !tbaa !5
  %18 = add nsw <4 x i32> %wide.load.9, <i32 1, i32 1, i32 1, i32 1>
  %19 = add nsw <4 x i32> %wide.load6.9, <i32 1, i32 1, i32 1, i32 1>
  store <4 x i32> %18, ptr getelementptr inbounds (i8, ptr @B, i64 288), align 16, !tbaa !5
  store <4 x i32> %19, ptr getelementptr inbounds (i8, ptr @B, i64 304), align 16, !tbaa !5
  %wide.load.10 = load <4 x i32>, ptr getelementptr inbounds (i8, ptr @A, i64 320), align 16, !tbaa !5
  %wide.load6.10 = load <4 x i32>, ptr getelementptr inbounds (i8, ptr @A, i64 336), align 16, !tbaa !5
  %20 = add nsw <4 x i32> %wide.load.10, <i32 1, i32 1, i32 1, i32 1>
  %21 = add nsw <4 x i32> %wide.load6.10, <i32 1, i32 1, i32 1, i32 1>
  store <4 x i32> %20, ptr getelementptr inbounds (i8, ptr @B, i64 320), align 16, !tbaa !5
  store <4 x i32> %21, ptr getelementptr inbounds (i8, ptr @B, i64 336), align 16, !tbaa !5
  %wide.load.11 = load <4 x i32>, ptr getelementptr inbounds (i8, ptr @A, i64 352), align 16, !tbaa !5
  %wide.load6.11 = load <4 x i32>, ptr getelementptr inbounds (i8, ptr @A, i64 368), align 16, !tbaa !5
  %22 = add nsw <4 x i32> %wide.load.11, <i32 1, i32 1, i32 1, i32 1>
  %23 = add nsw <4 x i32> %wide.load6.11, <i32 1, i32 1, i32 1, i32 1>
  store <4 x i32> %22, ptr getelementptr inbounds (i8, ptr @B, i64 352), align 16, !tbaa !5
  store <4 x i32> %23, ptr getelementptr inbounds (i8, ptr @B, i64 368), align 16, !tbaa !5
  %24 = load i32, ptr getelementptr inbounds (i8, ptr @A, i64 384), align 16, !tbaa !5
  %25 = add nsw i32 %24, 1
  store i32 %25, ptr getelementptr inbounds (i8, ptr @B, i64 384), align 16, !tbaa !5
  %26 = load i32, ptr getelementptr inbounds (i8, ptr @A, i64 388), align 4, !tbaa !5
  %27 = add nsw i32 %26, 1
  store i32 %27, ptr getelementptr inbounds (i8, ptr @B, i64 388), align 4, !tbaa !5
  %28 = load i32, ptr getelementptr inbounds (i8, ptr @A, i64 392), align 8, !tbaa !5
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr getelementptr inbounds (i8, ptr @B, i64 392), align 8, !tbaa !5
  %30 = load i32, ptr getelementptr inbounds (i8, ptr @A, i64 396), align 4, !tbaa !5
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr getelementptr inbounds (i8, ptr @B, i64 396), align 4, !tbaa !5
  ret void
}

attributes #0 = { nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: 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" }

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


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