#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
double floor(double);
void hsv2rgb(double h, double s, double v, double *r, double *g, double *b) {
  h /= 360.0;
  h = 6 * (h - floor(h));
  if (s == 0.0) {
    *r = *g = *b = v;
  } else {
    int i = (int)h;
    double t, u, w;
    h = h - floor(h);
    u = v * (s * (1.0 - h));
    w = v * (1.0 - s);
    t = v * (s * h + 1.0 - s);
    switch (i) {
    case 0:
      *r = v;
      *g = t;
      *b = w;
      break;
    case 1:
      *r = u;
      *g = v;
      *b = w;
      break;
    case 2:
      *r = w;
      *g = v;
      *b = t;
      break;
    case 3:
      *r = w;
      *g = u;
      *b = v;
      break;
    case 4:
      *r = t;
      *g = w;
      *b = v;
      break;
    case 5:
      *r = v;
      *g = w;
      *b = u;
      break;
    }
  }
}


x86 assembly (clang, -O0):
<hsv2rgb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
mov    %rdi,-0x20(%rbp)
mov    %rsi,-0x28(%rbp)
mov    %rdx,-0x30(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xec8(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1030 <floor@plt>
movsd  -0x58(%rbp),%xmm1
subsd  %xmm0,%xmm1
movsd  0xe92(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11b1 <hsv2rgb+0xa1>
jp     11b1 <hsv2rgb+0xa1>
movsd  -0x18(%rbp),%xmm0
mov    -0x30(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    1372 <hsv2rgb+0x262>
cvttsd2si -0x8(%rbp),%eax
mov    %eax,-0x34(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
call   1030 <floor@plt>
movaps %xmm0,%xmm1
movsd  -0x68(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  -0x8(%rbp),%xmm4
movsd  0xe20(%rip),%xmm3
movaps %xmm3,%xmm2
subsd  %xmm4,%xmm2
mulsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm2
movaps %xmm3,%xmm1
subsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm2
movsd  -0x8(%rbp),%xmm4
movaps %xmm2,%xmm1
mulsd  %xmm4,%xmm1
addsd  %xmm3,%xmm1
subsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x34(%rbp),%eax
mov    %rax,-0x60(%rbp)
sub    $0x5,%rax
ja     136d <hsv2rgb+0x25d>
mov    -0x60(%rbp),%rax
lea    0xdb7(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movsd  -0x18(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x40(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x50(%rbp),%xmm0
mov    -0x30(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    136d <hsv2rgb+0x25d>
movsd  -0x48(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x18(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x50(%rbp),%xmm0
mov    -0x30(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    136d <hsv2rgb+0x25d>
movsd  -0x50(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x18(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x40(%rbp),%xmm0
mov    -0x30(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    136d <hsv2rgb+0x25d>
movsd  -0x50(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x48(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x18(%rbp),%xmm0
mov    -0x30(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    136d <hsv2rgb+0x25d>
movsd  -0x40(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x50(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x18(%rbp),%xmm0
mov    -0x30(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    136d <hsv2rgb+0x25d>
movsd  -0x18(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x50(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x48(%rbp),%xmm0
mov    -0x30(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    1372 <hsv2rgb+0x262>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hsv2rgb>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
movsd  %xmm2,0x8(%rsp)
movsd  %xmm1,0x10(%rsp)
divsd  0xec8(%rip),%xmm0
movsd  %xmm0,(%rsp)
call   1030 <floor@plt>
xorpd  %xmm1,%xmm1
movsd  0x10(%rsp),%xmm2
ucomisd %xmm1,%xmm2
jne    1174 <hsv2rgb+0x64>
jp     1174 <hsv2rgb+0x64>
movsd  0x8(%rsp),%xmm0
movsd  %xmm0,(%r14)
movsd  %xmm0,(%r15)
movsd  %xmm0,(%rbx)
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
movsd  (%rsp),%xmm1
subsd  %xmm0,%xmm1
mulsd  0xe83(%rip),%xmm1
cvttsd2si %xmm1,%r12d
movsd  %xmm1,(%rsp)
movapd %xmm1,%xmm0
call   1030 <floor@plt>
cmp    $0x5,%r12d
ja     1168 <hsv2rgb+0x58>
movsd  (%rsp),%xmm3
subsd  %xmm0,%xmm3
movsd  0xe61(%rip),%xmm1
movapd %xmm1,%xmm0
subsd  %xmm3,%xmm0
movsd  0x10(%rsp),%xmm4
mulsd  %xmm4,%xmm0
movsd  0x8(%rsp),%xmm2
mulsd  %xmm2,%xmm0
mulsd  %xmm4,%xmm3
addsd  %xmm1,%xmm3
subsd  %xmm4,%xmm1
mulsd  %xmm2,%xmm1
subsd  %xmm4,%xmm3
mulsd  %xmm2,%xmm3
lea    0xe2e(%rip),%rax
movslq (%rax,%r12,4),%rcx
add    %rax,%rcx
jmp    *%rcx
movsd  %xmm2,(%rbx)
movsd  %xmm3,(%r15)
movsd  %xmm1,(%r14)
jmp    1168 <hsv2rgb+0x58>
movsd  %xmm0,(%rbx)
movsd  %xmm2,(%r15)
movsd  %xmm1,(%r14)
jmp    1168 <hsv2rgb+0x58>
movsd  %xmm1,(%rbx)
movsd  %xmm2,(%r15)
movsd  %xmm3,(%r14)
jmp    1168 <hsv2rgb+0x58>
movsd  %xmm1,(%rbx)
movsd  %xmm0,(%r15)
movsd  %xmm2,(%r14)
jmp    1168 <hsv2rgb+0x58>
movsd  %xmm3,(%rbx)
movsd  %xmm1,(%r15)
movsd  %xmm2,(%r14)
jmp    1168 <hsv2rgb+0x58>
movsd  %xmm2,(%rbx)
movsd  %xmm1,(%r15)
movsd  %xmm0,(%r14)
jmp    1168 <hsv2rgb+0x58>

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

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