#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(int);
unsigned char GetBitRangeFromByte(unsigned char theByte, int start, int end) {
  static unsigned char bitmask[8][8] = {{
                                            1,
                                            3,
                                            7,
                                            15,
                                            31,
                                            63,
                                            127,
                                            255,
                                        },
                                        {
                                            3,
                                            2,
                                            6,
                                            14,
                                            30,
                                            62,
                                            126,
                                            254,
                                        },
                                        {
                                            7,
                                            6,
                                            4,
                                            12,
                                            28,
                                            60,
                                            124,
                                            252,
                                        },
                                        {
                                            15,
                                            14,
                                            12,
                                            8,
                                            24,
                                            56,
                                            120,
                                            248,
                                        },
                                        {
                                            31,
                                            30,
                                            28,
                                            24,
                                            16,
                                            48,
                                            112,
                                            240,
                                        },
                                        {
                                            63,
                                            62,
                                            60,
                                            56,
                                            48,
                                            32,
                                            96,
                                            224,
                                        },
                                        {
                                            127,
                                            126,
                                            124,
                                            120,
                                            112,
                                            96,
                                            64,
                                            192,
                                        },
                                        {
                                            255,
                                            254,
                                            252,
                                            248,
                                            240,
                                            224,
                                            192,
                                            128,
                                        }};
  assert(start <= end);
  assert(start >= 0 && start <= 7);
  assert(end >= 0 && end <= 7);
  return (theByte & bitmask[start][end]) >> (start);
}


x86 assembly (clang, -O0):
<GetBitRangeFromByte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
setle  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
xor    %eax,%eax
cmpl   $0x0,-0x8(%rbp)
mov    %al,-0xd(%rbp)
jl     1150 <GetBitRangeFromByte+0x40>
cmpl   $0x7,-0x8(%rbp)
setle  %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
xor    %eax,%eax
cmpl   $0x0,-0xc(%rbp)
mov    %al,-0xe(%rbp)
jl     1176 <GetBitRangeFromByte+0x66>
cmpl   $0x7,-0xc(%rbp)
setle  %al
mov    %al,-0xe(%rbp)
mov    -0xe(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
movzbl -0x1(%rbp),%eax
movslq -0x8(%rbp),%rdx
lea    0x2e9e(%rip),%rcx
shl    $0x3,%rdx
add    %rdx,%rcx
movslq -0xc(%rbp),%rdx
movzbl (%rcx,%rdx,1),%ecx
and    %ecx,%eax
mov    -0x8(%rbp),%ecx
sar    %cl,%eax
movzbl %al,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetBitRangeFromByte>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %esi,%ebx
mov    %edi,%r14d
xor    %edi,%edi
cmp    %edx,%esi
setle  %dil
call   1030 <assert@plt>
xor    %edi,%edi
cmp    $0x8,%ebx
setb   %dil
call   1030 <assert@plt>
xor    %edi,%edi
cmp    $0x8,%ebp
setb   %dil
call   1030 <assert@plt>
movslq %ebx,%rcx
movslq %ebp,%rax
lea    0xeaf(%rip),%rdx
lea    (%rdx,%rcx,8),%rdx
and    (%rax,%rdx,1),%r14b
movzbl %r14b,%eax
shr    %cl,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@GetBitRangeFromByte.bitmask = internal global [8 x [8 x i8]] [[8 x i8] c"\01\03\07\0F\1F?\7F\FF", [8 x i8] c"\03\02\06\0E\1E>~\FE", [8 x i8] c"\07\06\04\0C\1C<|\FC", [8 x i8] c"\0F\0E\0C\08\188x\F8", [8 x i8] c"\1F\1E\1C\18\100p\F0", [8 x i8] c"?><80 `\E0", [8 x i8] c"\7F~|xp`@\C0", [8 x i8] c"\FF\FE\FC\F8\F0\E0\C0\80"]
define zeroext i8 @GetBitRangeFromByte(i8 zeroext %0, i32 %1, i32 %2) {
%4 = alloca i8
%5 = alloca i32
%6 = alloca i32
store i8 %0, i8* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%7 = load i32, i32* %5
%8 = load i32, i32* %6
%9 = icmp sle i32 %7, %8
%10 = zext i1 %9 to i32
%11 = call i32 @assert(i32 %10)
%12 = load i32, i32* %5
%13 = icmp sge i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %3
%15 = load i32, i32* %5
%16 = icmp sle i32 %15, 7
br label %17
17: ; preds = %14, %3
%18 = phi i1 [ false, %3 ], [ %16, %14 ]
%19 = zext i1 %18 to i32
%20 = call i32 @assert(i32 %19)
%21 = load i32, i32* %6
%22 = icmp sge i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %17
%24 = load i32, i32* %6
%25 = icmp sle i32 %24, 7
br label %26
26: ; preds = %23, %17
%27 = phi i1 [ false, %17 ], [ %25, %23 ]
%28 = zext i1 %27 to i32
%29 = call i32 @assert(i32 %28)
%30 = load i8, i8* %4
%31 = zext i8 %30 to i32
%32 = load i32, i32* %5
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [8 x [8 x i8]], [8 x [8 x i8]]* @GetBitRangeFromByte.bitmask, i64 0, i64 %33
%35 = load i32, i32* %6
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [8 x i8], [8 x i8]* %34, i64 0, i64 %36
%38 = load i8, i8* %37
%39 = zext i8 %38 to i32
%40 = and i32 %31, %39
%41 = load i32, i32* %5
%42 = ashr i32 %40, %41
%43 = trunc i32 %42 to i8
ret i8 %43
}

LLVM IR (-O2):
@GetBitRangeFromByte.bitmask = internal unnamed_addr constant [8 x [8 x i8]] [[8 x i8] c"\01\03\07\0F\1F?\7F\FF", [8 x i8] c"\03\02\06\0E\1E>~\FE", [8 x i8] c"\07\06\04\0C\1C<|\FC", [8 x i8] c"\0F\0E\0C\08\188x\F8", [8 x i8] c"\1F\1E\1C\18\100p\F0", [8 x i8] c"?><80 `\E0", [8 x i8] c"\7F~|xp`@\C0", [8 x i8] c"\FF\FE\FC\F8\F0\E0\C0\80"]
define zeroext i8 @GetBitRangeFromByte(i8 zeroext %0, i32 %1, i32 %2) {
%4 = icmp sle i32 %1, %2
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = icmp ult i32 %1, 8
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = icmp ult i32 %2, 8
%11 = zext i1 %10 to i32
%12 = tail call i32 @assert(i32 %11)
%13 = sext i32 %1 to i64
%14 = sext i32 %2 to i64
%15 = getelementptr inbounds [8 x [8 x i8]], [8 x [8 x i8]]* @GetBitRangeFromByte.bitmask, i64 0, i64 %13, i64 %14
%16 = load i8, i8* %15
%17 = and i8 %16, %0
%18 = zext i8 %17 to i32
%19 = lshr i32 %18, %1
%20 = trunc i32 %19 to i8
ret i8 %20
}