#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(unsigned char);
unsigned char memory_get_bit_from_byte(unsigned char, int);
unsigned char memory_get_bit_from_dword(unsigned int, int);
unsigned char memory_get_bit_from_word(unsigned short, int);
void test_is_bit_set(void) {
  unsigned char test_case = (unsigned char)0b10000010;
  unsigned char is_bit_set = memory_get_bit_from_byte(test_case, 0);
  assert(!is_bit_set);
  is_bit_set = memory_get_bit_from_byte(test_case, 1);
  assert(is_bit_set);
  is_bit_set = memory_get_bit_from_byte(test_case, 7);
  assert(is_bit_set);
  unsigned short instruction = 0b1000000000000000;
  is_bit_set = memory_get_bit_from_word(instruction, 0);
  assert(!is_bit_set);
  is_bit_set = memory_get_bit_from_word(instruction, 15);
  assert(is_bit_set);
  unsigned int instruction32 = 0b10000000000000000000000000000001;
  is_bit_set = memory_get_bit_from_dword(instruction32, 0);
  assert(is_bit_set);
  is_bit_set = memory_get_bit_from_dword(instruction32, 15);
  assert(!is_bit_set);
  is_bit_set = memory_get_bit_from_dword(instruction32, 31);
  assert(is_bit_set);
}


