; LLVM IR from achilles288/robot-monitor-graphics :: src/base/color.ll (ZNK3rmg9ColorRGBAcvNS_9ColorHSLAEEv)

; 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.rmg::ColorHSLA" = type { float, float, float, float }
%"struct.rmg::ColorRGBA" = type { float, float, float, float }

; Function Attrs: mustprogress nounwind uwtable
define dso_local { <2 x float>, <2 x float> } @_ZNK3rmg9ColorRGBAcvNS_9ColorHSLAEEv(ptr noundef nonnull align 4 dereferenceable(16) %0) #0 align 2 {
  %2 = alloca %"struct.rmg::ColorHSLA", align 4
  %3 = alloca ptr, align 8
  %4 = alloca i8, align 1
  %5 = alloca float, align 4
  %6 = alloca float, align 4
  %7 = alloca float, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %8 = load ptr, ptr %3, align 8
  call void @_ZN3rmg9ColorHSLAC2Ev(ptr noundef nonnull align 4 dereferenceable(16) %2) #4
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %9 = getelementptr inbounds %"struct.rmg::ColorRGBA", ptr %8, i32 0, i32 0
  %10 = load float, ptr %9, align 4, !tbaa !9
  %11 = getelementptr inbounds %"struct.rmg::ColorRGBA", ptr %8, i32 0, i32 1
  %12 = load float, ptr %11, align 4, !tbaa !12
  %13 = fcmp ogt float %10, %12
  br i1 %13, label %14, label %29

14:                                               ; preds = %1
  %15 = getelementptr inbounds %"struct.rmg::ColorRGBA", ptr %8, i32 0, i32 1
  %16 = load float, ptr %15, align 4, !tbaa !12
  store float %16, ptr %6, align 4, !tbaa !13
  %17 = getelementptr inbounds %"struct.rmg::ColorRGBA", ptr %8, i32 0, i32 0
  %18 = load float, ptr %17, align 4, !tbaa !9
  %19 = getelementptr inbounds %"struct.rmg::ColorRGBA", ptr %8, i32 0, i32 2
  %20 = load float, ptr %19, align 4, !tbaa !14
  %21 = fcmp ogt float %18, %20
  br i1 %21, label %22, label %25

22:                                               ; preds = %14
  %23 = getelementptr inbounds %"struct.rmg::ColorRGBA", ptr %8, i32 0, i32 0
  %24 = load float, ptr %23, align 4, !tbaa !9
  store float %24, ptr %5, align 4, !tbaa !13
  store i8 1, ptr %4, align 1, !tbaa !15
  br label %28

25:                                               ; preds = %14
  %26 = getelementptr inbounds %"struct.rmg::ColorRGBA", ptr %8, i32 0, i32 2
  %27 = load float, ptr %26, align 4, !tbaa !14
  store float %27, ptr %5, align 4, !tbaa !13
  store i8 3, ptr %4, align 1, !tbaa !15
  br label %28

28:                                               ; preds = %25, %22
  br label %56

29:                                               ; preds = %1
  %30 = getelementptr inbounds %"struct.rmg::ColorRGBA", ptr %8, i32 0, i32 2
  %31 = load float, ptr %30, align 4, !tbaa !14
  %32 = getelementptr inbounds %"struct.rmg::ColorRGBA", ptr %8, i32 0, i32 1
  %33 = load float, ptr %32, align 4, !tbaa !12
  %34 = fcmp ogt float %31, %33
  br i1 %34, label %35, label %40

35:                                               ; preds = %29
  %36 = getelementptr inbounds %"struct.rmg::ColorRGBA", ptr %8, i32 0, i32 2
  %37 = load float, ptr %36, align 4, !tbaa !14
  store float %37, ptr %5, align 4, !tbaa !13
  %38 = getelementptr inbounds %"struct.rmg::ColorRGBA", ptr %8, i32 0, i32 0
  %39 = load float, ptr %38, align 4, !tbaa !9
  store float %39, ptr %6, align 4, !tbaa !13
  store i8 3, ptr %4, align 1, !tbaa !15
  br label %55

40:                                               ; preds = %29
  %41 = getelementptr inbounds %"struct.rmg::ColorRGBA", ptr %8, i32 0, i32 1
  %42 = load float, ptr %41, align 4, !tbaa !12
  store float %42, ptr %5, align 4, !tbaa !13
  store i8 2, ptr %4, align 1, !tbaa !15
  %43 = getelementptr inbounds %"struct.rmg::ColorRGBA", ptr %8, i32 0, i32 0
  %44 = load float, ptr %43, align 4, !tbaa !9
  %45 = getelementptr inbounds %"struct.rmg::ColorRGBA", ptr %8, i32 0, i32 2
  %46 = load float, ptr %45, align 4, !tbaa !14
  %47 = fcmp olt float %44, %46
  br i1 %47, label %48, label %51

