#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 /*<<< orphan*/ HSV2RGB(double, double, double, float *, float *, float *);
double fabs(double);
int getBrownGreenRGB(double v, double vmin, double vmax, float *rgb) {
  double scale;
  double ans;
  if (vmax != vmin)
    scale = 1.0 / (vmax - vmin);
  else {
    rgb[0] = 1.0;
    rgb[1] = 0;
    rgb[2] = 0;
    return 1;
  }
  ans = (v - vmin) * scale;
  if (ans < 0.0)
    ans = 0.0;
  if (ans > 1.0)
    ans = 1.0;
  double H, S, V;
  double aa = ans - 0.5;
  if (ans < 0.5) {
    H = 22 + 2 * (40.0 - 22.) * ans;
  } else {
    H = 40 + 2 * (ans - 0.5) * (127 - 40);
  }
  if (ans < 0.45 || ans > 0.55)
    S = 1;
  else
    S = 0.3 + 0.7 * fabs(0.5 - ans) / 0.05;
  V = 1.0 - (0.66 / 0.5) * fabs(ans - 0.5);
  HSV2RGB(H, S, V, rgb, rgb + 1, rgb + 2);
  return 0;
}


x86 assembly (clang, -O0):
<getBrownGreenRGB>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
mov    %rdi,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
ucomisd -0x18(%rbp),%xmm0
jne    1146 <getBrownGreenRGB+0x36>
jp     1146 <getBrownGreenRGB+0x36>
jmp    1166 <getBrownGreenRGB+0x56>
movsd  -0x20(%rbp),%xmm1
subsd  -0x18(%rbp),%xmm1
movsd  0xeb0(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    119a <getBrownGreenRGB+0x8a>
mov    -0x28(%rbp),%rax
movss  0xe8e(%rip),%xmm0
movss  %xmm0,(%rax)
mov    -0x28(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,0x4(%rax)
mov    -0x28(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,0x8(%rax)
movl   $0x1,-0x4(%rbp)
jmp    1357 <getBrownGreenRGB+0x247>
movsd  -0x10(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x38(%rbp),%xmm0
jbe    11c4 <getBrownGreenRGB+0xb4>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  0xe37(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11e8 <getBrownGreenRGB+0xd8>
movsd  0xe25(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  0xe1b(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  0xe0a(%rip),%xmm0
ucomisd -0x38(%rbp),%xmm0
jbe    1238 <getBrownGreenRGB+0x128>
movsd  -0x38(%rbp),%xmm0
movsd  0xe12(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe0e(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
jmp    1272 <getBrownGreenRGB+0x162>
movsd  -0x38(%rbp),%xmm1
movsd  0xdcb(%rip),%xmm0
subsd  %xmm0,%xmm1
movsd  0xdd7(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  0xdbb(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xdb7(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  0xdc6(%rip),%xmm0
ucomisd -0x38(%rbp),%xmm0
ja     129c <getBrownGreenRGB+0x18c>
movsd  -0x38(%rbp),%xmm0
movsd  0xdb6(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    12ae <getBrownGreenRGB+0x19e>
movsd  0xd64(%rip),%xmm0
movsd  %xmm0,-0x48(%rbp)
jmp    12ef <getBrownGreenRGB+0x1df>
movsd  0xd5a(%rip),%xmm0
subsd  -0x38(%rbp),%xmm0
movaps 0xdae(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  0xd92(%rip),%xmm1
mulsd  %xmm0,%xmm1
movsd  0xd7e(%rip),%xmm0
divsd  %xmm0,%xmm1
movsd  0xd6a(%rip),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  0xd14(%rip),%xmm1
subsd  %xmm1,%xmm0
movaps 0xd69(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  0xd55(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xce9(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm1
movsd  -0x50(%rbp),%xmm2
mov    -0x28(%rbp),%rdi
mov    -0x28(%rbp),%rsi
add    $0x4,%rsi
mov    -0x28(%rbp),%rdx
add    $0x8,%rdx
call   1030 <HSV2RGB@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getBrownGreenRGB>:
push   %rax
ucomisd %xmm1,%xmm2
jne    1119 <getBrownGreenRGB+0x9>
jnp    116d <getBrownGreenRGB+0x5d>
movapd %xmm1,%xmm3
subsd  %xmm1,%xmm2
movsd  0xed7(%rip),%xmm1
movapd %xmm1,%xmm4
divsd  %xmm2,%xmm4
subsd  %xmm3,%xmm0
mulsd  %xmm4,%xmm0
xorpd  %xmm3,%xmm3
maxsd  %xmm0,%xmm3
movapd %xmm1,%xmm2
minsd  %xmm3,%xmm2
movsd  0xeb7(%rip),%xmm3
ucomisd %xmm2,%xmm3
jbe    1182 <getBrownGreenRGB+0x72>
movsd  0xec9(%rip),%xmm0
mulsd  %xmm2,%xmm0
addsd  0xec5(%rip),%xmm0
jmp    11a2 <getBrownGreenRGB+0x92>
movq   $0x3f800000,(%rdi)
movl   $0x0,0x8(%rdi)
mov    $0x1,%eax
pop    %rcx
ret
movsd  0xe86(%rip),%xmm0
addsd  %xmm2,%xmm0
addsd  %xmm0,%xmm0
mulsd  0xe7e(%rip),%xmm0
addsd  0xe7e(%rip),%xmm0
movsd  0xe8e(%rip),%xmm4
ucomisd %xmm2,%xmm4
ja     11e2 <getBrownGreenRGB+0xd2>
ucomisd 0xe88(%rip),%xmm2
ja     11e2 <getBrownGreenRGB+0xd2>
subsd  %xmm2,%xmm3
andpd  0xeaa(%rip),%xmm3
mulsd  0xe7a(%rip),%xmm3
divsd  0xe7a(%rip),%xmm3
addsd  0xe7a(%rip),%xmm3
movapd %xmm3,%xmm1
addsd  0xe26(%rip),%xmm2
andpd  0xe7e(%rip),%xmm2
mulsd  0xe66(%rip),%xmm2
addsd  0xdfe(%rip),%xmm2
lea    0x4(%rdi),%rsi
lea    0x8(%rdi),%rdx
call   1030 <HSV2RGB@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
define i32 @getBrownGreenRGB(double %0, double %1, double %2, float* %3) {
%5 = alloca i32
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca float*
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = alloca double
store double %0, double* %6
store double %1, double* %7
store double %2, double* %8
store float* %3, float** %9
%16 = load double, double* %8
%17 = load double, double* %7
%18 = fcmp une double %16, %17
br i1 %18, label %19, label %24
19: ; preds = %4
%20 = load double, double* %8
%21 = load double, double* %7
%22 = fsub double %20, %21
%23 = fdiv double 1.000000e+00, %22
store double %23, double* %10
br label %31
24: ; preds = %4
%25 = load float*, float** %9
%26 = getelementptr inbounds float, float* %25, i64 0
store float 1.000000e+00, float* %26
%27 = load float*, float** %9
%28 = getelementptr inbounds float, float* %27, i64 1
store float 0.000000e+00, float* %28
%29 = load float*, float** %9
%30 = getelementptr inbounds float, float* %29, i64 2
store float 0.000000e+00, float* %30
store i32 1, i32* %5
br label %85
31: ; preds = %19
%32 = load double, double* %6
%33 = load double, double* %7
%34 = fsub double %32, %33
%35 = load double, double* %10
%36 = fmul double %34, %35
store double %36, double* %11
%37 = load double, double* %11
%38 = fcmp olt double %37, 0.000000e+00
br i1 %38, label %39, label %40
39: ; preds = %31
store double 0.000000e+00, double* %11
br label %40
40: ; preds = %39, %31
%41 = load double, double* %11
%42 = fcmp ogt double %41, 1.000000e+00
br i1 %42, label %43, label %44
43: ; preds = %40
store double 1.000000e+00, double* %11
br label %44
44: ; preds = %43, %40
%45 = load double, double* %11
%46 = fsub double %45, 5.000000e-01
store double %46, double* %15
%47 = load double, double* %11
%48 = fcmp olt double %47, 5.000000e-01
br i1 %48, label %49, label %52
49: ; preds = %44
%50 = load double, double* %11
%51 = call double @llvm.fmuladd.f64(double 3.600000e+01, double %50, double 2.200000e+01)
store double %51, double* %12
br label %57
52: ; preds = %44
%53 = load double, double* %11
%54 = fsub double %53, 5.000000e-01
%55 = fmul double 2.000000e+00, %54
%56 = call double @llvm.fmuladd.f64(double %55, double 8.700000e+01, double 4.000000e+01)
store double %56, double* %12
br label %57
57: ; preds = %52, %49
%58 = load double, double* %11
%59 = fcmp olt double %58, 4.500000e-01
br i1 %59, label %63, label %60
60: ; preds = %57
%61 = load double, double* %11
%62 = fcmp ogt double %61, 5.500000e-01
br i1 %62, label %63, label %64
63: ; preds = %60, %57
store double 1.000000e+00, double* %13
br label %71
64: ; preds = %60
%65 = load double, double* %11
%66 = fsub double 5.000000e-01, %65
%67 = call double @llvm.fabs.f64(double %66)
%68 = fmul double 0x3FE6666666666666, %67
%69 = fdiv double %68, 5.000000e-02
%70 = fadd double 3.000000e-01, %69
store double %70, double* %13
br label %71
71: ; preds = %64, %63
%72 = load double, double* %11
%73 = fsub double %72, 5.000000e-01
%74 = call double @llvm.fabs.f64(double %73)
%75 = call double @llvm.fmuladd.f64(double -1.320000e+00, double %74, double 1.000000e+00)
store double %75, double* %14
%76 = load double, double* %12
%77 = load double, double* %13
%78 = load double, double* %14
%79 = load float*, float** %9
%80 = load float*, float** %9
%81 = getelementptr inbounds float, float* %80, i64 1
%82 = load float*, float** %9
%83 = getelementptr inbounds float, float* %82, i64 2
%84 = call i32 @HSV2RGB(double %76, double %77, double %78, float* %79, float* %81, float* %83)
store i32 0, i32* %5
br label %85
85: ; preds = %71, %24
%86 = load i32, i32* %5
ret i32 %86
}

LLVM IR (-O2):
define i32 @getBrownGreenRGB(double %0, double %1, double %2, float* %3) {
%5 = fcmp une double %2, %1
br i1 %5, label %6, label %16
6: ; preds = %4
%7 = fsub double %2, %1
%8 = fdiv double 1.000000e+00, %7
%9 = fsub double %0, %1
%10 = fmul double %9, %8
%11 = fcmp olt double %10, 0.000000e+00
%12 = select i1 %11, double 0.000000e+00, double %10
%13 = fcmp ogt double %12, 1.000000e+00
%14 = select i1 %13, double 1.000000e+00, double %12
%15 = fcmp olt double %14, 5.000000e-01
br i1 %15, label %19, label %21
16: ; preds = %4
store float 1.000000e+00, float* %3
%17 = getelementptr inbounds float, float* %3, i64 1
store float 0.000000e+00, float* %17
%18 = getelementptr inbounds float, float* %3, i64 2
store float 0.000000e+00, float* %18
br label %44
19: ; preds = %6
%20 = tail call double @llvm.fmuladd.f64(double %14, double 3.600000e+01, double 2.200000e+01)
br label %25
21: ; preds = %6
%22 = fadd double %14, -5.000000e-01
%23 = fmul double %22, 2.000000e+00
%24 = tail call double @llvm.fmuladd.f64(double %23, double 8.700000e+01, double 4.000000e+01)
br label %25
25: ; preds = %21, %19
%26 = phi double [ %20, %19 ], [ %24, %21 ]
%27 = fcmp olt double %14, 4.500000e-01
%28 = fcmp ogt double %14, 5.500000e-01
%29 = or i1 %27, %28
br i1 %29, label %36, label %30
30: ; preds = %25
%31 = fsub double 5.000000e-01, %14
%32 = tail call double @llvm.fabs.f64(double %31)
%33 = fmul double %32, 0x3FE6666666666666
%34 = fdiv double %33, 5.000000e-02
%35 = fadd double %34, 3.000000e-01
br label %36
36: ; preds = %25, %30
%37 = phi double [ %35, %30 ], [ 1.000000e+00, %25 ]
%38 = fadd double %14, -5.000000e-01
%39 = tail call double @llvm.fabs.f64(double %38)
%40 = tail call double @llvm.fmuladd.f64(double %39, double -1.320000e+00, double 1.000000e+00)
%41 = getelementptr inbounds float, float* %3, i64 1
%42 = getelementptr inbounds float, float* %3, i64 2
%43 = tail call i32 @HSV2RGB(double %26, double %37, double %40, float* %3, float* %41, float* %42)
br label %44
44: ; preds = %36, %16
%45 = phi i32 [ 0, %36 ], [ 1, %16 ]
ret i32 %45
}