void rgb2hsv(double *rgb_in, double *hsv_out) {
  double min, max, delta;
  min = rgb_in[0] < rgb_in[1] ? rgb_in[0] : rgb_in[1];
  min = min < rgb_in[2] ? min : rgb_in[2];
  max = rgb_in[0] > rgb_in[1] ? rgb_in[0] : rgb_in[1];
  max = max > rgb_in[2] ? max : rgb_in[2];
  hsv_out[2] = max;
  delta = max - min;
  if (delta < 0.00001) {
    hsv_out[1] = 0;
    hsv_out[0] = 0;
    return;
  }
  if (max > 0.0) {
    hsv_out[1] = (delta / max);
  } else {
    hsv_out[1] = 0.0;
    hsv_out[0] = 1;
    return;
  }
  if (rgb_in[0] >= max)
    hsv_out[0] = (rgb_in[1] - rgb_in[2]) / delta;
  else if (rgb_in[1] >= max)
    hsv_out[0] = 2.0 + (rgb_in[2] - rgb_in[0]) / delta;
  else
    hsv_out[0] = 4.0 + (rgb_in[0] - rgb_in[1]) / delta;
  hsv_out[0] *= 60.0;
  if (hsv_out[0] < 0.0)
    hsv_out[0] += 360.0;
  return;
}


