; LLVM IR from JessonYue/LeetCodeLearning :: Array/linchuanxin/homework/homework_0714_0718 (homework5_str)

; 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 ptr @mine_memcpy(ptr noundef %0, ptr noundef %1, i32 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = icmp eq ptr %10, null
  br i1 %11, label %15, label %12

12:                                               ; preds = %3
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = icmp eq ptr %13, null
  br i1 %14, label %15, label %16

15:                                               ; preds = %12, %3
  store ptr null, ptr %4, align 8
  br label %31

16:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %17, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %18, ptr %9, align 8, !tbaa !5
  br label %19

19:                                               ; preds = %23, %16
  %20 = load i32, ptr %7, align 4, !tbaa !9
  %21 = add nsw i32 %20, -1
  store i32 %21, ptr %7, align 4, !tbaa !9
  %22 = icmp sgt i32 %20, 0
  br i1 %22, label %23, label %29

23:                                               ; preds = %19
  %24 = load ptr, ptr %8, align 8, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %24, i32 1
  store ptr %25, ptr %8, align 8, !tbaa !5
  %26 = load i8, ptr %24, align 1, !tbaa !11
  %27 = load ptr, ptr %9, align 8, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %27, i32 1
  store ptr %28, ptr %9, align 8, !tbaa !5
  store i8 %26, ptr %27, align 1, !tbaa !11
  br label %19, !llvm.loop !12

29:                                               ; preds = %19
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %30, ptr %4, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  br label %31

31:                                               ; preds = %29, %15
  %32 = load ptr, ptr %4, align 8
  ret ptr %32
}

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


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

.preheader:                                       ; preds = %3
  %8 = icmp sgt i32 %2, 0
  br i1 %8, label %iter.check, label %.loopexit

iter.check:                                       ; preds = %.preheader
  %9 = zext nneg i32 %2 to i64
  %min.iters.check = icmp ult i32 %2, 8
  %10 = sub i64 %5, %4
  %diff.check = icmp ult i64 %10, 32
  %or.cond38 = or i1 %min.iters.check, %diff.check
  br i1 %or.cond38, label %.lr.ph.preheader, label %vector.main.loop.iter.check

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

vector.ph:                                        ; preds = %vector.main.loop.iter.check
  %n.vec = and i64 %9, 2147483616
  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 %0, i64 %index
  %next.gep19 = getelementptr i8, ptr %1, i64 %index
  %11 = getelementptr i8, ptr %next.gep19, i64 16
  %wide.load = load <16 x i8>, ptr %next.gep19, align 1, !tbaa !5
  %wide.load21 = load <16 x i8>, ptr %11, align 1, !tbaa !5
  %12 = getelementptr i8, ptr %next.gep, i64 16
  store <16 x i8> %wide.load, ptr %next.gep, align 1, !tbaa !5
  store <16 x i8> %wide.load21, ptr %12, align 1, !tbaa !5
  %index.next = add nuw i64 %index, 32
  %13 = icmp eq i64 %index.next, %n.vec
  br i1 %13, label %middle.block, label %vector.body, !llvm.loop !8

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

vec.epilog.iter.check:                            ; preds = %middle.block
  %.cast29 = trunc nuw nsw i64 %n.vec to i32
  %ind.end30 = sub nsw i32 %2, %.cast29
  %ind.end26 = getelementptr i8, ptr %1, i64 %n.vec
  %ind.end24 = getelementptr i8, ptr %0, i64 %n.vec
  %n.vec.remaining = and i64 %9, 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

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.vec23 = and i64 %9, 2147483640
  %ind.end = getelementptr i8, ptr %0, i64 %n.vec23
  %ind.end25 = getelementptr i8, ptr %1, i64 %n.vec23
  %.cast = trunc nuw nsw i64 %n.vec23 to i32
  %ind.end28 = sub nsw i32 %2, %.cast
  br label %vec.epilog.vector.body

vec.epilog.vector.body:                           ; preds = %vec.epilog.vector.body, %vec.epilog.ph
  %index32 = phi i64 [ %vec.epilog.resume.val, %vec.epilog.ph ], [ %index.next36, %vec.epilog.vector.body ]
  %next.gep33 = getelementptr i8, ptr %0, i64 %index32
  %next.gep34 = getelementptr i8, ptr %1, i64 %index32
  %wide.load35 = load <8 x i8>, ptr %next.gep34, align 1, !tbaa !5
  store <8 x i8> %wide.load35, ptr %next.gep33, align 1, !tbaa !5
  %index.next36 = add nuw i64 %index32, 8
  %14 = icmp eq i64 %index.next36, %n.vec23
  br i1 %14, label %vec.epilog.middle.block, label %vec.epilog.vector.body, !llvm.loop !12

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

.lr.ph.preheader:                                 ; preds = %vec.epilog.middle.block, %iter.check, %vec.epilog.iter.check
  %.016.ph = phi ptr [ %0, %iter.check ], [ %ind.end24, %vec.epilog.iter.check ], [ %ind.end, %vec.epilog.middle.block ]
  %.0915.ph = phi ptr [ %1, %iter.check ], [ %ind.end26, %vec.epilog.iter.check ], [ %ind.end25, %vec.epilog.middle.block ]
  %.01014.ph = phi i32 [ %2, %iter.check ], [ %ind.end30, %vec.epilog.iter.check ], [ %ind.end28, %vec.epilog.middle.block ]
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %.016 = phi ptr [ %18, %.lr.ph ], [ %.016.ph, %.lr.ph.preheader ]
  %.0915 = phi ptr [ %16, %.lr.ph ], [ %.0915.ph, %.lr.ph.preheader ]
  %.01014 = phi i32 [ %15, %.lr.ph ], [ %.01014.ph, %.lr.ph.preheader ]
  %15 = add nsw i32 %.01014, -1
  %16 = getelementptr inbounds i8, ptr %.0915, i64 1
  %17 = load i8, ptr %.0915, align 1, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %.016, i64 1
  store i8 %17, ptr %.016, align 1, !tbaa !5
  %19 = icmp ugt i32 %.01014, 1
  br i1 %19, label %.lr.ph, label %.loopexit, !llvm.loop !13

.loopexit:                                        ; preds = %.lr.ph, %middle.block, %vec.epilog.middle.block, %.preheader, %3
  %.011 = phi ptr [ null, %3 ], [ %0, %.preheader ], [ %0, %vec.epilog.middle.block ], [ %0, %middle.block ], [ %0, %.lr.ph ]
  ret ptr %.011
}

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 = !{!"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, !9, !10, !11}
!13 = distinct !{!13, !9, !10}


; Effective O3 passes: CorrelatedValuePropagationPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass