; LLVM IR from ssvb/tinymembench :: util (aligned_block_copy_backwards_bs32)

; 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 void @aligned_block_copy_backwards_bs32(ptr noalias noundef %0, ptr noalias 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 i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, 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
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %12, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  %13 = load i32, ptr %6, align 4, !tbaa !9
  %14 = sdiv i32 %13, 8
  %15 = sub nsw i32 %14, 8
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = sext i32 %15 to i64
  %18 = getelementptr inbounds i64, ptr %16, i64 %17
  store ptr %18, ptr %5, align 8, !tbaa !5
  %19 = load i32, ptr %6, align 4, !tbaa !9
  %20 = sdiv i32 %19, 8
  %21 = sub nsw i32 %20, 8
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = sext i32 %21 to i64
  %24 = getelementptr inbounds i64, ptr %22, i64 %23
  store ptr %24, ptr %7, align 8, !tbaa !5
  br label %25

25:                                               ; preds = %29, %3
  %26 = load i32, ptr %6, align 4, !tbaa !9
  %27 = sub nsw i32 %26, 64
  store i32 %27, ptr %6, align 4, !tbaa !9
  %28 = icmp sge i32 %27, 0
  br i1 %28, label %29, label %82

29:                                               ; preds = %25
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = getelementptr inbounds i64, ptr %30, i64 4
  %32 = load i64, ptr %31, align 8, !tbaa !11
  store i64 %32, ptr %8, align 8, !tbaa !11
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds i64, ptr %33, i64 5
  %35 = load i64, ptr %34, align 8, !tbaa !11
  store i64 %35, ptr %9, align 8, !tbaa !11
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = getelementptr inbounds i64, ptr %36, i64 6
  %38 = load i64, ptr %37, align 8, !tbaa !11
  store i64 %38, ptr %10, align 8, !tbaa !11
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = getelementptr inbounds i64, ptr %39, i64 7
  %41 = load i64, ptr %40, align 8, !tbaa !11
  store i64 %41, ptr %11, align 8, !tbaa !11
  %42 = load i64, ptr %8, align 8, !tbaa !11
  %43 = load ptr, ptr %7, align 8, !tbaa !5
  %44 = getelementptr inbounds i64, ptr %43, i64 4
  store volatile i64 %42, ptr %44, align 8, !tbaa !11
  %45 = load i64, ptr %9, align 8, !tbaa !11
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = getelementptr inbounds i64, ptr %46, i64 5
  store volatile i64 %45, ptr %47, align 8, !tbaa !11
  %48 = load i64, ptr %10, align 8, !tbaa !11
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  %50 = getelementptr inbounds i64, ptr %49, i64 6
  store volatile i64 %48, ptr %50, align 8, !tbaa !11
  %51 = load i64, ptr %11, align 8, !tbaa !11
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  %53 = getelementptr inbounds i64, ptr %52, i64 7
  store volatile i64 %51, ptr %53, align 8, !tbaa !11
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = getelementptr inbounds i64, ptr %54, i64 0
  %56 = load i64, ptr %55, align 8, !tbaa !11
  store i64 %56, ptr %8, align 8, !tbaa !11
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  %58 = getelementptr inbounds i64, ptr %57, i64 1
  %59 = load i64, ptr %58, align 8, !tbaa !11
  store i64 %59, ptr %9, align 8, !tbaa !11
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = getelementptr inbounds i64, ptr %60, i64 2
  %62 = load i64, ptr %61, align 8, !tbaa !11
  store i64 %62, ptr %10, align 8, !tbaa !11
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = getelementptr inbounds i64, ptr %63, i64 3
  %65 = load i64, ptr %64, align 8, !tbaa !11
  store i64 %65, ptr %11, align 8, !tbaa !11
  %66 = load i64, ptr %8, align 8, !tbaa !11
  %67 = load ptr, ptr %7, align 8, !tbaa !5
  %68 = getelementptr inbounds i64, ptr %67, i64 0
  store volatile i64 %66, ptr %68, align 8, !tbaa !11
  %69 = load i64, ptr %9, align 8, !tbaa !11
  %70 = load ptr, ptr %7, align 8, !tbaa !5
  %71 = getelementptr inbounds i64, ptr %70, i64 1
  store volatile i64 %69, ptr %71, align 8, !tbaa !11
  %72 = load i64, ptr %10, align 8, !tbaa !11
  %73 = load ptr, ptr %7, align 8, !tbaa !5
  %74 = getelementptr inbounds i64, ptr %73, i64 2
  store volatile i64 %72, ptr %74, align 8, !tbaa !11
  %75 = load i64, ptr %11, align 8, !tbaa !11
  %76 = load ptr, ptr %7, align 8, !tbaa !5
  %77 = getelementptr inbounds i64, ptr %76, i64 3
  store volatile i64 %75, ptr %77, align 8, !tbaa !11
  %78 = load ptr, ptr %5, align 8, !tbaa !5
  %79 = getelementptr inbounds i64, ptr %78, i64 -8
  store ptr %79, ptr %5, align 8, !tbaa !5
  %80 = load ptr, ptr %7, align 8, !tbaa !5
  %81 = getelementptr inbounds i64, ptr %80, i64 -8
  store ptr %81, ptr %7, align 8, !tbaa !5
  br label %25, !llvm.loop !13

82:                                               ; preds = %25
  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 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  ret void
}

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 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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 nounwind uwtable
define dso_local void @aligned_block_copy_backwards_bs32(ptr noalias noundef %0, ptr noalias nocapture noundef readonly %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = icmp sgt i32 %2, 63
  br i1 %4, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %3
  %5 = lshr i32 %2, 3
  %6 = add nsw i32 %5, -8
  %7 = zext nneg i32 %6 to i64
  %8 = getelementptr inbounds i64, ptr %0, i64 %7
  %9 = getelementptr inbounds i64, ptr %1, i64 %7
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %.036 = phi ptr [ %33, %.lr.ph ], [ %9, %.lr.ph.preheader ]
  %.03135 = phi i32 [ %10, %.lr.ph ], [ %2, %.lr.ph.preheader ]
  %.03234 = phi ptr [ %34, %.lr.ph ], [ %8, %.lr.ph.preheader ]
  %10 = add nsw i32 %.03135, -64
  %11 = getelementptr inbounds i8, ptr %.036, i64 32
  %12 = load i64, ptr %11, align 8, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %.036, i64 40
  %14 = load i64, ptr %13, align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %.036, i64 48
  %16 = load i64, ptr %15, align 8, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %.036, i64 56
  %18 = load i64, ptr %17, align 8, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %.03234, i64 32
  store volatile i64 %12, ptr %19, align 8, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %.03234, i64 40
  store volatile i64 %14, ptr %20, align 8, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %.03234, i64 48
  store volatile i64 %16, ptr %21, align 8, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %.03234, i64 56
  store volatile i64 %18, ptr %22, align 8, !tbaa !5
  %23 = load i64, ptr %.036, align 8, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %.036, i64 8
  %25 = load i64, ptr %24, align 8, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %.036, i64 16
  %27 = load i64, ptr %26, align 8, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %.036, i64 24
  %29 = load i64, ptr %28, align 8, !tbaa !5
  store volatile i64 %23, ptr %.03234, align 8, !tbaa !5
  %30 = getelementptr inbounds i8, ptr %.03234, i64 8
  store volatile i64 %25, ptr %30, align 8, !tbaa !5
  %31 = getelementptr inbounds i8, ptr %.03234, i64 16
  store volatile i64 %27, ptr %31, align 8, !tbaa !5
  %32 = getelementptr inbounds i8, ptr %.03234, i64 24
  store volatile i64 %29, ptr %32, align 8, !tbaa !5
  %33 = getelementptr inbounds i8, ptr %.036, i64 -64
  %34 = getelementptr inbounds i8, ptr %.03234, i64 -64
  %35 = icmp ugt i32 %.03135, 127
  br i1 %35, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %3
  ret void
}

attributes #0 = { nofree norecurse 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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