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

; 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: 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 i32 @Xil_SecureMemCpy(ptr noundef %0, i32 noundef %1, ptr noundef %2, i32 noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  store i32 %3, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  store i32 1, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %12, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  %13 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %13, ptr %11, align 8, !tbaa !5
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = icmp eq ptr %14, null
  br i1 %15, label %19, label %16

16:                                               ; preds = %4
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = icmp eq ptr %17, null
  br i1 %18, label %19, label %20

19:                                               ; preds = %16, %4
  br label %50

20:                                               ; preds = %16
  %21 = load i32, ptr %8, align 4, !tbaa !9
  %22 = load i32, ptr %6, align 4, !tbaa !9
  %23 = icmp ugt i32 %21, %22
  br i1 %23, label %24, label %35

24:                                               ; preds = %20
  br label %25

25:                                               ; preds = %28, %24
  %26 = load i32, ptr %6, align 4, !tbaa !9
  %27 = icmp ne i32 %26, 0
  br i1 %27, label %28, label %34

28:                                               ; preds = %25
  %29 = load ptr, ptr %10, align 8, !tbaa !5
  store i8 0, ptr %29, align 1, !tbaa !11
  %30 = load ptr, ptr %10, align 8, !tbaa !5
  %31 = getelementptr inbounds i8, ptr %30, i32 1
  store ptr %31, ptr %10, align 8, !tbaa !5
  %32 = load i32, ptr %6, align 4, !tbaa !9
  %33 = add i32 %32, -1
  store i32 %33, ptr %6, align 4, !tbaa !9
  br label %25, !llvm.loop !12

34:                                               ; preds = %25
  br label %50

35:                                               ; preds = %20
  br label %36

36:                                               ; preds = %39, %35
  %37 = load i32, ptr %8, align 4, !tbaa !9
  %38 = icmp ne i32 %37, 0
  br i1 %38, label %39, label %49

39:                                               ; preds = %36
  %40 = load ptr, ptr %11, align 8, !tbaa !5
  %41 = load i8, ptr %40, align 1, !tbaa !11
  %42 = load ptr, ptr %10, align 8, !tbaa !5
  store i8 %41, ptr %42, align 1, !tbaa !11
  %43 = load ptr, ptr %10, align 8, !tbaa !5
  %44 = getelementptr inbounds i8, ptr %43, i32 1
  store ptr %44, ptr %10, align 8, !tbaa !5
  %45 = load ptr, ptr %11, align 8, !tbaa !5
  %46 = getelementptr inbounds i8, ptr %45, i32 1
  store ptr %46, ptr %11, align 8, !tbaa !5
  %47 = load i32, ptr %8, align 4, !tbaa !9
  %48 = add i32 %47, -1
  store i32 %48, ptr %8, align 4, !tbaa !9
  br label %36, !llvm.loop !14

49:                                               ; preds = %36
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %50

50:                                               ; preds = %49, %34, %19
  %51 = load i32, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  ret i32 %51
}

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 = !{!"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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


; 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 range(i32 0, 2) i32 @Xil_SecureMemCpy(ptr noundef writeonly %0, i32 noundef %1, ptr noundef readonly %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = ptrtoint ptr %2 to i64
  %6 = ptrtoint ptr %0 to i64
  %7 = icmp eq ptr %0, null
  %8 = icmp eq ptr %2, null
  %or.cond = or i1 %7, %8
  br i1 %or.cond, label %.loopexit, label %9

9:                                                ; preds = %4
  %10 = icmp ugt i32 %3, %1
  br i1 %10, label %.preheader, label %.preheader26

.preheader26:                                     ; preds = %9
  %.not28 = icmp eq i32 %3, 0
  br i1 %.not28, label %.loopexit, label %iter.check

iter.check:                                       ; preds = %.preheader26
  %11 = zext i32 %3 to i64
  %min.iters.check = icmp ult i32 %3, 8
  %12 = sub i64 %6, %5
  %diff.check = icmp ult i64 %12, 32
  %or.cond58 = or i1 %min.iters.check, %diff.check
  br i1 %or.cond58, label %.lr.ph.preheader, label %vector.main.loop.iter.check

vector.main.loop.iter.check:                      ; preds = %iter.check
  %min.iters.check37 = icmp ult i32 %3, 32
  br i1 %min.iters.check37, label %vec.epilog.ph, label %vector.ph

vector.ph:                                        ; preds = %vector.main.loop.iter.check
  %n.vec = and i64 %11, 4294967264
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %next.gep = getelementptr i8, ptr %2, i64 %index
  %next.gep39 = getelementptr i8, ptr %0, i64 %index
  %13 = getelementptr i8, ptr %next.gep, i64 16
  %wide.load = load <16 x i8>, ptr %next.gep, align 1, !tbaa !5
  %wide.load41 = load <16 x i8>, ptr %13, align 1, !tbaa !5
  %14 = getelementptr i8, ptr %next.gep39, i64 16
  store <16 x i8> %wide.load, ptr %next.gep39, align 1, !tbaa !5
  store <16 x i8> %wide.load41, ptr %14, align 1, !tbaa !5
  %index.next = add nuw i64 %index, 32
  %15 = icmp eq i64 %index.next, %n.vec
  br i1 %15, label %middle.block, label %vector.body, !llvm.loop !8

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %11
  br i1 %cmp.n, label %.loopexit, label %vec.epilog.iter.check

vec.epilog.iter.check:                            ; preds = %middle.block
  %.cast49 = trunc nuw i64 %n.vec to i32
  %ind.end50 = sub i32 %3, %.cast49
  %ind.end46 = getelementptr i8, ptr %0, i64 %n.vec
  %ind.end44 = getelementptr i8, ptr %2, i64 %n.vec
  %n.vec.remaining = and i64 %11, 24
  %min.epilog.iters.check = icmp eq i64 %n.vec.remaining, 0
  br i1 %min.epilog.iters.check, label %.lr.ph.preheader, label %vec.epilog.ph

.lr.ph.preheader:                                 ; preds = %vec.epilog.middle.block, %iter.check, %vec.epilog.iter.check
  %.031.ph = phi ptr [ %2, %iter.check ], [ %ind.end44, %vec.epilog.iter.check ], [ %ind.end, %vec.epilog.middle.block ]
  %.130.ph = phi ptr [ %0, %iter.check ], [ %ind.end46, %vec.epilog.iter.check ], [ %ind.end45, %vec.epilog.middle.block ]
  %.01929.ph = phi i32 [ %3, %iter.check ], [ %ind.end50, %vec.epilog.iter.check ], [ %ind.end48, %vec.epilog.middle.block ]
  %16 = add i32 %.01929.ph, -1
  %xtraiter = and i32 %.01929.ph, 7
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol

.lr.ph.prol:                                      ; preds = %.lr.ph.preheader, %.lr.ph.prol
  %.031.prol = phi ptr [ %19, %.lr.ph.prol ], [ %.031.ph, %.lr.ph.preheader ]
  %.130.prol = phi ptr [ %18, %.lr.ph.prol ], [ %.130.ph, %.lr.ph.preheader ]
  %.01929.prol = phi i32 [ %20, %.lr.ph.prol ], [ %.01929.ph, %.lr.ph.preheader ]
  %prol.iter = phi i32 [ %prol.iter.next, %.lr.ph.prol ], [ 0, %.lr.ph.preheader ]
  %17 = load i8, ptr %.031.prol, align 1, !tbaa !5
  store i8 %17, ptr %.130.prol, align 1, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %.130.prol, i64 1
  %19 = getelementptr inbounds i8, ptr %.031.prol, i64 1
  %20 = add i32 %.01929.prol, -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 %.lr.ph.prol.loopexit, label %.lr.ph.prol, !llvm.loop !12

.lr.ph.prol.loopexit:                             ; preds = %.lr.ph.prol, %.lr.ph.preheader
  %.031.unr = phi ptr [ %.031.ph, %.lr.ph.preheader ], [ %19, %.lr.ph.prol ]
  %.130.unr = phi ptr [ %.130.ph, %.lr.ph.preheader ], [ %18, %.lr.ph.prol ]
  %.01929.unr = phi i32 [ %.01929.ph, %.lr.ph.preheader ], [ %20, %.lr.ph.prol ]
  %21 = icmp ult i32 %16, 7
  br i1 %21, label %.loopexit, label %.lr.ph

vec.epilog.ph:                                    ; preds = %vector.main.loop.iter.check, %vec.epilog.iter.check
  %vec.epilog.resume.val = phi i64 [ %n.vec, %vec.epilog.iter.check ], [ 0, %vector.main.loop.iter.check ]
  %n.vec43 = and i64 %11, 4294967288
  %ind.end = getelementptr i8, ptr %2, i64 %n.vec43
  %ind.end45 = getelementptr i8, ptr %0, i64 %n.vec43
  %.cast = trunc nuw i64 %n.vec43 to i32
  %ind.end48 = sub i32 %3, %.cast
  br label %vec.epilog.vector.body

vec.epilog.vector.body:                           ; preds = %vec.epilog.vector.body, %vec.epilog.ph
  %index52 = phi i64 [ %vec.epilog.resume.val, %vec.epilog.ph ], [ %index.next56, %vec.epilog.vector.body ]
  %next.gep53 = getelementptr i8, ptr %2, i64 %index52
  %next.gep54 = getelementptr i8, ptr %0, i64 %index52
  %wide.load55 = load <8 x i8>, ptr %next.gep53, align 1, !tbaa !5
  store <8 x i8> %wide.load55, ptr %next.gep54, align 1, !tbaa !5
  %index.next56 = add nuw i64 %index52, 8
  %22 = icmp eq i64 %index.next56, %n.vec43
  br i1 %22, label %vec.epilog.middle.block, label %vec.epilog.vector.body, !llvm.loop !14

vec.epilog.middle.block:                          ; preds = %vec.epilog.vector.body
  %cmp.n57 = icmp eq i64 %n.vec43, %11
  br i1 %cmp.n57, label %.loopexit, label %.lr.ph.preheader

.preheader:                                       ; preds = %9
  %.not2532 = icmp eq i32 %1, 0
  br i1 %.not2532, label %.loopexit, label %.lr.ph35.preheader

.lr.ph35.preheader:                               ; preds = %.preheader
  %23 = zext i32 %1 to i64
  tail call void @llvm.memset.p0.i64(ptr nonnull align 1 %0, i8 0, i64 %23, i1 false), !tbaa !5
  br label %.loopexit

.lr.ph:                                           ; preds = %.lr.ph.prol.loopexit, %.lr.ph
  %.031 = phi ptr [ %47, %.lr.ph ], [ %.031.unr, %.lr.ph.prol.loopexit ]
  %.130 = phi ptr [ %46, %.lr.ph ], [ %.130.unr, %.lr.ph.prol.loopexit ]
  %.01929 = phi i32 [ %48, %.lr.ph ], [ %.01929.unr, %.lr.ph.prol.loopexit ]
  %24 = load i8, ptr %.031, align 1, !tbaa !5
  store i8 %24, ptr %.130, align 1, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %.130, i64 1
  %26 = getelementptr inbounds i8, ptr %.031, i64 1
  %27 = load i8, ptr %26, align 1, !tbaa !5
  store i8 %27, ptr %25, align 1, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %.130, i64 2
  %29 = getelementptr inbounds i8, ptr %.031, i64 2
  %30 = load i8, ptr %29, align 1, !tbaa !5
  store i8 %30, ptr %28, align 1, !tbaa !5
  %31 = getelementptr inbounds i8, ptr %.130, i64 3
  %32 = getelementptr inbounds i8, ptr %.031, i64 3
  %33 = load i8, ptr %32, align 1, !tbaa !5
  store i8 %33, ptr %31, align 1, !tbaa !5
  %34 = getelementptr inbounds i8, ptr %.130, i64 4
  %35 = getelementptr inbounds i8, ptr %.031, i64 4
  %36 = load i8, ptr %35, align 1, !tbaa !5
  store i8 %36, ptr %34, align 1, !tbaa !5
  %37 = getelementptr inbounds i8, ptr %.130, i64 5
  %38 = getelementptr inbounds i8, ptr %.031, i64 5
  %39 = load i8, ptr %38, align 1, !tbaa !5
  store i8 %39, ptr %37, align 1, !tbaa !5
  %40 = getelementptr inbounds i8, ptr %.130, i64 6
  %41 = getelementptr inbounds i8, ptr %.031, i64 6
  %42 = load i8, ptr %41, align 1, !tbaa !5
  store i8 %42, ptr %40, align 1, !tbaa !5
  %43 = getelementptr inbounds i8, ptr %.130, i64 7
  %44 = getelementptr inbounds i8, ptr %.031, i64 7
  %45 = load i8, ptr %44, align 1, !tbaa !5
  store i8 %45, ptr %43, align 1, !tbaa !5
  %46 = getelementptr inbounds i8, ptr %.130, i64 8
  %47 = getelementptr inbounds i8, ptr %.031, i64 8
  %48 = add i32 %.01929, -8
  %.not.7 = icmp eq i32 %48, 0
  br i1 %.not.7, label %.loopexit, label %.lr.ph, !llvm.loop !15

.loopexit:                                        ; preds = %.lr.ph.prol.loopexit, %.lr.ph, %middle.block, %vec.epilog.middle.block, %.lr.ph35.preheader, %.preheader26, %.preheader, %4
  %.018 = phi i32 [ 1, %4 ], [ 1, %.preheader ], [ 0, %.preheader26 ], [ 1, %.lr.ph35.preheader ], [ 0, %vec.epilog.middle.block ], [ 0, %middle.block ], [ 0, %.lr.ph ], [ 0, %.lr.ph.prol.loopexit ]
  ret i32 %.018
}

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

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

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9, !10, !11}
!9 = !{!"llvm.loop.mustprogress"}
!10 = !{!"llvm.loop.isvectorized", i32 1}
!11 = !{!"llvm.loop.unroll.runtime.disable"}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.unroll.disable"}
!14 = distinct !{!14, !9, !10, !11}
!15 = distinct !{!15, !9, !10}


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