; LLVM IR from awawa-dev/HyperHDR :: sources/image/ColorRgb.ll (ZN8ColorRgb7yuv2rgbEhhhRhS0_S0_)

; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i8 @_ZN8ColorRgb5clampEi(i32 noundef) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN8ColorRgb7yuv2rgbEhhhRhS0_S0_(i8 noundef zeroext %0, i8 noundef zeroext %1, i8 noundef zeroext %2, ptr noundef nonnull align 1 dereferenceable(1) %3, ptr noundef nonnull align 1 dereferenceable(1) %4, ptr noundef nonnull align 1 dereferenceable(1) %5) #2 align 2 {
  %7 = alloca i8, align 1
  %8 = alloca i8, align 1
  %9 = alloca i8, align 1
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  store i8 %0, ptr %7, align 1, !tbaa !5
  store i8 %1, ptr %8, align 1, !tbaa !5
  store i8 %2, ptr %9, align 1, !tbaa !5
  store ptr %3, ptr %10, align 8, !tbaa !8
  store ptr %4, ptr %11, align 8, !tbaa !8
  store ptr %5, ptr %12, align 8, !tbaa !8
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %16 = load i8, ptr %7, align 1, !tbaa !5
  %17 = zext i8 %16 to i32
  %18 = sub nsw i32 %17, 16
  %19 = call noundef zeroext i8 @_ZN8ColorRgb5clampEi(i32 noundef %18)
  %20 = zext i8 %19 to i32
  store i32 %20, ptr %13, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  %21 = load i8, ptr %8, align 1, !tbaa !5
  %22 = zext i8 %21 to i32
  %23 = sub nsw i32 %22, 128
  store i32 %23, ptr %14, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  %24 = load i8, ptr %9, align 1, !tbaa !5
  %25 = zext i8 %24 to i32
  %26 = sub nsw i32 %25, 128
  store i32 %26, ptr %15, align 4, !tbaa !10
  %27 = load i32, ptr %13, align 4, !tbaa !10
  %28 = mul nsw i32 298, %27
  %29 = load i32, ptr %15, align 4, !tbaa !10
  %30 = mul nsw i32 409, %29
  %31 = add nsw i32 %28, %30
  %32 = add nsw i32 %31, 128
  %33 = ashr i32 %32, 8
  %34 = call noundef zeroext i8 @_ZN8ColorRgb5clampEi(i32 noundef %33)
  %35 = load ptr, ptr %10, align 8, !tbaa !8
  store i8 %34, ptr %35, align 1, !tbaa !5
  %36 = load i32, ptr %13, align 4, !tbaa !10
  %37 = mul nsw i32 298, %36
  %38 = load i32, ptr %14, align 4, !tbaa !10
  %39 = mul nsw i32 100, %38
  %40 = sub nsw i32 %37, %39
  %41 = load i32, ptr %15, align 4, !tbaa !10
  %42 = mul nsw i32 208, %41
  %43 = sub nsw i32 %40, %42
  %44 = add nsw i32 %43, 128
  %45 = ashr i32 %44, 8
  %46 = call noundef zeroext i8 @_ZN8ColorRgb5clampEi(i32 noundef %45)
  %47 = load ptr, ptr %11, align 8, !tbaa !8
  store i8 %46, ptr %47, align 1, !tbaa !5
  %48 = load i32, ptr %13, align 4, !tbaa !10
  %49 = mul nsw i32 298, %48
  %50 = load i32, ptr %14, align 4, !tbaa !10
  %51 = mul nsw i32 516, %50
  %52 = add nsw i32 %49, %51
  %53 = add nsw i32 %52, 128
  %54 = ashr i32 %53, 8
  %55 = call noundef zeroext i8 @_ZN8ColorRgb5clampEi(i32 noundef %54)
  %56 = load ptr, ptr %12, align 8, !tbaa !8
  store i8 %55, ptr %56, align 1, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 #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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"any pointer", !6, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !6, 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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i8 @_ZN8ColorRgb5clampEi(i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN8ColorRgb7yuv2rgbEhhhRhS0_S0_(i8 noundef zeroext %0, i8 noundef zeroext %1, i8 noundef zeroext %2, ptr nocapture noundef nonnull writeonly align 1 dereferenceable(1) %3, ptr nocapture noundef nonnull writeonly align 1 dereferenceable(1) %4, ptr nocapture noundef nonnull writeonly align 1 dereferenceable(1) %5) local_unnamed_addr #1 align 2 {
  %7 = zext i8 %0 to i32
  %8 = add nsw i32 %7, -16
  %9 = tail call noundef zeroext i8 @_ZN8ColorRgb5clampEi(i32 noundef %8)
  %10 = zext i8 %9 to i32
  %11 = zext i8 %1 to i32
  %12 = add nsw i32 %11, -128
  %13 = zext i8 %2 to i32
  %14 = add nsw i32 %13, -128
  %15 = mul nuw nsw i32 %10, 298
  %16 = mul nsw i32 %14, 409
  %17 = add nuw nsw i32 %15, 128
  %18 = add nsw i32 %17, %16
  %19 = ashr i32 %18, 8
  %20 = tail call noundef zeroext i8 @_ZN8ColorRgb5clampEi(i32 noundef %19)
  store i8 %20, ptr %3, align 1, !tbaa !5
  %.neg = mul nsw i32 %12, -100
  %.neg12 = mul nsw i32 %14, -208
  %21 = add nsw i32 %17, %.neg
  %22 = add nsw i32 %21, %.neg12
  %23 = ashr i32 %22, 8
  %24 = tail call noundef zeroext i8 @_ZN8ColorRgb5clampEi(i32 noundef %23)
  store i8 %24, ptr %4, align 1, !tbaa !5
  %25 = mul nsw i32 %12, 516
  %26 = add nsw i32 %17, %25
  %27 = ashr i32 %26, 8
  %28 = tail call noundef zeroext i8 @_ZN8ColorRgb5clampEi(i32 noundef %27)
  store i8 %28, ptr %5, align 1, !tbaa !5
  ret void
}

attributes #0 = { inlinehint 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 = { 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 = !{!6, !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,TailCallElimPass