; LLVM IR from awawa-dev/HyperHDR :: sources/image/ColorRgb.ll (ZN8ColorRgb7hsv2rgbEthhRhS0_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: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.round.f64(double) #2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN8ColorRgb7hsv2rgbEthhRhS0_S0_(i16 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) #3 align 2 {
  %7 = alloca i16, align 2
  %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 float, align 4
  %14 = alloca float, align 4
  %15 = alloca float, align 4
  %16 = alloca float, align 4
  %17 = alloca float, align 4
  %18 = alloca i64, align 8
  %19 = alloca float, align 4
  %20 = alloca float, align 4
  %21 = alloca float, align 4
  %22 = alloca float, align 4
  %23 = alloca float, align 4
  store i16 %0, ptr %7, align 2, !tbaa !5
  store i8 %1, ptr %8, align 1, !tbaa !9
  store i8 %2, ptr %9, align 1, !tbaa !9
  store ptr %3, ptr %10, align 8, !tbaa !10
  store ptr %4, ptr %11, align 8, !tbaa !10
  store ptr %5, ptr %12, align 8, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #5
  %24 = load i16, ptr %7, align 2, !tbaa !5
  %25 = uitofp i16 %24 to float
  store float %25, ptr %13, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %20) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %21) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %22) #5
  %26 = load i8, ptr %8, align 1, !tbaa !9
  %27 = zext i8 %26 to i32
  %28 = sitofp i32 %27 to double
  %29 = fdiv double %28, 2.550000e+02
  %30 = fptrunc double %29 to float
  store float %30, ptr %22, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %23) #5
  %31 = load i8, ptr %9, align 1, !tbaa !9
  %32 = zext i8 %31 to i32
  %33 = sitofp i32 %32 to double
  %34 = fdiv double %33, 2.550000e+02
  %35 = fptrunc double %34 to float
  store float %35, ptr %23, align 4, !tbaa !12
  %36 = load float, ptr %22, align 4, !tbaa !12
  %37 = fcmp oeq float %36, 0.000000e+00
  br i1 %37, label %38, label %42

38:                                               ; preds = %6
  %39 = load float, ptr %23, align 4, !tbaa !12
  store float %39, ptr %19, align 4, !tbaa !12
  %40 = load float, ptr %23, align 4, !tbaa !12
  store float %40, ptr %20, align 4, !tbaa !12
  %41 = load float, ptr %23, align 4, !tbaa !12
  store float %41, ptr %21, align 4, !tbaa !12
  br label %133

42:                                               ; preds = %6
  br label %43

43:                                               ; preds = %47, %42
  %44 = load float, ptr %13, align 4, !tbaa !12
  %45 = fpext float %44 to double
  %46 = fcmp olt double %45, 0.000000e+00
  br i1 %46, label %47, label %52

47:                                               ; preds = %43
  %48 = load float, ptr %13, align 4, !tbaa !12
  %49 = fpext float %48 to double
  %50 = fadd double %49, 3.600000e+02
  %51 = fptrunc double %50 to float
  store float %51, ptr %13, align 4, !tbaa !12
  br label %43, !llvm.loop !14

52:                                               ; preds = %43
  br label %53

53:                                               ; preds = %57, %52
  %54 = load float, ptr %13, align 4, !tbaa !12
  %55 = fpext float %54 to double
  %56 = fcmp ogt double %55, 3.600000e+02
  br i1 %56, label %57, label %62

57:                                               ; preds = %53
  %58 = load float, ptr %13, align 4, !tbaa !12
  %59 = fpext float %58 to double
  %60 = fsub double %59, 3.600000e+02
  %61 = fptrunc double %60 to float
  store float %61, ptr %13, align 4, !tbaa !12
  br label %53, !llvm.loop !16

62:                                               ; preds = %53
  %63 = load float, ptr %13, align 4, !tbaa !12
  %64 = fpext float %63 to double
  %65 = fcmp oge double %64, 3.600000e+02
  br i1 %65, label %66, label %67

66:                                               ; preds = %62
  store float 0.000000e+00, ptr %13, align 4, !tbaa !12
  br label %67

67:                                               ; preds = %66, %62
  %68 = load float, ptr %13, align 4, !tbaa !12
  %69 = fpext float %68 to double
  %70 = fdiv double %69, 6.000000e+01
  %71 = fptrunc double %70 to float
  store float %71, ptr %13, align 4, !tbaa !12
  %72 = load float, ptr %13, align 4, !tbaa !12
  %73 = call noundef float @_ZSt5truncf(float noundef %72)
  %74 = fptosi float %73 to i64
  store i64 %74, ptr %18, align 8, !tbaa !17
  %75 = load float, ptr %13, align 4, !tbaa !12
  %76 = load i64, ptr %18, align 8, !tbaa !17
  %77 = sitofp i64 %76 to float
  %78 = fsub float %75, %77
  store float %78, ptr %17, align 4, !tbaa !12
  %79 = load float, ptr %23, align 4, !tbaa !12
  %80 = fpext float %79 to double
  %81 = load float, ptr %22, align 4, !tbaa !12
  %82 = fpext float %81 to double
  %83 = fsub double 1.000000e+00, %82
  %84 = fmul double %80, %83
  %85 = fptrunc double %84 to float
  store float %85, ptr %14, align 4, !tbaa !12
  %86 = load float, ptr %23, align 4, !tbaa !12
  %87 = fpext float %86 to double
  %88 = load float, ptr %22, align 4, !tbaa !12
  %89 = load float, ptr %17, align 4, !tbaa !12
  %90 = fmul float %88, %89
  %91 = fpext float %90 to double
  %92 = fsub double 1.000000e+00, %91
  %93 = fmul double %87, %92
  %94 = fptrunc double %93 to float
  store float %94, ptr %15, align 4, !tbaa !12
  %95 = load float, ptr %23, align 4, !tbaa !12
  %96 = fpext float %95 to double
  %97 = load float, ptr %22, align 4, !tbaa !12
  %98 = fpext float %97 to double
  %99 = load float, ptr %17, align 4, !tbaa !12
  %100 = fpext float %99 to double
  %101 = fsub double 1.000000e+00, %100
  %102 = fneg double %98
  %103 = call double @llvm.fmuladd.f64(double %102, double %101, double 1.000000e+00)
  %104 = fmul double %96, %103
  %105 = fptrunc double %104 to float
  store float %105, ptr %16, align 4, !tbaa !12
  %106 = load i64, ptr %18, align 8, !tbaa !17
  switch i64 %106, label %128 [
    i64 0, label %107
    i64 1, label %111
    i64 2, label %115
    i64 3, label %119
    i64 4, label %123
    i64 5, label %127
  ]

107:                                              ; preds = %67
  %108 = load float, ptr %23, align 4, !tbaa !12
  store float %108, ptr %19, align 4, !tbaa !12
  %109 = load float, ptr %16, align 4, !tbaa !12
  store float %109, ptr %20, align 4, !tbaa !12
  %110 = load float, ptr %14, align 4, !tbaa !12
  store float %110, ptr %21, align 4, !tbaa !12
  br label %132

111:                                              ; preds = %67
  %112 = load float, ptr %15, align 4, !tbaa !12
  store float %112, ptr %19, align 4, !tbaa !12
  %113 = load float, ptr %23, align 4, !tbaa !12
  store float %113, ptr %20, align 4, !tbaa !12
  %114 = load float, ptr %14, align 4, !tbaa !12
  store float %114, ptr %21, align 4, !tbaa !12
  br label %132

115:                                              ; preds = %67
  %116 = load float, ptr %14, align 4, !tbaa !12
  store float %116, ptr %19, align 4, !tbaa !12
  %117 = load float, ptr %23, align 4, !tbaa !12
  store float %117, ptr %20, align 4, !tbaa !12
  %118 = load float, ptr %16, align 4, !tbaa !12
  store float %118, ptr %21, align 4, !tbaa !12
  br label %132

119:                                              ; preds = %67
  %120 = load float, ptr %14, align 4, !tbaa !12
  store float %120, ptr %19, align 4, !tbaa !12
  %121 = load float, ptr %15, align 4, !tbaa !12
  store float %121, ptr %20, align 4, !tbaa !12
  %122 = load float, ptr %23, align 4, !tbaa !12
  store float %122, ptr %21, align 4, !tbaa !12
  br label %132

123:                                              ; preds = %67
  %124 = load float, ptr %16, align 4, !tbaa !12
  store float %124, ptr %19, align 4, !tbaa !12
  %125 = load float, ptr %14, align 4, !tbaa !12
  store float %125, ptr %20, align 4, !tbaa !12
  %126 = load float, ptr %23, align 4, !tbaa !12
  store float %126, ptr %21, align 4, !tbaa !12
  br label %132

127:                                              ; preds = %67
  br label %128

128:                                              ; preds = %127, %67
  %129 = load float, ptr %23, align 4, !tbaa !12
  store float %129, ptr %19, align 4, !tbaa !12
  %130 = load float, ptr %14, align 4, !tbaa !12
  store float %130, ptr %20, align 4, !tbaa !12
  %131 = load float, ptr %15, align 4, !tbaa !12
  store float %131, ptr %21, align 4, !tbaa !12
  br label %132

132:                                              ; preds = %128, %123, %119, %115, %111, %107
  br label %133

133:                                              ; preds = %132, %38
  %134 = load float, ptr %19, align 4, !tbaa !12
  %135 = fpext float %134 to double
  %136 = fmul double %135, 2.550000e+02
  %137 = call double @llvm.round.f64(double %136)
  %138 = fptosi double %137 to i32
  %139 = call noundef zeroext i8 @_ZN8ColorRgb5clampEi(i32 noundef %138)
  %140 = load ptr, ptr %10, align 8, !tbaa !10
  store i8 %139, ptr %140, align 1, !tbaa !9
  %141 = load float, ptr %20, align 4, !tbaa !12
  %142 = fpext float %141 to double
  %143 = fmul double %142, 2.550000e+02
  %144 = call double @llvm.round.f64(double %143)
  %145 = fptosi double %144 to i32
  %146 = call noundef zeroext i8 @_ZN8ColorRgb5clampEi(i32 noundef %145)
  %147 = load ptr, ptr %11, align 8, !tbaa !10
  store i8 %146, ptr %147, align 1, !tbaa !9
  %148 = load float, ptr %21, align 4, !tbaa !12
  %149 = fpext float %148 to double
  %150 = fmul double %149, 2.550000e+02
  %151 = call double @llvm.round.f64(double %150)
  %152 = fptosi double %151 to i32
  %153 = call noundef zeroext i8 @_ZN8ColorRgb5clampEi(i32 noundef %152)
  %154 = load ptr, ptr %12, align 8, !tbaa !10
  store i8 %153, ptr %154, align 1, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %23) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %22) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %21) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #5
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef float @_ZSt5truncf(float noundef) #4

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

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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 #4 = { 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 #5 = { 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 = !{!"short", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"float", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}
!17 = !{!18, !18, i64 0}
!18 = !{!"long", !7, 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 nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.round.f64(double) #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN8ColorRgb7hsv2rgbEthhRhS0_S0_(i16 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 #2 align 2 {
  %7 = uitofp i8 %1 to double
  %8 = fdiv double %7, 2.550000e+02
  %9 = fptrunc double %8 to float
  %10 = uitofp i8 %2 to double
  %11 = fdiv double %10, 2.550000e+02
  %12 = fptrunc double %11 to float
  %13 = fcmp oeq float %9, 0.000000e+00
  br i1 %13, label %46, label %.preheader

.preheader:                                       ; preds = %6
  %14 = uitofp i16 %0 to float
  %15 = icmp ugt i16 %0, 360
  br i1 %15, label %.lr.ph57, label %._crit_edge

.lr.ph57:                                         ; preds = %.preheader, %.lr.ph57
  %.156 = phi float [ %16, %.lr.ph57 ], [ %14, %.preheader ]
  %16 = fadd float %.156, -3.600000e+02
  %17 = fcmp ogt float %16, 3.600000e+02
  br i1 %17, label %.lr.ph57, label %._crit_edge, !llvm.loop !5

._crit_edge:                                      ; preds = %.lr.ph57, %.preheader
  %.1.lcssa = phi float [ %14, %.preheader ], [ %16, %.lr.ph57 ]
  %18 = fcmp ult float %.1.lcssa, 3.600000e+02
  %19 = fdiv float %.1.lcssa, 6.000000e+01
  %20 = select i1 %18, float %19, float 0.000000e+00
  %21 = tail call noundef float @_ZSt5truncf(float noundef %20)
  %22 = fptosi float %21 to i64
  %23 = sitofp i64 %22 to float
  %24 = fsub float %20, %23
  %25 = fpext float %12 to double
  %26 = fpext float %9 to double
  %27 = fsub double 1.000000e+00, %26
  %28 = fmul double %27, %25
  %29 = fptrunc double %28 to float
  %30 = fmul float %24, %9
  %31 = fpext float %30 to double
  %32 = fsub double 1.000000e+00, %31
  %33 = fmul double %32, %25
  %34 = fptrunc double %33 to float
  %35 = fpext float %24 to double
  %36 = fsub double 1.000000e+00, %35
  %37 = fneg double %26
  %38 = tail call double @llvm.fmuladd.f64(double %37, double %36, double 1.000000e+00)
  %39 = fmul double %38, %25
  %40 = fptrunc double %39 to float
  switch i64 %22, label %45 [
    i64 0, label %46
    i64 1, label %41
    i64 2, label %42
    i64 3, label %43
    i64 4, label %44
  ]

41:                                               ; preds = %._crit_edge
  br label %46

42:                                               ; preds = %._crit_edge
  br label %46

43:                                               ; preds = %._crit_edge
  br label %46

44:                                               ; preds = %._crit_edge
  br label %46

45:                                               ; preds = %._crit_edge
  br label %46

46:                                               ; preds = %._crit_edge, %6, %41, %42, %43, %44, %45
  %.050 = phi float [ %29, %45 ], [ %29, %44 ], [ %34, %43 ], [ %12, %42 ], [ %12, %41 ], [ %12, %6 ], [ %40, %._crit_edge ]
  %.049 = phi float [ %34, %45 ], [ %12, %44 ], [ %12, %43 ], [ %40, %42 ], [ %29, %41 ], [ %12, %6 ], [ %29, %._crit_edge ]
  %.048 = phi float [ %12, %45 ], [ %40, %44 ], [ %29, %43 ], [ %29, %42 ], [ %34, %41 ], [ %12, %6 ], [ %12, %._crit_edge ]
  %47 = fpext float %.048 to double
  %48 = fmul double %47, 2.550000e+02
  %49 = tail call double @llvm.round.f64(double %48)
  %50 = fptosi double %49 to i32
  %51 = tail call noundef zeroext i8 @_ZN8ColorRgb5clampEi(i32 noundef %50)
  store i8 %51, ptr %3, align 1, !tbaa !7
  %52 = fpext float %.050 to double
  %53 = fmul double %52, 2.550000e+02
  %54 = tail call double @llvm.round.f64(double %53)
  %55 = fptosi double %54 to i32
  %56 = tail call noundef zeroext i8 @_ZN8ColorRgb5clampEi(i32 noundef %55)
  store i8 %56, ptr %4, align 1, !tbaa !7
  %57 = fpext float %.049 to double
  %58 = fmul double %57, 2.550000e+02
  %59 = tail call double @llvm.round.f64(double %58)
  %60 = fptosi double %59 to i32
  %61 = tail call noundef zeroext i8 @_ZN8ColorRgb5clampEi(i32 noundef %60)
  store i8 %61, ptr %5, align 1, !tbaa !7
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef float @_ZSt5truncf(float noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

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 nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass