unsigned short blend_screen16(unsigned short color1, unsigned short color2) {
  return (
      (((((((color1 >> 11)) ^ (0x1F)) * (((color2 >> 11)) ^ (0x1F)) / (0x1F)) ^
         (0x1F)))
       << 11) |
      ((((((((color1 & 0x7E0) >> 5)) ^ (0x3F)) *
          ((((color2 & 0x7E0) >> 5)) ^ (0x3F)) / (0x3F)) ^
         (0x3F)))
       << 5) |
      (((((color1 & 0x1F)) ^ (0x1F)) * (((color2 & 0x1F)) ^ (0x1F)) / (0x1F)) ^
       (0x1F)));
}


x86 assembly (clang, -O0):
<blend_screen16>:
push   %rbp
mov    %rsp,%rbp
mov    %si,%ax
mov    %di,%cx
mov    %cx,-0x2(%rbp)
mov    %ax,-0x4(%rbp)
movzwl -0x2(%rbp),%eax
sar    $0xb,%eax
xor    $0x1f,%eax
movzwl -0x4(%rbp),%ecx
sar    $0xb,%ecx
xor    $0x1f,%ecx
imul   %ecx,%eax
mov    $0x1f,%ecx
cltd
idiv   %ecx
xor    $0x1f,%eax
shl    $0xb,%eax
mov    %eax,-0xc(%rbp)
movzwl -0x2(%rbp),%eax
and    $0x7e0,%eax
sar    $0x5,%eax
xor    $0x3f,%eax
movzwl -0x4(%rbp),%ecx
and    $0x7e0,%ecx
sar    $0x5,%ecx
xor    $0x3f,%ecx
imul   %ecx,%eax
mov    $0x3f,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0xc(%rbp),%eax
xor    $0x3f,%ecx
shl    $0x5,%ecx
or     %ecx,%eax
mov    %eax,-0x8(%rbp)
movzwl -0x2(%rbp),%eax
and    $0x1f,%eax
xor    $0x1f,%eax
movzwl -0x4(%rbp),%ecx
and    $0x1f,%ecx
xor    $0x1f,%ecx
imul   %ecx,%eax
mov    $0x1f,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x8(%rbp),%eax
xor    $0x1f,%ecx
or     %ecx,%eax
movzwl %ax,%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<blend_screen16>:
mov    %edi,%r8d
not    %r8d
movzwl %r8w,%edx
shr    $0xb,%edx
mov    %esi,%r9d
not    %r9d
movzwl %r9w,%ecx
shr    $0xb,%ecx
imul   %edx,%ecx
imul   $0x843,%ecx,%eax
shr    $0x10,%eax
sub    %eax,%ecx
movzwl %cx,%edx
shr    %edx
add    %eax,%edx
shr    $0x4,%edx
not    %edx
shl    $0xb,%edx
shr    $0x5,%edi
not    %edi
and    $0x3f,%edi
shr    $0x5,%esi
not    %esi
and    $0x3f,%esi
imul   %edi,%esi
imul   $0x411,%esi,%eax
shr    $0x10,%eax
sub    %eax,%esi
movzwl %si,%esi
shr    %esi
add    %eax,%esi
and    $0xf87fffe0,%esi
or     %edx,%esi
xor    $0x7e0,%esi
and    $0x1f,%r8d
and    $0x1f,%r9d
imul   %r8d,%r9d
imul   $0x843,%r9d,%ecx
shr    $0x10,%ecx
sub    %ecx,%r9d
movzwl %r9w,%eax
shr    %eax
add    %ecx,%eax
shr    $0x4,%eax
or     %esi,%eax
xor    $0x1f,%eax
ret

LLVM IR (-O0):
define zeroext i16 @blend_screen16(i16 zeroext %0, i16 zeroext %1) {
%3 = alloca i16
%4 = alloca i16
store i16 %0, i16* %3
store i16 %1, i16* %4
%5 = load i16, i16* %3
%6 = zext i16 %5 to i32
%7 = ashr i32 %6, 11
%8 = xor i32 %7, 31
%9 = load i16, i16* %4
%10 = zext i16 %9 to i32
%11 = ashr i32 %10, 11
%12 = xor i32 %11, 31
%13 = mul nsw i32 %8, %12
%14 = sdiv i32 %13, 31
%15 = xor i32 %14, 31
%16 = shl i32 %15, 11
%17 = load i16, i16* %3
%18 = zext i16 %17 to i32
%19 = and i32 %18, 2016
%20 = ashr i32 %19, 5
%21 = xor i32 %20, 63
%22 = load i16, i16* %4
%23 = zext i16 %22 to i32
%24 = and i32 %23, 2016
%25 = ashr i32 %24, 5
%26 = xor i32 %25, 63
%27 = mul nsw i32 %21, %26
%28 = sdiv i32 %27, 63
%29 = xor i32 %28, 63
%30 = shl i32 %29, 5
%31 = or i32 %16, %30
%32 = load i16, i16* %3
%33 = zext i16 %32 to i32
%34 = and i32 %33, 31
%35 = xor i32 %34, 31
%36 = load i16, i16* %4
%37 = zext i16 %36 to i32
%38 = and i32 %37, 31
%39 = xor i32 %38, 31
%40 = mul nsw i32 %35, %39
%41 = sdiv i32 %40, 31
%42 = xor i32 %41, 31
%43 = or i32 %31, %42
%44 = trunc i32 %43 to i16
ret i16 %44
}

LLVM IR (-O2):
define zeroext i16 @blend_screen16(i16 zeroext %0, i16 zeroext %1) {
%3 = xor i16 %0, -1
%4 = lshr i16 %3, 11
%5 = xor i16 %1, -1
%6 = lshr i16 %5, 11
%7 = mul nuw nsw i16 %6, %4
%8 = udiv i16 %7, 31
%9 = xor i16 %8, -1
%10 = shl i16 %9, 11
%11 = lshr i16 %0, 5
%12 = and i16 %11, 63
%13 = xor i16 %12, 63
%14 = lshr i16 %1, 5
%15 = and i16 %14, 63
%16 = xor i16 %15, 63
%17 = mul nuw nsw i16 %16, %13
%18 = udiv i16 %17, 63
%19 = shl nuw nsw i16 %18, 5
%20 = or i16 %19, %10
%21 = xor i16 %20, 2016
%22 = and i16 %0, 31
%23 = xor i16 %22, 31
%24 = and i16 %1, 31
%25 = xor i16 %24, 31
%26 = mul nuw nsw i16 %25, %23
%27 = udiv i16 %26, 31
%28 = or i16 %21, %27
%29 = xor i16 %28, 31
ret i16 %29
}