x86 assembly (clang, -O0):
<rgb2hsv>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm1
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
ucomisd %xmm1,%xmm0
jbe    1139 <rgb2hsv+0x39>
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    1147 <rgb2hsv+0x47>
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm1
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm0
ucomisd %xmm1,%xmm0
jbe    1178 <rgb2hsv+0x78>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    1186 <rgb2hsv+0x86>
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x8(%rbp),%rax
ucomisd 0x8(%rax),%xmm0
jbe    11b9 <rgb2hsv+0xb9>
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x40(%rbp)
jmp    11c7 <rgb2hsv+0xc7>
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
mov    -0x8(%rbp),%rax
ucomisd 0x10(%rax),%xmm0
jbe    11f4 <rgb2hsv+0xf4>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
jmp    1202 <rgb2hsv+0x102>
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x10(%rax)
movsd  -0x20(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xdcf(%rip),%xmm0
ucomisd -0x28(%rbp),%xmm0
jbe    1258 <rgb2hsv+0x158>
mov    -0x10(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,0x8(%rax)
mov    -0x10(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
jmp    138a <rgb2hsv+0x28a>
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    1282 <rgb2hsv+0x182>
movsd  -0x28(%rbp),%xmm0
divsd  -0x20(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x8(%rax)
jmp    12a3 <rgb2hsv+0x1a3>
mov    -0x10(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,0x8(%rax)
mov    -0x10(%rbp),%rax
movsd  0xd6e(%rip),%xmm0
movsd  %xmm0,(%rax)
jmp    138a <rgb2hsv+0x28a>
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
ucomisd -0x20(%rbp),%xmm0
jb     12da <rgb2hsv+0x1da>
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x8(%rbp),%rax
subsd  0x10(%rax),%xmm0
divsd  -0x28(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    134c <rgb2hsv+0x24c>
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
ucomisd -0x20(%rbp),%xmm0
jb     131d <rgb2hsv+0x21d>
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm1
mov    -0x8(%rbp),%rax
subsd  (%rax),%xmm1
divsd  -0x28(%rbp),%xmm1
movsd  0xd0c(%rip),%xmm0
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    1347 <rgb2hsv+0x247>
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm1
mov    -0x8(%rbp),%rax
subsd  0x8(%rax),%xmm1
divsd  -0x28(%rbp),%xmm1
movsd  0xcd5(%rip),%xmm0
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    134c <rgb2hsv+0x24c>
mov    -0x10(%rbp),%rax
movsd  0xcc8(%rip),%xmm0
mulsd  (%rax),%xmm0
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
xorps  %xmm0,%xmm0
ucomisd (%rax),%xmm0
jbe    1385 <rgb2hsv+0x285>
mov    -0x10(%rbp),%rax
movsd  0xcab(%rip),%xmm0
addsd  (%rax),%xmm0
movsd  %xmm0,(%rax)
jmp    138a <rgb2hsv+0x28a>
pop    %rbp
ret

x86 assembly (clang, -O2):
<rgb2hsv>:
movsd  (%rdi),%xmm2
movsd  0x8(%rdi),%xmm0
movapd %xmm2,%xmm3
minsd  %xmm0,%xmm3
movsd  0x10(%rdi),%xmm1
minsd  %xmm1,%xmm3
maxsd  %xmm0,%xmm2
maxsd  %xmm1,%xmm2
movsd  %xmm2,0x10(%rsi)
movapd %xmm2,%xmm1
subsd  %xmm3,%xmm1
movsd  0xec9(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1146 <rgb2hsv+0x46>
xorpd  %xmm0,%xmm0
movupd %xmm0,(%rsi)
ret
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm2
jbe    1188 <rgb2hsv+0x88>
movapd %xmm1,%xmm0
divsd  %xmm2,%xmm0
movsd  %xmm0,0x8(%rsi)
movsd  (%rdi),%xmm3
movsd  0x8(%rdi),%xmm0
ucomisd %xmm2,%xmm3
jae    1194 <rgb2hsv+0x94>
ucomisd %xmm2,%xmm0
jae    119f <rgb2hsv+0x9f>
subsd  %xmm0,%xmm3
divsd  %xmm1,%xmm3
addsd  0xe96(%rip),%xmm3
movapd %xmm3,%xmm0
jmp    11b4 <rgb2hsv+0xb4>
movsd  0xe78(%rip),%xmm0
movups %xmm0,(%rsi)
ret
subsd  0x10(%rdi),%xmm0
divsd  %xmm1,%xmm0
jmp    11b4 <rgb2hsv+0xb4>
movsd  0x10(%rdi),%xmm0
subsd  %xmm3,%xmm0
divsd  %xmm1,%xmm0
addsd  0xe5c(%rip),%xmm0
mulsd  0xe64(%rip),%xmm0
movsd  0xe64(%rip),%xmm1
addsd  %xmm0,%xmm1
xorpd  %xmm2,%xmm2
movapd %xmm0,%xmm3
cmpltsd %xmm2,%xmm3
andpd  %xmm3,%xmm1
andnpd %xmm0,%xmm3
orpd   %xmm1,%xmm3
movlpd %xmm3,(%rsi)
ret

LLVM IR (-O0):
define void @rgb2hsv(double* %0, double* %1) {
%3 = alloca double*
%4 = alloca double*
%5 = alloca double
%6 = alloca double
%7 = alloca double
store double* %0, double** %3
store double* %1, double** %4
%8 = load double*, double** %3
%9 = getelementptr inbounds double, double* %8, i64 0
%10 = load double, double* %9
%11 = load double*, double** %3
%12 = getelementptr inbounds double, double* %11, i64 1
%13 = load double, double* %12
%14 = fcmp olt double %10, %13
br i1 %14, label %15, label %19
15: ; preds = %2
%16 = load double*, double** %3
%17 = getelementptr inbounds double, double* %16, i64 0
%18 = load double, double* %17
br label %23
19: ; preds = %2
%20 = load double*, double** %3
%21 = getelementptr inbounds double, double* %20, i64 1
%22 = load double, double* %21
br label %23
23: ; preds = %19, %15
%24 = phi double [ %18, %15 ], [ %22, %19 ]
store double %24, double* %5
%25 = load double, double* %5
%26 = load double*, double** %3
%27 = getelementptr inbounds double, double* %26, i64 2
%28 = load double, double* %27
%29 = fcmp olt double %25, %28
br i1 %29, label %30, label %32
30: ; preds = %23
%31 = load double, double* %5
br label %36
32: ; preds = %23
%33 = load double*, double** %3
%34 = getelementptr inbounds double, double* %33, i64 2
%35 = load double, double* %34
br label %36
36: ; preds = %32, %30
%37 = phi double [ %31, %30 ], [ %35, %32 ]
store double %37, double* %5
%38 = load double*, double** %3
%39 = getelementptr inbounds double, double* %38, i64 0
%40 = load double, double* %39
%41 = load double*, double** %3
%42 = getelementptr inbounds double, double* %41, i64 1
%43 = load double, double* %42
%44 = fcmp ogt double %40, %43
br i1 %44, label %45, label %49
45: ; preds = %36
%46 = load double*, double** %3
%47 = getelementptr inbounds double, double* %46, i64 0
%48 = load double, double* %47
br label %53
49: ; preds = %36
%50 = load double*, double** %3
%51 = getelementptr inbounds double, double* %50, i64 1
%52 = load double, double* %51
br label %53
53: ; preds = %49, %45
%54 = phi double [ %48, %45 ], [ %52, %49 ]
store double %54, double* %6
%55 = load double, double* %6
%56 = load double*, double** %3
%57 = getelementptr inbounds double, double* %56, i64 2
%58 = load double, double* %57
%59 = fcmp ogt double %55, %58
br i1 %59, label %60, label %62
60: ; preds = %53
%61 = load double, double* %6
br label %66
62: ; preds = %53
%63 = load double*, double** %3
%64 = getelementptr inbounds double, double* %63, i64 2
%65 = load double, double* %64
br label %66
66: ; preds = %62, %60
%67 = phi double [ %61, %60 ], [ %65, %62 ]
store double %67, double* %6
%68 = load double, double* %6
%69 = load double*, double** %4
%70 = getelementptr inbounds double, double* %69, i64 2
store double %68, double* %70
%71 = load double, double* %6
%72 = load double, double* %5
%73 = fsub double %71, %72
store double %73, double* %7
%74 = load double, double* %7
%75 = fcmp olt double %74, 1.000000e-05
br i1 %75, label %76, label %81
76: ; preds = %66
%77 = load double*, double** %4
%78 = getelementptr inbounds double, double* %77, i64 1
store double 0.000000e+00, double* %78
%79 = load double*, double** %4
%80 = getelementptr inbounds double, double* %79, i64 0
store double 0.000000e+00, double* %80
br label %161
81: ; preds = %66
%82 = load double, double* %6
%83 = fcmp ogt double %82, 0.000000e+00
br i1 %83, label %84, label %90
84: ; preds = %81
%85 = load double, double* %7
%86 = load double, double* %6
%87 = fdiv double %85, %86
%88 = load double*, double** %4
%89 = getelementptr inbounds double, double* %88, i64 1
store double %87, double* %89
br label %95
90: ; preds = %81
%91 = load double*, double** %4
%92 = getelementptr inbounds double, double* %91, i64 1
store double 0.000000e+00, double* %92
%93 = load double*, double** %4
%94 = getelementptr inbounds double, double* %93, i64 0
store double 1.000000e+00, double* %94
br label %161
95: ; preds = %84
%96 = load double*, double** %3
%97 = getelementptr inbounds double, double* %96, i64 0
%98 = load double, double* %97
%99 = load double, double* %6
%100 = fcmp oge double %98, %99
br i1 %100, label %101, label %113
101: ; preds = %95
%102 = load double*, double** %3
%103 = getelementptr inbounds double, double* %102, i64 1
%104 = load double, double* %103
%105 = load double*, double** %3
%106 = getelementptr inbounds double, double* %105, i64 2
%107 = load double, double* %106
%108 = fsub double %104, %107
%109 = load double, double* %7
%110 = fdiv double %108, %109
%111 = load double*, double** %4
%112 = getelementptr inbounds double, double* %111, i64 0
store double %110, double* %112
br label %146
113: ; preds = %95
%114 = load double*, double** %3
%115 = getelementptr inbounds double, double* %114, i64 1
%116 = load double, double* %115
%117 = load double, double* %6
%118 = fcmp oge double %116, %117
br i1 %118, label %119, label %132
119: ; preds = %113
%120 = load double*, double** %3
%121 = getelementptr inbounds double, double* %120, i64 2
%122 = load double, double* %121
%123 = load double*, double** %3
%124 = getelementptr inbounds double, double* %123, i64 0
%125 = load double, double* %124
%126 = fsub double %122, %125
%127 = load double, double* %7
%128 = fdiv double %126, %127
%129 = fadd double 2.000000e+00, %128
%130 = load double*, double** %4
%131 = getelementptr inbounds double, double* %130, i64 0
store double %129, double* %131
br label %145
132: ; preds = %113
%133 = load double*, double** %3
%134 = getelementptr inbounds double, double* %133, i64 0
%135 = load double, double* %134
%136 = load double*, double** %3
%137 = getelementptr inbounds double, double* %136, i64 1
%138 = load double, double* %137
%139 = fsub double %135, %138
%140 = load double, double* %7
%141 = fdiv double %139, %140
%142 = fadd double 4.000000e+00, %141
%143 = load double*, double** %4
%144 = getelementptr inbounds double, double* %143, i64 0
store double %142, double* %144
br label %145
145: ; preds = %132, %119
br label %146
146: ; preds = %145, %101
%147 = load double*, double** %4
%148 = getelementptr inbounds double, double* %147, i64 0
%149 = load double, double* %148
%150 = fmul double %149, 6.000000e+01
store double %150, double* %148
%151 = load double*, double** %4
%152 = getelementptr inbounds double, double* %151, i64 0
%153 = load double, double* %152
%154 = fcmp olt double %153, 0.000000e+00
br i1 %154, label %155, label %160
155: ; preds = %146
%156 = load double*, double** %4
%157 = getelementptr inbounds double, double* %156, i64 0
%158 = load double, double* %157
%159 = fadd double %158, 3.600000e+02
store double %159, double* %157
br label %160
160: ; preds = %155, %146
br label %161
161: ; preds = %160, %90, %76
ret void
}

LLVM IR (-O2):
define void @rgb2hsv(double* nocapture %0, double* nocapture %1) {
%3 = load double, double* %0
%4 = getelementptr inbounds double, double* %0, i64 1
%5 = load double, double* %4
%6 = fcmp olt double %3, %5
%7 = select i1 %6, double %3, double %5
%8 = getelementptr inbounds double, double* %0, i64 2
%9 = load double, double* %8
%10 = fcmp olt double %7, %9
%11 = select i1 %10, double %7, double %9
%12 = fcmp ogt double %3, %5
%13 = select i1 %12, double %3, double %5
%14 = fcmp ogt double %13, %9
%15 = select i1 %14, double %13, double %9
%16 = getelementptr inbounds double, double* %1, i64 2
store double %15, double* %16
%17 = fsub double %15, %11
%18 = fcmp olt double %17, 1.000000e-05
br i1 %18, label %19, label %21
19: ; preds = %2
%20 = bitcast double* %1 to i8*
br label %52
21: ; preds = %2
%22 = fcmp ogt double %15, 0.000000e+00
br i1 %22, label %23, label %29
23: ; preds = %21
%24 = fdiv double %17, %15
%25 = getelementptr inbounds double, double* %1, i64 1
store double %24, double* %25
%26 = load double, double* %0
%27 = fcmp ult double %26, %15
%28 = load double, double* %4
br i1 %27, label %35, label %31
29: ; preds = %21
%30 = bitcast double* %1 to <2 x double>*
store <2 x double> <double 1.000000e+00, double 0.000000e+00>, <2 x double>* %30
br label %52
31: ; preds = %23
%32 = load double, double* %8
%33 = fsub double %28, %32
%34 = fdiv double %33, %17
br label %46
35: ; preds = %23
%36 = fcmp ult double %28, %15
br i1 %36, label %42, label %37
37: ; preds = %35
%38 = load double, double* %8
%39 = fsub double %38, %26
%40 = fdiv double %39, %17
%41 = fadd double %40, 2.000000e+00
br label %46
42: ; preds = %35
%43 = fsub double %26, %28
%44 = fdiv double %43, %17
%45 = fadd double %44, 4.000000e+00
br label %46
46: ; preds = %37, %42, %31
%47 = phi double [ %41, %37 ], [ %45, %42 ], [ %34, %31 ]
%48 = fmul double %47, 6.000000e+01
%49 = fcmp olt double %48, 0.000000e+00
%50 = fadd double %48, 3.600000e+02
%51 = select i1 %49, double %50, double %48
store double %51, double* %1
br label %52
52: ; preds = %46, %29, %19
ret void
}