; LLVM IR from clibraries/array-algorithms :: test (impl)

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

11:                                               ; preds = %3
  %12 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %12, ptr %4, align 8
  br label %28

13:                                               ; preds = %3
  br label %14

14:                                               ; preds = %22, %13
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = getelementptr inbounds i32, ptr %15, i32 -1
  store ptr %16, ptr %6, align 8, !tbaa !5
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = load i32, ptr %17, align 4, !tbaa !9
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 %18, ptr %19, align 4, !tbaa !9
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = getelementptr inbounds i32, ptr %20, i32 1
  store ptr %21, ptr %7, align 8, !tbaa !5
  br label %22

22:                                               ; preds = %14
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = icmp ne ptr %23, %24
  br i1 %25, label %14, label %26, !llvm.loop !11

26:                                               ; preds = %22
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %27, ptr %4, align 8
  br label %28

28:                                               ; preds = %26, %11
  %29 = load ptr, ptr %4, align 8
  ret ptr %29
}

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

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


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

.preheader.preheader:                             ; preds = %3
  %7 = ptrtoint ptr %1 to i64
  %8 = ptrtoint ptr %0 to i64
  %9 = add i64 %7, -4
  %10 = sub i64 %9, %8
  %11 = lshr i64 %10, 2
  %12 = add nuw nsw i64 %11, 1
  %min.iters.check = icmp ult i64 %10, 124
  br i1 %min.iters.check, label %.preheader.preheader23, label %vector.memcheck

vector.memcheck:                                  ; preds = %.preheader.preheader
  %13 = add i64 %5, -4
  %14 = sub i64 %13, %4
  %15 = and i64 %14, -4
  %16 = getelementptr i8, ptr %2, i64 %15
  %scevgep = getelementptr i8, ptr %16, i64 4
  %17 = sub nuw nsw i64 -4, %15
  %scevgep14 = getelementptr i8, ptr %1, i64 %17
  %bound0 = icmp ult ptr %2, %1
  %bound1 = icmp ult ptr %scevgep14, %scevgep
  %found.conflict = and i1 %bound0, %bound1
  br i1 %found.conflict, label %.preheader.preheader23, label %vector.ph

vector.ph:                                        ; preds = %vector.memcheck
  %n.vec = and i64 %12, 9223372036854775800
  %18 = mul i64 %n.vec, -4
  %ind.end = getelementptr i8, ptr %1, i64 %18
  %19 = shl i64 %n.vec, 2
  %ind.end15 = getelementptr i8, ptr %2, i64 %19
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %offset.idx = mul i64 %index, -4
  %next.gep = getelementptr i8, ptr %1, i64 %offset.idx
  %offset.idx18 = shl i64 %index, 2
  %next.gep19 = getelementptr i8, ptr %2, i64 %offset.idx18
  %20 = getelementptr inbounds i8, ptr %next.gep, i64 -16
  %21 = getelementptr inbounds i8, ptr %next.gep, i64 -32
  %wide.load = load <4 x i32>, ptr %20, align 4, !tbaa !5, !alias.scope !9
  %reverse = shufflevector <4 x i32> %wide.load, <4 x i32> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
  %wide.load21 = load <4 x i32>, ptr %21, align 4, !tbaa !5, !alias.scope !9
  %reverse22 = shufflevector <4 x i32> %wide.load21, <4 x i32> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
  %22 = getelementptr i8, ptr %next.gep19, i64 16
  store <4 x i32> %reverse, ptr %next.gep19, align 4, !tbaa !5, !alias.scope !12, !noalias !9
  store <4 x i32> %reverse22, ptr %22, align 4, !tbaa !5, !alias.scope !12, !noalias !9
  %index.next = add nuw i64 %index, 8
  %23 = icmp eq i64 %index.next, %n.vec
  br i1 %23, label %middle.block, label %vector.body, !llvm.loop !14

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

.preheader.preheader23:                           ; preds = %middle.block, %vector.memcheck, %.preheader.preheader
  %.011.ph = phi ptr [ %1, %vector.memcheck ], [ %1, %.preheader.preheader ], [ %ind.end, %middle.block ]
  %.0.ph = phi ptr [ %2, %vector.memcheck ], [ %2, %.preheader.preheader ], [ %ind.end15, %middle.block ]
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader23, %.preheader
  %.011 = phi ptr [ %24, %.preheader ], [ %.011.ph, %.preheader.preheader23 ]
  %.0 = phi ptr [ %26, %.preheader ], [ %.0.ph, %.preheader.preheader23 ]
  %24 = getelementptr inbounds i8, ptr %.011, i64 -4
  %25 = load i32, ptr %24, align 4, !tbaa !5
  store i32 %25, ptr %.0, align 4, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %.0, i64 4
  %.not = icmp eq ptr %24, %0
  br i1 %.not, label %.loopexit, label %.preheader, !llvm.loop !18

.loopexit:                                        ; preds = %.preheader, %middle.block, %3
  %.012 = phi ptr [ %2, %3 ], [ %ind.end15, %middle.block ], [ %26, %.preheader ]
  ret ptr %.012
}

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 = !{!10}
!10 = distinct !{!10, !11}
!11 = distinct !{!11, !"LVerDomain"}
!12 = !{!13}
!13 = distinct !{!13, !11}
!14 = distinct !{!14, !15, !16, !17}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!"llvm.loop.isvectorized", i32 1}
!17 = !{!"llvm.loop.unroll.runtime.disable"}
!18 = distinct !{!18, !15, !16}


; Effective O3 passes: GVNPass,GlobalOptPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopLoadEliminationPass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass