; LLVM IR from ermig1979/Simd :: src/Simd/SimdBaseBgrToHsl.ll (ZN4Simd4Base8BgrToHslEPKhmmmPhm)

; 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 @_ZN4Simd4Base8BgrToHslEPKhmmmPhm(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 ptr, align 8
  %16 = alloca ptr, align 8
  %17 = alloca ptr, 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 %18

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

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

23:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  %25 = load i64, ptr %13, align 8, !tbaa !9
  %26 = load i64, ptr %10, align 8, !tbaa !9
  %27 = mul i64 %25, %26
  %28 = getelementptr inbounds i8, ptr %24, i64 %27
  store ptr %28, ptr %15, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  %29 = load ptr, ptr %11, align 8, !tbaa !5
  %30 = load i64, ptr %13, align 8, !tbaa !9
  %31 = load i64, ptr %12, align 8, !tbaa !9
  %32 = mul i64 %30, %31
  %33 = getelementptr inbounds i8, ptr %29, i64 %32
  store ptr %33, ptr %16, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #3
  %34 = load ptr, ptr %15, align 8, !tbaa !5
  %35 = load i64, ptr %8, align 8, !tbaa !9
  %36 = mul i64 %35, 3
  %37 = getelementptr inbounds i8, ptr %34, i64 %36
  store ptr %37, ptr %17, align 8, !tbaa !5
  br label %38

38:                                               ; preds = %57, %23
  %39 = load ptr, ptr %15, align 8, !tbaa !5
  %40 = load ptr, ptr %17, align 8, !tbaa !5
  %41 = icmp ult ptr %39, %40
  br i1 %41, label %43, label %42

42:                                               ; preds = %38
  store i32 5, ptr %14, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #3
  br label %62

43:                                               ; preds = %38
  %44 = load ptr, ptr %15, align 8, !tbaa !5
  %45 = getelementptr inbounds i8, ptr %44, i64 0
  %46 = load i8, ptr %45, align 1, !tbaa !11
  %47 = zext i8 %46 to i32
  %48 = load ptr, ptr %15, align 8, !tbaa !5
  %49 = getelementptr inbounds i8, ptr %48, i64 1
  %50 = load i8, ptr %49, align 1, !tbaa !11
  %51 = zext i8 %50 to i32
  %52 = load ptr, ptr %15, align 8, !tbaa !5
  %53 = getelementptr inbounds i8, ptr %52, i64 2
  %54 = load i8, ptr %53, align 1, !tbaa !11
  %55 = zext i8 %54 to i32
  %56 = load ptr, ptr %16, align 8, !tbaa !5
  call void @_ZN4Simd4Base8BgrToHslEiiiPh(i32 noundef %47, i32 noundef %51, i32 noundef %55, ptr noundef %56)
  br label %57

57:                                               ; preds = %43
  %58 = load ptr, ptr %15, align 8, !tbaa !5
  %59 = getelementptr inbounds i8, ptr %58, i64 3
  store ptr %59, ptr %15, align 8, !tbaa !5
  %60 = load ptr, ptr %16, align 8, !tbaa !5
  %61 = getelementptr inbounds i8, ptr %60, i64 3
  store ptr %61, ptr %16, align 8, !tbaa !5
  br label %38, !llvm.loop !12

62:                                               ; preds = %42
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  br label %63

63:                                               ; preds = %62
  %64 = load i64, ptr %13, align 8, !tbaa !9
  %65 = add i64 %64, 1
  store i64 %65, ptr %13, align 8, !tbaa !9
  br label %18, !llvm.loop !14

66:                                               ; preds = %22
  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 uwtable
declare dso_local void @_ZN4Simd4Base8BgrToHslEiiiPh(i32 noundef, i32 noundef, i32 noundef, 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 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 = !{!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 uwtable
define dso_local void @_ZN4Simd4Base8BgrToHslEPKhmmmPhm(ptr noundef readonly %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
  br i1 %.not, label %._crit_edge25, label %.lr.ph24

.lr.ph24:                                         ; preds = %6
  %7 = mul i64 %1, 3
  %8 = icmp sgt i64 %7, 0
  br label %9

._crit_edge25:                                    ; preds = %._crit_edge, %6
  ret void

9:                                                ; preds = %.lr.ph24, %._crit_edge
  %.022 = phi i64 [ 0, %.lr.ph24 ], [ %15, %._crit_edge ]
  %10 = mul i64 %.022, %3
  %11 = getelementptr inbounds i8, ptr %0, i64 %10
  %12 = getelementptr inbounds i8, ptr %11, i64 %7
  br i1 %8, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %9
  %13 = mul i64 %.022, %5
  %14 = getelementptr inbounds i8, ptr %4, i64 %13
  br label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %9
  %15 = add nuw i64 %.022, 1
  %exitcond.not = icmp eq i64 %15, %2
  br i1 %exitcond.not, label %._crit_edge25, label %9, !llvm.loop !5

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %.01821 = phi ptr [ %25, %.lr.ph ], [ %14, %.lr.ph.preheader ]
  %.01920 = phi ptr [ %24, %.lr.ph ], [ %11, %.lr.ph.preheader ]
  %16 = load i8, ptr %.01920, align 1, !tbaa !7
  %17 = zext i8 %16 to i32
  %18 = getelementptr inbounds i8, ptr %.01920, i64 1
  %19 = load i8, ptr %18, align 1, !tbaa !7
  %20 = zext i8 %19 to i32
  %21 = getelementptr inbounds i8, ptr %.01920, i64 2
  %22 = load i8, ptr %21, align 1, !tbaa !7
  %23 = zext i8 %22 to i32
  tail call void @_ZN4Simd4Base8BgrToHslEiiiPh(i32 noundef %17, i32 noundef %20, i32 noundef %23, ptr noundef %.01821)
  %24 = getelementptr inbounds i8, ptr %.01920, i64 3
  %25 = getelementptr inbounds i8, ptr %.01821, i64 3
  %26 = icmp ult ptr %24, %12
  br i1 %26, label %.lr.ph, label %._crit_edge, !llvm.loop !10
}

; Function Attrs: alwaysinline mustprogress uwtable
declare dso_local void @_ZN4Simd4Base8BgrToHslEiiiPh(i32 noundef, i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #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 = { alwaysinline 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" }

!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 = !{!8, !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = distinct !{!10, !6}


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