; LLVM IR from ermig1979/Simd :: src/Simd/SimdBaseYuvToHue.ll (ZN4Simd4Base12Yuv444pToHueEPKhmS2_mS2_mmmPhm)

; 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: alwaysinline mustprogress uwtable
declare dso_local noundef i32 @_ZN4Simd4Base8YuvToHueEiii(i32 noundef, i32 noundef, i32 noundef) #1

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4Simd4Base12Yuv444pToHueEPKhmS2_mS2_mmmPhm(ptr noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %3, ptr noundef %4, i64 noundef %5, i64 noundef %6, i64 noundef %7, ptr noundef %8, i64 noundef %9) #2 {
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i64, align 8
  %15 = alloca ptr, align 8
  %16 = alloca i64, align 8
  %17 = alloca i64, align 8
  %18 = alloca i64, align 8
  %19 = alloca ptr, align 8
  %20 = alloca i64, align 8
  %21 = alloca i64, align 8
  %22 = alloca i32, align 4
  %23 = alloca i64, align 8
  store ptr %0, ptr %11, align 8, !tbaa !5
  store i64 %1, ptr %12, align 8, !tbaa !9
  store ptr %2, ptr %13, align 8, !tbaa !5
  store i64 %3, ptr %14, align 8, !tbaa !9
  store ptr %4, ptr %15, align 8, !tbaa !5
  store i64 %5, ptr %16, align 8, !tbaa !9
  store i64 %6, ptr %17, align 8, !tbaa !9
  store i64 %7, ptr %18, align 8, !tbaa !9
  store ptr %8, ptr %19, align 8, !tbaa !5
  store i64 %9, ptr %20, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %21) #3
  store i64 0, ptr %21, align 8, !tbaa !9
  br label %24

24:                                               ; preds = %72, %10
  %25 = load i64, ptr %21, align 8, !tbaa !9
  %26 = load i64, ptr %18, align 8, !tbaa !9
  %27 = icmp ult i64 %25, %26
  br i1 %27, label %29, label %28

28:                                               ; preds = %24
  store i32 2, ptr %22, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %21) #3
  br label %75

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

30:                                               ; preds = %56, %29
  %31 = load i64, ptr %23, align 8, !tbaa !9
  %32 = load i64, ptr %17, align 8, !tbaa !9
  %33 = icmp ult i64 %31, %32
  br i1 %33, label %35, label %34

34:                                               ; preds = %30
  store i32 5, ptr %22, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %23) #3
  br label %59

35:                                               ; preds = %30
  %36 = load ptr, ptr %11, align 8, !tbaa !5
  %37 = load i64, ptr %23, align 8, !tbaa !9
  %38 = getelementptr inbounds i8, ptr %36, i64 %37
  %39 = load i8, ptr %38, align 1, !tbaa !11
  %40 = zext i8 %39 to i32
  %41 = load ptr, ptr %13, align 8, !tbaa !5
  %42 = load i64, ptr %23, align 8, !tbaa !9
  %43 = getelementptr inbounds i8, ptr %41, i64 %42
  %44 = load i8, ptr %43, align 1, !tbaa !11
  %45 = zext i8 %44 to i32
  %46 = load ptr, ptr %15, align 8, !tbaa !5
  %47 = load i64, ptr %23, align 8, !tbaa !9
  %48 = getelementptr inbounds i8, ptr %46, i64 %47
  %49 = load i8, ptr %48, align 1, !tbaa !11
  %50 = zext i8 %49 to i32
  %51 = call noundef i32 @_ZN4Simd4Base8YuvToHueEiii(i32 noundef %40, i32 noundef %45, i32 noundef %50)
  %52 = trunc i32 %51 to i8
  %53 = load ptr, ptr %19, align 8, !tbaa !5
  %54 = load i64, ptr %23, align 8, !tbaa !9
  %55 = getelementptr inbounds i8, ptr %53, i64 %54
  store i8 %52, ptr %55, align 1, !tbaa !11
  br label %56

56:                                               ; preds = %35
  %57 = load i64, ptr %23, align 8, !tbaa !9
  %58 = add i64 %57, 1
  store i64 %58, ptr %23, align 8, !tbaa !9
  br label %30, !llvm.loop !12

59:                                               ; preds = %34
  %60 = load i64, ptr %12, align 8, !tbaa !9
  %61 = load ptr, ptr %11, align 8, !tbaa !5
  %62 = getelementptr inbounds i8, ptr %61, i64 %60
  store ptr %62, ptr %11, align 8, !tbaa !5
  %63 = load i64, ptr %14, align 8, !tbaa !9
  %64 = load ptr, ptr %13, align 8, !tbaa !5
  %65 = getelementptr inbounds i8, ptr %64, i64 %63
  store ptr %65, ptr %13, align 8, !tbaa !5
  %66 = load i64, ptr %16, align 8, !tbaa !9
  %67 = load ptr, ptr %15, align 8, !tbaa !5
  %68 = getelementptr inbounds i8, ptr %67, i64 %66
  store ptr %68, ptr %15, align 8, !tbaa !5
  %69 = load i64, ptr %20, align 8, !tbaa !9
  %70 = load ptr, ptr %19, align 8, !tbaa !5
  %71 = getelementptr inbounds i8, ptr %70, i64 %69
  store ptr %71, ptr %19, align 8, !tbaa !5
  br label %72

72:                                               ; preds = %59
  %73 = load i64, ptr %21, align 8, !tbaa !9
  %74 = add i64 %73, 1
  store i64 %74, ptr %21, align 8, !tbaa !9
  br label %24, !llvm.loop !14

75:                                               ; preds = %28
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #2 = { 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: alwaysinline mustprogress uwtable
declare dso_local noundef i32 @_ZN4Simd4Base8YuvToHueEiii(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4Simd4Base12Yuv444pToHueEPKhmS2_mS2_mmmPhm(ptr nocapture noundef readonly %0, i64 noundef %1, ptr nocapture noundef readonly %2, i64 noundef %3, ptr nocapture noundef readonly %4, i64 noundef %5, i64 noundef %6, i64 noundef %7, ptr nocapture noundef writeonly %8, i64 noundef %9) local_unnamed_addr #1 {
  %.not = icmp eq i64 %7, 0
  %.not33 = icmp eq i64 %6, 0
  %or.cond = or i1 %.not, %.not33
  br i1 %or.cond, label %._crit_edge32, label %.preheader.us

.preheader.us:                                    ; preds = %10, %._crit_edge.us
  %.02131.us = phi i64 [ %29, %._crit_edge.us ], [ 0, %10 ]
  %.02230.us = phi ptr [ %25, %._crit_edge.us ], [ %0, %10 ]
  %.02329.us = phi ptr [ %28, %._crit_edge.us ], [ %8, %10 ]
  %.02428.us = phi ptr [ %26, %._crit_edge.us ], [ %2, %10 ]
  %.02527.us = phi ptr [ %27, %._crit_edge.us ], [ %4, %10 ]
  br label %11

11:                                               ; preds = %.preheader.us, %11
  %.026.us = phi i64 [ 0, %.preheader.us ], [ %24, %11 ]
  %12 = getelementptr inbounds i8, ptr %.02230.us, i64 %.026.us
  %13 = load i8, ptr %12, align 1, !tbaa !5
  %14 = zext i8 %13 to i32
  %15 = getelementptr inbounds i8, ptr %.02428.us, i64 %.026.us
  %16 = load i8, ptr %15, align 1, !tbaa !5
  %17 = zext i8 %16 to i32
  %18 = getelementptr inbounds i8, ptr %.02527.us, i64 %.026.us
  %19 = load i8, ptr %18, align 1, !tbaa !5
  %20 = zext i8 %19 to i32
  %21 = tail call noundef i32 @_ZN4Simd4Base8YuvToHueEiii(i32 noundef %14, i32 noundef %17, i32 noundef %20)
  %22 = trunc i32 %21 to i8
  %23 = getelementptr inbounds i8, ptr %.02329.us, i64 %.026.us
  store i8 %22, ptr %23, align 1, !tbaa !5
  %24 = add nuw i64 %.026.us, 1
  %exitcond.not = icmp eq i64 %24, %6
  br i1 %exitcond.not, label %._crit_edge.us, label %11, !llvm.loop !8

._crit_edge.us:                                   ; preds = %11
  %25 = getelementptr inbounds i8, ptr %.02230.us, i64 %1
  %26 = getelementptr inbounds i8, ptr %.02428.us, i64 %3
  %27 = getelementptr inbounds i8, ptr %.02527.us, i64 %5
  %28 = getelementptr inbounds i8, ptr %.02329.us, i64 %9
  %29 = add nuw i64 %.02131.us, 1
  %exitcond35.not = icmp eq i64 %29, %7
  br i1 %exitcond35.not, label %._crit_edge32, label %.preheader.us, !llvm.loop !10

._crit_edge32:                                    ; preds = %._crit_edge.us, %10
  ret void
}

attributes #0 = { 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 #1 = { 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 = !{!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,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass