#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 */
size_t reverseLowerBits(size_t value, size_t cnt) {
  value =
      ((value & 0b1010101010101010) >> 1) | ((value & 0b0101010101010101) << 1);
  value =
      ((value & 0b1100110011001100) >> 2) | ((value & 0b0011001100110011) << 2);
  value =
      ((value & 0b1111000011110000) >> 4) | ((value & 0b0000111100001111) << 4);
  value =
      ((value & 0b1111111100000000) >> 8) | ((value & 0b0000000011111111) << 8);
  return value >> (16 - cnt);
}


x86 assembly (clang, -O0):
<reverseLowerBits>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
and    $0xaaaa,%rax
shr    $0x1,%rax
mov    -0x8(%rbp),%rcx
and    $0x5555,%rcx
shl    $0x1,%rcx
or     %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
and    $0xcccc,%rax
shr    $0x2,%rax
mov    -0x8(%rbp),%rcx
and    $0x3333,%rcx
shl    $0x2,%rcx
or     %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
and    $0xf0f0,%rax
shr    $0x4,%rax
mov    -0x8(%rbp),%rcx
and    $0xf0f,%rcx
shl    $0x4,%rcx
or     %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
and    $0xff00,%rax
shr    $0x8,%rax
mov    -0x8(%rbp),%rcx
and    $0xff,%rcx
shl    $0x8,%rcx
or     %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    $0x10,%ecx
sub    -0x10(%rbp),%rcx
shr    %cl,%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverseLowerBits>:
rol    $0x8,%di
mov    %edi,%eax
and    $0xf0f,%eax
shl    $0x4,%eax
shr    $0x4,%edi
and    $0xf0f,%edi
or     %eax,%edi
mov    %edi,%eax
and    $0x3333,%eax
shr    $0x2,%edi
and    $0x3333,%edi
lea    (%rdi,%rax,4),%eax
mov    %eax,%ecx
and    $0x5555,%ecx
shr    %eax
and    $0x5555,%eax
lea    (%rax,%rcx,2),%eax
mov    $0x10,%cl
sub    %sil,%cl
shr    %cl,%rax
ret

LLVM IR (-O0):
define i64 @reverseLowerBits(i64 %0, i64 %1) {
%3 = alloca i64
%4 = alloca i64
store i64 %0, i64* %3
store i64 %1, i64* %4
%5 = load i64, i64* %3
%6 = and i64 %5, 43690
%7 = lshr i64 %6, 1
%8 = load i64, i64* %3
%9 = and i64 %8, 21845
%10 = shl i64 %9, 1
%11 = or i64 %7, %10
store i64 %11, i64* %3
%12 = load i64, i64* %3
%13 = and i64 %12, 52428
%14 = lshr i64 %13, 2
%15 = load i64, i64* %3
%16 = and i64 %15, 13107
%17 = shl i64 %16, 2
%18 = or i64 %14, %17
store i64 %18, i64* %3
%19 = load i64, i64* %3
%20 = and i64 %19, 61680
%21 = lshr i64 %20, 4
%22 = load i64, i64* %3
%23 = and i64 %22, 3855
%24 = shl i64 %23, 4
%25 = or i64 %21, %24
store i64 %25, i64* %3
%26 = load i64, i64* %3
%27 = and i64 %26, 65280
%28 = lshr i64 %27, 8
%29 = load i64, i64* %3
%30 = and i64 %29, 255
%31 = shl i64 %30, 8
%32 = or i64 %28, %31
store i64 %32, i64* %3
%33 = load i64, i64* %3
%34 = load i64, i64* %4
%35 = sub i64 16, %34
%36 = lshr i64 %33, %35
ret i64 %36
}

LLVM IR (-O2):
define i64 @reverseLowerBits(i64 %0, i64 %1) {
%3 = trunc i64 %0 to i16
%4 = tail call i16 @llvm.bitreverse.i16(i16 %3)
%5 = zext i16 %4 to i64
%6 = sub i64 16, %1
%7 = lshr i64 %5, %6
ret i64 %7
}