int diffYUV(int yuv1, int yuv2) {
  static const int Ymask = 0x00FF0000;
  static const int Umask = 0x0000FF00;
  static const int Vmask = 0x000000FF;
  static const int trY = 0x00300000;
  static const int trU = 0x00000700;
  static const int trV = 0x00000006;
  int diff;
  int mask;
  diff = ((yuv1 & Ymask) - (yuv2 & Ymask));
  mask = diff >> 31;
  diff = (diff ^ mask) - mask;
  if (diff > trY)
    return 1;
  diff = ((yuv1 & Umask) - (yuv2 & Umask));
  mask = diff >> 31;
  diff = (diff ^ mask) - mask;
  if (diff > trU)
    return 1;
  diff = ((yuv1 & Vmask) - (yuv2 & Vmask));
  mask = diff >> 31;
  diff = (diff ^ mask) - mask;
  if (diff > trV)
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<diffYUV>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%eax
and    $0xff0000,%eax
mov    -0xc(%rbp),%ecx
and    $0xff0000,%ecx
sub    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
sar    $0x1f,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
xor    -0x14(%rbp),%eax
sub    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x300000,-0x10(%rbp)
jle    114e <diffYUV+0x4e>
movl   $0x1,-0x4(%rbp)
jmp    11da <diffYUV+0xda>
mov    -0x8(%rbp),%eax
and    $0xff00,%eax
mov    -0xc(%rbp),%ecx
and    $0xff00,%ecx
sub    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
sar    $0x1f,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
xor    -0x14(%rbp),%eax
sub    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x700,-0x10(%rbp)
jle    1192 <diffYUV+0x92>
movl   $0x1,-0x4(%rbp)
jmp    11da <diffYUV+0xda>
mov    -0x8(%rbp),%eax
and    $0xff,%eax
mov    -0xc(%rbp),%ecx
and    $0xff,%ecx
sub    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
sar    $0x1f,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
xor    -0x14(%rbp),%eax
sub    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x6,-0x10(%rbp)
jle    11d3 <diffYUV+0xd3>
movl   $0x1,-0x4(%rbp)
jmp    11da <diffYUV+0xda>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<diffYUV>:
mov    %edi,%eax
and    $0xff0000,%eax
mov    %esi,%ecx
and    $0xff0000,%ecx
sub    %ecx,%eax
mov    %eax,%ecx
neg    %ecx
cmovs  %eax,%ecx
mov    $0x1,%eax
cmp    $0x300000,%ecx
ja     115f <diffYUV+0x5f>
mov    %edi,%ecx
and    $0xff00,%ecx
mov    %esi,%edx
and    $0xff00,%edx
sub    %edx,%ecx
mov    %ecx,%edx
neg    %edx
cmovs  %ecx,%edx
cmp    $0x700,%edx
ja     115f <diffYUV+0x5f>
movzbl %dil,%eax
movzbl %sil,%ecx
sub    %ecx,%eax
mov    %eax,%ecx
neg    %ecx
cmovs  %eax,%ecx
xor    %eax,%eax
cmp    $0x7,%ecx
setae  %al
ret

LLVM IR (-O0):
@diffYUV.Ymask = internal constant i32 16711680
@diffYUV.Umask = internal constant i32 65280
@diffYUV.Vmask = internal constant i32 255
@diffYUV.trY = internal constant i32 3145728
@diffYUV.trU = internal constant i32 1792
@diffYUV.trV = internal constant i32 6
define i32 @diffYUV(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%8 = load i32, i32* %4
%9 = and i32 %8, 16711680
%10 = load i32, i32* %5
%11 = and i32 %10, 16711680
%12 = sub nsw i32 %9, %11
store i32 %12, i32* %6
%13 = load i32, i32* %6
%14 = ashr i32 %13, 31
store i32 %14, i32* %7
%15 = load i32, i32* %6
%16 = load i32, i32* %7
%17 = xor i32 %15, %16
%18 = load i32, i32* %7
%19 = sub nsw i32 %17, %18
store i32 %19, i32* %6
%20 = load i32, i32* %6
%21 = icmp sgt i32 %20, 3145728
br i1 %21, label %22, label %23
22: ; preds = %2
store i32 1, i32* %3
br label %56
23: ; preds = %2
%24 = load i32, i32* %4
%25 = and i32 %24, 65280
%26 = load i32, i32* %5
%27 = and i32 %26, 65280
%28 = sub nsw i32 %25, %27
store i32 %28, i32* %6
%29 = load i32, i32* %6
%30 = ashr i32 %29, 31
store i32 %30, i32* %7
%31 = load i32, i32* %6
%32 = load i32, i32* %7
%33 = xor i32 %31, %32
%34 = load i32, i32* %7
%35 = sub nsw i32 %33, %34
store i32 %35, i32* %6
%36 = load i32, i32* %6
%37 = icmp sgt i32 %36, 1792
br i1 %37, label %38, label %39
38: ; preds = %23
store i32 1, i32* %3
br label %56
39: ; preds = %23
%40 = load i32, i32* %4
%41 = and i32 %40, 255
%42 = load i32, i32* %5
%43 = and i32 %42, 255
%44 = sub nsw i32 %41, %43
store i32 %44, i32* %6
%45 = load i32, i32* %6
%46 = ashr i32 %45, 31
store i32 %46, i32* %7
%47 = load i32, i32* %6
%48 = load i32, i32* %7
%49 = xor i32 %47, %48
%50 = load i32, i32* %7
%51 = sub nsw i32 %49, %50
store i32 %51, i32* %6
%52 = load i32, i32* %6
%53 = icmp sgt i32 %52, 6
br i1 %53, label %54, label %55
54: ; preds = %39
store i32 1, i32* %3
br label %56
55: ; preds = %39
store i32 0, i32* %3
br label %56
56: ; preds = %55, %54, %38, %22
%57 = load i32, i32* %3
ret i32 %57
}

LLVM IR (-O2):
define i32 @diffYUV(i32 %0, i32 %1) {
%3 = and i32 %0, 16711680
%4 = and i32 %1, 16711680
%5 = sub nsw i32 %3, %4
%6 = tail call i32 @llvm.abs.i32(i32 %5, i1 true)
%7 = icmp ugt i32 %6, 3145728
br i1 %7, label %21, label %8
8: ; preds = %2
%9 = and i32 %0, 65280
%10 = and i32 %1, 65280
%11 = sub nsw i32 %9, %10
%12 = tail call i32 @llvm.abs.i32(i32 %11, i1 true)
%13 = icmp ugt i32 %12, 1792
br i1 %13, label %21, label %14
14: ; preds = %8
%15 = and i32 %0, 255
%16 = and i32 %1, 255
%17 = sub nsw i32 %15, %16
%18 = tail call i32 @llvm.abs.i32(i32 %17, i1 true)
%19 = icmp ugt i32 %18, 6
%20 = zext i1 %19 to i32
br label %21
21: ; preds = %14, %8, %2
%22 = phi i32 [ 1, %2 ], [ 1, %8 ], [ %20, %14 ]
ret i32 %22
}