#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 uint32_t;
typedef int uint16_t;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
uint8_t get_bit(void *payload, uint8_t bit_size, uint8_t bitno) {
  assert(bitno < bit_size);
  assert(bit_size == 8 || bit_size == 16 || bit_size == 32);
  switch (bit_size) {
  case 8:
    return (*((uint8_t *)payload) >> bitno) & 0xFF;
  case 16:
    return (*((uint16_t *)payload) >> bitno) & 0xFF;
  case 32:
    return (*((uint32_t *)payload) >> bitno) & 0xFF;
  }
  assert(0);
  return 0;
}


x86 assembly (clang, -O0):
<get_bit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
setl   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    $0x1,%al
cmpl   $0x8,-0x14(%rbp)
mov    %al,-0x19(%rbp)
je     115d <get_bit+0x4d>
mov    $0x1,%al
cmpl   $0x10,-0x14(%rbp)
mov    %al,-0x19(%rbp)
je     115d <get_bit+0x4d>
cmpl   $0x20,-0x14(%rbp)
sete   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
movzbl %al,%edi
and    $0x1,%edi
call   1030 <assert@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x20(%rbp)
sub    $0x8,%eax
je     11a1 <get_bit+0x91>
jmp    117f <get_bit+0x6f>
mov    -0x20(%rbp),%eax
sub    $0x10,%eax
je     11b9 <get_bit+0xa9>
jmp    1190 <get_bit+0x80>
mov    -0x20(%rbp),%eax
sub    $0x20,%eax
je     11d1 <get_bit+0xc1>
jmp    11e9 <get_bit+0xd9>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    -0x18(%rbp),%ecx
sar    %cl,%eax
and    $0xff,%eax
mov    %eax,-0x4(%rbp)
jmp    11f7 <get_bit+0xe7>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    -0x18(%rbp),%ecx
sar    %cl,%eax
and    $0xff,%eax
mov    %eax,-0x4(%rbp)
jmp    11f7 <get_bit+0xe7>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    -0x18(%rbp),%ecx
sar    %cl,%eax
and    $0xff,%eax
mov    %eax,-0x4(%rbp)
jmp    11f7 <get_bit+0xe7>
xor    %edi,%edi
call   1030 <assert@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_bit>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebx
mov    %esi,%ebp
mov    %rdi,%r14
xor    %edi,%edi
cmp    %esi,%edx
setl   %dil
call   1030 <assert@plt>
mov    $0x1,%edi
cmp    $0x8,%ebp
je     1140 <get_bit+0x30>
cmp    $0x10,%ebp
je     1140 <get_bit+0x30>
xor    %edi,%edi
cmp    $0x20,%ebp
sete   %dil
call   1030 <assert@plt>
cmp    $0x20,%ebp
je     1154 <get_bit+0x44>
cmp    $0x10,%ebp
je     1154 <get_bit+0x44>
cmp    $0x8,%ebp
jne    1160 <get_bit+0x50>
mov    (%r14),%eax
mov    %ebx,%ecx
sar    %cl,%eax
movzbl %al,%ebx
jmp    1169 <get_bit+0x59>
xor    %ebx,%ebx
xor    %edi,%edi
call   1030 <assert@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @get_bit(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%8 = load i32, i32* %7
%9 = load i32, i32* %6
%10 = icmp slt i32 %8, %9
%11 = zext i1 %10 to i32
%12 = call i32 @assert(i32 %11)
%13 = load i32, i32* %6
%14 = icmp eq i32 %13, 8
br i1 %14, label %21, label %15
15: ; preds = %3
%16 = load i32, i32* %6
%17 = icmp eq i32 %16, 16
br i1 %17, label %21, label %18
18: ; preds = %15
%19 = load i32, i32* %6
%20 = icmp eq i32 %19, 32
br label %21
21: ; preds = %18, %15, %3
%22 = phi i1 [ true, %15 ], [ true, %3 ], [ %20, %18 ]
%23 = zext i1 %22 to i32
%24 = call i32 @assert(i32 %23)
%25 = load i32, i32* %6
switch i32 %25, label %47 [
i32 8, label %26
i32 16, label %33
i32 32, label %40
]
26: ; preds = %21
%27 = load i8*, i8** %5
%28 = bitcast i8* %27 to i32*
%29 = load i32, i32* %28
%30 = load i32, i32* %7
%31 = ashr i32 %29, %30
%32 = and i32 %31, 255
store i32 %32, i32* %4
br label %49
33: ; preds = %21
%34 = load i8*, i8** %5
%35 = bitcast i8* %34 to i32*
%36 = load i32, i32* %35
%37 = load i32, i32* %7
%38 = ashr i32 %36, %37
%39 = and i32 %38, 255
store i32 %39, i32* %4
br label %49
40: ; preds = %21
%41 = load i8*, i8** %5
%42 = bitcast i8* %41 to i32*
%43 = load i32, i32* %42
%44 = load i32, i32* %7
%45 = ashr i32 %43, %44
%46 = and i32 %45, 255
store i32 %46, i32* %4
br label %49
47: ; preds = %21
%48 = call i32 @assert(i32 0)
store i32 0, i32* %4
br label %49
49: ; preds = %47, %40, %33, %26
%50 = load i32, i32* %4
ret i32 %50
}

LLVM IR (-O2):
define i32 @get_bit(i8* nocapture %0, i32 %1, i32 %2) {
%4 = icmp slt i32 %2, %1
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
switch i32 %1, label %7 [
i32 16, label %10
i32 8, label %10
]
7: ; preds = %3
%8 = icmp eq i32 %1, 32
%9 = zext i1 %8 to i32
br label %10
10: ; preds = %3, %3, %7
%11 = phi i32 [ 1, %3 ], [ %9, %7 ], [ 1, %3 ]
%12 = tail call i32 @assert(i32 %11)
switch i32 %1, label %28 [
i32 8, label %13
i32 16, label %18
i32 32, label %23
]
13: ; preds = %10
%14 = bitcast i8* %0 to i32*
%15 = load i32, i32* %14
%16 = ashr i32 %15, %2
%17 = and i32 %16, 255
br label %30
18: ; preds = %10
%19 = bitcast i8* %0 to i32*
%20 = load i32, i32* %19
%21 = ashr i32 %20, %2
%22 = and i32 %21, 255
br label %30
23: ; preds = %10
%24 = bitcast i8* %0 to i32*
%25 = load i32, i32* %24
%26 = ashr i32 %25, %2
%27 = and i32 %26, 255
br label %30
28: ; preds = %10
%29 = tail call i32 @assert(i32 0)
br label %30
30: ; preds = %28, %23, %18, %13
%31 = phi i32 [ 0, %28 ], [ %27, %23 ], [ %22, %18 ], [ %17, %13 ]
ret i32 %31
}