; LLVM IR from ARM-software/Arm-2D :: Acceleration/Arm/ACI/arm_2d_rgb565_aci_fvp_plugin (arm_2d_rgb565_aci_fvp)

; 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 @_Z29arm_mix_unpack_green_uint16x2PtPKtb(ptr noundef %0, ptr noundef %1, i1 noundef zeroext %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i8, align 1
  %7 = alloca i32, align 4
  %8 = alloca i16, align 2
  %9 = alloca i8, align 1
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %10 = zext i1 %2 to i8
  store i8 %10, ptr %6, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 2, ptr %8) #2
  store i16 63, ptr %8, align 2, !tbaa !11
  store i32 2, ptr %7, align 4, !tbaa !13
  br label %11

11:                                               ; preds = %41, %3
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #2
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = getelementptr inbounds i16, ptr %12, i32 1
  store ptr %13, ptr %5, align 8, !tbaa !5
  %14 = load i16, ptr %12, align 2, !tbaa !11
  %15 = zext i16 %14 to i32
  %16 = ashr i32 %15, 5
  %17 = load i16, ptr %8, align 2, !tbaa !11
  %18 = zext i16 %17 to i32
  %19 = and i32 %16, %18
  %20 = trunc i32 %19 to i8
  store i8 %20, ptr %9, align 1, !tbaa !15
  %21 = load i8, ptr %9, align 1, !tbaa !15
  %22 = zext i8 %21 to i32
  %23 = shl i32 %22, 2
  %24 = trunc i32 %23 to i8
  store i8 %24, ptr %9, align 1, !tbaa !15
  %25 = load i8, ptr %6, align 1, !tbaa !9, !range !16, !noundef !17
  %26 = trunc i8 %25 to i1
  br i1 %26, label %27, label %30

27:                                               ; preds = %11
  %28 = load i8, ptr %9, align 1, !tbaa !15
  %29 = zext i8 %28 to i32
  br label %34

30:                                               ; preds = %11
  %31 = load i8, ptr %9, align 1, !tbaa !15
  %32 = zext i8 %31 to i32
  %33 = shl i32 %32, 8
  br label %34

34:                                               ; preds = %30, %27
  %35 = phi i32 [ %29, %27 ], [ %33, %30 ]
  %36 = trunc i32 %35 to i16
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds i16, ptr %37, i32 1
  store ptr %38, ptr %4, align 8, !tbaa !5
  store i16 %36, ptr %37, align 2, !tbaa !11
  %39 = load i32, ptr %7, align 4, !tbaa !13
  %40 = sub nsw i32 %39, 1
  store i32 %40, ptr %7, align 4, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #2
  br label %41

41:                                               ; preds = %34
  %42 = load i32, ptr %7, align 4, !tbaa !13
  %43 = icmp sgt i32 %42, 0
  br i1 %43, label %11, label %44, !llvm.loop !18

44:                                               ; preds = %41
  call void @llvm.lifetime.end.p0(i64 2, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #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 = !{!"bool", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!7, !7, i64 0}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = distinct !{!18, !19}
!19 = !{!"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 willreturn memory(argmem: readwrite) uwtable
define dso_local void @_Z29arm_mix_unpack_green_uint16x2PtPKtb(ptr nocapture noundef writeonly %0, ptr nocapture noundef readonly %1, i1 noundef zeroext %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %1, i64 2
  %5 = load i16, ptr %1, align 2, !tbaa !5
  br i1 %2, label %.split.us.preheader, label %.split.preheader

.split.preheader:                                 ; preds = %3
  %6 = shl i16 %5, 5
  %7 = and i16 %6, -1024
  store i16 %7, ptr %0, align 2, !tbaa !5
  %8 = load i16, ptr %4, align 2, !tbaa !5
  %9 = shl i16 %8, 5
  %10 = and i16 %9, -1024
  br label %.split11.us

.split.us.preheader:                              ; preds = %3
  %11 = lshr i16 %5, 3
  %12 = and i16 %11, 252
  store i16 %12, ptr %0, align 2, !tbaa !5
  %13 = load i16, ptr %4, align 2, !tbaa !5
  %14 = lshr i16 %13, 3
  %15 = and i16 %14, 252
  br label %.split11.us

.split11.us:                                      ; preds = %.split.preheader, %.split.us.preheader
  %.sink = phi i16 [ %10, %.split.preheader ], [ %15, %.split.us.preheader ]
  %16 = getelementptr inbounds i8, ptr %0, i64 2
  store i16 %.sink, ptr %16, align 2, !tbaa !5
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) 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"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,LoopInstSimplifyPass,LoopSimplifyCFGPass,LoopSimplifyPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass