int getNextCodeword(long *bitsRead, unsigned char *compressedMem) {
  int codeword = (compressedMem[(*bitsRead) / 8] << 8) +
                 compressedMem[(*bitsRead) / 8 + 1];
  codeword = codeword >> (4 - ((*bitsRead) % 8));
  codeword = codeword & 0xfff;
  (*bitsRead) += 12;
  return (codeword);
}


x86 assembly (clang, -O0):
<getNextCodeword>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    $0x8,%ecx
cqto
idiv   %rcx
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
movzbl (%rax,%rcx,1),%eax
shl    $0x8,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    $0x8,%esi
cqto
idiv   %rsi
mov    %rax,%rdx
mov    -0x1c(%rbp),%eax
movzbl 0x1(%rcx,%rdx,1),%ecx
add    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    $0x8,%ecx
cqto
idiv   %rcx
mov    -0x18(%rbp),%eax
mov    $0x4,%ecx
sub    %rdx,%rcx
sar    %cl,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
and    $0xfff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
add    $0xc,%rcx
mov    %rcx,(%rax)
mov    -0x14(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<getNextCodeword>:
mov    (%rdi),%rdx
lea    0x7(%rdx),%rcx
test   %rdx,%rdx
cmovns %rdx,%rcx
sar    $0x3,%rcx
movzwl (%rsi,%rcx,1),%eax
shl    $0x10,%eax
bswap  %eax
shl    $0x3,%ecx
mov    %edx,%esi
sub    %ecx,%esi
mov    $0x4,%cl
sub    %sil,%cl
shr    %cl,%eax
and    $0xfff,%eax
add    $0xc,%rdx
mov    %rdx,(%rdi)
ret

LLVM IR (-O0):
define i32 @getNextCodeword(i64* %0, i8* %1) {
%3 = alloca i64*
%4 = alloca i8*
%5 = alloca i32
store i64* %0, i64** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %4
%7 = load i64*, i64** %3
%8 = load i64, i64* %7
%9 = sdiv i64 %8, 8
%10 = getelementptr inbounds i8, i8* %6, i64 %9
%11 = load i8, i8* %10
%12 = zext i8 %11 to i32
%13 = shl i32 %12, 8
%14 = load i8*, i8** %4
%15 = load i64*, i64** %3
%16 = load i64, i64* %15
%17 = sdiv i64 %16, 8
%18 = add nsw i64 %17, 1
%19 = getelementptr inbounds i8, i8* %14, i64 %18
%20 = load i8, i8* %19
%21 = zext i8 %20 to i32
%22 = add nsw i32 %13, %21
store i32 %22, i32* %5
%23 = load i32, i32* %5
%24 = load i64*, i64** %3
%25 = load i64, i64* %24
%26 = srem i64 %25, 8
%27 = sub nsw i64 4, %26
%28 = trunc i64 %27 to i32
%29 = ashr i32 %23, %28
store i32 %29, i32* %5
%30 = load i32, i32* %5
%31 = and i32 %30, 4095
store i32 %31, i32* %5
%32 = load i64*, i64** %3
%33 = load i64, i64* %32
%34 = add nsw i64 %33, 12
store i64 %34, i64* %32
%35 = load i32, i32* %5
ret i32 %35
}

LLVM IR (-O2):
define i32 @getNextCodeword(i64* nocapture %0, i8* nocapture %1) {
%3 = load i64, i64* %0
%4 = sdiv i64 %3, 8
%5 = getelementptr inbounds i8, i8* %1, i64 %4
%6 = load i8, i8* %5
%7 = zext i8 %6 to i32
%8 = shl nuw nsw i32 %7, 8
%9 = add nsw i64 %4, 1
%10 = getelementptr inbounds i8, i8* %1, i64 %9
%11 = load i8, i8* %10
%12 = zext i8 %11 to i32
%13 = or i32 %8, %12
%14 = srem i64 %3, 8
%15 = trunc i64 %14 to i32
%16 = sub nsw i32 4, %15
%17 = lshr i32 %13, %16
%18 = and i32 %17, 4095
%19 = add nsw i64 %3, 12
store i64 %19, i64* %0
ret i32 %18
}