#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*/ assert(int);
int encode_thumb_shift(int v, int type) {
  switch (type) {
  case 0x00000040:
  case 0x00000000:
  case 0x00000020:
    type >>= 1;
    break;
  default:
    assert(!"handled shift");
  }
  assert(v >= 0 && v <= 31);
  return (((v & 0x1c) << 10) | ((v & 3) << 6) | type);
}


x86 assembly (clang, -O0):
<encode_thumb_shift>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
test   %eax,%eax
je     1153 <encode_thumb_shift+0x43>
jmp    1131 <encode_thumb_shift+0x21>
mov    -0xc(%rbp),%eax
sub    $0x20,%eax
je     1153 <encode_thumb_shift+0x43>
jmp    1142 <encode_thumb_shift+0x32>
mov    -0xc(%rbp),%eax
sub    $0x40,%eax
jne    1161 <encode_thumb_shift+0x51>
jmp    1153 <encode_thumb_shift+0x43>
mov    -0x8(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1168 <encode_thumb_shift+0x58>
xor    %edi,%edi
call   1030 <assert@plt>
xor    %eax,%eax
cmpl   $0x0,-0x4(%rbp)
mov    %al,-0xd(%rbp)
jl     1181 <encode_thumb_shift+0x71>
cmpl   $0x1f,-0x4(%rbp)
setle  %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x4(%rbp),%eax
and    $0x1c,%eax
shl    $0xa,%eax
mov    -0x4(%rbp),%ecx
and    $0x3,%ecx
shl    $0x6,%ecx
or     %ecx,%eax
or     -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<encode_thumb_shift>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %edi,%ebp
test   %esi,%esi
je     1125 <encode_thumb_shift+0x15>
cmp    $0x40,%ebx
je     1125 <encode_thumb_shift+0x15>
cmp    $0x20,%ebx
jne    1129 <encode_thumb_shift+0x19>
shr    %ebx
jmp    1130 <encode_thumb_shift+0x20>
xor    %edi,%edi
call   1030 <assert@plt>
xor    %edi,%edi
cmp    $0x20,%ebp
setb   %dil
call   1030 <assert@plt>
mov    %ebp,%ecx
and    $0x1c,%ecx
shl    $0xa,%ecx
shl    $0x6,%ebp
movzbl %bpl,%eax
or     %ecx,%eax
or     %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"handled shift\00"
define i32 @encode_thumb_shift(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%5 = load i32, i32* %4
switch i32 %5, label %9 [
i32 64, label %6
i32 0, label %6
i32 32, label %6
]
6: ; preds = %2, %2, %2
%7 = load i32, i32* %4
%8 = ashr i32 %7, 1
store i32 %8, i32* %4
br label %11
9: ; preds = %2
%10 = call i32 @assert(i32 0)
br label %11
11: ; preds = %9, %6
%12 = load i32, i32* %3
%13 = icmp sge i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = load i32, i32* %3
%16 = icmp sle i32 %15, 31
br label %17
17: ; preds = %14, %11
%18 = phi i1 [ false, %11 ], [ %16, %14 ]
%19 = zext i1 %18 to i32
%20 = call i32 @assert(i32 %19)
%21 = load i32, i32* %3
%22 = and i32 %21, 28
%23 = shl i32 %22, 10
%24 = load i32, i32* %3
%25 = and i32 %24, 3
%26 = shl i32 %25, 6
%27 = or i32 %23, %26
%28 = load i32, i32* %4
%29 = or i32 %27, %28
ret i32 %29
}

LLVM IR (-O2):
define i32 @encode_thumb_shift(i32 %0, i32 %1) {
switch i32 %1, label %5 [
i32 64, label %3
i32 0, label %3
i32 32, label %3
]
3: ; preds = %2, %2, %2
%4 = lshr i32 %1, 1
br label %7
5: ; preds = %2
%6 = tail call i32 @assert(i32 0)
br label %7
7: ; preds = %5, %3
%8 = phi i32 [ %1, %5 ], [ %4, %3 ]
%9 = icmp ult i32 %0, 32
%10 = zext i1 %9 to i32
%11 = tail call i32 @assert(i32 %10)
%12 = shl i32 %0, 10
%13 = and i32 %12, 28672
%14 = shl i32 %0, 6
%15 = and i32 %14, 192
%16 = or i32 %13, %15
%17 = or i32 %16, %8
ret i32 %17
}