48:                                               ; preds = %40
  %49 = getelementptr inbounds %"struct.rmg::ColorRGBA", ptr %8, i32 0, i32 0
  %50 = load float, ptr %49, align 4, !tbaa !9
  store float %50, ptr %6, align 4, !tbaa !13
  br label %54

51:                                               ; preds = %40
  %52 = getelementptr inbounds %"struct.rmg::ColorRGBA", ptr %8, i32 0, i32 2
  %53 = load float, ptr %52, align 4, !tbaa !14
  store float %53, ptr %6, align 4, !tbaa !13
  br label %54

54:                                               ; preds = %51, %48
  br label %55

55:                                               ; preds = %54, %35
  br label %56

56:                                               ; preds = %55, %28
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %57 = load float, ptr %5, align 4, !tbaa !13
  %58 = load float, ptr %6, align 4, !tbaa !13
  %59 = fsub float %57, %58
  store float %59, ptr %7, align 4, !tbaa !13
  %60 = load float, ptr %7, align 4, !tbaa !13
  %61 = fcmp olt float %60, 0x3F1A36E2E0000000
  br i1 %61, label %62, label %64

62:                                               ; preds = %56
  %63 = getelementptr inbounds %"struct.rmg::ColorHSLA", ptr %2, i32 0, i32 0
  store float 0.000000e+00, ptr %63, align 4, !tbaa !16
  br label %109

64:                                               ; preds = %56
  %65 = load i8, ptr %4, align 1, !tbaa !15
  %66 = zext i8 %65 to i32
  %67 = icmp eq i32 %66, 1
  br i1 %67, label %68, label %81

68:                                               ; preds = %64
  %69 = getelementptr inbounds %"struct.rmg::ColorRGBA", ptr %8, i32 0, i32 1
  %70 = load float, ptr %69, align 4, !tbaa !12
  %71 = getelementptr inbounds %"struct.rmg::ColorRGBA", ptr %8, i32 0, i32 2
  %72 = load float, ptr %71, align 4, !tbaa !14
  %73 = fsub float %70, %72
  %74 = load float, ptr %7, align 4, !tbaa !13
  %75 = fdiv float %73, %74
  %76 = fpext float %75 to double
  %77 = call double @fmod(double noundef %76, double noundef 6.000000e+00) #4
  %78 = fmul double 6.000000e+01, %77
  %79 = fptrunc double %78 to float
  %80 = getelementptr inbounds %"struct.rmg::ColorHSLA", ptr %2, i32 0, i32 0
  store float %79, ptr %80, align 4, !tbaa !16
  br label %108

81:                                               ; preds = %64
  %82 = load i8, ptr %4, align 1, !tbaa !15
  %83 = zext i8 %82 to i32
  %84 = icmp eq i32 %83, 2
  br i1 %84, label %85, label %96

85:                                               ; preds = %81
  %86 = getelementptr inbounds %"struct.rmg::ColorRGBA", ptr %8, i32 0, i32 2
  %87 = load float, ptr %86, align 4, !tbaa !14
  %88 = getelementptr inbounds %"struct.rmg::ColorRGBA", ptr %8, i32 0, i32 0
  %89 = load float, ptr %88, align 4, !tbaa !9
  %90 = fsub float %87, %89
  %91 = load float, ptr %7, align 4, !tbaa !13
  %92 = fdiv float %90, %91
  %93 = fadd float %92, 2.000000e+00
  %94 = fmul float 6.000000e+01, %93
  %95 = getelementptr inbounds %"struct.rmg::ColorHSLA", ptr %2, i32 0, i32 0
  store float %94, ptr %95, align 4, !tbaa !16
  br label %107

96:                                               ; preds = %81
  %97 = getelementptr inbounds %"struct.rmg::ColorRGBA", ptr %8, i32 0, i32 2
  %98 = load float, ptr %97, align 4, !tbaa !14
  %99 = getelementptr inbounds %"struct.rmg::ColorRGBA", ptr %8, i32 0, i32 0
  %100 = load float, ptr %99, align 4, !tbaa !9
  %101 = fsub float %98, %100
  %102 = load float, ptr %7, align 4, !tbaa !13
  %103 = fdiv float %101, %102
  %104 = fadd float %103, 4.000000e+00
  %105 = fmul float 6.000000e+01, %104
  %106 = getelementptr inbounds %"struct.rmg::ColorHSLA", ptr %2, i32 0, i32 0
  store float %105, ptr %106, align 4, !tbaa !16
  br label %107

107:                                              ; preds = %96, %85
  br label %108

108:                                              ; preds = %107, %68
  br label %109

109:                                              ; preds = %108, %62
  %110 = load float, ptr %5, align 4, !tbaa !13
  %111 = load float, ptr %6, align 4, !tbaa !13
  %112 = fadd float %110, %111
  %113 = fdiv float %112, 2.000000e+00
  %114 = getelementptr inbounds %"struct.rmg::ColorHSLA", ptr %2, i32 0, i32 2
  store float %113, ptr %114, align 4, !tbaa !18
  %115 = load float, ptr %7, align 4, !tbaa !13
  %116 = fcmp olt float %115, 0x3F1A36E2E0000000
  br i1 %116, label %117, label %119

117:                                              ; preds = %109
  %118 = getelementptr inbounds %"struct.rmg::ColorHSLA", ptr %2, i32 0, i32 1
  store float 0.000000e+00, ptr %118, align 4, !tbaa !19
  br label %131

119:                                              ; preds = %109
  %120 = load float, ptr %7, align 4, !tbaa !13
  %121 = fpext float %120 to double
  %122 = getelementptr inbounds %"struct.rmg::ColorHSLA", ptr %2, i32 0, i32 2
  %123 = load float, ptr %122, align 4, !tbaa !18
  %124 = call float @llvm.fmuladd.f32(float 2.000000e+00, float %123, float -1.000000e+00)
  %125 = fpext float %124 to double
  %126 = call double @llvm.fabs.f64(double %125)
  %127 = fsub double 1.000000e+00, %126
  %128 = fdiv double %121, %127
  %129 = fptrunc double %128 to float
  %130 = getelementptr inbounds %"struct.rmg::ColorHSLA", ptr %2, i32 0, i32 1
  store float %129, ptr %130, align 4, !tbaa !19
  br label %131

131:                                              ; preds = %119, %117
  %132 = getelementptr inbounds %"struct.rmg::ColorRGBA", ptr %8, i32 0, i32 3
  %133 = load float, ptr %132, align 4, !tbaa !20
  %134 = getelementptr inbounds %"struct.rmg::ColorHSLA", ptr %2, i32 0, i32 3
  store float %133, ptr %134, align 4, !tbaa !21
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #4
  %135 = load { <2 x float>, <2 x float> }, ptr %2, align 4
  ret { <2 x float>, <2 x float> } %135
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3rmg9ColorHSLAC2Ev(ptr noundef nonnull align 4 dereferenceable(16)) unnamed_addr #0 align 2

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

; Function Attrs: nounwind
declare double @fmod(double noundef, double noundef) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fabs.f64(double) #3

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

attributes #0 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nounwind "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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 = !{!"_ZTSN3rmg9ColorRGBAE", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12}
!11 = !{!"float", !7, i64 0}
!12 = !{!10, !11, i64 4}
!13 = !{!11, !11, i64 0}
!14 = !{!10, !11, i64 8}
!15 = !{!7, !7, i64 0}
!16 = !{!17, !11, i64 0}
!17 = !{!"_ZTSN3rmg9ColorHSLAE", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12}
!18 = !{!17, !11, i64 8}
!19 = !{!17, !11, i64 4}
!20 = !{!10, !11, i64 12}
!21 = !{!17, !11, i64 12}


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

%"struct.rmg::ColorHSLA" = type { float, float, float, float }

; Function Attrs: mustprogress nounwind uwtable
define dso_local { <2 x float>, <2 x float> } @_ZNK3rmg9ColorRGBAcvNS_9ColorHSLAEEv(ptr nocapture noundef nonnull readonly align 4 dereferenceable(16) %0) local_unnamed_addr #0 align 2 {
  %2 = alloca %"struct.rmg::ColorHSLA", align 8
  call void @_ZN3rmg9ColorHSLAC2Ev(ptr noundef nonnull align 4 dereferenceable(16) %2) #4
  %3 = load float, ptr %0, align 4, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 4
  %5 = load float, ptr %4, align 4, !tbaa !10
  %6 = fcmp ogt float %3, %5
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  %8 = load float, ptr %7, align 4, !tbaa !11
  br i1 %6, label %9, label %11

9:                                                ; preds = %1
  %10 = fcmp ogt float %3, %8
  %. = select i1 %10, float %3, float %8
  br label %15

11:                                               ; preds = %1
  %12 = fcmp ogt float %8, %5
  br i1 %12, label %15, label %13

