user: Please show me the C implementation that matches the assembly code listed below:

```asm
<hsv_to_rgb>:
  endbr64
  movapd %xmm0,%xmm3
  pxor   %xmm0,%xmm0
  comisd %xmm3,%xmm0
  ja     L141
  comisd %xmm1,%xmm0
  ja     L21
L33:
  comisd D29(%rip),%xmm3
  jbe    L191
  movsd  D29(%rip),%xmm3
L191:
  comisd D29(%rip),%xmm1
  jbe    L26
  movsd  D29(%rip),%xmm1
L26:
  movslq %edi,%rax
  imul   $0xffffffffb60b60b7,%rax,%rax
  shr    $0x20,%rax
  add    %edi,%eax
  sar    $0x8,%eax
  mov    %edi,%r8d
  sar    $0x1f,%r8d
  sub    %r8d,%eax
  imul   $0x168,%eax,%eax
  sub    %eax,%edi
  pxor   %xmm0,%xmm0
  cvtsi2sd %edi,%xmm0
  divsd  D9(%rip),%xmm0
  cvttsd2si %xmm0,%eax
  pxor   %xmm4,%xmm4
  cvtsi2sd %eax,%xmm4
  movapd %xmm0,%xmm2
  subsd  %xmm4,%xmm2
  movsd  D29(%rip),%xmm0
  movapd %xmm0,%xmm4
  subsd  %xmm3,%xmm4
  mulsd  %xmm1,%xmm4
  movapd %xmm0,%xmm5
  subsd  %xmm2,%xmm5
  mulsd  %xmm3,%xmm5
  subsd  %xmm5,%xmm0
  mulsd  %xmm1,%xmm0
  test   %eax,%eax
  je     L74
  mulsd  %xmm3,%xmm2
  movsd  D29(%rip),%xmm3
  subsd  %xmm2,%xmm3
  mulsd  %xmm1,%xmm3
  cmp    $0x3,%eax
  je     L181
  cmp    $0x3,%eax
  jg     L144
  cmp    $0x1,%eax
  je     L169
  cmp    $0x2,%eax
  jne    L87
  movq   %xmm1,%rax
  movapd %xmm4,%xmm1
  movapd %xmm0,%xmm4
  movq   %rax,%xmm0
L74:
  movsd  D33(%rip),%xmm2
  mulsd  %xmm2,%xmm1
  cvttsd2si %xmm1,%eax
  mov    %ax,(%rsi)
  mulsd  %xmm2,%xmm0
  cvttsd2si %xmm0,%eax
  mov    %ax,(%rdx)
  mulsd  %xmm2,%xmm4
  cvttsd2si %xmm4,%eax
  mov    %ax,(%rcx)
  ret
L144:
  cmp    $0x4,%eax
  jne    L199
  movq   %xmm1,%rax
  movapd %xmm0,%xmm1
  movapd %xmm4,%xmm0
  movq   %rax,%xmm4
  jmp    L74
L181:
  movapd %xmm3,%xmm0
  movq   %xmm1,%rax
  movapd %xmm4,%xmm1
  movq   %rax,%xmm4
  jmp    L74
L169:
  movapd %xmm1,%xmm0
  movapd %xmm3,%xmm1
  jmp    L74
L87:
  movapd %xmm4,%xmm0
  movapd %xmm3,%xmm4
  jmp    L74
L199:
  movapd %xmm4,%xmm0
  movapd %xmm3,%xmm4
  jmp    L74
L21:
  comisd D29(%rip),%xmm3
  jbe    L72
  movsd  D29(%rip),%xmm3
  pxor   %xmm1,%xmm1
  jmp    L26
L72:
  pxor   %xmm1,%xmm1
  jmp    L26
L141:
  pxor   %xmm0,%xmm0
  movapd %xmm0,%xmm3
  comisd %xmm1,%xmm0
  jbe    L33
  pxor   %xmm3,%xmm3
  movapd %xmm3,%xmm1
  jmp    L26
```

tool_calls: name: unpack_data
arguments: data_label: D29
data_type: byte[16]
name: unpack_data
arguments: data_label: D9
data_type: f64
name: unpack_data
arguments: data_label: D33
data_type: byte[8]

tool: {"D29": [0x00,0x00,0x00,0x00,0x00,0x00,0xf0,0x3f,0x00,0x00,0x00,0x00,0x00,0x00,0x4e,0x40]}

tool: D9: 60

tool: {"D33": [0x00,0x00,0x00,0x00,0xe0,0xff,0xef,0x40]}

assistant: ```c
void hsv_to_rgb(int h, double s, double v, unsigned short *r, unsigned short *g, unsigned short *b) {
  double H, S, V, R, G, B;
  double p1, p2, p3;
  double f;
  int i;
  if (s < 0)
    s = 0;
  if (v < 0)
    v = 0;
  if (s > 1)
    s = 1;
  if (v > 1)
    v = 1;
  S = s;
  V = v;
  H = (h % 360) / 60.0;
  i = H;
  f = H - i;
  p1 = V * (1 - S);
  p2 = V * (1 - (S * f));
  p3 = V * (1 - (S * (1 - f)));
  if (i == 0) {
    R = V;
    G = p3;
    B = p1;
  } else if (i == 1) {
    R = p2;
    G = V;
    B = p1;
  } else if (i == 2) {
    R = p1;
    G = V;
    B = p3;
  } else if (i == 3) {
    R = p1;
    G = p2;
    B = V;
  } else if (i == 4) {
    R = p3;
    G = p1;
    B = V;
  } else {
    R = V;
    G = p1;
    B = p2;
  }
  *r = R * 65535;
  *g = G * 65535;
  *b = B * 65535;
}
```