int constrain_rgb_gamut(r, g, b)
double *r, *g, *b;
{
  double w;
  w = (0 < *r) ? 0 : *r;
  w = (w < *g) ? w : *g;
  w = (w < *b) ? w : *b;
  w = -w;
  if (w > 0) {
    *r += w;
    *g += w;
    *b += w;
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<constrain_rgb_gamut>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    1132 <constrain_rgb_gamut+0x32>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    113f <constrain_rgb_gamut+0x3f>
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm1
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
ucomisd %xmm1,%xmm0
jbe    116f <constrain_rgb_gamut+0x6f>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    117c <constrain_rgb_gamut+0x7c>
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm1
mov    -0x20(%rbp),%rax
movsd  (%rax),%xmm0
ucomisd %xmm1,%xmm0
jbe    11ac <constrain_rgb_gamut+0xac>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
jmp    11b9 <constrain_rgb_gamut+0xb9>
mov    -0x20(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    1235 <constrain_rgb_gamut+0x135>
movsd  -0x28(%rbp),%xmm0
mov    -0x10(%rbp),%rax
addsd  (%rax),%xmm0
movsd  %xmm0,(%rax)
movsd  -0x28(%rbp),%xmm0
mov    -0x18(%rbp),%rax
addsd  (%rax),%xmm0
movsd  %xmm0,(%rax)
movsd  -0x28(%rbp),%xmm0
mov    -0x20(%rbp),%rax
addsd  (%rax),%xmm0
movsd  %xmm0,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    123c <constrain_rgb_gamut+0x13c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<constrain_rgb_gamut>:
movsd  (%rdi),%xmm1
xorpd  %xmm0,%xmm0
minsd  %xmm1,%xmm0
minsd  (%rsi),%xmm0
minsd  (%rdx),%xmm0
xorpd  %xmm2,%xmm2
xor    %eax,%eax
ucomisd %xmm0,%xmm2
jbe    1145 <constrain_rgb_gamut+0x45>
subsd  %xmm0,%xmm1
movsd  %xmm1,(%rdi)
movsd  (%rsi),%xmm1
subsd  %xmm0,%xmm1
movsd  %xmm1,(%rsi)
movsd  (%rdx),%xmm1
subsd  %xmm0,%xmm1
movsd  %xmm1,(%rdx)
mov    $0x1,%eax
ret

LLVM IR (-O0):
define i32 @constrain_rgb_gamut(double* %0, double* %1, double* %2) {
%4 = alloca i32
%5 = alloca double*
%6 = alloca double*
%7 = alloca double*
%8 = alloca double
store double* %0, double** %5
store double* %1, double** %6
store double* %2, double** %7
%9 = load double*, double** %5
%10 = load double, double* %9
%11 = fcmp olt double 0.000000e+00, %10
br i1 %11, label %12, label %13
12: ; preds = %3
br label %16
13: ; preds = %3
%14 = load double*, double** %5
%15 = load double, double* %14
br label %16
16: ; preds = %13, %12
%17 = phi double [ 0.000000e+00, %12 ], [ %15, %13 ]
store double %17, double* %8
%18 = load double, double* %8
%19 = load double*, double** %6
%20 = load double, double* %19
%21 = fcmp olt double %18, %20
br i1 %21, label %22, label %24
22: ; preds = %16
%23 = load double, double* %8
br label %27
24: ; preds = %16
%25 = load double*, double** %6
%26 = load double, double* %25
br label %27
27: ; preds = %24, %22
%28 = phi double [ %23, %22 ], [ %26, %24 ]
store double %28, double* %8
%29 = load double, double* %8
%30 = load double*, double** %7
%31 = load double, double* %30
%32 = fcmp olt double %29, %31
br i1 %32, label %33, label %35
33: ; preds = %27
%34 = load double, double* %8
br label %38
35: ; preds = %27
%36 = load double*, double** %7
%37 = load double, double* %36
br label %38
38: ; preds = %35, %33
%39 = phi double [ %34, %33 ], [ %37, %35 ]
store double %39, double* %8
%40 = load double, double* %8
%41 = fneg double %40
store double %41, double* %8
%42 = load double, double* %8
%43 = fcmp ogt double %42, 0.000000e+00
br i1 %43, label %44, label %57
44: ; preds = %38
%45 = load double, double* %8
%46 = load double*, double** %5
%47 = load double, double* %46
%48 = fadd double %47, %45
store double %48, double* %46
%49 = load double, double* %8
%50 = load double*, double** %6
%51 = load double, double* %50
%52 = fadd double %51, %49
store double %52, double* %50
%53 = load double, double* %8
%54 = load double*, double** %7
%55 = load double, double* %54
%56 = fadd double %55, %53
store double %56, double* %54
store i32 1, i32* %4
br label %58
57: ; preds = %38
store i32 0, i32* %4
br label %58
58: ; preds = %57, %44
%59 = load i32, i32* %4
ret i32 %59
}

LLVM IR (-O2):
define i32 @constrain_rgb_gamut(double* nocapture %0, double* nocapture %1, double* nocapture %2) {
%4 = load double, double* %0
%5 = fcmp ogt double %4, 0.000000e+00
%6 = select i1 %5, double 0.000000e+00, double %4
%7 = load double, double* %1
%8 = fcmp olt double %6, %7
%9 = select i1 %8, double %6, double %7
%10 = load double, double* %2
%11 = fcmp olt double %9, %10
%12 = select i1 %11, double %9, double %10
%13 = fcmp olt double %12, 0.000000e+00
br i1 %13, label %14, label %20
14: ; preds = %3
%15 = fsub double %4, %12
store double %15, double* %0
%16 = load double, double* %1
%17 = fsub double %16, %12
store double %17, double* %1
%18 = load double, double* %2
%19 = fsub double %18, %12
store double %19, double* %2
br label %20
20: ; preds = %3, %14
%21 = phi i32 [ 1, %14 ], [ 0, %3 ]
ret i32 %21
}