; LLVM IR from ermig1979/Simd :: src/Simd/SimdBaseBgrToRgb.ll (ZN4Simd4Base8BgrToRgbEPKhmmmPhm)

; 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 @_ZN4Simd4Base8BgrToRgbEPKhmmmPhm(ptr noundef %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, ptr noundef %4, i64 noundef %5) #0 {
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  %14 = alloca i64, align 8
  %15 = alloca i32, align 4
  %16 = alloca i64, align 8
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i64 %1, ptr %8, align 8, !tbaa !9
  store i64 %2, ptr %9, align 8, !tbaa !9
  store i64 %3, ptr %10, align 8, !tbaa !9
  store ptr %4, ptr %11, align 8, !tbaa !5
  store i64 %5, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #2
  %17 = load i64, ptr %8, align 8, !tbaa !9
  %18 = mul i64 %17, 3
  store i64 %18, ptr %13, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #2
  store i64 0, ptr %14, align 8, !tbaa !9
  br label %19

19:                                               ; preds = %68, %6
  %20 = load i64, ptr %14, align 8, !tbaa !9
  %21 = load i64, ptr %9, align 8, !tbaa !9
  %22 = icmp ult i64 %20, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %19
  store i32 2, ptr %15, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #2
  br label %71

24:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #2
  store i64 0, ptr %16, align 8, !tbaa !9
  br label %25

25:                                               ; preds = %58, %24
  %26 = load i64, ptr %16, align 8, !tbaa !9
  %27 = load i64, ptr %13, align 8, !tbaa !9
  %28 = icmp ult i64 %26, %27
  br i1 %28, label %30, label %29

29:                                               ; preds = %25
  store i32 5, ptr %15, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #2
  br label %61

30:                                               ; preds = %25
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = load i64, ptr %16, align 8, !tbaa !9
  %33 = add i64 %32, 2
  %34 = getelementptr inbounds i8, ptr %31, i64 %33
  %35 = load i8, ptr %34, align 1, !tbaa !11
  %36 = load ptr, ptr %11, align 8, !tbaa !5
  %37 = load i64, ptr %16, align 8, !tbaa !9
  %38 = add i64 %37, 0
  %39 = getelementptr inbounds i8, ptr %36, i64 %38
  store i8 %35, ptr %39, align 1, !tbaa !11
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = load i64, ptr %16, align 8, !tbaa !9
  %42 = add i64 %41, 1
  %43 = getelementptr inbounds i8, ptr %40, i64 %42
  %44 = load i8, ptr %43, align 1, !tbaa !11
  %45 = load ptr, ptr %11, align 8, !tbaa !5
  %46 = load i64, ptr %16, align 8, !tbaa !9
  %47 = add i64 %46, 1
  %48 = getelementptr inbounds i8, ptr %45, i64 %47
  store i8 %44, ptr %48, align 1, !tbaa !11
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  %50 = load i64, ptr %16, align 8, !tbaa !9
  %51 = add i64 %50, 0
  %52 = getelementptr inbounds i8, ptr %49, i64 %51
  %53 = load i8, ptr %52, align 1, !tbaa !11
  %54 = load ptr, ptr %11, align 8, !tbaa !5
  %55 = load i64, ptr %16, align 8, !tbaa !9
  %56 = add i64 %55, 2
  %57 = getelementptr inbounds i8, ptr %54, i64 %56
  store i8 %53, ptr %57, align 1, !tbaa !11
  br label %58

58:                                               ; preds = %30
  %59 = load i64, ptr %16, align 8, !tbaa !9
  %60 = add i64 %59, 3
  store i64 %60, ptr %16, align 8, !tbaa !9
  br label %25, !llvm.loop !12

61:                                               ; preds = %29
  %62 = load i64, ptr %10, align 8, !tbaa !9
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  %64 = getelementptr inbounds i8, ptr %63, i64 %62
  store ptr %64, ptr %7, align 8, !tbaa !5
  %65 = load i64, ptr %12, align 8, !tbaa !9
  %66 = load ptr, ptr %11, align 8, !tbaa !5
  %67 = getelementptr inbounds i8, ptr %66, i64 %65
  store ptr %67, ptr %11, align 8, !tbaa !5
  br label %68

68:                                               ; preds = %61
  %69 = load i64, ptr %14, align 8, !tbaa !9
  %70 = add i64 %69, 1
  store i64 %70, ptr %14, align 8, !tbaa !9
  br label %19, !llvm.loop !14

71:                                               ; preds = %23
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #2
  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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


; 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 @_ZN4Simd4Base8BgrToRgbEPKhmmmPhm(ptr nocapture noundef readonly %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, ptr nocapture noundef writeonly %4, i64 noundef %5) local_unnamed_addr #0 {
  %7 = mul i64 %1, 3
  %.not = icmp eq i64 %2, 0
  %.not30 = icmp eq i64 %1, 0
  %or.cond = or i1 %.not, %.not30
  br i1 %or.cond, label %._crit_edge29, label %.preheader.us

.preheader.us:                                    ; preds = %6, %._crit_edge.us
  %.02228.us = phi i64 [ %24, %._crit_edge.us ], [ 0, %6 ]
  %.02327.us = phi ptr [ %22, %._crit_edge.us ], [ %0, %6 ]
  %.02426.us = phi ptr [ %23, %._crit_edge.us ], [ %4, %6 ]
  br label %8

8:                                                ; preds = %.preheader.us, %8
  %.025.us = phi i64 [ 0, %.preheader.us ], [ %20, %8 ]
  %9 = add i64 %.025.us, 2
  %10 = getelementptr inbounds i8, ptr %.02327.us, i64 %9
  %11 = load i8, ptr %10, align 1, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %.02426.us, i64 %.025.us
  store i8 %11, ptr %12, align 1, !tbaa !5
  %13 = add nuw i64 %.025.us, 1
  %14 = getelementptr inbounds i8, ptr %.02327.us, i64 %13
  %15 = load i8, ptr %14, align 1, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %.02426.us, i64 %13
  store i8 %15, ptr %16, align 1, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %.02327.us, i64 %.025.us
  %18 = load i8, ptr %17, align 1, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %.02426.us, i64 %9
  store i8 %18, ptr %19, align 1, !tbaa !5
  %20 = add i64 %.025.us, 3
  %21 = icmp ult i64 %20, %7
  br i1 %21, label %8, label %._crit_edge.us, !llvm.loop !8

._crit_edge.us:                                   ; preds = %8
  %22 = getelementptr inbounds i8, ptr %.02327.us, i64 %3
  %23 = getelementptr inbounds i8, ptr %.02426.us, i64 %5
  %24 = add nuw i64 %.02228.us, 1
  %exitcond.not = icmp eq i64 %24, %2
  br i1 %exitcond.not, label %._crit_edge29, label %.preheader.us, !llvm.loop !10

._crit_edge29:                                    ; preds = %._crit_edge.us, %6
  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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = distinct !{!10, !9}


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