#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 u_char;

/* Variables and functions */
int getb(u_char *field, unsigned pos) {
  u_char mask;
  int i;
  mask = 0x80;
  for (i = 0; i < (pos % 8); i++)
    mask = (mask >> 1);
  return (((mask & field[(int)(pos / 8)]) == mask) ? 1 : 0);
}


x86 assembly (clang, -O0):
<getb>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x80,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0xc(%rbp),%ecx
and    $0x7,%ecx
cmp    %ecx,%eax
jae    1141 <getb+0x41>
mov    -0x10(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1119 <getb+0x19>
mov    -0x10(%rbp),%edx
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
shr    $0x3,%ecx
movslq %ecx,%rcx
and    (%rax,%rcx,4),%edx
mov    -0x10(%rbp),%esi
xor    %eax,%eax
mov    $0x1,%ecx
cmp    %esi,%edx
cmove  %ecx,%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<getb>:
mov    %esi,%edx
and    $0x7,%edx
cmp    $0x6,%edx
ja     112b <getb+0x2b>
mov    $0x40,%eax
mov    $0x80,%ecx
lea    0xee5(%rip),%r8
movslq (%r8,%rdx,4),%rdx
add    %r8,%rdx
jmp    *%rdx
mov    $0x20,%eax
jmp    114c <getb+0x4c>
mov    $0x1,%eax
jmp    114c <getb+0x4c>
mov    $0x10,%eax
jmp    114c <getb+0x4c>
mov    $0x8,%eax
jmp    114c <getb+0x4c>
mov    $0x4,%eax
jmp    114c <getb+0x4c>
mov    $0x2,%eax
mov    %eax,%ecx
shr    $0x3,%esi
mov    (%rdi,%rsi,4),%edx
not    %edx
xor    %eax,%eax
test   %edx,%ecx
sete   %al
ret

LLVM IR (-O0):
define i32 @getb(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
store i32 128, i32* %5
store i32 0, i32* %6
br label %7
7: ; preds = %15, %2
%8 = load i32, i32* %6
%9 = load i32, i32* %4
%10 = urem i32 %9, 8
%11 = icmp ult i32 %8, %10
br i1 %11, label %12, label %18
12: ; preds = %7
%13 = load i32, i32* %5
%14 = ashr i32 %13, 1
store i32 %14, i32* %5
br label %15
15: ; preds = %12
%16 = load i32, i32* %6
%17 = add nsw i32 %16, 1
store i32 %17, i32* %6
br label %7
18: ; preds = %7
%19 = load i32, i32* %5
%20 = load i32*, i32** %3
%21 = load i32, i32* %4
%22 = udiv i32 %21, 8
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i32, i32* %20, i64 %23
%25 = load i32, i32* %24
%26 = and i32 %19, %25
%27 = load i32, i32* %5
%28 = icmp eq i32 %26, %27
%29 = zext i1 %28 to i64
%30 = select i1 %28, i32 1, i32 0
ret i32 %30
}

LLVM IR (-O2):
define i32 @getb(i32* nocapture %0, i32 %1) {
%3 = and i32 %1, 7
switch i32 %3, label %4 [
i32 0, label %12
i32 1, label %10
i32 2, label %5
i32 3, label %6
i32 4, label %7
i32 5, label %8
i32 6, label %9
]
4: ; preds = %2
br label %10
5: ; preds = %2
br label %10
6: ; preds = %2
br label %10
7: ; preds = %2
br label %10
8: ; preds = %2
br label %10
9: ; preds = %2
br label %10
10: ; preds = %2, %9, %8, %7, %6, %5, %4
%11 = phi i32 [ 1, %4 ], [ 64, %2 ], [ 32, %5 ], [ 16, %6 ], [ 8, %7 ], [ 4, %8 ], [ 2, %9 ]
br label %12
12: ; preds = %2, %10
%13 = phi i32 [ 128, %2 ], [ %11, %10 ]
%14 = lshr i32 %1, 3
%15 = zext i32 %14 to i64
%16 = getelementptr inbounds i32, i32* %0, i64 %15
%17 = load i32, i32* %16
%18 = and i32 %17, %13
%19 = icmp eq i32 %18, %13
%20 = zext i1 %19 to i32
ret i32 %20
}