int encodeImmDoubleHigh(int value) {
  int res;
  int bitA = (value & 0x80000000) >> 31;
  int notBitB = (value & 0x40000000) >> 30;
  int bitB = (value & 0x20000000) >> 29;
  int bSmear = (value & 0x3fc00000) >> 22;
  int slice = (value & 0x003f0000) >> 16;
  int zeroes = (value & 0x0000ffff);
  if (zeroes != 0)
    return -1;
  if (bitB) {
    if ((notBitB != 0) || (bSmear != 0x1f))
      return -1;
  } else {
    if ((notBitB != 1) || (bSmear != 0x0))
      return -1;
  }
  res = (bitA << 7) | (bitB << 6) | slice;
  return res;
}


x86 assembly (clang, -O0):
<encodeImmDoubleHigh>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
and    $0x80000000,%eax
shr    $0x1f,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
and    $0x40000000,%eax
sar    $0x1e,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
and    $0x20000000,%eax
sar    $0x1d,%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%eax
and    $0x3fc00000,%eax
sar    $0x16,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%eax
and    $0x3f0000,%eax
sar    $0x10,%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%eax
and    $0xffff,%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     116e <encodeImmDoubleHigh+0x6e>
movl   $0xffffffff,-0x4(%rbp)
jmp    11dc <encodeImmDoubleHigh+0xdc>
cmpl   $0x0,-0x18(%rbp)
je     119d <encodeImmDoubleHigh+0x9d>
cmpl   $0x0,-0x14(%rbp)
jne    118c <encodeImmDoubleHigh+0x8c>
cmpl   $0x1f,-0x1c(%rbp)
je     1198 <encodeImmDoubleHigh+0x98>
movl   $0xffffffff,-0x4(%rbp)
jmp    11dc <encodeImmDoubleHigh+0xdc>
jmp    11c2 <encodeImmDoubleHigh+0xc2>
cmpl   $0x1,-0x14(%rbp)
jne    11b1 <encodeImmDoubleHigh+0xb1>
cmpl   $0x0,-0x1c(%rbp)
je     11bd <encodeImmDoubleHigh+0xbd>
movl   $0xffffffff,-0x4(%rbp)
jmp    11dc <encodeImmDoubleHigh+0xdc>
jmp    11c2 <encodeImmDoubleHigh+0xc2>
mov    -0x10(%rbp),%eax
shl    $0x7,%eax
mov    -0x18(%rbp),%ecx
shl    $0x6,%ecx
or     %ecx,%eax
or     -0x20(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<encodeImmDoubleHigh>:
mov    $0xffffffff,%eax
test   %di,%di
je     110b <encodeImmDoubleHigh+0xb>
ret
mov    %edi,%edx
shr    $0x1e,%edx
mov    %edi,%ecx
shr    $0x1d,%ecx
and    $0x1,%ecx
mov    %edi,%esi
shr    $0x16,%esi
movzbl %sil,%esi
test   %ecx,%ecx
jne    1130 <encodeImmDoubleHigh+0x30>
test   $0x1,%dl
je     110a <encodeImmDoubleHigh+0xa>
test   %esi,%esi
je     113a <encodeImmDoubleHigh+0x3a>
jmp    110a <encodeImmDoubleHigh+0xa>
test   $0x1,%dl
jne    110a <encodeImmDoubleHigh+0xa>
cmp    $0x1f,%esi
jne    110a <encodeImmDoubleHigh+0xa>
mov    %edi,%eax
shr    $0x10,%eax
and    $0x3f,%eax
shr    $0x18,%edi
and    $0xffffff80,%edi
shl    $0x6,%ecx
or     %edi,%ecx
or     %eax,%ecx
mov    %ecx,%eax
ret

LLVM IR (-O0):
define i32 @encodeImmDoubleHigh(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %3
%11 = load i32, i32* %3
%12 = and i32 %11, -2147483648
%13 = lshr i32 %12, 31
store i32 %13, i32* %5
%14 = load i32, i32* %3
%15 = and i32 %14, 1073741824
%16 = ashr i32 %15, 30
store i32 %16, i32* %6
%17 = load i32, i32* %3
%18 = and i32 %17, 536870912
%19 = ashr i32 %18, 29
store i32 %19, i32* %7
%20 = load i32, i32* %3
%21 = and i32 %20, 1069547520
%22 = ashr i32 %21, 22
store i32 %22, i32* %8
%23 = load i32, i32* %3
%24 = and i32 %23, 4128768
%25 = ashr i32 %24, 16
store i32 %25, i32* %9
%26 = load i32, i32* %3
%27 = and i32 %26, 65535
store i32 %27, i32* %10
%28 = load i32, i32* %10
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %1
store i32 -1, i32* %2
br label %59
31: ; preds = %1
%32 = load i32, i32* %7
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %42
34: ; preds = %31
%35 = load i32, i32* %6
%36 = icmp ne i32 %35, 0
br i1 %36, label %40, label %37
37: ; preds = %34
%38 = load i32, i32* %8
%39 = icmp ne i32 %38, 31
br i1 %39, label %40, label %41
40: ; preds = %37, %34
store i32 -1, i32* %2
br label %59
41: ; preds = %37
br label %50
42: ; preds = %31
%43 = load i32, i32* %6
%44 = icmp ne i32 %43, 1
br i1 %44, label %48, label %45
45: ; preds = %42
%46 = load i32, i32* %8
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %49
48: ; preds = %45, %42
store i32 -1, i32* %2
br label %59
49: ; preds = %45
br label %50
50: ; preds = %49, %41
%51 = load i32, i32* %5
%52 = shl i32 %51, 7
%53 = load i32, i32* %7
%54 = shl i32 %53, 6
%55 = or i32 %52, %54
%56 = load i32, i32* %9
%57 = or i32 %55, %56
store i32 %57, i32* %4
%58 = load i32, i32* %4
store i32 %58, i32* %2
br label %59
59: ; preds = %50, %48, %40, %30
%60 = load i32, i32* %2
ret i32 %60
}

LLVM IR (-O2):
define i32 @encodeImmDoubleHigh(i32 %0) {
%2 = lshr i32 %0, 30
%3 = and i32 %2, 1
%4 = lshr i32 %0, 29
%5 = and i32 %4, 1
%6 = lshr i32 %0, 22
%7 = and i32 %6, 255
%8 = lshr i32 %0, 16
%9 = and i32 %8, 63
%10 = and i32 %0, 65535
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %28
12: ; preds = %1
%13 = icmp eq i32 %5, 0
br i1 %13, label %18, label %14
14: ; preds = %12
%15 = icmp ne i32 %3, 0
%16 = icmp ne i32 %7, 31
%17 = or i1 %15, %16
br i1 %17, label %28, label %22
18: ; preds = %12
%19 = icmp eq i32 %3, 0
%20 = icmp ne i32 %7, 0
%21 = or i1 %19, %20
br i1 %21, label %28, label %22
22: ; preds = %18, %14
%23 = lshr i32 %0, 24
%24 = and i32 %23, 128
%25 = shl nuw nsw i32 %5, 6
%26 = or i32 %25, %24
%27 = or i32 %26, %9
br label %28
28: ; preds = %18, %14, %1, %22
%29 = phi i32 [ %27, %22 ], [ -1, %1 ], [ -1, %14 ], [ -1, %18 ]
ret i32 %29
}