; LLVM IR from MinaFaried3/Assiut-University-Training---Newcomers :: e-sheet3_array/try.ll (Z17countVowelStringsi)

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

@__const._Z17countVowelStringsi.arr = external hidden unnamed_addr constant [5 x i32], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z17countVowelStringsi(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca [5 x i32], align 16
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 20, ptr %3) #3
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %3, ptr align 16 @__const._Z17countVowelStringsi.arr, i64 20, i1 false)
  br label %6

6:                                                ; preds = %34, %1
  %7 = load i32, ptr %2, align 4, !tbaa !5
  %8 = add nsw i32 %7, -1
  store i32 %8, ptr %2, align 4, !tbaa !5
  %9 = icmp ne i32 %8, 0
  br i1 %9, label %10, label %35

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

11:                                               ; preds = %30, %10
  %12 = load i32, ptr %4, align 4, !tbaa !5
  %13 = icmp sge i32 %12, 0
  br i1 %13, label %15, label %14

14:                                               ; preds = %11
  store i32 4, ptr %5, align 4
  br label %33

15:                                               ; preds = %11
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = add nsw i32 %16, 1
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [5 x i32], ptr %3, i64 0, i64 %18
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %21 = load i32, ptr %4, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [5 x i32], ptr %3, i64 0, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = add nsw i32 %24, %20
  store i32 %25, ptr %23, align 4, !tbaa !5
  %26 = load i32, ptr %4, align 4, !tbaa !5
  %27 = icmp eq i32 %26, 0
  br i1 %27, label %28, label %29

28:                                               ; preds = %15
  store i32 4, ptr %5, align 4
  br label %33

29:                                               ; preds = %15
  br label %30

30:                                               ; preds = %29
  %31 = load i32, ptr %4, align 4, !tbaa !5
  %32 = add nsw i32 %31, -1
  store i32 %32, ptr %4, align 4, !tbaa !5
  br label %11, !llvm.loop !9

33:                                               ; preds = %28, %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %34

34:                                               ; preds = %33
  br label %6, !llvm.loop !11

35:                                               ; preds = %6
  %36 = getelementptr inbounds [5 x i32], ptr %3, i64 0, i64 0
  %37 = load i32, ptr %36, align 16, !tbaa !5
  %38 = getelementptr inbounds [5 x i32], ptr %3, i64 0, i64 1
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %40 = add nsw i32 %37, %39
  %41 = getelementptr inbounds [5 x i32], ptr %3, i64 0, i64 2
  %42 = load i32, ptr %41, align 8, !tbaa !5
  %43 = add nsw i32 %40, %42
  %44 = getelementptr inbounds [5 x i32], ptr %3, i64 0, i64 3
  %45 = load i32, ptr %44, align 4, !tbaa !5
  %46 = add nsw i32 %43, %45
  %47 = getelementptr inbounds [5 x i32], ptr %3, i64 0, i64 4
  %48 = load i32, ptr %47, align 16, !tbaa !5
  %49 = add nsw i32 %46, %48
  store i32 1, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 20, ptr %3) #3
  ret i32 %49
}

; 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

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

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


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

@__const._Z17countVowelStringsi.arr = external hidden unnamed_addr constant [5 x i32], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none) uwtable
define dso_local noundef i32 @_Z17countVowelStringsi(i32 noundef %0) local_unnamed_addr #0 {
  %.sroa.0.0.copyload = load i32, ptr @__const._Z17countVowelStringsi.arr, align 16
  %.sroa.6.0.copyload = load i32, ptr getelementptr inbounds (i8, ptr @__const._Z17countVowelStringsi.arr, i64 4), align 4
  %.sroa.10.0.copyload = load i32, ptr getelementptr inbounds (i8, ptr @__const._Z17countVowelStringsi.arr, i64 8), align 8
  %.sroa.14.0.copyload = load i32, ptr getelementptr inbounds (i8, ptr @__const._Z17countVowelStringsi.arr, i64 12), align 4
  %.sroa.18.0.copyload = load i32, ptr getelementptr inbounds (i8, ptr @__const._Z17countVowelStringsi.arr, i64 16), align 16
  %2 = add nsw i32 %0, -1
  %.not8 = icmp eq i32 %2, 0
  br i1 %.not8, label %._crit_edge, label %.preheader.preheader

.preheader.preheader:                             ; preds = %1
  %3 = add i32 %0, -2
  %xtraiter = and i32 %2, 3
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.preheader.prol.loopexit, label %.preheader.prol

.preheader.prol:                                  ; preds = %.preheader.preheader, %.preheader.prol
  %.sroa.14.0.prol = phi i32 [ %5, %.preheader.prol ], [ %.sroa.14.0.copyload, %.preheader.preheader ]
  %.sroa.10.0.prol = phi i32 [ %6, %.preheader.prol ], [ %.sroa.10.0.copyload, %.preheader.preheader ]
  %.sroa.6.0.prol = phi i32 [ %7, %.preheader.prol ], [ %.sroa.6.0.copyload, %.preheader.preheader ]
  %.sroa.0.0.prol = phi i32 [ %8, %.preheader.prol ], [ %.sroa.0.0.copyload, %.preheader.preheader ]
  %4 = phi i32 [ %9, %.preheader.prol ], [ %2, %.preheader.preheader ]
  %prol.iter = phi i32 [ %prol.iter.next, %.preheader.prol ], [ 0, %.preheader.preheader ]
  %5 = add nsw i32 %.sroa.14.0.prol, %.sroa.18.0.copyload
  %6 = add nsw i32 %.sroa.10.0.prol, %5
  %7 = add nsw i32 %.sroa.6.0.prol, %6
  %8 = add nsw i32 %.sroa.0.0.prol, %7
  %9 = add nsw i32 %4, -1
  %prol.iter.next = add i32 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i32 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %.preheader.prol.loopexit, label %.preheader.prol, !llvm.loop !5

