; LLVM IR from JessonYue/LeetCodeLearning :: Array/zhuqiguang/c (StringU)

; 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 @my_memcpy(ptr noundef %0, ptr noundef %1, i32 noundef %2) #1 {
  %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
  %11 = load ptr, ptr %7, align 8, !tbaa !5
  %12 = load ptr, ptr %8, align 8, !tbaa !5
  %13 = load i32, ptr %6, align 4, !tbaa !9
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds i8, ptr %12, i64 %14
  %16 = icmp ult ptr %11, %15
  br i1 %16, label %17, label %42

17:                                               ; preds = %3
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = load ptr, ptr %8, align 8, !tbaa !5
  %20 = icmp ult ptr %18, %19
  br i1 %20, label %21, label %42

21:                                               ; preds = %17
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = load i32, ptr %6, align 4, !tbaa !9
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds i8, ptr %22, i64 %24
  store ptr %25, ptr %7, align 8, !tbaa !5
  %26 = load ptr, ptr %8, align 8, !tbaa !5
  %27 = load i32, ptr %6, align 4, !tbaa !9
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds i8, ptr %26, i64 %28
  store ptr %29, ptr %8, align 8, !tbaa !5
  br label %30

30:                                               ; preds = %33, %21
  %31 = load i32, ptr %6, align 4, !tbaa !9
  %32 = icmp sgt i32 %31, 0
  br i1 %32, label %33, label %41

33:                                               ; preds = %30
  %34 = load ptr, ptr %8, align 8, !tbaa !5
  %35 = getelementptr inbounds i8, ptr %34, i32 -1
  store ptr %35, ptr %8, align 8, !tbaa !5
  %36 = load i8, ptr %34, align 1, !tbaa !11
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = getelementptr inbounds i8, ptr %37, i32 -1
  store ptr %38, ptr %7, align 8, !tbaa !5
  store i8 %36, ptr %37, align 1, !tbaa !11
  %39 = load i32, ptr %6, align 4, !tbaa !9
  %40 = add nsw i32 %39, -1
  store i32 %40, ptr %6, align 4, !tbaa !9
  br label %30, !llvm.loop !12

41:                                               ; preds = %30
  br label %55

42:                                               ; preds = %17, %3
  br label %43

43:                                               ; preds = %46, %42
  %44 = load i32, ptr %6, align 4, !tbaa !9
  %45 = icmp sgt i32 %44, 0
  br i1 %45, label %46, label %54

46:                                               ; preds = %43
  %47 = load ptr, ptr %8, align 8, !tbaa !5
  %48 = getelementptr inbounds i8, ptr %47, i32 1
  store ptr %48, ptr %8, align 8, !tbaa !5
  %49 = load i8, ptr %47, align 1, !tbaa !11
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  %51 = getelementptr inbounds i8, ptr %50, i32 1
  store ptr %51, ptr %7, align 8, !tbaa !5
  store i8 %49, ptr %50, align 1, !tbaa !11
  %52 = load i32, ptr %6, align 4, !tbaa !9
  %53 = add nsw i32 %52, -1
  store i32 %53, ptr %6, align 4, !tbaa !9
  br label %43, !llvm.loop !14

54:                                               ; preds = %43
  br label %55

