; LLVM IR from ermig1979/Simd :: src/Simd/SimdBaseGrayToBgr.ll (ZN4Simd4Base9GrayToBgrEPKhmmmPhm)

; 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 uwtable
define dso_local void @_ZN4Simd4Base9GrayToBgrEPKhmmmPhm(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 i32, align 4
  %15 = alloca i64, align 8
  %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) #3
  store i64 0, ptr %13, align 8, !tbaa !9
  br label %17

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

21:                                               ; preds = %17
  store i32 2, ptr %14, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  br label %50

22:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  store i64 0, ptr %15, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  store i64 0, ptr %16, align 8, !tbaa !9
  br label %23

23:                                               ; preds = %35, %22
  %24 = load i64, ptr %15, align 8, !tbaa !9
  %25 = load i64, ptr %8, align 8, !tbaa !9
  %26 = icmp ult i64 %24, %25
  br i1 %26, label %28, label %27

27:                                               ; preds = %23
  store i32 5, ptr %14, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  br label %40

28:                                               ; preds = %23
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = load i64, ptr %15, align 8, !tbaa !9
  %31 = getelementptr inbounds i8, ptr %29, i64 %30
  %32 = load ptr, ptr %11, align 8, !tbaa !5
  %33 = load i64, ptr %16, align 8, !tbaa !9
  %34 = getelementptr inbounds i8, ptr %32, i64 %33
  call void @_ZN4Simd4Base9GrayToBgrERKhPh(ptr noundef nonnull align 1 dereferenceable(1) %31, ptr noundef %34)
  br label %35

35:                                               ; preds = %28
  %36 = load i64, ptr %15, align 8, !tbaa !9
  %37 = add i64 %36, 1
  store i64 %37, ptr %15, align 8, !tbaa !9
  %38 = load i64, ptr %16, align 8, !tbaa !9
  %39 = add i64 %38, 3
  store i64 %39, ptr %16, align 8, !tbaa !9
  br label %23, !llvm.loop !11

40:                                               ; preds = %27
  %41 = load i64, ptr %10, align 8, !tbaa !9
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = getelementptr inbounds i8, ptr %42, i64 %41
  store ptr %43, ptr %7, align 8, !tbaa !5
  %44 = load i64, ptr %12, align 8, !tbaa !9
  %45 = load ptr, ptr %11, align 8, !tbaa !5
  %46 = getelementptr inbounds i8, ptr %45, i64 %44
  store ptr %46, ptr %11, align 8, !tbaa !5
  br label %47

47:                                               ; preds = %40
  %48 = load i64, ptr %13, align 8, !tbaa !9
  %49 = add i64 %48, 1
  store i64 %49, ptr %13, align 8, !tbaa !9
  br label %17, !llvm.loop !13

50:                                               ; preds = %21
  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: alwaysinline mustprogress nounwind uwtable
declare dso_local void @_ZN4Simd4Base9GrayToBgrERKhPh(ptr noundef nonnull align 1 dereferenceable(1), ptr noundef) #2

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

attributes #0 = { mustprogress 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 = { alwaysinline 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 #3 = { 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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; 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 nounwind uwtable
define dso_local void @_ZN4Simd4Base9GrayToBgrEPKhmmmPhm(ptr noundef %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, ptr noundef %4, i64 noundef %5) local_unnamed_addr #0 {
  %.not = icmp eq i64 %2, 0
  %.not24 = icmp eq i64 %1, 0
  %or.cond = or i1 %.not, %.not24
  br i1 %or.cond, label %._crit_edge23, label %.preheader.us

.preheader.us:                                    ; preds = %6, %._crit_edge.us
  %.01522.us = phi i64 [ %14, %._crit_edge.us ], [ 0, %6 ]
  %.01621.us = phi ptr [ %12, %._crit_edge.us ], [ %0, %6 ]
  %.01720.us = phi ptr [ %13, %._crit_edge.us ], [ %4, %6 ]
  br label %7

7:                                                ; preds = %.preheader.us, %7
  %.019.us = phi i64 [ 0, %.preheader.us ], [ %11, %7 ]
  %.01418.us = phi i64 [ 0, %.preheader.us ], [ %10, %7 ]
  %8 = getelementptr inbounds i8, ptr %.01621.us, i64 %.01418.us
  %9 = getelementptr inbounds i8, ptr %.01720.us, i64 %.019.us
  tail call void @_ZN4Simd4Base9GrayToBgrERKhPh(ptr noundef nonnull align 1 dereferenceable(1) %8, ptr noundef %9)
  %10 = add nuw i64 %.01418.us, 1
  %11 = add i64 %.019.us, 3
  %exitcond.not = icmp eq i64 %10, %1
  br i1 %exitcond.not, label %._crit_edge.us, label %7, !llvm.loop !5

._crit_edge.us:                                   ; preds = %7
  %12 = getelementptr inbounds i8, ptr %.01621.us, i64 %3
  %13 = getelementptr inbounds i8, ptr %.01720.us, i64 %5
  %14 = add nuw i64 %.01522.us, 1
  %exitcond26.not = icmp eq i64 %14, %2
  br i1 %exitcond26.not, label %._crit_edge23, label %.preheader.us, !llvm.loop !7

._crit_edge23:                                    ; preds = %._crit_edge.us, %6
  ret void
}

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local void @_ZN4Simd4Base9GrayToBgrERKhPh(ptr noundef nonnull align 1 dereferenceable(1), ptr noundef) local_unnamed_addr #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 = { alwaysinline 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" }

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}


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