13:                                               ; preds = %11
  %14 = fcmp olt float %3, %8
  %.23 = select i1 %14, float %3, float %8
  br label %15

15:                                               ; preds = %13, %11, %9
  %.013 = phi float [ %., %9 ], [ %8, %11 ], [ %5, %13 ]
  %.012 = phi float [ %5, %9 ], [ %3, %11 ], [ %.23, %13 ]
  %16 = phi i1 [ %10, %9 ], [ false, %11 ], [ false, %13 ]
  %17 = phi i1 [ false, %9 ], [ false, %11 ], [ true, %13 ]
  %18 = fsub float %.013, %.012
  %19 = fcmp olt float %18, 0x3F1A36E2E0000000
  br i1 %19, label %37, label %20

20:                                               ; preds = %15
  br i1 %16, label %21, label %28

21:                                               ; preds = %20
  %22 = fsub float %5, %8
  %23 = fdiv float %22, %18
  %24 = fpext float %23 to double
  %25 = call double @fmod(double noundef %24, double noundef 6.000000e+00) #4
  %26 = fmul double %25, 6.000000e+01
  %27 = fptrunc double %26 to float
  store float %27, ptr %2, align 8, !tbaa !12
  br label %41

28:                                               ; preds = %20
  %29 = fsub float %8, %3
  %30 = fdiv float %29, %18
  br i1 %17, label %31, label %34

31:                                               ; preds = %28
  %32 = fadd float %30, 2.000000e+00
  %33 = fmul float %32, 6.000000e+01
  store float %33, ptr %2, align 8, !tbaa !12
  br label %41

34:                                               ; preds = %28
  %35 = fadd float %30, 4.000000e+00
  %36 = fmul float %35, 6.000000e+01
  store float %36, ptr %2, align 8, !tbaa !12
  br label %41

37:                                               ; preds = %15
  store float 0.000000e+00, ptr %2, align 8, !tbaa !12
  %38 = fadd float %.013, %.012
  %39 = fmul float %38, 5.000000e-01
  %40 = getelementptr inbounds i8, ptr %2, i64 8
  store float %39, ptr %40, align 8, !tbaa !14
  br label %52

41:                                               ; preds = %21, %34, %31
  %42 = fadd float %.013, %.012
  %43 = fmul float %42, 5.000000e-01
  %44 = getelementptr inbounds i8, ptr %2, i64 8
  store float %43, ptr %44, align 8, !tbaa !14
  %45 = fpext float %18 to double
  %46 = call float @llvm.fmuladd.f32(float %43, float 2.000000e+00, float -1.000000e+00)
  %47 = call float @llvm.fabs.f32(float %46)
  %48 = fpext float %47 to double
  %49 = fsub double 1.000000e+00, %48
  %50 = fdiv double %45, %49
  %51 = fptrunc double %50 to float
  br label %52

52:                                               ; preds = %41, %37
  %.sink = phi float [ %51, %41 ], [ 0.000000e+00, %37 ]
  %53 = phi ptr [ %44, %41 ], [ %40, %37 ]
  %54 = getelementptr inbounds i8, ptr %2, i64 4
  store float %.sink, ptr %54, align 4, !tbaa !15
  %55 = getelementptr inbounds i8, ptr %0, i64 12
  %56 = load float, ptr %55, align 4, !tbaa !16
  %57 = getelementptr inbounds i8, ptr %2, i64 12
  store float %56, ptr %57, align 4, !tbaa !17
  %.fca.0.load = load <2 x float>, ptr %2, align 8
  %.fca.0.insert = insertvalue { <2 x float>, <2 x float> } poison, <2 x float> %.fca.0.load, 0
  %.fca.1.load = load <2 x float>, ptr %53, align 4
  %.fca.1.insert = insertvalue { <2 x float>, <2 x float> } %.fca.0.insert, <2 x float> %.fca.1.load, 1
  ret { <2 x float>, <2 x float> } %.fca.1.insert
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3rmg9ColorHSLAC2Ev(ptr noundef nonnull align 4 dereferenceable(16)) unnamed_addr #0 align 2

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @fmod(double noundef, double noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fabs.f32(float) #3

attributes #0 = { 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 nofree nounwind willreturn memory(write) "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 nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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, !7, i64 0}
!6 = !{!"_ZTSN3rmg9ColorRGBAE", !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}
!12 = !{!13, !7, i64 0}
!13 = !{!"_ZTSN3rmg9ColorHSLAE", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12}
!14 = !{!13, !7, i64 8}
!15 = !{!13, !7, i64 4}
!16 = !{!6, !7, i64 12}
!17 = !{!13, !7, i64 12}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass