#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 */
int floor(double);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, double, int);
int modff(double, float *);
int /*<<< orphan*/ stderr;
void dhsv2rgb(double h, double s, double v, double *r, double *g, double *b) {
  int i;
  double f, m, n, k;
  float trash;
  h = 6 * modff(h, &trash);
  i = floor(h);
  f = h - i;
  m = (1 - s);
  n = (1 - s * f);
  k = (1 - (s * (1 - f)));
  switch (i) {
  case 0:
    *r = 1;
    *g = k;
    *b = m;
    break;
  case 1:
    *r = n;
    *g = 1;
    *b = m;
    break;
  case 2:
    *r = m;
    *g = 1;
    *b = k;
    break;
  case 3:
    *r = m;
    *g = n;
    *b = 1;
    break;
  case 4:
    *r = k;
    *g = m;
    *b = 1;
    break;
  case 5:
    *r = 1;
    *g = m;
    *b = n;
    break;
  default:
    fprintf(stderr, "bad i: %f %d", h, i);
    return;
  }
  f = *r;
  if (f < *g)
    f = *g;
  if (f < *b)
    f = *b;
  f = v / f;
  *r *= f;
  *g *= f;
  *b *= f;
}


x86 assembly (clang, -O0):
<dhsv2rgb>:
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
lea    -0x5c(%rbp),%rdi
call   1030 <modff@plt>
mov    %eax,%ecx
add    %ecx,%ecx
mov    %ecx,%eax
lea    (%rax,%rax,2),%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1050 <floor@plt>
mov    %eax,-0x34(%rbp)
movsd  -0x8(%rbp),%xmm0
cvtsi2sdl -0x34(%rbp),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x10(%rbp),%xmm2
movsd  0xe60(%rip),%xmm0
movaps %xmm0,%xmm1
subsd  %xmm2,%xmm1
movsd  %xmm1,-0x48(%rbp)
movsd  -0x10(%rbp),%xmm2
movsd  -0x40(%rbp),%xmm1
mulsd  %xmm1,%xmm2
movaps %xmm0,%xmm1
subsd  %xmm2,%xmm1
movsd  %xmm1,-0x50(%rbp)
movsd  -0x10(%rbp),%xmm1
movsd  -0x40(%rbp),%xmm3
movaps %xmm0,%xmm2
subsd  %xmm3,%xmm2
mulsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x34(%rbp),%eax
mov    %rax,-0x68(%rbp)
sub    $0x5,%rax
ja     1323 <dhsv2rgb+0x1f3>
mov    -0x68(%rbp),%rax
lea    0xe08(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x20(%rbp),%rax
movsd  0xdeb(%rip),%xmm0
movsd  %xmm0,(%rax)
movsd  -0x58(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x48(%rbp),%xmm0
mov    -0x30(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    1345 <dhsv2rgb+0x215>
movsd  -0x50(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x28(%rbp),%rax
movsd  0xdaf(%rip),%xmm0
movsd  %xmm0,(%rax)
movsd  -0x48(%rbp),%xmm0
mov    -0x30(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    1345 <dhsv2rgb+0x215>
movsd  -0x48(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x28(%rbp),%rax
movsd  0xd80(%rip),%xmm0
movsd  %xmm0,(%rax)
movsd  -0x58(%rbp),%xmm0
mov    -0x30(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    1345 <dhsv2rgb+0x215>
movsd  -0x48(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x50(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x30(%rbp),%rax
movsd  0xd44(%rip),%xmm0
movsd  %xmm0,(%rax)
jmp    1345 <dhsv2rgb+0x215>
movsd  -0x58(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x48(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x30(%rbp),%rax
movsd  0xd15(%rip),%xmm0
movsd  %xmm0,(%rax)
jmp    1345 <dhsv2rgb+0x215>
mov    -0x20(%rbp),%rax
movsd  0xd00(%rip),%xmm0
movsd  %xmm0,(%rax)
movsd  -0x48(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x50(%rbp),%xmm0
mov    -0x30(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    1345 <dhsv2rgb+0x215>
mov    0x2cb6(%rip),%rax
mov    (%rax),%edi
movsd  -0x8(%rbp),%xmm0
mov    -0x34(%rbp),%edx
lea    0xce5(%rip),%rsi
call   1040 <fprintf@plt>
jmp    13dc <dhsv2rgb+0x2ac>
mov    -0x20(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm1
mov    -0x28(%rbp),%rax
movsd  (%rax),%xmm0
ucomisd %xmm1,%xmm0
jbe    1376 <dhsv2rgb+0x246>
mov    -0x28(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm1
mov    -0x30(%rbp),%rax
movsd  (%rax),%xmm0
ucomisd %xmm1,%xmm0
jbe    139a <dhsv2rgb+0x26a>
mov    -0x30(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x18(%rbp),%xmm0
divsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
mov    -0x20(%rbp),%rax
mulsd  (%rax),%xmm0
movsd  %xmm0,(%rax)
movsd  -0x40(%rbp),%xmm0
mov    -0x28(%rbp),%rax
mulsd  (%rax),%xmm0
movsd  %xmm0,(%rax)
movsd  -0x40(%rbp),%xmm0
mov    -0x30(%rbp),%rax
mulsd  (%rax),%xmm0
movsd  %xmm0,(%rax)
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dhsv2rgb>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
movsd  %xmm2,0x10(%rsp)
movsd  %xmm1,0x8(%rsp)
lea    0x1c(%rsp),%rdi
call   1030 <modff@plt>
add    %eax,%eax
lea    (%rax,%rax,2),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,(%rsp)
call   1050 <floor@plt>
cmp    $0x5,%eax
ja     11e1 <dhsv2rgb+0xb1>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  (%rsp),%xmm5
subsd  %xmm0,%xmm5
movsd  0xe75(%rip),%xmm1
movapd %xmm1,%xmm0
movsd  0x8(%rsp),%xmm4
subsd  %xmm4,%xmm0
movapd %xmm4,%xmm2
mulsd  %xmm5,%xmm2
movapd %xmm1,%xmm3
subsd  %xmm2,%xmm3
movapd %xmm1,%xmm2
subsd  %xmm5,%xmm2
mulsd  %xmm4,%xmm2
movapd %xmm1,%xmm4
subsd  %xmm2,%xmm4
mov    %eax,%eax
lea    0xe42(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
movapd %xmm4,%xmm2
jmp    *%rax
movsd  0xe25(%rip),%xmm2
movapd %xmm3,%xmm1
jmp    1244 <dhsv2rgb+0x114>
mov    0x2df8(%rip),%rcx
mov    (%rcx),%edi
lea    0xe2f(%rip),%rsi
movsd  (%rsp),%xmm0
mov    %eax,%edx
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <fprintf@plt>
movsd  0xdf2(%rip),%xmm2
movapd %xmm0,%xmm1
movapd %xmm4,%xmm0
jmp    1244 <dhsv2rgb+0x114>
movapd %xmm0,%xmm1
movsd  0xddc(%rip),%xmm0
movapd %xmm3,%xmm2
jmp    1244 <dhsv2rgb+0x114>
movapd %xmm0,%xmm2
movsd  0xdca(%rip),%xmm0
movapd %xmm4,%xmm1
jmp    1244 <dhsv2rgb+0x114>
movapd %xmm0,%xmm2
movapd %xmm3,%xmm0
movsd  %xmm1,(%r15)
movsd  %xmm2,(%rbx)
movsd  %xmm0,(%r14)
movsd  (%r15),%xmm1
movsd  (%rbx),%xmm2
maxsd  %xmm1,%xmm2
maxsd  %xmm2,%xmm0
movsd  0x10(%rsp),%xmm2
divsd  %xmm0,%xmm2
mulsd  %xmm2,%xmm1
movsd  %xmm1,(%r15)
movsd  (%rbx),%xmm0
mulsd  %xmm2,%xmm0
movsd  %xmm0,(%rbx)
mulsd  (%r14),%xmm2
movsd  %xmm2,(%r14)
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [13 x i8] c"bad i: %f %d\00"
define void @dhsv2rgb(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
%18 = alloca float
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
%19 = load double, double* %7
%20 = call i32 @modff(double %19, float* %18)
%21 = mul nsw i32 6, %20
%22 = sitofp i32 %21 to double
store double %22, double* %7
%23 = load double, double* %7
%24 = call i32 @floor(double %23)
store i32 %24, i32* %13
%25 = load double, double* %7
%26 = load i32, i32* %13
%27 = sitofp i32 %26 to double
%28 = fsub double %25, %27
store double %28, double* %14
%29 = load double, double* %8
%30 = fsub double 1.000000e+00, %29
store double %30, double* %15
%31 = load double, double* %8
%32 = load double, double* %14
%33 = fneg double %31
%34 = call double @llvm.fmuladd.f64(double %33, double %32, double 1.000000e+00)
store double %34, double* %16
%35 = load double, double* %8
%36 = load double, double* %14
%37 = fsub double 1.000000e+00, %36
%38 = fneg double %35
%39 = call double @llvm.fmuladd.f64(double %38, double %37, double 1.000000e+00)
store double %39, double* %17
%40 = load i32, i32* %13
switch i32 %40, label %77 [
i32 0, label %41
i32 1, label %47
i32 2, label %53
i32 3, label %59
i32 4, label %65
i32 5, label %71
]
41: ; preds = %6
%42 = load double*, double** %10
store double 1.000000e+00, double* %42
%43 = load double, double* %17
%44 = load double*, double** %11
store double %43, double* %44
%45 = load double, double* %15
%46 = load double*, double** %12
store double %45, double* %46
br label %82
47: ; preds = %6
%48 = load double, double* %16
%49 = load double*, double** %10
store double %48, double* %49
%50 = load double*, double** %11
store double 1.000000e+00, double* %50
%51 = load double, double* %15
%52 = load double*, double** %12
store double %51, double* %52
br label %82
53: ; preds = %6
%54 = load double, double* %15
%55 = load double*, double** %10
store double %54, double* %55
%56 = load double*, double** %11
store double 1.000000e+00, double* %56
%57 = load double, double* %17
%58 = load double*, double** %12
store double %57, double* %58
br label %82
59: ; preds = %6
%60 = load double, double* %15
%61 = load double*, double** %10
store double %60, double* %61
%62 = load double, double* %16
%63 = load double*, double** %11
store double %62, double* %63
%64 = load double*, double** %12
store double 1.000000e+00, double* %64
br label %82
65: ; preds = %6
%66 = load double, double* %17
%67 = load double*, double** %10
store double %66, double* %67
%68 = load double, double* %15
%69 = load double*, double** %11
store double %68, double* %69
%70 = load double*, double** %12
store double 1.000000e+00, double* %70
br label %82
71: ; preds = %6
%72 = load double*, double** %10
store double 1.000000e+00, double* %72
%73 = load double, double* %15
%74 = load double*, double** %11
store double %73, double* %74
%75 = load double, double* %16
%76 = load double*, double** %12
store double %75, double* %76
br label %82
77: ; preds = %6
%78 = load i32, i32* @stderr
%79 = load double, double* %7
%80 = load i32, i32* %13
%81 = call i32 @fprintf(i32 %78, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), double %79, i32 %80)
br label %116
82: ; preds = %71, %65, %59, %53, %47, %41
%83 = load double*, double** %10
%84 = load double, double* %83
store double %84, double* %14
%85 = load double, double* %14
%86 = load double*, double** %11
%87 = load double, double* %86
%88 = fcmp olt double %85, %87
br i1 %88, label %89, label %92
89: ; preds = %82
%90 = load double*, double** %11
%91 = load double, double* %90
store double %91, double* %14
br label %92
92: ; preds = %89, %82
%93 = load double, double* %14
%94 = load double*, double** %12
%95 = load double, double* %94
%96 = fcmp olt double %93, %95
br i1 %96, label %97, label %100
97: ; preds = %92
%98 = load double*, double** %12
%99 = load double, double* %98
store double %99, double* %14
br label %100
100: ; preds = %97, %92
%101 = load double, double* %9
%102 = load double, double* %14
%103 = fdiv double %101, %102
store double %103, double* %14
%104 = load double, double* %14
%105 = load double*, double** %10
%106 = load double, double* %105
%107 = fmul double %106, %104
store double %107, double* %105
%108 = load double, double* %14
%109 = load double*, double** %11
%110 = load double, double* %109
%111 = fmul double %110, %108
store double %111, double* %109
%112 = load double, double* %14
%113 = load double*, double** %12
%114 = load double, double* %113
%115 = fmul double %114, %112
store double %115, double* %113
br label %116
116: ; preds = %100, %77
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [13 x i8] c"bad i: %f %d\00"
define void @dhsv2rgb(double %0, double %1, double %2, double* nocapture %3, double* nocapture %4, double* nocapture %5) {
%7 = alloca float
%8 = bitcast float* %7 to i8*
%9 = call i32 @modff(double %0, float* %7)
%10 = mul nsw i32 %9, 6
%11 = sitofp i32 %10 to double
%12 = tail call i32 @floor(double %11)
%13 = sitofp i32 %12 to double
%14 = fsub double %11, %13
%15 = fsub double 1.000000e+00, %1
%16 = fneg double %1
%17 = tail call double @llvm.fmuladd.f64(double %16, double %14, double 1.000000e+00)
%18 = fsub double 1.000000e+00, %14
%19 = tail call double @llvm.fmuladd.f64(double %16, double %18, double 1.000000e+00)
switch i32 %12, label %25 [
i32 0, label %28
i32 1, label %20
i32 2, label %21
i32 3, label %22
i32 4, label %23
i32 5, label %24
]
20: ; preds = %6
br label %28
21: ; preds = %6
br label %28
22: ; preds = %6
br label %28
23: ; preds = %6
br label %28
24: ; preds = %6
br label %28
25: ; preds = %6
%26 = load i32, i32* @stderr
%27 = tail call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), double %11, i32 %12)
br label %44
28: ; preds = %6, %24, %23, %22, %21, %20
%29 = phi double [ 1.000000e+00, %24 ], [ %19, %23 ], [ %15, %22 ], [ %15, %21 ], [ %17, %20 ], [ 1.000000e+00, %6 ]
%30 = phi double [ %15, %24 ], [ %15, %23 ], [ %17, %22 ], [ 1.000000e+00, %21 ], [ 1.000000e+00, %20 ], [ %19, %6 ]
%31 = phi double [ %17, %24 ], [ 1.000000e+00, %23 ], [ 1.000000e+00, %22 ], [ %19, %21 ], [ %15, %20 ], [ %15, %6 ]
store double %29, double* %3
store double %30, double* %4
store double %31, double* %5
%32 = load double, double* %3
%33 = load double, double* %4
%34 = fcmp olt double %32, %33
%35 = select i1 %34, double %33, double %32
%36 = fcmp olt double %35, %31
%37 = select i1 %36, double %31, double %35
%38 = fdiv double %2, %37
%39 = fmul double %32, %38
store double %39, double* %3
%40 = load double, double* %4
%41 = fmul double %40, %38
store double %41, double* %4
%42 = load double, double* %5
%43 = fmul double %42, %38
store double %43, double* %5
br label %44
44: ; preds = %28, %25
ret void
}