int getBitFromByte(int maskposition, unsigned char byte) {
  unsigned char mask = 0x80;
  switch (maskposition) {
  case 1:
    mask = 0x80;
    break;
  case 2:
    mask = 0x40;
    break;
  case 3:
    mask = 0x20;
    break;
  case 4:
    mask = 0x10;
    break;
  case 5:
    mask = 0x08;
    break;
  case 6:
    mask = 0x04;
    break;
  case 7:
    mask = 0x02;
    break;
  case 8:
    mask = 0x01;
    break;
  }
  return ((byte & mask) != 0);
}


x86 assembly (clang, -O0):
<getBitFromByte>:
push   %rbp
mov    %rsp,%rbp
mov    %sil,%al
mov    %edi,-0x4(%rbp)
mov    %al,-0x5(%rbp)
movb   $0x80,-0x6(%rbp)
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x10(%rbp)
sub    $0x7,%eax
ja     117d <getBitFromByte+0x7d>
mov    -0x10(%rbp),%rax
lea    0xecf(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movb   $0x80,-0x6(%rbp)
jmp    117d <getBitFromByte+0x7d>
movb   $0x40,-0x6(%rbp)
jmp    117d <getBitFromByte+0x7d>
movb   $0x20,-0x6(%rbp)
jmp    117d <getBitFromByte+0x7d>
movb   $0x10,-0x6(%rbp)
jmp    117d <getBitFromByte+0x7d>
movb   $0x8,-0x6(%rbp)
jmp    117d <getBitFromByte+0x7d>
movb   $0x4,-0x6(%rbp)
jmp    117d <getBitFromByte+0x7d>
movb   $0x2,-0x6(%rbp)
jmp    117d <getBitFromByte+0x7d>
movb   $0x1,-0x6(%rbp)
movzbl -0x5(%rbp),%eax
movzbl -0x6(%rbp),%ecx
and    %ecx,%eax
cmp    $0x0,%eax
setne  %al
and    $0x1,%al
movzbl %al,%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<getBitFromByte>:
add    $0xfffffffe,%edi
mov    $0x80,%ecx
cmp    $0x6,%edi
ja     111a <getBitFromByte+0x1a>
movslq %edi,%rax
lea    0xee9(%rip),%rcx
mov    (%rcx,%rax,4),%ecx
movzbl %sil,%edx
xor    %eax,%eax
test   %edx,%ecx
setne  %al
ret

LLVM IR (-O0):
define i32 @getBitFromByte(i32 %0, i8 zeroext %1) {
%3 = alloca i32
%4 = alloca i8
%5 = alloca i8
store i32 %0, i32* %3
store i8 %1, i8* %4
store i8 -128, i8* %5
%6 = load i32, i32* %3
switch i32 %6, label %15 [
i32 1, label %7
i32 2, label %8
i32 3, label %9
i32 4, label %10
i32 5, label %11
i32 6, label %12
i32 7, label %13
i32 8, label %14
]
7: ; preds = %2
store i8 -128, i8* %5
br label %15
8: ; preds = %2
store i8 64, i8* %5
br label %15
9: ; preds = %2
store i8 32, i8* %5
br label %15
10: ; preds = %2
store i8 16, i8* %5
br label %15
11: ; preds = %2
store i8 8, i8* %5
br label %15
12: ; preds = %2
store i8 4, i8* %5
br label %15
13: ; preds = %2
store i8 2, i8* %5
br label %15
14: ; preds = %2
store i8 1, i8* %5
br label %15
15: ; preds = %2, %14, %13, %12, %11, %10, %9, %8, %7
%16 = load i8, i8* %4
%17 = zext i8 %16 to i32
%18 = load i8, i8* %5
%19 = zext i8 %18 to i32
%20 = and i32 %17, %19
%21 = icmp ne i32 %20, 0
%22 = zext i1 %21 to i32
ret i32 %22
}

LLVM IR (-O2):
@switch.table.getBitFromByte = [7 x i32] [i32 64, i32 32, i32 16, i32 8, i32 4, i32 2, i32 1]
define i32 @getBitFromByte(i32 %0, i8 zeroext %1) {
%3 = add i32 %0, -2
%4 = icmp ult i32 %3, 7
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = sext i32 %3 to i64
%7 = getelementptr inbounds [7 x i32], [7 x i32]* @switch.table.getBitFromByte, i64 0, i64 %6
%8 = load i32, i32* %7
br label %9
9: ; preds = %5, %2
%10 = phi i32 [ 128, %2 ], [ %8, %5 ]
%11 = zext i8 %1 to i32
%12 = and i32 %10, %11
%13 = icmp ne i32 %12, 0
%14 = zext i1 %13 to i32
ret i32 %14
}