.preheader.prol.loopexit:                         ; preds = %.preheader.prol, %.preheader.preheader
  %.lcssa26.unr = phi i32 [ poison, %.preheader.preheader ], [ %5, %.preheader.prol ]
  %.lcssa25.unr = phi i32 [ poison, %.preheader.preheader ], [ %6, %.preheader.prol ]
  %.lcssa24.unr = phi i32 [ poison, %.preheader.preheader ], [ %7, %.preheader.prol ]
  %.lcssa.unr = phi i32 [ poison, %.preheader.preheader ], [ %8, %.preheader.prol ]
  %.sroa.14.0.unr = phi i32 [ %.sroa.14.0.copyload, %.preheader.preheader ], [ %5, %.preheader.prol ]
  %.sroa.10.0.unr = phi i32 [ %.sroa.10.0.copyload, %.preheader.preheader ], [ %6, %.preheader.prol ]
  %.sroa.6.0.unr = phi i32 [ %.sroa.6.0.copyload, %.preheader.preheader ], [ %7, %.preheader.prol ]
  %.sroa.0.0.unr = phi i32 [ %.sroa.0.0.copyload, %.preheader.preheader ], [ %8, %.preheader.prol ]
  %.unr = phi i32 [ %2, %.preheader.preheader ], [ %9, %.preheader.prol ]
  %10 = icmp ult i32 %3, 3
  br i1 %10, label %._crit_edge, label %.preheader

.preheader:                                       ; preds = %.preheader.prol.loopexit, %.preheader
  %.sroa.14.0 = phi i32 [ %24, %.preheader ], [ %.sroa.14.0.unr, %.preheader.prol.loopexit ]
  %.sroa.10.0 = phi i32 [ %25, %.preheader ], [ %.sroa.10.0.unr, %.preheader.prol.loopexit ]
  %.sroa.6.0 = phi i32 [ %26, %.preheader ], [ %.sroa.6.0.unr, %.preheader.prol.loopexit ]
  %.sroa.0.0 = phi i32 [ %27, %.preheader ], [ %.sroa.0.0.unr, %.preheader.prol.loopexit ]
  %11 = phi i32 [ %28, %.preheader ], [ %.unr, %.preheader.prol.loopexit ]
  %12 = add nsw i32 %.sroa.14.0, %.sroa.18.0.copyload
  %13 = add nsw i32 %.sroa.10.0, %12
  %14 = add nsw i32 %.sroa.6.0, %13
  %15 = add nsw i32 %.sroa.0.0, %14
  %16 = add nsw i32 %12, %.sroa.18.0.copyload
  %17 = add nsw i32 %13, %16
  %18 = add nsw i32 %14, %17
  %19 = add nsw i32 %15, %18
  %20 = add nsw i32 %16, %.sroa.18.0.copyload
  %21 = add nsw i32 %17, %20
  %22 = add nsw i32 %18, %21
  %23 = add nsw i32 %19, %22
  %24 = add nsw i32 %20, %.sroa.18.0.copyload
  %25 = add nsw i32 %21, %24
  %26 = add nsw i32 %22, %25
  %27 = add nsw i32 %23, %26
  %28 = add nsw i32 %11, -4
  %.not.3 = icmp eq i32 %28, 0
  br i1 %.not.3, label %._crit_edge, label %.preheader, !llvm.loop !7

._crit_edge:                                      ; preds = %.preheader.prol.loopexit, %.preheader, %1
  %.sroa.14.1 = phi i32 [ %.sroa.14.0.copyload, %1 ], [ %.lcssa26.unr, %.preheader.prol.loopexit ], [ %24, %.preheader ]
  %.sroa.10.1 = phi i32 [ %.sroa.10.0.copyload, %1 ], [ %.lcssa25.unr, %.preheader.prol.loopexit ], [ %25, %.preheader ]
  %.sroa.6.1 = phi i32 [ %.sroa.6.0.copyload, %1 ], [ %.lcssa24.unr, %.preheader.prol.loopexit ], [ %26, %.preheader ]
  %.sroa.0.1 = phi i32 [ %.sroa.0.0.copyload, %1 ], [ %.lcssa.unr, %.preheader.prol.loopexit ], [ %27, %.preheader ]
  %29 = add nsw i32 %.sroa.6.1, %.sroa.0.1
  %30 = add nsw i32 %29, %.sroa.10.1
  %31 = add nsw i32 %30, %.sroa.14.1
  %32 = add nsw i32 %31, %.sroa.18.0.copyload
  ret i32 %32
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn 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" }

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.unroll.disable"}
!7 = distinct !{!7, !8}
!8 = !{!"llvm.loop.mustprogress"}


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