void HSVtoRGB(double *r, double *g, double *b, double h, double s, double v) {
  if (s == 0) {
    *r = *g = *b = v;
    return;
  }
  h /= 60;
  int i = (int)h;
  double f = h - i;
  double p = v * (1 - s);
  if (i & 1) {
    double q = v * (1 - s * f);
    switch (i) {
    case 1:
      *r = q;
      *g = v;
      *b = p;
      break;
    case 3:
      *r = p;
      *g = q;
      *b = v;
      break;
    case 5:
      *r = v;
      *g = p;
      *b = q;
      break;
    }
  } else {
    double t = v * (1 - s * (1 - f));
    switch (i) {
    case 0:
      *r = v;
      *g = t;
      *b = p;
      break;
    case 2:
      *r = p;
      *g = v;
      *b = t;
      break;
    case 4:
      *r = t;
      *g = p;
      *b = v;
      break;
    }
  }
}


x86 assembly (clang, -O0):
<HSVtoRGB>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movsd  %xmm0,-0x20(%rbp)
movsd  %xmm1,-0x28(%rbp)
movsd  %xmm2,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1159 <HSVtoRGB+0x59>
jp     1159 <HSVtoRGB+0x59>
movsd  -0x30(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    137e <HSVtoRGB+0x27e>
movsd  -0x20(%rbp),%xmm0
movsd  0xea2(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
cvttsd2si -0x20(%rbp),%eax
mov    %eax,-0x34(%rbp)
movsd  -0x20(%rbp),%xmm0
cvtsi2sdl -0x34(%rbp),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  0xe69(%rip),%xmm1
subsd  -0x28(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x34(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1296 <HSVtoRGB+0x196>
movsd  -0x30(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm2
movsd  -0x40(%rbp),%xmm1
mulsd  %xmm1,%xmm2
movsd  0xe31(%rip),%xmm1
subsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x5c(%rbp)
sub    $0x1,%eax
je     1212 <HSVtoRGB+0x112>
jmp    11f0 <HSVtoRGB+0xf0>
mov    -0x5c(%rbp),%eax
sub    $0x3,%eax
je     123e <HSVtoRGB+0x13e>
jmp    1201 <HSVtoRGB+0x101>
mov    -0x5c(%rbp),%eax
sub    $0x5,%eax
je     126a <HSVtoRGB+0x16a>
jmp    1291 <HSVtoRGB+0x191>
movsd  -0x50(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x30(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x48(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    1291 <HSVtoRGB+0x191>
movsd  -0x48(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x50(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x30(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    1291 <HSVtoRGB+0x191>
movsd  -0x30(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x48(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x50(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    137e <HSVtoRGB+0x27e>
movsd  -0x30(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm2
movsd  -0x40(%rbp),%xmm4
movsd  0xd53(%rip),%xmm1
movaps %xmm1,%xmm3
subsd  %xmm4,%xmm3
mulsd  %xmm3,%xmm2
subsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x60(%rbp)
test   %eax,%eax
je     12fa <HSVtoRGB+0x1fa>
jmp    12d8 <HSVtoRGB+0x1d8>
mov    -0x60(%rbp),%eax
sub    $0x2,%eax
je     1326 <HSVtoRGB+0x226>
jmp    12e9 <HSVtoRGB+0x1e9>
mov    -0x60(%rbp),%eax
sub    $0x4,%eax
je     1352 <HSVtoRGB+0x252>
jmp    1379 <HSVtoRGB+0x279>
movsd  -0x30(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x58(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x48(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    1379 <HSVtoRGB+0x279>
movsd  -0x48(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x30(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x58(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    1379 <HSVtoRGB+0x279>
movsd  -0x58(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x48(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x30(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    137e <HSVtoRGB+0x27e>
pop    %rbp
ret

x86 assembly (clang, -O2):
<HSVtoRGB>:
xorpd  %xmm3,%xmm3
ucomisd %xmm3,%xmm1
jne    1119 <HSVtoRGB+0x19>
jp     1119 <HSVtoRGB+0x19>
movsd  %xmm2,(%rdx)
movsd  %xmm2,(%rsi)
movsd  %xmm2,(%rdi)
ret
divsd  0xedf(%rip),%xmm0
cvttsd2si %xmm0,%eax
cvttpd2dq %xmm0,%xmm3
cvtdq2pd %xmm3,%xmm3
subsd  %xmm3,%xmm0
movsd  0xecf(%rip),%xmm3
movapd %xmm3,%xmm4
subsd  %xmm1,%xmm4
mulsd  %xmm2,%xmm4
test   $0x1,%al
jne    1178 <HSVtoRGB+0x78>
movapd %xmm3,%xmm5
subsd  %xmm0,%xmm5
mulsd  %xmm5,%xmm1
subsd  %xmm1,%xmm3
mulsd  %xmm2,%xmm3
cmp    $0x4,%eax
je     11a0 <HSVtoRGB+0xa0>
cmp    $0x2,%eax
je     11aa <HSVtoRGB+0xaa>
test   %eax,%eax
jne    11d0 <HSVtoRGB+0xd0>
movsd  %xmm2,(%rdi)
movsd  %xmm3,(%rsi)
movsd  %xmm4,(%rdx)
ret
mulsd  %xmm0,%xmm1
subsd  %xmm1,%xmm3
mulsd  %xmm2,%xmm3
cmp    $0x5,%eax
je     11b7 <HSVtoRGB+0xb7>
cmp    $0x3,%eax
je     11c4 <HSVtoRGB+0xc4>
cmp    $0x1,%eax
jne    11d0 <HSVtoRGB+0xd0>
movsd  %xmm3,(%rdi)
movsd  %xmm2,(%rsi)
movsd  %xmm4,(%rdx)
ret
movsd  %xmm3,(%rdi)
movsd  %xmm4,(%rsi)
jmp    11cc <HSVtoRGB+0xcc>
movsd  %xmm4,(%rdi)
movsd  %xmm2,(%rsi)
movsd  %xmm3,(%rdx)
ret
movsd  %xmm2,(%rdi)
movsd  %xmm4,(%rsi)
movsd  %xmm3,(%rdx)
ret
movsd  %xmm4,(%rdi)
movsd  %xmm3,(%rsi)
movsd  %xmm2,(%rdx)
ret

LLVM IR (-O0):
define void @HSVtoRGB(double* %0, double* %1, double* %2, double %3, double %4, double %5) {
%7 = alloca double*
%8 = alloca double*
%9 = alloca double*
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca i32
%14 = alloca double
%15 = alloca double
%16 = alloca double
%17 = alloca double
store double* %0, double** %7
store double* %1, double** %8
store double* %2, double** %9
store double %3, double* %10
store double %4, double* %11
store double %5, double* %12
%18 = load double, double* %11
%19 = fcmp oeq double %18, 0.000000e+00
br i1 %19, label %20, label %25
20: ; preds = %6
%21 = load double, double* %12
%22 = load double*, double** %9
store double %21, double* %22
%23 = load double*, double** %8
store double %21, double* %23
%24 = load double*, double** %7
store double %21, double* %24
br label %102
25: ; preds = %6
%26 = load double, double* %10
%27 = fdiv double %26, 6.000000e+01
store double %27, double* %10
%28 = load double, double* %10
%29 = fptosi double %28 to i32
store i32 %29, i32* %13
%30 = load double, double* %10
%31 = load i32, i32* %13
%32 = sitofp i32 %31 to double
%33 = fsub double %30, %32
store double %33, double* %14
%34 = load double, double* %12
%35 = load double, double* %11
%36 = fsub double 1.000000e+00, %35
%37 = fmul double %34, %36
store double %37, double* %15
%38 = load i32, i32* %13
%39 = and i32 %38, 1
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %71
41: ; preds = %25
%42 = load double, double* %12
%43 = load double, double* %11
%44 = load double, double* %14
%45 = fneg double %43
%46 = call double @llvm.fmuladd.f64(double %45, double %44, double 1.000000e+00)
%47 = fmul double %42, %46
store double %47, double* %16
%48 = load i32, i32* %13
switch i32 %48, label %70 [
i32 1, label %49
i32 3, label %56
i32 5, label %63
]
49: ; preds = %41
%50 = load double, double* %16
%51 = load double*, double** %7
store double %50, double* %51
%52 = load double, double* %12
%53 = load double*, double** %8
store double %52, double* %53
%54 = load double, double* %15
%55 = load double*, double** %9
store double %54, double* %55
br label %70
56: ; preds = %41
%57 = load double, double* %15
%58 = load double*, double** %7
store double %57, double* %58
%59 = load double, double* %16
%60 = load double*, double** %8
store double %59, double* %60
%61 = load double, double* %12
%62 = load double*, double** %9
store double %61, double* %62
br label %70
63: ; preds = %41
%64 = load double, double* %12
%65 = load double*, double** %7
store double %64, double* %65
%66 = load double, double* %15
%67 = load double*, double** %8
store double %66, double* %67
%68 = load double, double* %16
%69 = load double*, double** %9
store double %68, double* %69
br label %70
70: ; preds = %41, %63, %56, %49
br label %102
71: ; preds = %25
%72 = load double, double* %12
%73 = load double, double* %11
%74 = load double, double* %14
%75 = fsub double 1.000000e+00, %74
%76 = fneg double %73
%77 = call double @llvm.fmuladd.f64(double %76, double %75, double 1.000000e+00)
%78 = fmul double %72, %77
store double %78, double* %17
%79 = load i32, i32* %13
switch i32 %79, label %101 [
i32 0, label %80
i32 2, label %87
i32 4, label %94
]
80: ; preds = %71
%81 = load double, double* %12
%82 = load double*, double** %7
store double %81, double* %82
%83 = load double, double* %17
%84 = load double*, double** %8
store double %83, double* %84
%85 = load double, double* %15
%86 = load double*, double** %9
store double %85, double* %86
br label %101
87: ; preds = %71
%88 = load double, double* %15
%89 = load double*, double** %7
store double %88, double* %89
%90 = load double, double* %12
%91 = load double*, double** %8
store double %90, double* %91
%92 = load double, double* %17
%93 = load double*, double** %9
store double %92, double* %93
br label %101
94: ; preds = %71
%95 = load double, double* %17
%96 = load double*, double** %7
store double %95, double* %96
%97 = load double, double* %15
%98 = load double*, double** %8
store double %97, double* %98
%99 = load double, double* %12
%100 = load double*, double** %9
store double %99, double* %100
br label %101
101: ; preds = %71, %94, %87, %80
br label %102
102: ; preds = %20, %101, %70
ret void
}

LLVM IR (-O2):
define void @HSVtoRGB(double* nocapture writeonly %0, double* nocapture writeonly %1, double* nocapture writeonly %2, double %3, double %4, double %5) {
%7 = fcmp oeq double %4, 0.000000e+00
br i1 %7, label %8, label %9
8: ; preds = %6
store double %5, double* %2
store double %5, double* %1
store double %5, double* %0
br label %33
9: ; preds = %6
%10 = fdiv double %3, 6.000000e+01
%11 = fptosi double %10 to i32
%12 = sitofp i32 %11 to double
%13 = fsub double %10, %12
%14 = fsub double 1.000000e+00, %4
%15 = fmul double %14, %5
%16 = and i32 %11, 1
%17 = icmp eq i32 %16, 0
br i1 %17, label %25, label %18
18: ; preds = %9
%19 = fneg double %4
%20 = tail call double @llvm.fmuladd.f64(double %19, double %13, double 1.000000e+00)
%21 = fmul double %20, %5
switch i32 %11, label %33 [
i32 1, label %22
i32 3, label %23
i32 5, label %24
]
22: ; preds = %18
store double %21, double* %0
store double %5, double* %1
store double %15, double* %2
br label %33
23: ; preds = %18
store double %15, double* %0
store double %21, double* %1
store double %5, double* %2
br label %33
24: ; preds = %18
store double %5, double* %0
store double %15, double* %1
store double %21, double* %2
br label %33
25: ; preds = %9
%26 = fsub double 1.000000e+00, %13
%27 = fneg double %4
%28 = tail call double @llvm.fmuladd.f64(double %27, double %26, double 1.000000e+00)
%29 = fmul double %28, %5
switch i32 %11, label %33 [
i32 0, label %30
i32 2, label %31
i32 4, label %32
]
30: ; preds = %25
store double %5, double* %0
store double %29, double* %1
store double %15, double* %2
br label %33
31: ; preds = %25
store double %15, double* %0
store double %5, double* %1
store double %29, double* %2
br label %33
32: ; preds = %25
store double %29, double* %0
store double %15, double* %1
store double %5, double* %2
br label %33
33: ; preds = %18, %24, %23, %22, %25, %32, %31, %30, %8
ret void
}