; LLVM IR from aap/librw :: src/base.ll (ZN2rw16memLittle16_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 @_ZN2rw16memLittle16_funcEPvj(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i16, align 2
  %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 2, 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, 1
  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 %30

16:                                               ; preds = %12
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = getelementptr inbounds i16, ptr %17, i32 1
  store ptr %18, ptr %7, align 8, !tbaa !5
  %19 = load i16, ptr %17, align 2, !tbaa !11
  store i16 %19, ptr %5, align 2, !tbaa !11
  %20 = load i16, ptr %5, align 2, !tbaa !11
  %21 = trunc i16 %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 !13
  %24 = load i16, ptr %5, align 2, !tbaa !11
  %25 = zext i16 %24 to i32
  %26 = ashr i32 %25, 8
  %27 = trunc i32 %26 to i8
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %28, i32 1
  store ptr %29, ptr %6, align 8, !tbaa !5
  store i8 %27, ptr %28, align 1, !tbaa !13
  br label %12, !llvm.loop !14

30:                                               ; 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 2, 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 = !{!12, !12, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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 @_ZN2rw16memLittle16_funcEPvj(ptr nocapture noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %.not10 = icmp ult i32 %1, 2
  br i1 %.not10, label %._crit_edge, label %.lr.ph.preheader

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

.lr.ph.prol:                                      ; preds = %.lr.ph.preheader, %.lr.ph.prol
  %.013.prol = phi ptr [ %6, %.lr.ph.prol ], [ %0, %.lr.ph.preheader ]
  %.0911.prol = phi i32 [ %5, %.lr.ph.prol ], [ %3, %.lr.ph.preheader ]
  %prol.iter = phi i32 [ %prol.iter.next, %.lr.ph.prol ], [ 0, %.lr.ph.preheader ]
  %5 = add nsw i32 %.0911.prol, -1
  %6 = getelementptr i8, ptr %.013.prol, i64 2
  %7 = load i16, ptr %.013.prol, align 2, !tbaa !5
  %8 = trunc i16 %7 to i8
  %9 = getelementptr inbounds i8, ptr %.013.prol, i64 1
  store i8 %8, ptr %.013.prol, align 1, !tbaa !9
  %10 = lshr i16 %7, 8
  %11 = trunc nuw i16 %10 to i8
  store i8 %11, ptr %9, align 1, !tbaa !9
  %prol.iter.next = add i32 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i32 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol, !llvm.loop !10

.lr.ph.prol.loopexit:                             ; preds = %.lr.ph.prol, %.lr.ph.preheader
  %.013.unr = phi ptr [ %0, %.lr.ph.preheader ], [ %6, %.lr.ph.prol ]
  %.0911.unr = phi i32 [ %3, %.lr.ph.preheader ], [ %5, %.lr.ph.prol ]
  %12 = icmp ult i32 %4, 3
  br i1 %12, label %._crit_edge, label %.lr.ph

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

._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 = !{!"short", !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.unroll.disable"}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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