x86 assembly (clang, -O0):
<test_is_bit_set>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movb   $0x82,-0x1(%rbp)
xor    %esi,%esi
movzbl -0x1(%rbp),%edi
call   1030 <memory_get_bit_from_byte@plt>
mov    %al,-0x2(%rbp)
cmpb   $0x0,-0x2(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
movzbl %al,%edi
call   1050 <assert@plt>
mov    $0x1,%esi
movzbl -0x1(%rbp),%edi
call   1030 <memory_get_bit_from_byte@plt>
mov    %al,-0x2(%rbp)
movzbl -0x2(%rbp),%edi
call   1050 <assert@plt>
mov    $0x7,%esi
movzbl -0x1(%rbp),%edi
call   1030 <memory_get_bit_from_byte@plt>
mov    %al,-0x2(%rbp)
movzbl -0x2(%rbp),%edi
call   1050 <assert@plt>
movw   $0x8000,-0x4(%rbp)
xor    %esi,%esi
movzwl -0x4(%rbp),%edi
call   1060 <memory_get_bit_from_word@plt>
mov    %al,-0x2(%rbp)
cmpb   $0x0,-0x2(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
movzbl %al,%edi
call   1050 <assert@plt>
mov    $0xf,%esi
movzwl -0x4(%rbp),%edi
call   1060 <memory_get_bit_from_word@plt>
mov    %al,-0x2(%rbp)
movzbl -0x2(%rbp),%edi
call   1050 <assert@plt>
movl   $0x80000001,-0x8(%rbp)
mov    -0x8(%rbp),%edi
xor    %esi,%esi
call   1040 <memory_get_bit_from_dword@plt>
mov    %al,-0x2(%rbp)
movzbl -0x2(%rbp),%edi
call   1050 <assert@plt>
mov    -0x8(%rbp),%edi
mov    $0xf,%esi
call   1040 <memory_get_bit_from_dword@plt>
mov    %al,-0x2(%rbp)
cmpb   $0x0,-0x2(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x8(%rbp),%edi
mov    $0x1f,%esi
call   1040 <memory_get_bit_from_dword@plt>
mov    %al,-0x2(%rbp)
movzbl -0x2(%rbp),%edi
call   1050 <assert@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_is_bit_set>:
push   %rax
mov    $0x82,%edi
xor    %esi,%esi
call   1030 <memory_get_bit_from_byte@plt>
xor    %edi,%edi
test   %al,%al
sete   %dil
call   1050 <assert@plt>
mov    $0x82,%edi
mov    $0x1,%esi
call   1030 <memory_get_bit_from_byte@plt>
movzbl %al,%edi
call   1050 <assert@plt>
mov    $0x82,%edi
mov    $0x7,%esi
call   1030 <memory_get_bit_from_byte@plt>
movzbl %al,%edi
call   1050 <assert@plt>
mov    $0x8000,%edi
xor    %esi,%esi
call   1060 <memory_get_bit_from_word@plt>
xor    %edi,%edi
test   %al,%al
sete   %dil
call   1050 <assert@plt>
mov    $0x8000,%edi
mov    $0xf,%esi
call   1060 <memory_get_bit_from_word@plt>
movzbl %al,%edi
call   1050 <assert@plt>
mov    $0x80000001,%edi
xor    %esi,%esi
call   1040 <memory_get_bit_from_dword@plt>
movzbl %al,%edi
call   1050 <assert@plt>
mov    $0x80000001,%edi
mov    $0xf,%esi
call   1040 <memory_get_bit_from_dword@plt>
xor    %edi,%edi
test   %al,%al
sete   %dil
call   1050 <assert@plt>
mov    $0x80000001,%edi
mov    $0x1f,%esi
call   1040 <memory_get_bit_from_dword@plt>
movzbl %al,%edi
pop    %rax
jmp    1050 <assert@plt>

LLVM IR (-O0):
define void @test_is_bit_set() {
%1 = alloca i8
%2 = alloca i8
%3 = alloca i16
%4 = alloca i32
store i8 -126, i8* %1
%5 = load i8, i8* %1
%6 = call zeroext i8 @memory_get_bit_from_byte(i8 zeroext %5, i32 0)
store i8 %6, i8* %2
%7 = load i8, i8* %2
%8 = icmp ne i8 %7, 0
%9 = xor i1 %8, true
%10 = zext i1 %9 to i32
%11 = trunc i32 %10 to i8
%12 = call i32 @assert(i8 zeroext %11)
%13 = load i8, i8* %1
%14 = call zeroext i8 @memory_get_bit_from_byte(i8 zeroext %13, i32 1)
store i8 %14, i8* %2
%15 = load i8, i8* %2
%16 = call i32 @assert(i8 zeroext %15)
%17 = load i8, i8* %1
%18 = call zeroext i8 @memory_get_bit_from_byte(i8 zeroext %17, i32 7)
store i8 %18, i8* %2
%19 = load i8, i8* %2
%20 = call i32 @assert(i8 zeroext %19)
store i16 -32768, i16* %3
%21 = load i16, i16* %3
%22 = call zeroext i8 @memory_get_bit_from_word(i16 zeroext %21, i32 0)
store i8 %22, i8* %2
%23 = load i8, i8* %2
%24 = icmp ne i8 %23, 0
%25 = xor i1 %24, true
%26 = zext i1 %25 to i32
%27 = trunc i32 %26 to i8
%28 = call i32 @assert(i8 zeroext %27)
%29 = load i16, i16* %3
%30 = call zeroext i8 @memory_get_bit_from_word(i16 zeroext %29, i32 15)
store i8 %30, i8* %2
%31 = load i8, i8* %2
%32 = call i32 @assert(i8 zeroext %31)
store i32 -2147483647, i32* %4
%33 = load i32, i32* %4
%34 = call zeroext i8 @memory_get_bit_from_dword(i32 %33, i32 0)
store i8 %34, i8* %2
%35 = load i8, i8* %2
%36 = call i32 @assert(i8 zeroext %35)
%37 = load i32, i32* %4
%38 = call zeroext i8 @memory_get_bit_from_dword(i32 %37, i32 15)
store i8 %38, i8* %2
%39 = load i8, i8* %2
%40 = icmp ne i8 %39, 0
%41 = xor i1 %40, true
%42 = zext i1 %41 to i32
%43 = trunc i32 %42 to i8
%44 = call i32 @assert(i8 zeroext %43)
%45 = load i32, i32* %4
%46 = call zeroext i8 @memory_get_bit_from_dword(i32 %45, i32 31)
store i8 %46, i8* %2
%47 = load i8, i8* %2
%48 = call i32 @assert(i8 zeroext %47)
ret void
}

LLVM IR (-O2):
define void @test_is_bit_set() {
%1 = tail call zeroext i8 @memory_get_bit_from_byte(i8 zeroext -126, i32 0)
%2 = icmp eq i8 %1, 0
%3 = zext i1 %2 to i8
%4 = tail call i32 @assert(i8 zeroext %3)
%5 = tail call zeroext i8 @memory_get_bit_from_byte(i8 zeroext -126, i32 1)
%6 = tail call i32 @assert(i8 zeroext %5)
%7 = tail call zeroext i8 @memory_get_bit_from_byte(i8 zeroext -126, i32 7)
%8 = tail call i32 @assert(i8 zeroext %7)
%9 = tail call zeroext i8 @memory_get_bit_from_word(i16 zeroext -32768, i32 0)
%10 = icmp eq i8 %9, 0
%11 = zext i1 %10 to i8
%12 = tail call i32 @assert(i8 zeroext %11)
%13 = tail call zeroext i8 @memory_get_bit_from_word(i16 zeroext -32768, i32 15)
%14 = tail call i32 @assert(i8 zeroext %13)
%15 = tail call zeroext i8 @memory_get_bit_from_dword(i32 -2147483647, i32 0)
%16 = tail call i32 @assert(i8 zeroext %15)
%17 = tail call zeroext i8 @memory_get_bit_from_dword(i32 -2147483647, i32 15)
%18 = icmp eq i8 %17, 0
%19 = zext i1 %18 to i8
%20 = tail call i32 @assert(i8 zeroext %19)
%21 = tail call zeroext i8 @memory_get_bit_from_dword(i32 -2147483647, i32 31)
%22 = tail call i32 @assert(i8 zeroext %21)
ret void
}