; LLVM IR from ermig1979/Simd :: src/Simd/SimdBaseBgraToBgr.ll (ZN4Simd4Base9BgraToBgrEPKhmPhb)

; 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: mustprogress nounwind uwtable
define dso_local void @_ZN4Simd4Base9BgraToBgrEPKhmPhb(ptr noundef %0, i64 noundef %1, ptr noundef %2, i1 noundef zeroext %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i8, align 1
  %9 = alloca i64, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  %10 = zext i1 %3 to i8
  store i8 %10, ptr %8, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %11 = load i8, ptr %8, align 1, !tbaa !11, !range !13, !noundef !14
  %12 = trunc i8 %11 to i1
  %13 = zext i1 %12 to i64
  %14 = select i1 %12, i32 1, i32 0
  %15 = sext i32 %14 to i64
  store i64 %15, ptr %9, align 8, !tbaa !9
  br label %16

16:                                               ; preds = %25, %4
  %17 = load i64, ptr %9, align 8, !tbaa !9
  %18 = load i64, ptr %6, align 8, !tbaa !9
  %19 = icmp ult i64 %17, %18
  br i1 %19, label %21, label %20

20:                                               ; preds = %16
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  br label %32

21:                                               ; preds = %16
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = load i32, ptr %22, align 4, !tbaa !15
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 %23, ptr %24, align 4, !tbaa !15
  br label %25

25:                                               ; preds = %21
  %26 = load i64, ptr %9, align 8, !tbaa !9
  %27 = add i64 %26, 1
  store i64 %27, ptr %9, align 8, !tbaa !9
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %28, i64 3
  store ptr %29, ptr %7, align 8, !tbaa !5
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = getelementptr inbounds i8, ptr %30, i64 4
  store ptr %31, ptr %5, align 8, !tbaa !5
  br label %16, !llvm.loop !17

32:                                               ; preds = %20
  %33 = load i8, ptr %8, align 1, !tbaa !11, !range !13, !noundef !14
  %34 = trunc i8 %33 to i1
  br i1 %34, label %35, label %51

35:                                               ; preds = %32
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = getelementptr inbounds i8, ptr %36, i64 0
  %38 = load i8, ptr %37, align 1, !tbaa !19
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = getelementptr inbounds i8, ptr %39, i64 0
  store i8 %38, ptr %40, align 1, !tbaa !19
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = getelementptr inbounds i8, ptr %41, i64 1
  %43 = load i8, ptr %42, align 1, !tbaa !19
  %44 = load ptr, ptr %7, align 8, !tbaa !5
  %45 = getelementptr inbounds i8, ptr %44, i64 1
  store i8 %43, ptr %45, align 1, !tbaa !19
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = getelementptr inbounds i8, ptr %46, i64 2
  %48 = load i8, ptr %47, align 1, !tbaa !19
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  %50 = getelementptr inbounds i8, ptr %49, i64 2
  store i8 %48, ptr %50, align 1, !tbaa !19
  br label %51

51:                                               ; preds = %35, %32
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!16, !16, i64 0}
!16 = !{!"int", !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!7, !7, i64 0}


; 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 @_ZN4Simd4Base9BgraToBgrEPKhmPhb(ptr nocapture noundef readonly %0, i64 noundef %1, ptr nocapture noundef writeonly %2, i1 noundef zeroext %3) local_unnamed_addr #0 {
  %5 = zext i1 %3 to i64
  %6 = icmp ult i64 %5, %1
  br i1 %6, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %4
  %7 = sub i64 %1, %5
  %xtraiter = and i64 %7, 7
  %lcmp.mod.not = icmp eq i64 %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
  %.018.prol = phi i64 [ %9, %.lr.ph.prol ], [ %5, %.lr.ph.preheader ]
  %.01417.prol = phi ptr [ %11, %.lr.ph.prol ], [ %0, %.lr.ph.preheader ]
  %.01516.prol = phi ptr [ %10, %.lr.ph.prol ], [ %2, %.lr.ph.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %.lr.ph.prol ], [ 0, %.lr.ph.preheader ]
  %8 = load i32, ptr %.01417.prol, align 4, !tbaa !5
  store i32 %8, ptr %.01516.prol, align 4, !tbaa !5
  %9 = add nuw i64 %.018.prol, 1
  %10 = getelementptr inbounds i8, ptr %.01516.prol, i64 3
  %11 = getelementptr inbounds i8, ptr %.01417.prol, i64 4
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol, !llvm.loop !9

.lr.ph.prol.loopexit:                             ; preds = %.lr.ph.prol, %.lr.ph.preheader
  %.lcssa23.unr = phi ptr [ poison, %.lr.ph.preheader ], [ %10, %.lr.ph.prol ]
  %.lcssa.unr = phi ptr [ poison, %.lr.ph.preheader ], [ %11, %.lr.ph.prol ]
  %.018.unr = phi i64 [ %5, %.lr.ph.preheader ], [ %9, %.lr.ph.prol ]
  %.01417.unr = phi ptr [ %0, %.lr.ph.preheader ], [ %11, %.lr.ph.prol ]
  %.01516.unr = phi ptr [ %2, %.lr.ph.preheader ], [ %10, %.lr.ph.prol ]
  %12 = sub i64 %5, %1
  %13 = icmp ugt i64 %12, -8
  br i1 %13, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph.prol.loopexit, %.lr.ph, %4
  %.015.lcssa = phi ptr [ %2, %4 ], [ %.lcssa23.unr, %.lr.ph.prol.loopexit ], [ %37, %.lr.ph ]
  %.014.lcssa = phi ptr [ %0, %4 ], [ %.lcssa.unr, %.lr.ph.prol.loopexit ], [ %38, %.lr.ph ]
  br i1 %3, label %39, label %47

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

39:                                               ; preds = %._crit_edge
  %40 = load i8, ptr %.014.lcssa, align 1, !tbaa !13
  store i8 %40, ptr %.015.lcssa, align 1, !tbaa !13
  %41 = getelementptr inbounds i8, ptr %.014.lcssa, i64 1
  %42 = load i8, ptr %41, align 1, !tbaa !13
  %43 = getelementptr inbounds i8, ptr %.015.lcssa, i64 1
  store i8 %42, ptr %43, align 1, !tbaa !13
  %44 = getelementptr inbounds i8, ptr %.014.lcssa, i64 2
  %45 = load i8, ptr %44, align 1, !tbaa !13
  %46 = getelementptr inbounds i8, ptr %.015.lcssa, i64 2
  store i8 %45, ptr %46, align 1, !tbaa !13
  br label %47

47:                                               ; preds = %39, %._crit_edge
  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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.unroll.disable"}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!7, !7, i64 0}


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