; LLVM IR from FrancesoM/Bisc8FX :: sdk_projects/bisc8_platform/ps7_cortexa9_0/standalone_domain/bsp/ps7_cortexa9_0_ (MemCpy)

; 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 @Xil_MemCpy(ptr noundef %0, ptr noundef %1, i32 noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %9, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %10, ptr %8, align 8, !tbaa !5
  br label %11

11:                                               ; preds = %15, %3
  %12 = load i32, ptr %6, align 4, !tbaa !9
  %13 = zext i32 %12 to i64
  %14 = icmp uge i64 %13, 4
  br i1 %14, label %15, label %27

15:                                               ; preds = %11
  %16 = load ptr, ptr %8, align 8, !tbaa !5
  %17 = load i32, ptr %16, align 4, !tbaa !9
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 %17, ptr %18, align 4, !tbaa !9
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %19, i64 4
  store ptr %20, ptr %7, align 8, !tbaa !5
  %21 = load ptr, ptr %8, align 8, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %21, i64 4
  store ptr %22, ptr %8, align 8, !tbaa !5
  %23 = load i32, ptr %6, align 4, !tbaa !9
  %24 = zext i32 %23 to i64
  %25 = sub i64 %24, 4
  %26 = trunc i64 %25 to i32
  store i32 %26, ptr %6, align 4, !tbaa !9
  br label %11, !llvm.loop !11

27:                                               ; preds = %11
  br label %28

28:                                               ; preds = %32, %27
  %29 = load i32, ptr %6, align 4, !tbaa !9
  %30 = zext i32 %29 to i64
  %31 = icmp uge i64 %30, 2
  br i1 %31, label %32, label %44

32:                                               ; preds = %28
  %33 = load ptr, ptr %8, align 8, !tbaa !5
  %34 = load i16, ptr %33, align 2, !tbaa !13
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  store i16 %34, ptr %35, align 2, !tbaa !13
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = getelementptr inbounds i8, ptr %36, i64 2
  store ptr %37, ptr %7, align 8, !tbaa !5
  %38 = load ptr, ptr %8, align 8, !tbaa !5
  %39 = getelementptr inbounds i8, ptr %38, i64 2
  store ptr %39, ptr %8, align 8, !tbaa !5
  %40 = load i32, ptr %6, align 4, !tbaa !9
  %41 = zext i32 %40 to i64
  %42 = sub i64 %41, 2
  %43 = trunc i64 %42 to i32
  store i32 %43, ptr %6, align 4, !tbaa !9
  br label %28, !llvm.loop !15

44:                                               ; preds = %28
  br label %45

45:                                               ; preds = %48, %44
  %46 = load i32, ptr %6, align 4, !tbaa !9
  %47 = icmp ugt i32 %46, 0
  br i1 %47, label %48, label %58

48:                                               ; preds = %45
  %49 = load ptr, ptr %8, align 8, !tbaa !5
  %50 = load i8, ptr %49, align 1, !tbaa !16
  %51 = load ptr, ptr %7, align 8, !tbaa !5
  store i8 %50, ptr %51, align 1, !tbaa !16
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  %53 = getelementptr inbounds i8, ptr %52, i64 1
  store ptr %53, ptr %7, align 8, !tbaa !5
  %54 = load ptr, ptr %8, align 8, !tbaa !5
  %55 = getelementptr inbounds i8, ptr %54, i64 1
  store ptr %55, ptr %8, align 8, !tbaa !5
  %56 = load i32, ptr %6, align 4, !tbaa !9
  %57 = sub i32 %56, 1
  store i32 %57, ptr %6, align 4, !tbaa !9
  br label %45, !llvm.loop !17

58:                                               ; preds = %45
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !14, i64 0}
!14 = !{!"short", !7, i64 0}
!15 = distinct !{!15, !12}
!16 = !{!7, !7, i64 0}
!17 = distinct !{!17, !12}


; 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(readwrite, inaccessiblemem: none) uwtable
define dso_local void @Xil_MemCpy(ptr nocapture noundef writeonly %0, ptr nocapture noundef readonly %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = icmp ugt i32 %2, 3
  br i1 %4, label %.lr.ph.preheader, label %.preheader27

.lr.ph.preheader:                                 ; preds = %3
  %5 = ptrtoint ptr %0 to i64
  %6 = ptrtoint ptr %1 to i64
  %7 = add i32 %2, -4
  %8 = lshr i32 %7, 2
  %narrow = add nuw nsw i32 %8, 1
  %9 = zext nneg i32 %narrow to i64
  %min.iters.check = icmp ult i32 %7, 28
  %10 = sub i64 %5, %6
  %diff.check = icmp ult i64 %10, 32
  %or.cond = or i1 %min.iters.check, %diff.check
  br i1 %or.cond, label %.lr.ph.preheader107, label %vector.ph

.lr.ph.preheader107:                              ; preds = %middle.block, %.lr.ph.preheader
  %.030.ph = phi ptr [ %1, %.lr.ph.preheader ], [ %ind.end, %middle.block ]
  %.01929.ph = phi ptr [ %0, %.lr.ph.preheader ], [ %ind.end60, %middle.block ]
  %.02228.ph = phi i32 [ %2, %.lr.ph.preheader ], [ %ind.end62, %middle.block ]
  br label %.lr.ph

vector.ph:                                        ; preds = %.lr.ph.preheader
  %n.vec = and i64 %9, 2147483640
  %11 = shl nuw nsw i64 %n.vec, 2
  %ind.end = getelementptr i8, ptr %1, i64 %11
  %12 = shl nuw nsw i64 %n.vec, 2
  %ind.end60 = getelementptr i8, ptr %0, i64 %12
  %.cast = trunc nuw nsw i64 %n.vec to i32
  %13 = shl i32 %.cast, 2
  %ind.end62 = sub i32 %2, %13
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %offset.idx = shl i64 %index, 2
  %next.gep = getelementptr i8, ptr %1, i64 %offset.idx
  %offset.idx65 = shl i64 %index, 2
  %next.gep66 = getelementptr i8, ptr %0, i64 %offset.idx65
  %14 = getelementptr i8, ptr %next.gep, i64 16
  %wide.load = load <4 x i32>, ptr %next.gep, align 4, !tbaa !5
  %wide.load70 = load <4 x i32>, ptr %14, align 4, !tbaa !5
  %15 = getelementptr i8, ptr %next.gep66, i64 16
  store <4 x i32> %wide.load, ptr %next.gep66, align 4, !tbaa !5
  store <4 x i32> %wide.load70, ptr %15, align 4, !tbaa !5
  %index.next = add nuw i64 %index, 8
  %16 = icmp eq i64 %index.next, %n.vec
  br i1 %16, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %9
  br i1 %cmp.n, label %.preheader27, label %.lr.ph.preheader107

.preheader27:                                     ; preds = %.lr.ph, %middle.block, %3
  %.022.lcssa = phi i32 [ %2, %3 ], [ %ind.end62, %middle.block ], [ %31, %.lr.ph ]
  %.019.lcssa = phi ptr [ %0, %3 ], [ %ind.end60, %middle.block ], [ %29, %.lr.ph ]
  %.0.lcssa = phi ptr [ %1, %3 ], [ %ind.end, %middle.block ], [ %30, %.lr.ph ]
  %17 = icmp ugt i32 %.022.lcssa, 1
  br i1 %17, label %.lr.ph36.preheader, label %.preheader

.lr.ph36.preheader:                               ; preds = %.preheader27
  %.0.lcssa73 = ptrtoint ptr %.0.lcssa to i64
  %.019.lcssa72 = ptrtoint ptr %.019.lcssa to i64
  %18 = add i32 %.022.lcssa, -2
  %19 = lshr i32 %18, 1
  %narrow102 = add nuw i32 %19, 1
  %20 = zext i32 %narrow102 to i64
  %min.iters.check77 = icmp ult i32 %18, 30
  %21 = sub i64 %.019.lcssa72, %.0.lcssa73
  %diff.check74 = icmp ult i64 %21, 32
  %or.cond103 = select i1 %min.iters.check77, i1 true, i1 %diff.check74
  br i1 %or.cond103, label %.lr.ph36.preheader104, label %vector.ph78

.lr.ph36.preheader104:                            ; preds = %middle.block75, %.lr.ph36.preheader
  %.135.ph = phi ptr [ %.0.lcssa, %.lr.ph36.preheader ], [ %ind.end81, %middle.block75 ]
  %.12034.ph = phi ptr [ %.019.lcssa, %.lr.ph36.preheader ], [ %ind.end83, %middle.block75 ]
  %.12333.ph = phi i32 [ %.022.lcssa, %.lr.ph36.preheader ], [ %ind.end86, %middle.block75 ]
  br label %.lr.ph36

vector.ph78:                                      ; preds = %.lr.ph36.preheader
  %n.vec80 = and i64 %20, 4294967280
  %22 = shl nuw nsw i64 %n.vec80, 1
  %ind.end81 = getelementptr i8, ptr %.0.lcssa, i64 %22
  %23 = shl nuw nsw i64 %n.vec80, 1
  %ind.end83 = getelementptr i8, ptr %.019.lcssa, i64 %23
  %.cast85 = trunc nuw i64 %n.vec80 to i32
  %24 = shl i32 %.cast85, 1
  %ind.end86 = sub i32 %.022.lcssa, %24
  br label %vector.body88

vector.body88:                                    ; preds = %vector.body88, %vector.ph78
  %index89 = phi i64 [ 0, %vector.ph78 ], [ %index.next100, %vector.body88 ]
  %offset.idx90 = shl i64 %index89, 1
  %next.gep91 = getelementptr i8, ptr %.0.lcssa, i64 %offset.idx90
  %offset.idx93 = shl i64 %index89, 1
  %next.gep94 = getelementptr i8, ptr %.019.lcssa, i64 %offset.idx93
  %25 = getelementptr i8, ptr %next.gep91, i64 16
  %wide.load98 = load <8 x i16>, ptr %next.gep91, align 2, !tbaa !13
  %wide.load99 = load <8 x i16>, ptr %25, align 2, !tbaa !13
  %26 = getelementptr i8, ptr %next.gep94, i64 16
  store <8 x i16> %wide.load98, ptr %next.gep94, align 2, !tbaa !13
  store <8 x i16> %wide.load99, ptr %26, align 2, !tbaa !13
  %index.next100 = add nuw i64 %index89, 16
  %27 = icmp eq i64 %index.next100, %n.vec80
  br i1 %27, label %middle.block75, label %vector.body88, !llvm.loop !15

middle.block75:                                   ; preds = %vector.body88
  %cmp.n101 = icmp eq i64 %n.vec80, %20
  br i1 %cmp.n101, label %.preheader, label %.lr.ph36.preheader104

.lr.ph:                                           ; preds = %.lr.ph.preheader107, %.lr.ph
  %.030 = phi ptr [ %30, %.lr.ph ], [ %.030.ph, %.lr.ph.preheader107 ]
  %.01929 = phi ptr [ %29, %.lr.ph ], [ %.01929.ph, %.lr.ph.preheader107 ]
  %.02228 = phi i32 [ %31, %.lr.ph ], [ %.02228.ph, %.lr.ph.preheader107 ]
  %28 = load i32, ptr %.030, align 4, !tbaa !5
  store i32 %28, ptr %.01929, align 4, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %.01929, i64 4
  %30 = getelementptr inbounds i8, ptr %.030, i64 4
  %31 = add i32 %.02228, -4
  %32 = icmp ugt i32 %31, 3
  br i1 %32, label %.lr.ph, label %.preheader27, !llvm.loop !16

.preheader:                                       ; preds = %.lr.ph36, %middle.block75, %.preheader27
  %.123.lcssa = phi i32 [ %.022.lcssa, %.preheader27 ], [ %ind.end86, %middle.block75 ], [ %36, %.lr.ph36 ]
  %.120.lcssa = phi ptr [ %.019.lcssa, %.preheader27 ], [ %ind.end83, %middle.block75 ], [ %34, %.lr.ph36 ]
  %.1.lcssa = phi ptr [ %.0.lcssa, %.preheader27 ], [ %ind.end81, %middle.block75 ], [ %35, %.lr.ph36 ]
  %.not40 = icmp eq i32 %.123.lcssa, 0
  br i1 %.not40, label %._crit_edge, label %.lr.ph44

.lr.ph36:                                         ; preds = %.lr.ph36.preheader104, %.lr.ph36
  %.135 = phi ptr [ %35, %.lr.ph36 ], [ %.135.ph, %.lr.ph36.preheader104 ]
  %.12034 = phi ptr [ %34, %.lr.ph36 ], [ %.12034.ph, %.lr.ph36.preheader104 ]
  %.12333 = phi i32 [ %36, %.lr.ph36 ], [ %.12333.ph, %.lr.ph36.preheader104 ]
  %33 = load i16, ptr %.135, align 2, !tbaa !13
  store i16 %33, ptr %.12034, align 2, !tbaa !13
  %34 = getelementptr inbounds i8, ptr %.12034, i64 2
  %35 = getelementptr inbounds i8, ptr %.135, i64 2
  %36 = add i32 %.12333, -2
  %37 = icmp ugt i32 %36, 1
  br i1 %37, label %.lr.ph36, label %.preheader, !llvm.loop !17

.lr.ph44:                                         ; preds = %.preheader
  %38 = load i8, ptr %.1.lcssa, align 1, !tbaa !18
  store i8 %38, ptr %.120.lcssa, align 1, !tbaa !18
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph44, %.preheader
  ret void
}

attributes #0 = { nofree norecurse nosync nounwind memory(readwrite, 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"}
!9 = distinct !{!9, !10, !11, !12}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = !{!14, !14, i64 0}
!14 = !{!"short", !7, i64 0}
!15 = distinct !{!15, !10, !11, !12}
!16 = distinct !{!16, !10, !11}
!17 = distinct !{!17, !10, !11}
!18 = !{!7, !7, i64 0}


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