#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 uint32_t;

/* Variables and functions */
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int);
uint32_t bitfield(int bytecount) {
  switch (bytecount) {
  case (1):
    return 0x000000FF;
  case (2):
    return 0x0000FFFF;
  case (3):
    return 0x00FFFFFF;
  case (4):
    return 0xFFFFFFFF;
  default:
    printf("unexpected bytecount %d\n", bytecount);
    assert(0);
  }
}


x86 assembly (clang, -O0):
<bitfield>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x10(%rbp)
sub    $0x3,%eax
ja     1184 <bitfield+0x64>
mov    -0x10(%rbp),%rax
lea    0xeb5(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0xff,-0x4(%rbp)
jmp    119a <bitfield+0x7a>
movl   $0xffff,-0x4(%rbp)
jmp    119a <bitfield+0x7a>
movl   $0xffffff,-0x4(%rbp)
jmp    119a <bitfield+0x7a>
movl   $0xffffffff,-0x4(%rbp)
jmp    119a <bitfield+0x7a>
mov    -0x8(%rbp),%esi
lea    0xe82(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1040 <assert@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bitfield>:
push   %rax
mov    %edi,%esi
lea    -0x1(%rsi),%eax
cmp    $0x4,%eax
jae    1139 <bitfield+0x19>
cltq
lea    0xee8(%rip),%rcx
mov    (%rcx,%rax,4),%eax
pop    %rcx
ret
lea    0xec0(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1040 <assert@plt>
pop    %rcx
ret

LLVM IR (-O0):
@.str = [25 x i8] c"unexpected bytecount %d\0A\00"
define i32 @bitfield(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
switch i32 %4, label %9 [
i32 1, label %5
i32 2, label %6
i32 3, label %7
i32 4, label %8
]
5: ; preds = %1
store i32 255, i32* %2
br label %13
6: ; preds = %1
store i32 65535, i32* %2
br label %13
7: ; preds = %1
store i32 16777215, i32* %2
br label %13
8: ; preds = %1
store i32 -1, i32* %2
br label %13
9: ; preds = %1
%10 = load i32, i32* %3
%11 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = call i32 @assert(i32 0)
br label %13
13: ; preds = %5, %6, %7, %8, %9
%14 = load i32, i32* %2
ret i32 %14
}

LLVM IR (-O2):
@.str = [25 x i8] c"unexpected bytecount %d\0A\00"
@switch.table.bitfield = [4 x i32] [i32 255, i32 65535, i32 16777215, i32 -1]
define i32 @bitfield(i32 %0) {
%2 = add i32 %0, -1
%3 = icmp ult i32 %2, 4
br i1 %3, label %7, label %4
4: ; preds = %1
%5 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %0)
%6 = tail call i32 @assert(i32 0)
br label %11
7: ; preds = %1
%8 = sext i32 %2 to i64
%9 = getelementptr inbounds [4 x i32], [4 x i32]* @switch.table.bitfield, i64 0, i64 %8
%10 = load i32, i32* %9
br label %11
11: ; preds = %7, %4
%12 = phi i32 [ undef, %4 ], [ %10, %7 ]
ret i32 %12
}