; 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: nounwind uwtable
define dso_local float @TCOD_color_get_value(i24 %0) #0 {
  %2 = alloca %struct.TCOD_ColorRGB, align 1
  store i24 %0, ptr %2, align 1
  %3 = getelementptr inbounds %struct.TCOD_ColorRGB, ptr %2, i32 0, i32 0
  %4 = load i8, ptr %3, align 1, !tbaa !5
  %5 = zext i8 %4 to i32
  %6 = getelementptr inbounds %struct.TCOD_ColorRGB, ptr %2, i32 0, i32 1
  %7 = load i8, ptr %6, align 1, !tbaa !9
  %8 = zext i8 %7 to i32
  %9 = getelementptr inbounds %struct.TCOD_ColorRGB, ptr %2, i32 0, i32 2
  %10 = load i8, ptr %9, align 1, !tbaa !10
  %11 = zext i8 %10 to i32
  %12 = icmp sgt i32 %8, %11
  br i1 %12, label %13, label %17

13:                                               ; preds = %1
  %14 = getelementptr inbounds %struct.TCOD_ColorRGB, ptr %2, i32 0, i32 1
  %15 = load i8, ptr %14, align 1, !tbaa !9
  %16 = zext i8 %15 to i32
  br label %21

17:                                               ; preds = %1
  %18 = getelementptr inbounds %struct.TCOD_ColorRGB, ptr %2, i32 0, i32 2
  %19 = load i8, ptr %18, align 1, !tbaa !10
  %20 = zext i8 %19 to i32
  br label %21

21:                                               ; preds = %17, %13
  %22 = phi i32 [ %16, %13 ], [ %20, %17 ]
  %23 = icmp sgt i32 %5, %22
  br i1 %23, label %24, label %28

24:                                               ; preds = %21
  %25 = getelementptr inbounds %struct.TCOD_ColorRGB, ptr %2, i32 0, i32 0
  %26 = load i8, ptr %25, align 1, !tbaa !5
  %27 = zext i8 %26 to i32
  br label %46

28:                                               ; preds = %21
  %29 = getelementptr inbounds %struct.TCOD_ColorRGB, ptr %2, i32 0, i32 1
  %30 = load i8, ptr %29, align 1, !tbaa !9
  %31 = zext i8 %30 to i32
  %32 = getelementptr inbounds %struct.TCOD_ColorRGB, ptr %2, i32 0, i32 2
  %33 = load i8, ptr %32, align 1, !tbaa !10
  %34 = zext i8 %33 to i32
  %35 = icmp sgt i32 %31, %34
  br i1 %35, label %36, label %40

36:                                               ; preds = %28
  %37 = getelementptr inbounds %struct.TCOD_ColorRGB, ptr %2, i32 0, i32 1
  %38 = load i8, ptr %37, align 1, !tbaa !9
  %39 = zext i8 %38 to i32
  br label %44

40:                                               ; preds = %28
  %41 = getelementptr inbounds %struct.TCOD_ColorRGB, ptr %2, i32 0, i32 2
  %42 = load i8, ptr %41, align 1, !tbaa !10
  %43 = zext i8 %42 to i32
  br label %44

44:                                               ; preds = %40, %36
  %45 = phi i32 [ %39, %36 ], [ %43, %40 ]
  br label %46

46:                                               ; preds = %44, %24
  %47 = phi i32 [ %27, %24 ], [ %45, %44 ]
  %48 = sitofp i32 %47 to float
  %49 = fdiv float %48, 2.550000e+02
  ret float %49
}

attributes #0 = { 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 float @TCOD_color_get_value(i24 %0) local_unnamed_addr #0 {
  %.sroa.3.0.extract.shift = lshr i24 %0, 8
  %.sroa.7.0.extract.shift = lshr i24 %0, 16
  %2 = and i24 %0, 255
  %3 = and i24 %.sroa.3.0.extract.shift, 255
  %4 = tail call i24 @llvm.umax.i24(i24 %3, i24 %.sroa.7.0.extract.shift)
  %.v = tail call i24 @llvm.umax.i24(i24 %2, i24 %4)
  %5 = uitofp nneg i24 %.v to float
  %6 = fdiv float %5, 2.550000e+02
  ret float %6
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i24 @llvm.umax.i24(i24, i24) #1

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" }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass