; LLVM IR from ashishzero/karma :: src/modules/core/lin_maths.ll (Z10hsv_to_rgb4Vec3)

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

%union.Vec3 = type { %struct.anon }
%struct.anon = type { float, float, float }

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local { <2 x float>, float } @_Z4vec3fff(float noundef, float noundef, float noundef) #0

; 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) #1

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local { <2 x float>, float } @_Z10hsv_to_rgb4Vec3(<2 x float> %0, float %1) #4 {
  %3 = alloca %union.Vec3, align 4
  %4 = alloca %union.Vec3, align 4
  %5 = alloca { <2 x float>, float }, align 4
  %6 = alloca float, align 4
  %7 = alloca float, align 4
  %8 = alloca float, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca float, align 4
  %12 = alloca float, align 4
  %13 = alloca float, align 4
  %14 = alloca float, align 4
  %15 = alloca %union.Vec3, align 4
  %16 = alloca { <2 x float>, float }, align 8
  %17 = alloca %union.Vec3, align 4
  %18 = alloca { <2 x float>, float }, align 8
  %19 = alloca %union.Vec3, align 4
  %20 = alloca { <2 x float>, float }, align 8
  %21 = alloca %union.Vec3, align 4
  %22 = alloca { <2 x float>, float }, align 8
  %23 = alloca %union.Vec3, align 4
  %24 = alloca { <2 x float>, float }, align 8
  %25 = alloca %union.Vec3, align 4
  %26 = alloca { <2 x float>, float }, align 8
  %27 = alloca { <2 x float>, float }, align 8
  %28 = getelementptr inbounds { <2 x float>, float }, ptr %5, i32 0, i32 0
  store <2 x float> %0, ptr %28, align 4
  %29 = getelementptr inbounds { <2 x float>, float }, ptr %5, i32 0, i32 1
  store float %1, ptr %29, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %4, ptr align 4 %5, i64 12, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  %30 = getelementptr inbounds %struct.anon, ptr %4, i32 0, i32 0
  %31 = load float, ptr %30, align 4, !tbaa !5
  store float %31, ptr %6, align 4, !tbaa !8
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #6
  %32 = getelementptr inbounds %struct.anon, ptr %4, i32 0, i32 1
  %33 = load float, ptr %32, align 4, !tbaa !5
  store float %33, ptr %7, align 4, !tbaa !8
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  %34 = getelementptr inbounds %struct.anon, ptr %4, i32 0, i32 2
  %35 = load float, ptr %34, align 4, !tbaa !5
  store float %35, ptr %8, align 4, !tbaa !8
  %36 = load float, ptr %7, align 4, !tbaa !8
  %37 = fcmp oeq float %36, 0.000000e+00
  br i1 %37, label %38, label %43

38:                                               ; preds = %2
  %39 = load float, ptr %8, align 4, !tbaa !8
  %40 = getelementptr inbounds %struct.anon, ptr %3, i32 0, i32 2
  store float %39, ptr %40, align 4, !tbaa !5
  %41 = getelementptr inbounds %struct.anon, ptr %3, i32 0, i32 1
  store float %39, ptr %41, align 4, !tbaa !5
  %42 = getelementptr inbounds %struct.anon, ptr %3, i32 0, i32 0
  store float %39, ptr %42, align 4, !tbaa !5
  store i32 1, ptr %9, align 4
  br label %109

43:                                               ; preds = %2
  %44 = load float, ptr %6, align 4, !tbaa !8
  %45 = call float @fmodf(float noundef %44, float noundef 1.000000e+00) #6
  %46 = fdiv float %45, 0x3FC5555560000000
  store float %46, ptr %6, align 4, !tbaa !8
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #6
  %47 = load float, ptr %6, align 4, !tbaa !8
  %48 = fptosi float %47 to i32
  store i32 %48, ptr %10, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #6
  %49 = load float, ptr %6, align 4, !tbaa !8
  %50 = load i32, ptr %10, align 4, !tbaa !10
  %51 = sitofp i32 %50 to float
  %52 = fsub float %49, %51
  store float %52, ptr %11, align 4, !tbaa !8
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #6
  %53 = load float, ptr %8, align 4, !tbaa !8
  %54 = load float, ptr %7, align 4, !tbaa !8
  %55 = fsub float 1.000000e+00, %54
  %56 = fmul float %53, %55
  store float %56, ptr %12, align 4, !tbaa !8
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #6
  %57 = load float, ptr %8, align 4, !tbaa !8
  %58 = load float, ptr %7, align 4, !tbaa !8
  %59 = load float, ptr %11, align 4, !tbaa !8
  %60 = fneg float %58
  %61 = call float @llvm.fmuladd.f32(float %60, float %59, float 1.000000e+00)
  %62 = fmul float %57, %61
  store float %62, ptr %13, align 4, !tbaa !8
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #6
  %63 = load float, ptr %8, align 4, !tbaa !8
  %64 = load float, ptr %7, align 4, !tbaa !8
  %65 = load float, ptr %11, align 4, !tbaa !8
  %66 = fsub float 1.000000e+00, %65
  %67 = fneg float %64
  %68 = call float @llvm.fmuladd.f32(float %67, float %66, float 1.000000e+00)
  %69 = fmul float %63, %68
  store float %69, ptr %14, align 4, !tbaa !8
  %70 = load i32, ptr %10, align 4, !tbaa !10
  switch i32 %70, label %102 [
    i32 0, label %71
    i32 1, label %77
    i32 2, label %83
    i32 3, label %89
    i32 4, label %95
    i32 5, label %101
  ]

71:                                               ; preds = %43
  call void @llvm.lifetime.start.p0(i64 12, ptr %15) #6
  %72 = load float, ptr %8, align 4, !tbaa !8
  %73 = load float, ptr %14, align 4, !tbaa !8
  %74 = load float, ptr %12, align 4, !tbaa !8
  %75 = call { <2 x float>, float } @_Z4vec3fff(float noundef %72, float noundef %73, float noundef %74)
  %76 = getelementptr inbounds %union.Vec3, ptr %15, i32 0, i32 0
  store { <2 x float>, float } %75, ptr %16, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %76, ptr align 8 %16, i64 12, i1 false)
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %3, ptr align 4 %15, i64 12, i1 false), !tbaa.struct !12
  call void @llvm.lifetime.end.p0(i64 12, ptr %15) #6
  br label %108

77:                                               ; preds = %43
  call void @llvm.lifetime.start.p0(i64 12, ptr %17) #6
  %78 = load float, ptr %13, align 4, !tbaa !8
  %79 = load float, ptr %8, align 4, !tbaa !8
  %80 = load float, ptr %12, align 4, !tbaa !8
  %81 = call { <2 x float>, float } @_Z4vec3fff(float noundef %78, float noundef %79, float noundef %80)
  %82 = getelementptr inbounds %union.Vec3, ptr %17, i32 0, i32 0
  store { <2 x float>, float } %81, ptr %18, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %82, ptr align 8 %18, i64 12, i1 false)
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %3, ptr align 4 %17, i64 12, i1 false), !tbaa.struct !12
  call void @llvm.lifetime.end.p0(i64 12, ptr %17) #6
  br label %108

83:                                               ; preds = %43
  call void @llvm.lifetime.start.p0(i64 12, ptr %19) #6
  %84 = load float, ptr %12, align 4, !tbaa !8
  %85 = load float, ptr %8, align 4, !tbaa !8
  %86 = load float, ptr %14, align 4, !tbaa !8
  %87 = call { <2 x float>, float } @_Z4vec3fff(float noundef %84, float noundef %85, float noundef %86)
  %88 = getelementptr inbounds %union.Vec3, ptr %19, i32 0, i32 0
  store { <2 x float>, float } %87, ptr %20, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %88, ptr align 8 %20, i64 12, i1 false)
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %3, ptr align 4 %19, i64 12, i1 false), !tbaa.struct !12
  call void @llvm.lifetime.end.p0(i64 12, ptr %19) #6
  br label %108

89:                                               ; preds = %43
  call void @llvm.lifetime.start.p0(i64 12, ptr %21) #6
  %90 = load float, ptr %12, align 4, !tbaa !8
  %91 = load float, ptr %13, align 4, !tbaa !8
  %92 = load float, ptr %8, align 4, !tbaa !8
  %93 = call { <2 x float>, float } @_Z4vec3fff(float noundef %90, float noundef %91, float noundef %92)
  %94 = getelementptr inbounds %union.Vec3, ptr %21, i32 0, i32 0
  store { <2 x float>, float } %93, ptr %22, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %94, ptr align 8 %22, i64 12, i1 false)
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %3, ptr align 4 %21, i64 12, i1 false), !tbaa.struct !12
  call void @llvm.lifetime.end.p0(i64 12, ptr %21) #6
  br label %108

95:                                               ; preds = %43
  call void @llvm.lifetime.start.p0(i64 12, ptr %23) #6
  %96 = load float, ptr %14, align 4, !tbaa !8
  %97 = load float, ptr %12, align 4, !tbaa !8
  %98 = load float, ptr %8, align 4, !tbaa !8
  %99 = call { <2 x float>, float } @_Z4vec3fff(float noundef %96, float noundef %97, float noundef %98)
  %100 = getelementptr inbounds %union.Vec3, ptr %23, i32 0, i32 0
  store { <2 x float>, float } %99, ptr %24, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %100, ptr align 8 %24, i64 12, i1 false)
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %3, ptr align 4 %23, i64 12, i1 false), !tbaa.struct !12
  call void @llvm.lifetime.end.p0(i64 12, ptr %23) #6
  br label %108

101:                                              ; preds = %43
  br label %102

102:                                              ; preds = %101, %43
  call void @llvm.lifetime.start.p0(i64 12, ptr %25) #6
  %103 = load float, ptr %8, align 4, !tbaa !8
  %104 = load float, ptr %12, align 4, !tbaa !8
  %105 = load float, ptr %13, align 4, !tbaa !8
  %106 = call { <2 x float>, float } @_Z4vec3fff(float noundef %103, float noundef %104, float noundef %105)
  %107 = getelementptr inbounds %union.Vec3, ptr %25, i32 0, i32 0
  store { <2 x float>, float } %106, ptr %26, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %107, ptr align 8 %26, i64 12, i1 false)
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %3, ptr align 4 %25, i64 12, i1 false), !tbaa.struct !12
  call void @llvm.lifetime.end.p0(i64 12, ptr %25) #6
  br label %108

108:                                              ; preds = %102, %95, %89, %83, %77, %71
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #6
  br label %109

109:                                              ; preds = %108, %38
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  %110 = getelementptr inbounds %union.Vec3, ptr %3, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %27, ptr align 4 %110, i64 12, i1 false)
  %111 = load { <2 x float>, float }, ptr %27, align 8
  ret { <2 x float>, float } %111
}

; Function Attrs: nounwind
declare float @fmodf(float noundef, float noundef) #5

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { mustprogress uwtable "min-legal-vector-width"="64" "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 "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 #6 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"float", !6, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !6, i64 0}
!12 = !{i64 0, i64 12, !5}


; 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 { <2 x float>, float } @_Z4vec3fff(float noundef, float noundef, float noundef) local_unnamed_addr #0

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local { <2 x float>, float } @_Z10hsv_to_rgb4Vec3(<2 x float> %0, float %1) local_unnamed_addr #2 {
  %.sroa.067.4.vec.extract = extractelement <2 x float> %0, i64 1
  %3 = fcmp oeq float %.sroa.067.4.vec.extract, 0.000000e+00
  br i1 %3, label %4, label %6

4:                                                ; preds = %2
  %5 = insertelement <2 x float> poison, float %1, i64 0
  %.sroa.068.0.vec.insert = shufflevector <2 x float> %5, <2 x float> poison, <2 x i32> zeroinitializer
  br label %33

6:                                                ; preds = %2
  %.sroa.067.0.vec.extract = extractelement <2 x float> %0, i64 0
  %7 = tail call float @fmodf(float noundef %.sroa.067.0.vec.extract, float noundef 1.000000e+00) #4
  %8 = fdiv float %7, 0x3FC5555560000000
  %9 = fptosi float %8 to i32
  %10 = sitofp i32 %9 to float
  %11 = fsub float %8, %10
  %12 = fsub float 1.000000e+00, %.sroa.067.4.vec.extract
  %13 = fmul float %12, %1
  %14 = fneg float %.sroa.067.4.vec.extract
  %15 = tail call float @llvm.fmuladd.f32(float %14, float %11, float 1.000000e+00)
  %16 = fmul float %15, %1
  %17 = fsub float 1.000000e+00, %11
  %18 = tail call float @llvm.fmuladd.f32(float %14, float %17, float 1.000000e+00)
  %19 = fmul float %18, %1
  switch i32 %9, label %30 [
    i32 0, label %20
    i32 1, label %22
    i32 2, label %24
    i32 3, label %26
    i32 4, label %28
  ]

20:                                               ; preds = %6
  %21 = tail call { <2 x float>, float } @_Z4vec3fff(float noundef %1, float noundef %19, float noundef %13)
  br label %32

22:                                               ; preds = %6
  %23 = tail call { <2 x float>, float } @_Z4vec3fff(float noundef %16, float noundef %1, float noundef %13)
  br label %32

24:                                               ; preds = %6
  %25 = tail call { <2 x float>, float } @_Z4vec3fff(float noundef %13, float noundef %1, float noundef %19)
  br label %32

26:                                               ; preds = %6
  %27 = tail call { <2 x float>, float } @_Z4vec3fff(float noundef %13, float noundef %16, float noundef %1)
  br label %32

28:                                               ; preds = %6
  %29 = tail call { <2 x float>, float } @_Z4vec3fff(float noundef %19, float noundef %13, float noundef %1)
  br label %32

30:                                               ; preds = %6
  %31 = tail call { <2 x float>, float } @_Z4vec3fff(float noundef %1, float noundef %13, float noundef %16)
  br label %32

32:                                               ; preds = %30, %28, %26, %24, %22, %20
  %.pn = phi { <2 x float>, float } [ %31, %30 ], [ %29, %28 ], [ %27, %26 ], [ %25, %24 ], [ %23, %22 ], [ %21, %20 ]
  %.sroa.9.0 = extractvalue { <2 x float>, float } %.pn, 1
  %.sroa.068.0 = extractvalue { <2 x float>, float } %.pn, 0
  br label %33

33:                                               ; preds = %32, %4
  %.sroa.068.1 = phi <2 x float> [ %.sroa.068.0.vec.insert, %4 ], [ %.sroa.068.0, %32 ]
  %.sroa.9.1 = phi float [ %1, %4 ], [ %.sroa.9.0, %32 ]
  %.fca.0.insert = insertvalue { <2 x float>, float } poison, <2 x float> %.sroa.068.1, 0
  %.fca.1.insert = insertvalue { <2 x float>, float } %.fca.0.insert, float %.sroa.9.1, 1
  ret { <2 x float>, float } %.fca.1.insert
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare float @fmodf(float noundef, float noundef) local_unnamed_addr #3

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"="64" "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 = { 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 #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)"}


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