; LLVM IR from libtcod/libtcod :: src/libtcod (color)

; 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"

%struct.TCOD_ColorRGB = type { i8, i8, i8 }

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0

; Function Attrs: nounwind uwtable
define dso_local i24 @TCOD_color_multiply(i24 %0, i24 %1) #1 {
  %3 = alloca %struct.TCOD_ColorRGB, align 1
  %4 = alloca %struct.TCOD_ColorRGB, align 1
  %5 = alloca %struct.TCOD_ColorRGB, align 1
  %6 = alloca i24, align 4
  store i24 %0, ptr %4, align 1
  store i24 %1, ptr %5, align 1
  %7 = getelementptr inbounds %struct.TCOD_ColorRGB, ptr %3, i32 0, i32 0
  %8 = getelementptr inbounds %struct.TCOD_ColorRGB, ptr %4, i32 0, i32 0
  %9 = load i8, ptr %8, align 1, !tbaa !5
  %10 = zext i8 %9 to i32
  %11 = getelementptr inbounds %struct.TCOD_ColorRGB, ptr %5, i32 0, i32 0
  %12 = load i8, ptr %11, align 1, !tbaa !5
  %13 = zext i8 %12 to i32
  %14 = mul nsw i32 %10, %13
  %15 = sdiv i32 %14, 255
  %16 = trunc i32 %15 to i8
  store i8 %16, ptr %7, align 1, !tbaa !5
  %17 = getelementptr inbounds %struct.TCOD_ColorRGB, ptr %3, i32 0, i32 1
  %18 = getelementptr inbounds %struct.TCOD_ColorRGB, ptr %4, i32 0, i32 1
  %19 = load i8, ptr %18, align 1, !tbaa !9
  %20 = zext i8 %19 to i32
  %21 = getelementptr inbounds %struct.TCOD_ColorRGB, ptr %5, i32 0, i32 1
  %22 = load i8, ptr %21, align 1, !tbaa !9
  %23 = zext i8 %22 to i32
  %24 = mul nsw i32 %20, %23
  %25 = sdiv i32 %24, 255
  %26 = trunc i32 %25 to i8
  store i8 %26, ptr %17, align 1, !tbaa !9
  %27 = getelementptr inbounds %struct.TCOD_ColorRGB, ptr %3, i32 0, i32 2
  %28 = getelementptr inbounds %struct.TCOD_ColorRGB, ptr %4, i32 0, i32 2
  %29 = load i8, ptr %28, align 1, !tbaa !10
  %30 = zext i8 %29 to i32
  %31 = getelementptr inbounds %struct.TCOD_ColorRGB, ptr %5, i32 0, i32 2
  %32 = load i8, ptr %31, align 1, !tbaa !10
  %33 = zext i8 %32 to i32
  %34 = mul nsw i32 %30, %33
  %35 = sdiv i32 %34, 255
  %36 = trunc i32 %35 to i8
  store i8 %36, ptr %27, align 1, !tbaa !10
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %6, ptr align 1 %3, i64 3, i1 false)
  %37 = load i24, ptr %6, align 4
  ret i24 %37
}

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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, !7, i64 0}
!6 = !{!"TCOD_ColorRGB", !7, i64 0, !7, i64 1, !7, i64 2}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!6, !7, i64 1}
!10 = !{!6, !7, i64 2}


; 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 willreturn memory(none) uwtable
define dso_local i24 @TCOD_color_multiply(i24 %0, i24 %1) local_unnamed_addr #0 {
  %.sroa.22.0.extract.shift = lshr i24 %0, 8
  %.sroa.33.0.extract.shift = lshr i24 %0, 16
  %.sroa.2.0.extract.shift = lshr i24 %1, 8
  %.sroa.3.0.extract.shift = lshr i24 %1, 16
  %3 = and i24 %0, 255
  %4 = and i24 %1, 255
  %narrow = mul nuw nsw i24 %4, %3
  %.lhs.trunc = trunc nuw i24 %narrow to i16
  %5 = udiv i16 %.lhs.trunc, 255
  %.zext = zext nneg i16 %5 to i24
  %6 = and i24 %.sroa.22.0.extract.shift, 255
  %7 = and i24 %.sroa.2.0.extract.shift, 255
  %narrow7 = mul nuw nsw i24 %7, %6
  %.lhs.trunc9 = trunc nuw i24 %narrow7 to i16
  %8 = udiv i16 %.lhs.trunc9, 255
  %.zext10 = zext nneg i16 %8 to i24
  %narrow8 = mul nuw nsw i24 %.sroa.3.0.extract.shift, %.sroa.33.0.extract.shift
  %.lhs.trunc11 = trunc nuw i24 %narrow8 to i16
  %9 = udiv i16 %.lhs.trunc11, 255
  %.zext12 = zext nneg i16 %9 to i24
  %.sroa.36.0.insert.ext = shl nuw i24 %.zext12, 16
  %.sroa.25.0.insert.ext = shl nuw nsw i24 %.zext10, 8
  %.sroa.25.0.insert.shift = and i24 %.sroa.25.0.insert.ext, 65280
  %.sroa.25.0.insert.insert = or disjoint i24 %.sroa.25.0.insert.shift, %.sroa.36.0.insert.ext
  %.sroa.04.0.insert.insert = add nuw nsw i24 %.sroa.25.0.insert.insert, %.zext
  ret i24 %.sroa.04.0.insert.insert
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(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)"}


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