; LLVM IR from aap/librw :: src/base.ll (ZN2rw16memLittle32_funcEPvj)

; 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: mustprogress nounwind uwtable
define dso_local void @_ZN2rw16memLittle32_funcEPvj(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %8, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %9, ptr %7, align 8, !tbaa !5
  %10 = load i32, ptr %4, align 4, !tbaa !9
  %11 = lshr i32 %10, 2
  store i32 %11, ptr %4, align 4, !tbaa !9
  br label %12

12:                                               ; preds = %16, %2
  %13 = load i32, ptr %4, align 4, !tbaa !9
  %14 = add i32 %13, -1
  store i32 %14, ptr %4, align 4, !tbaa !9
  %15 = icmp ne i32 %13, 0
  br i1 %15, label %16, label %39

16:                                               ; preds = %12
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = getelementptr inbounds i32, ptr %17, i32 1
  store ptr %18, ptr %7, align 8, !tbaa !5
  %19 = load i32, ptr %17, align 4, !tbaa !9
  store i32 %19, ptr %5, align 4, !tbaa !9
  %20 = load i32, ptr %5, align 4, !tbaa !9
  %21 = trunc i32 %20 to i8
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %22, i32 1
  store ptr %23, ptr %6, align 8, !tbaa !5
  store i8 %21, ptr %22, align 1, !tbaa !11
  %24 = load i32, ptr %5, align 4, !tbaa !9
  %25 = lshr i32 %24, 8
  %26 = trunc i32 %25 to i8
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %27, i32 1
  store ptr %28, ptr %6, align 8, !tbaa !5
  store i8 %26, ptr %27, align 1, !tbaa !11
  %29 = load i32, ptr %5, align 4, !tbaa !9
  %30 = lshr i32 %29, 16
  %31 = trunc i32 %30 to i8
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = getelementptr inbounds i8, ptr %32, i32 1
  store ptr %33, ptr %6, align 8, !tbaa !5
  store i8 %31, ptr %32, align 1, !tbaa !11
  %34 = load i32, ptr %5, align 4, !tbaa !9
  %35 = lshr i32 %34, 24
  %36 = trunc i32 %35 to i8
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = getelementptr inbounds i8, ptr %37, i32 1
  store ptr %38, ptr %6, align 8, !tbaa !5
  store i8 %36, ptr %37, align 1, !tbaa !11
  br label %12, !llvm.loop !12

39:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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++ 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: mustprogress nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @_ZN2rw16memLittle32_funcEPvj(ptr nocapture noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %.not14 = icmp ult i32 %1, 4
  br i1 %.not14, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %2
  %3 = lshr i32 %1, 2
  %4 = and i32 %1, 4
  %lcmp.mod.not = icmp eq i32 %4, 0
  br i1 %lcmp.mod.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol

.lr.ph.prol:                                      ; preds = %.lr.ph.preheader
  %5 = add nsw i32 %3, -1
  %6 = getelementptr i8, ptr %0, i64 4
  %7 = load i32, ptr %0, align 4, !tbaa !5
  %8 = trunc i32 %7 to i8
  %9 = getelementptr inbounds i8, ptr %0, i64 1
  store i8 %8, ptr %0, align 1, !tbaa !9
  %10 = lshr i32 %7, 8
  %11 = trunc i32 %10 to i8
  %12 = getelementptr inbounds i8, ptr %0, i64 2
  store i8 %11, ptr %9, align 1, !tbaa !9
  %13 = lshr i32 %7, 16
  %14 = trunc i32 %13 to i8
  %15 = getelementptr inbounds i8, ptr %0, i64 3
  store i8 %14, ptr %12, align 1, !tbaa !9
  %16 = lshr i32 %7, 24
  %17 = trunc nuw i32 %16 to i8
  store i8 %17, ptr %15, align 1, !tbaa !9
  br label %.lr.ph.prol.loopexit

.lr.ph.prol.loopexit:                             ; preds = %.lr.ph.prol, %.lr.ph.preheader
  %.017.unr = phi ptr [ %0, %.lr.ph.preheader ], [ %6, %.lr.ph.prol ]
  %.01315.unr = phi i32 [ %3, %.lr.ph.preheader ], [ %5, %.lr.ph.prol ]
  %18 = icmp eq i32 %3, 1
  br i1 %18, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.prol.loopexit, %.lr.ph
  %.017 = phi ptr [ %32, %.lr.ph ], [ %.017.unr, %.lr.ph.prol.loopexit ]
  %.01315 = phi i32 [ %31, %.lr.ph ], [ %.01315.unr, %.lr.ph.prol.loopexit ]
  %19 = getelementptr i8, ptr %.017, i64 4
  %20 = load i32, ptr %.017, align 4, !tbaa !5
  %21 = trunc i32 %20 to i8
  %22 = getelementptr inbounds i8, ptr %.017, i64 1
  store i8 %21, ptr %.017, align 1, !tbaa !9
  %23 = lshr i32 %20, 8
  %24 = trunc i32 %23 to i8
  %25 = getelementptr inbounds i8, ptr %.017, i64 2
  store i8 %24, ptr %22, align 1, !tbaa !9
  %26 = lshr i32 %20, 16
  %27 = trunc i32 %26 to i8
  %28 = getelementptr inbounds i8, ptr %.017, i64 3
  store i8 %27, ptr %25, align 1, !tbaa !9
  %29 = lshr i32 %20, 24
  %30 = trunc nuw i32 %29 to i8
  store i8 %30, ptr %28, align 1, !tbaa !9
  %31 = add nsw i32 %.01315, -2
  %32 = getelementptr i8, ptr %.017, i64 8
  %33 = load i32, ptr %19, align 4, !tbaa !5
  %34 = trunc i32 %33 to i8
  %35 = getelementptr i8, ptr %.017, i64 5
  store i8 %34, ptr %19, align 1, !tbaa !9
  %36 = lshr i32 %33, 8
  %37 = trunc i32 %36 to i8
  %38 = getelementptr i8, ptr %.017, i64 6
  store i8 %37, ptr %35, align 1, !tbaa !9
  %39 = lshr i32 %33, 16
  %40 = trunc i32 %39 to i8
  %41 = getelementptr i8, ptr %.017, i64 7
  store i8 %40, ptr %38, align 1, !tbaa !9
  %42 = lshr i32 %33, 24
  %43 = trunc nuw i32 %42 to i8
  store i8 %43, ptr %41, align 1, !tbaa !9
  %.not.1 = icmp eq i32 %31, 0
  br i1 %.not.1, label %._crit_edge, label %.lr.ph, !llvm.loop !10

._crit_edge:                                      ; preds = %.lr.ph.prol.loopexit, %.lr.ph, %2
  ret void
}

attributes #0 = { mustprogress 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++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


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