55:                                               ; preds = %54, %41
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  ret ptr %56
}

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 noundef ptr @my_memcpy(ptr noundef returned writeonly %0, ptr noundef readonly %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = ptrtoint ptr %0 to i64
  %5 = ptrtoint ptr %1 to i64
  %6 = ptrtoint ptr %0 to i64
  %7 = sext i32 %2 to i64
  %8 = getelementptr inbounds i8, ptr %1, i64 %7
  %9 = icmp ugt ptr %8, %0
  %10 = icmp ult ptr %0, %1
  %or.cond = and i1 %10, %9
  %11 = icmp sgt i32 %2, 0
  br i1 %or.cond, label %18, label %.preheader

.preheader:                                       ; preds = %3
  br i1 %11, label %iter.check, label %.loopexit

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

vector.main.loop.iter.check:                      ; preds = %iter.check
  %min.iters.check37 = icmp ult i32 %2, 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 %12, 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 %1, i64 %index
  %next.gep39 = getelementptr i8, ptr %0, i64 %index
  %14 = 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 %14, align 1, !tbaa !5
  %15 = 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 %15, align 1, !tbaa !5
  %index.next = add nuw i64 %index, 32
  %16 = icmp eq i64 %index.next, %n.vec
  br i1 %16, label %middle.block, label %vector.body, !llvm.loop !8

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

vec.epilog.iter.check:                            ; preds = %middle.block
  %.cast49 = trunc nuw nsw i64 %n.vec to i32
  %ind.end50 = sub nsw i32 %2, %.cast49
  %ind.end46 = getelementptr i8, ptr %0, i64 %n.vec
  %ind.end44 = getelementptr i8, ptr %1, i64 %n.vec
  %n.vec.remaining = and i64 %12, 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
  %.128.ph = phi ptr [ %1, %iter.check ], [ %ind.end44, %vec.epilog.iter.check ], [ %ind.end, %vec.epilog.middle.block ]
  %.12027.ph = phi ptr [ %0, %iter.check ], [ %ind.end46, %vec.epilog.iter.check ], [ %ind.end45, %vec.epilog.middle.block ]
  %.12226.ph = phi i32 [ %2, %iter.check ], [ %ind.end50, %vec.epilog.iter.check ], [ %ind.end48, %vec.epilog.middle.block ]
  br 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 %12, 2147483640
  %ind.end = getelementptr i8, ptr %1, i64 %n.vec43
  %ind.end45 = getelementptr i8, ptr %0, i64 %n.vec43
  %.cast = trunc nuw nsw i64 %n.vec43 to i32
  %ind.end48 = sub nsw i32 %2, %.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 %1, 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
  %17 = icmp eq i64 %index.next56, %n.vec43
  br i1 %17, label %vec.epilog.middle.block, label %vec.epilog.vector.body, !llvm.loop !12

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

18:                                               ; preds = %3
  br i1 %11, label %iter.check63, label %.loopexit

iter.check63:                                     ; preds = %18
  %19 = getelementptr inbounds i8, ptr %0, i64 %7
  %20 = zext nneg i32 %2 to i64
  %min.iters.check61 = icmp ult i32 %2, 4
  %21 = sub i64 %5, %4
  %diff.check59 = icmp ult i64 %21, 16
  %or.cond110 = or i1 %min.iters.check61, %diff.check59
  br i1 %or.cond110, label %.lr.ph32.preheader, label %vector.main.loop.iter.check65

vector.main.loop.iter.check65:                    ; preds = %iter.check63
  %min.iters.check64 = icmp ult i32 %2, 16
  br i1 %min.iters.check64, label %vec.epilog.ph80, label %vector.ph66

vector.ph66:                                      ; preds = %vector.main.loop.iter.check65
  %n.vec68 = and i64 %20, 2147483632
  %invariant.gep = getelementptr i8, ptr %8, i64 -15
  %invariant.gep112 = getelementptr i8, ptr %19, i64 -15
  br label %vector.body69

vector.body69:                                    ; preds = %vector.body69, %vector.ph66
  %index70 = phi i64 [ 0, %vector.ph66 ], [ %index.next76, %vector.body69 ]
  %offset.idx = sub i64 0, %index70
  %offset.idx72 = sub i64 0, %index70
  %gep = getelementptr i8, ptr %invariant.gep, i64 %offset.idx
  %wide.load74 = load <16 x i8>, ptr %gep, align 1, !tbaa !5
  %gep113 = getelementptr i8, ptr %invariant.gep112, i64 %offset.idx72
  store <16 x i8> %wide.load74, ptr %gep113, align 1, !tbaa !5
  %index.next76 = add nuw i64 %index70, 16
  %22 = icmp eq i64 %index.next76, %n.vec68
  br i1 %22, label %middle.block60, label %vector.body69, !llvm.loop !13

middle.block60:                                   ; preds = %vector.body69
  %cmp.n77 = icmp eq i64 %n.vec68, %20
  br i1 %cmp.n77, label %.loopexit, label %vec.epilog.iter.check81

vec.epilog.iter.check81:                          ; preds = %middle.block60
  %.cast95 = trunc nuw nsw i64 %n.vec68 to i32
  %ind.end96 = sub nsw i32 %2, %.cast95
  %23 = sub nsw i64 0, %n.vec68
  %ind.end91 = getelementptr i8, ptr %19, i64 %23
  %24 = sub nsw i64 0, %n.vec68
  %ind.end88 = getelementptr i8, ptr %8, i64 %24
  %n.vec.remaining82 = and i64 %20, 12
  %min.epilog.iters.check83 = icmp eq i64 %n.vec.remaining82, 0
  br i1 %min.epilog.iters.check83, label %.lr.ph32.preheader, label %vec.epilog.ph80

vec.epilog.ph80:                                  ; preds = %vector.main.loop.iter.check65, %vec.epilog.iter.check81
  %vec.epilog.resume.val84 = phi i64 [ %n.vec68, %vec.epilog.iter.check81 ], [ 0, %vector.main.loop.iter.check65 ]
  %n.vec86 = and i64 %20, 2147483644
  %25 = sub nsw i64 0, %n.vec86
  %ind.end87 = getelementptr i8, ptr %8, i64 %25
  %26 = sub nsw i64 0, %n.vec86
  %ind.end90 = getelementptr i8, ptr %19, i64 %26
  %.cast93 = trunc nuw nsw i64 %n.vec86 to i32
  %ind.end94 = sub nsw i32 %2, %.cast93
  %invariant.gep114 = getelementptr i8, ptr %8, i64 -3
  %invariant.gep116 = getelementptr i8, ptr %19, i64 -3
  br label %vec.epilog.vector.body98

vec.epilog.vector.body98:                         ; preds = %vec.epilog.vector.body98, %vec.epilog.ph80
  %index99 = phi i64 [ %vec.epilog.resume.val84, %vec.epilog.ph80 ], [ %index.next107, %vec.epilog.vector.body98 ]
  %offset.idx100 = sub i64 0, %index99
  %offset.idx102 = sub i64 0, %index99
  %gep115 = getelementptr i8, ptr %invariant.gep114, i64 %offset.idx100
  %wide.load104 = load <4 x i8>, ptr %gep115, align 1, !tbaa !5
  %gep117 = getelementptr i8, ptr %invariant.gep116, i64 %offset.idx102
  store <4 x i8> %wide.load104, ptr %gep117, align 1, !tbaa !5
  %index.next107 = add nuw i64 %index99, 4
  %27 = icmp eq i64 %index.next107, %n.vec86
  br i1 %27, label %vec.epilog.middle.block78, label %vec.epilog.vector.body98, !llvm.loop !14

vec.epilog.middle.block78:                        ; preds = %vec.epilog.vector.body98
  %cmp.n108 = icmp eq i64 %n.vec86, %20
  br i1 %cmp.n108, label %.loopexit, label %.lr.ph32.preheader

.lr.ph32.preheader:                               ; preds = %vec.epilog.middle.block78, %iter.check63, %vec.epilog.iter.check81
  %.031.ph = phi ptr [ %8, %iter.check63 ], [ %ind.end88, %vec.epilog.iter.check81 ], [ %ind.end87, %vec.epilog.middle.block78 ]
  %.01930.ph = phi ptr [ %19, %iter.check63 ], [ %ind.end91, %vec.epilog.iter.check81 ], [ %ind.end90, %vec.epilog.middle.block78 ]
  %.02129.ph = phi i32 [ %2, %iter.check63 ], [ %ind.end96, %vec.epilog.iter.check81 ], [ %ind.end94, %vec.epilog.middle.block78 ]
  br label %.lr.ph32

.lr.ph32:                                         ; preds = %.lr.ph32.preheader, %.lr.ph32
  %.031 = phi ptr [ %28, %.lr.ph32 ], [ %.031.ph, %.lr.ph32.preheader ]
  %.01930 = phi ptr [ %30, %.lr.ph32 ], [ %.01930.ph, %.lr.ph32.preheader ]
  %.02129 = phi i32 [ %31, %.lr.ph32 ], [ %.02129.ph, %.lr.ph32.preheader ]
  %28 = getelementptr inbounds i8, ptr %.031, i64 -1
  %29 = load i8, ptr %.031, align 1, !tbaa !5
  %30 = getelementptr inbounds i8, ptr %.01930, i64 -1
  store i8 %29, ptr %.01930, align 1, !tbaa !5
  %31 = add nsw i32 %.02129, -1
  %32 = icmp ugt i32 %.02129, 1
  br i1 %32, label %.lr.ph32, label %.loopexit, !llvm.loop !15

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %.128 = phi ptr [ %33, %.lr.ph ], [ %.128.ph, %.lr.ph.preheader ]
  %.12027 = phi ptr [ %35, %.lr.ph ], [ %.12027.ph, %.lr.ph.preheader ]
  %.12226 = phi i32 [ %36, %.lr.ph ], [ %.12226.ph, %.lr.ph.preheader ]
  %33 = getelementptr inbounds i8, ptr %.128, i64 1
  %34 = load i8, ptr %.128, align 1, !tbaa !5
  %35 = getelementptr inbounds i8, ptr %.12027, i64 1
  store i8 %34, ptr %.12027, align 1, !tbaa !5
  %36 = add nsw i32 %.12226, -1
  %37 = icmp ugt i32 %.12226, 1
  br i1 %37, label %.lr.ph, label %.loopexit, !llvm.loop !16

.loopexit:                                        ; preds = %.lr.ph, %.lr.ph32, %middle.block, %vec.epilog.middle.block, %middle.block60, %vec.epilog.middle.block78, %.preheader, %18
  ret ptr %0
}

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, !11}
!14 = distinct !{!14, !9, !10, !11}
!15 = distinct !{!15, !9, !10}
!16 = distinct !{!16, !9, !10}


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