#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 */
typedef int uint8_t;
typedef int uint16_t;

/* Variables and functions */
uint8_t _length(uint16_t flags) {
  if (flags & (0x2000)) {
    return 1;
  }
  switch (flags & (0x00f7)) {
  case (0x0010):
    return 1;
  case (0x0002):
    return sizeof(short);
  case (0x0020):
    return 2;
  case (0x0004):
    return sizeof(long);
  case (0x0080):
    return 8;
  case (0x0000):
  default:
    return 4;
  }
}


x86 assembly (clang, -O0):
<_length>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
and    $0x2000,%eax
cmp    $0x0,%eax
je     1124 <_length+0x24>
movl   $0x1,-0x4(%rbp)
jmp    11d9 <_length+0xd9>
mov    -0x8(%rbp),%eax
and    $0xf7,%eax
mov    %eax,-0xc(%rbp)
je     11cd <_length+0xcd>
jmp    113a <_length+0x3a>
mov    -0xc(%rbp),%eax
sub    $0x2,%eax
je     119d <_length+0x9d>
jmp    114b <_length+0x4b>
mov    -0xc(%rbp),%eax
sub    $0x4,%eax
je     11b5 <_length+0xb5>
jmp    115c <_length+0x5c>
mov    -0xc(%rbp),%eax
sub    $0x10,%eax
je     1191 <_length+0x91>
jmp    116d <_length+0x6d>
mov    -0xc(%rbp),%eax
sub    $0x20,%eax
je     11a9 <_length+0xa9>
jmp    117e <_length+0x7e>
mov    -0xc(%rbp),%eax
sub    $0x80,%eax
je     11c1 <_length+0xc1>
jmp    11d2 <_length+0xd2>
movl   $0x1,-0x4(%rbp)
jmp    11d9 <_length+0xd9>
movl   $0x2,-0x4(%rbp)
jmp    11d9 <_length+0xd9>
movl   $0x2,-0x4(%rbp)
jmp    11d9 <_length+0xd9>
movl   $0x8,-0x4(%rbp)
jmp    11d9 <_length+0xd9>
movl   $0x8,-0x4(%rbp)
jmp    11d9 <_length+0xd9>
jmp    11d2 <_length+0xd2>
movl   $0x4,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<_length>:
mov    $0x1,%eax
test   $0x2000,%edi
jne    1143 <_length+0x43>
and    $0xf7,%dil
lea    -0x2(%rdi),%ecx
cmp    $0x1e,%cl
ja     1132 <_length+0x32>
movzbl %cl,%ecx
lea    0xedd(%rip),%rdx
movslq (%rdx,%rcx,4),%rcx
add    %rdx,%rcx
jmp    *%rcx
mov    $0x2,%eax
ret
cmp    $0x80,%dil
jne    113e <_length+0x3e>
mov    $0x8,%eax
ret
mov    $0x4,%eax
ret

LLVM IR (-O0):
define i32 @_length(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = and i32 %4, 8192
%6 = icmp ne i32 %5, 0
br i1 %6, label %7, label %8
7: ; preds = %1
store i32 1, i32* %2
br label %18
8: ; preds = %1
%9 = load i32, i32* %3
%10 = and i32 %9, 247
switch i32 %10, label %17 [
i32 16, label %11
i32 2, label %12
i32 32, label %13
i32 4, label %14
i32 128, label %15
i32 0, label %16
]
11: ; preds = %8
store i32 1, i32* %2
br label %18
12: ; preds = %8
store i32 2, i32* %2
br label %18
13: ; preds = %8
store i32 2, i32* %2
br label %18
14: ; preds = %8
store i32 8, i32* %2
br label %18
15: ; preds = %8
store i32 8, i32* %2
br label %18
16: ; preds = %8
br label %17
17: ; preds = %8, %16
store i32 4, i32* %2
br label %18
18: ; preds = %17, %15, %14, %13, %12, %11, %7
%19 = load i32, i32* %2
ret i32 %19
}

LLVM IR (-O2):
define i32 @_length(i32 %0) {
%2 = and i32 %0, 8192
%3 = icmp eq i32 %2, 0
br i1 %3, label %4, label %12
4: ; preds = %1
%5 = trunc i32 %0 to i8
%6 = and i8 %5, -9
switch i8 %6, label %11 [
i8 16, label %12
i8 2, label %7
i8 32, label %8
i8 4, label %9
i8 -128, label %10
]
7: ; preds = %4
br label %12
8: ; preds = %4
br label %12
9: ; preds = %4
br label %12
10: ; preds = %4
br label %12
11: ; preds = %4
br label %12
12: ; preds = %4, %1, %11, %10, %9, %8, %7
%13 = phi i32 [ 4, %11 ], [ 8, %10 ], [ 8, %9 ], [ 2, %8 ], [ 2, %7 ], [ 1, %1 ], [ 1, %4 ]
ret i32 %13
}