#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 fmod(double, double);
int ImageKit_Colorspace_RGB2HSV(double r, double g, double b, double *oh,
                                double *os, double *ov) {
  double hue;
  double saturation;
  double value;
  double M;
  double m;
  double C;
  M = r;
  if (M < g)
    M = g;
  if (M < b)
    M = b;
  m = r;
  if (m > g)
    m = g;
  if (m > b)
    m = b;
  C = M - m;
  value = M;
  saturation = ((M > 0) ? C / M : 0.0);
  if (C == 0) {
    hue = 0.0;
  } else if (M == r) {
    hue = fmod((g - b) / C, 6.0);
  } else if (M == g) {
    hue = (b - r) / C + 2.0;
  } else {
    hue = (r - g) / C + 4.0;
  }
  *oh = hue / 6.0;
  *os = saturation;
  *ov = value;
  return 0;
}


x86 assembly (clang, -O0):
<ImageKit_Colorspace_RGB2HSV>:
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  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    115b <ImageKit_Colorspace_RGB2HSV+0x4b>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1179 <ImageKit_Colorspace_RGB2HSV+0x69>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    119d <ImageKit_Colorspace_RGB2HSV+0x8d>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    11b7 <ImageKit_Colorspace_RGB2HSV+0xa7>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x50(%rbp),%xmm0
subsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x50(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11f6 <ImageKit_Colorspace_RGB2HSV+0xe6>
movsd  -0x60(%rbp),%xmm0
divsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
jmp    1203 <ImageKit_Colorspace_RGB2HSV+0xf3>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x68(%rbp)
jmp    1203 <ImageKit_Colorspace_RGB2HSV+0xf3>
movsd  -0x68(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x60(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1232 <ImageKit_Colorspace_RGB2HSV+0x122>
jp     1232 <ImageKit_Colorspace_RGB2HSV+0x122>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    12d3 <ImageKit_Colorspace_RGB2HSV+0x1c3>
movsd  -0x50(%rbp),%xmm0
ucomisd -0x8(%rbp),%xmm0
jne    126e <ImageKit_Colorspace_RGB2HSV+0x15e>
jp     126e <ImageKit_Colorspace_RGB2HSV+0x15e>
movsd  -0x10(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
divsd  -0x60(%rbp),%xmm0
movsd  0xdb1(%rip),%xmm1
call   1030 <fmod@plt>
movsd  %xmm0,-0x38(%rbp)
jmp    12ce <ImageKit_Colorspace_RGB2HSV+0x1be>
movsd  -0x50(%rbp),%xmm0
ucomisd -0x10(%rbp),%xmm0
jne    12a9 <ImageKit_Colorspace_RGB2HSV+0x199>
jp     12a9 <ImageKit_Colorspace_RGB2HSV+0x199>
movsd  -0x18(%rbp),%xmm0
subsd  -0x8(%rbp),%xmm0
divsd  -0x60(%rbp),%xmm0
movsd  0xd6d(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    12c9 <ImageKit_Colorspace_RGB2HSV+0x1b9>
movsd  -0x8(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
divsd  -0x60(%rbp),%xmm0
movsd  0xd40(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    12ce <ImageKit_Colorspace_RGB2HSV+0x1be>
jmp    12d3 <ImageKit_Colorspace_RGB2HSV+0x1c3>
movsd  -0x38(%rbp),%xmm0
movsd  0xd30(%rip),%xmm1
divsd  %xmm1,%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x40(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x48(%rbp),%xmm0
mov    -0x30(%rbp),%rax
movsd  %xmm0,(%rax)
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ImageKit_Colorspace_RGB2HSV>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
movapd %xmm1,%xmm3
maxsd  %xmm0,%xmm3
movapd %xmm2,%xmm5
maxsd  %xmm3,%xmm5
movapd %xmm1,%xmm3
minsd  %xmm0,%xmm3
movapd %xmm2,%xmm4
minsd  %xmm3,%xmm4
movapd %xmm5,%xmm6
subsd  %xmm4,%xmm6
xorpd  %xmm4,%xmm4
ucomisd %xmm4,%xmm6
xorpd  %xmm3,%xmm3
jne    115a <ImageKit_Colorspace_RGB2HSV+0x4a>
jnp    119d <ImageKit_Colorspace_RGB2HSV+0x8d>
ucomisd %xmm0,%xmm5
jne    11cd <ImageKit_Colorspace_RGB2HSV+0xbd>
jp     11cd <ImageKit_Colorspace_RGB2HSV+0xbd>
subsd  %xmm2,%xmm1
divsd  %xmm6,%xmm1
movsd  0xe9e(%rip),%xmm2
movapd %xmm1,%xmm0
movapd %xmm2,%xmm1
movsd  %xmm5,0x8(%rsp)
movsd  %xmm6,(%rsp)
call   1030 <fmod@plt>
movsd  (%rsp),%xmm6
xorpd  %xmm4,%xmm4
movsd  0x8(%rsp),%xmm5
movapd %xmm0,%xmm3
ucomisd %xmm4,%xmm5
jbe    11ab <ImageKit_Colorspace_RGB2HSV+0x9b>
divsd  %xmm5,%xmm6
movapd %xmm6,%xmm4
divsd  0xe5d(%rip),%xmm3
movsd  %xmm3,(%rbx)
movsd  %xmm4,(%r15)
movsd  %xmm5,(%r14)
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
ucomisd %xmm1,%xmm5
jne    11f1 <ImageKit_Colorspace_RGB2HSV+0xe1>
jp     11f1 <ImageKit_Colorspace_RGB2HSV+0xe1>
subsd  %xmm0,%xmm2
divsd  %xmm6,%xmm2
addsd  0xe23(%rip),%xmm2
movapd %xmm2,%xmm3
ucomisd %xmm4,%xmm5
ja     11a3 <ImageKit_Colorspace_RGB2HSV+0x93>
jmp    11ab <ImageKit_Colorspace_RGB2HSV+0x9b>
subsd  %xmm1,%xmm0
divsd  %xmm6,%xmm0
addsd  0xdff(%rip),%xmm0
jmp    1199 <ImageKit_Colorspace_RGB2HSV+0x89>

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

LLVM IR (-O2):
define i32 @ImageKit_Colorspace_RGB2HSV(double %0, double %1, double %2, double* nocapture writeonly %3, double* nocapture writeonly %4, double* nocapture writeonly %5) {
%7 = fcmp olt double %0, %1
%8 = select i1 %7, double %1, double %0
%9 = fcmp olt double %8, %2
%10 = select i1 %9, double %2, double %8
%11 = fcmp ogt double %0, %1
%12 = select i1 %11, double %1, double %0
%13 = fcmp ogt double %12, %2
%14 = select i1 %13, double %2, double %12
%15 = fsub double %10, %14
%16 = fcmp oeq double %15, 0.000000e+00
br i1 %16, label %33, label %17
17: ; preds = %6
%18 = fcmp oeq double %10, %0
br i1 %18, label %19, label %23
19: ; preds = %17
%20 = fsub double %1, %2
%21 = fdiv double %20, %15
%22 = tail call double @fmod(double %21, double 6.000000e+00)
br label %33
23: ; preds = %17
%24 = fcmp oeq double %10, %1
br i1 %24, label %25, label %29
25: ; preds = %23
%26 = fsub double %2, %0
%27 = fdiv double %26, %15
%28 = fadd double %27, 2.000000e+00
br label %33
29: ; preds = %23
%30 = fsub double %0, %1
%31 = fdiv double %30, %15
%32 = fadd double %31, 4.000000e+00
br label %33
33: ; preds = %6, %19, %29, %25
%34 = phi double [ %22, %19 ], [ %28, %25 ], [ %32, %29 ], [ 0.000000e+00, %6 ]
%35 = fcmp ogt double %10, 0.000000e+00
%36 = fdiv double %15, %10
%37 = select i1 %35, double %36, double 0.000000e+00
%38 = fdiv double %34, 6.000000e+00
store double %38, double* %3
store double %37, double* %4
store double %10, double* %5
ret i32 0
}