#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*/ printf(char *);
unsigned int getOffset(unsigned int address, const int offsetSize) {
  switch (offsetSize) {
  case 0:
    return 0;
  case 1:
    return (address & 0x1);
  case 2:
    return (address & 0x3);
  case 3:
    return (address & 0x7);
  case 4:
    return (address & 0xF);
  case 5:
    return (address & 0x1F);
  case 6:
    return (address & 0x3F);
  case 7:
    return (address & 0x7F);
  case 8:
    return (address & 0xFF);
  default:
    printf("*** Offset should not be greater than 8. Returning 0.\n");
    return 0;
  }
}


x86 assembly (clang, -O0):
<getOffset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %rax,-0x18(%rbp)
sub    $0x8,%rax
ja     11c1 <getOffset+0xb1>
mov    -0x18(%rbp),%rax
lea    0xec6(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x0,-0x4(%rbp)
jmp    11d4 <getOffset+0xc4>
mov    -0x8(%rbp),%eax
and    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11d4 <getOffset+0xc4>
mov    -0x8(%rbp),%eax
and    $0x3,%eax
mov    %eax,-0x4(%rbp)
jmp    11d4 <getOffset+0xc4>
mov    -0x8(%rbp),%eax
and    $0x7,%eax
mov    %eax,-0x4(%rbp)
jmp    11d4 <getOffset+0xc4>
mov    -0x8(%rbp),%eax
and    $0xf,%eax
mov    %eax,-0x4(%rbp)
jmp    11d4 <getOffset+0xc4>
mov    -0x8(%rbp),%eax
and    $0x1f,%eax
mov    %eax,-0x4(%rbp)
jmp    11d4 <getOffset+0xc4>
mov    -0x8(%rbp),%eax
and    $0x3f,%eax
mov    %eax,-0x4(%rbp)
jmp    11d4 <getOffset+0xc4>
mov    -0x8(%rbp),%eax
and    $0x7f,%eax
mov    %eax,-0x4(%rbp)
jmp    11d4 <getOffset+0xc4>
mov    -0x8(%rbp),%eax
and    $0xff,%eax
mov    %eax,-0x4(%rbp)
jmp    11d4 <getOffset+0xc4>
lea    0xe5c(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getOffset>:
push   %rax
cmp    $0x8,%esi
ja     112f <getOffset+0x1f>
mov    %esi,%eax
mov    %esi,%ecx
lea    0xedf(%rip),%rdx
movslq (%rdx,%rcx,4),%rcx
add    %rdx,%rcx
jmp    *%rcx
and    $0x1,%edi
jmp    115b <getOffset+0x4b>
lea    0xeee(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret
and    $0x3,%edi
jmp    115b <getOffset+0x4b>
and    $0x7,%edi
jmp    115b <getOffset+0x4b>
and    $0xf,%edi
jmp    115b <getOffset+0x4b>
and    $0x1f,%edi
jmp    115b <getOffset+0x4b>
and    $0x3f,%edi
jmp    115b <getOffset+0x4b>
and    $0x7f,%edi
mov    %edi,%eax
pop    %rcx
ret
movzbl %dil,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [55 x i8] c"*** Offset should not be greater than 8. Returning 0.\0A\00"
define i32 @getOffset(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%6 = load i32, i32* %5
switch i32 %6, label %32 [
i32 0, label %7
i32 1, label %8
i32 2, label %11
i32 3, label %14
i32 4, label %17
i32 5, label %20
i32 6, label %23
i32 7, label %26
i32 8, label %29
]
7: ; preds = %2
store i32 0, i32* %3
br label %34
8: ; preds = %2
%9 = load i32, i32* %4
%10 = and i32 %9, 1
store i32 %10, i32* %3
br label %34
11: ; preds = %2
%12 = load i32, i32* %4
%13 = and i32 %12, 3
store i32 %13, i32* %3
br label %34
14: ; preds = %2
%15 = load i32, i32* %4
%16 = and i32 %15, 7
store i32 %16, i32* %3
br label %34
17: ; preds = %2
%18 = load i32, i32* %4
%19 = and i32 %18, 15
store i32 %19, i32* %3
br label %34
20: ; preds = %2
%21 = load i32, i32* %4
%22 = and i32 %21, 31
store i32 %22, i32* %3
br label %34
23: ; preds = %2
%24 = load i32, i32* %4
%25 = and i32 %24, 63
store i32 %25, i32* %3
br label %34
26: ; preds = %2
%27 = load i32, i32* %4
%28 = and i32 %27, 127
store i32 %28, i32* %3
br label %34
29: ; preds = %2
%30 = load i32, i32* %4
%31 = and i32 %30, 255
store i32 %31, i32* %3
br label %34
32: ; preds = %2
%33 = call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %34
34: ; preds = %32, %29, %26, %23, %20, %17, %14, %11, %8, %7
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
@str = [54 x i8] c"*** Offset should not be greater than 8. Returning 0.\00"
define i32 @getOffset(i32 %0, i32 %1) {
switch i32 %1, label %19 [
i32 0, label %21
i32 1, label %3
i32 2, label %5
i32 3, label %7
i32 4, label %9
i32 5, label %11
i32 6, label %13
i32 7, label %15
i32 8, label %17
]
3: ; preds = %2
%4 = and i32 %0, 1
br label %21
5: ; preds = %2
%6 = and i32 %0, 3
br label %21
7: ; preds = %2
%8 = and i32 %0, 7
br label %21
9: ; preds = %2
%10 = and i32 %0, 15
br label %21
11: ; preds = %2
%12 = and i32 %0, 31
br label %21
13: ; preds = %2
%14 = and i32 %0, 63
br label %21
15: ; preds = %2
%16 = and i32 %0, 127
br label %21
17: ; preds = %2
%18 = and i32 %0, 255
br label %21
19: ; preds = %2
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @str, i64 0, i64 0))
br label %21
21: ; preds = %2, %19, %17, %15, %13, %11, %9, %7, %5, %3
%22 = phi i32 [ 0, %19 ], [ %18, %17 ], [ %16, %15 ], [ %14, %13 ], [ %12, %11 ], [ %10, %9 ], [ %8, %7 ], [ %6, %5 ], [ %4, %3 ], [ %1, %2 ]
ret i32 %22
}