; LLVM IR from yangfengzzz/Arche-webgpu :: vox.math/color.ll (ZNK3vox5Color13getBrightnessEv)

; 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.vox::Color" = type { float, float, float, float }

; 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: mustprogress nounwind uwtable
define dso_local noundef float @_ZNK3vox5Color13getBrightnessEv(ptr noundef nonnull align 4 dereferenceable(16) %0) #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca float, align 4
  %4 = alloca float, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %5 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  %6 = getelementptr inbounds %"struct.vox::Color", ptr %5, i32 0, i32 0
  %7 = load float, ptr %6, align 4, !tbaa !9
  store float %7, ptr %3, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  %8 = getelementptr inbounds %"struct.vox::Color", ptr %5, i32 0, i32 0
  %9 = load float, ptr %8, align 4, !tbaa !9
  store float %9, ptr %4, align 4, !tbaa !12
  %10 = getelementptr inbounds %"struct.vox::Color", ptr %5, i32 0, i32 1
  %11 = load float, ptr %10, align 4, !tbaa !13
  %12 = load float, ptr %3, align 4, !tbaa !12
  %13 = fcmp ogt float %11, %12
  br i1 %13, label %14, label %17

14:                                               ; preds = %1
  %15 = getelementptr inbounds %"struct.vox::Color", ptr %5, i32 0, i32 1
  %16 = load float, ptr %15, align 4, !tbaa !13
  store float %16, ptr %3, align 4, !tbaa !12
  br label %17

17:                                               ; preds = %14, %1
  %18 = getelementptr inbounds %"struct.vox::Color", ptr %5, i32 0, i32 2
  %19 = load float, ptr %18, align 4, !tbaa !14
  %20 = load float, ptr %3, align 4, !tbaa !12
  %21 = fcmp ogt float %19, %20
  br i1 %21, label %22, label %25

22:                                               ; preds = %17
  %23 = getelementptr inbounds %"struct.vox::Color", ptr %5, i32 0, i32 2
  %24 = load float, ptr %23, align 4, !tbaa !14
  store float %24, ptr %3, align 4, !tbaa !12
  br label %25

25:                                               ; preds = %22, %17
  %26 = getelementptr inbounds %"struct.vox::Color", ptr %5, i32 0, i32 1
  %27 = load float, ptr %26, align 4, !tbaa !13
  %28 = load float, ptr %4, align 4, !tbaa !12
  %29 = fcmp olt float %27, %28
  br i1 %29, label %30, label %33

30:                                               ; preds = %25
  %31 = getelementptr inbounds %"struct.vox::Color", ptr %5, i32 0, i32 1
  %32 = load float, ptr %31, align 4, !tbaa !13
  store float %32, ptr %4, align 4, !tbaa !12
  br label %33

33:                                               ; preds = %30, %25
  %34 = getelementptr inbounds %"struct.vox::Color", ptr %5, i32 0, i32 2
  %35 = load float, ptr %34, align 4, !tbaa !14
  %36 = load float, ptr %4, align 4, !tbaa !12
  %37 = fcmp olt float %35, %36
  br i1 %37, label %38, label %41

38:                                               ; preds = %33
  %39 = getelementptr inbounds %"struct.vox::Color", ptr %5, i32 0, i32 2
  %40 = load float, ptr %39, align 4, !tbaa !14
  store float %40, ptr %4, align 4, !tbaa !12
  br label %41

41:                                               ; preds = %38, %33
  %42 = load float, ptr %3, align 4, !tbaa !12
  %43 = load float, ptr %4, align 4, !tbaa !12
  %44 = fadd float %42, %43
  %45 = fdiv float %44, 2.000000e+00
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret float %45
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #2 = { 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, !11, i64 0}
!10 = !{!"_ZTSN3vox5ColorE", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12}
!11 = !{!"float", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !11, i64 4}
!14 = !{!10, !11, i64 8}


; 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(argmem: read) uwtable
define dso_local noundef float @_ZNK3vox5Color13getBrightnessEv(ptr nocapture noundef nonnull readonly align 4 dereferenceable(16) %0) local_unnamed_addr #0 align 2 {
  %2 = load float, ptr %0, align 4, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %0, i64 4
  %4 = load float, ptr %3, align 4, !tbaa !10
  %5 = fcmp ogt float %4, %2
  %.07 = select i1 %5, float %4, float %2
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = load float, ptr %6, align 4, !tbaa !11
  %8 = fcmp ogt float %7, %.07
  %.18 = select i1 %8, float %7, float %.07
  %9 = fcmp olt float %4, %2
  %.0 = select i1 %9, float %4, float %2
  %10 = fcmp olt float %7, %.0
  %.1 = select i1 %10, float %7, float %.0
  %11 = fadd float %.18, %.1
  %12 = fmul float %11, 5.000000e-01
  ret float %12
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) 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 = !{!"_ZTSN3vox5ColorE", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12}
!7 = !{!"float", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!6, !7, i64 4}
!11 = !{!6, !7, i64 8}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass