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

/* Variables and functions */
uint16_t rev16(uint16_t a) {
  return ((a & 0x01) << 15) | ((a & 0x02) << 13) | ((a & 0x04) << 11) |
         ((a & 0x08) << 9) | ((a & 0x10) << 7) | ((a & 0x20) << 5) |
         ((a & 0x40) << 3) | ((a & 0x80) << 1) | ((a & 0x100) >> 1) |
         ((a & 0x200) >> 3) | ((a & 0x400) >> 5) | ((a & 0x800) >> 7) |
         ((a & 0x1000) >> 9) | ((a & 0x2000) >> 11) | ((a & 0x4000) >> 13) |
         ((a & 0x8000) >> 15);
}


x86 assembly (clang, -O0):
<rev16>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
and    $0x1,%eax
shl    $0xf,%eax
mov    -0x4(%rbp),%ecx
and    $0x2,%ecx
shl    $0xd,%ecx
or     %ecx,%eax
mov    -0x4(%rbp),%ecx
and    $0x4,%ecx
shl    $0xb,%ecx
or     %ecx,%eax
mov    -0x4(%rbp),%ecx
and    $0x8,%ecx
shl    $0x9,%ecx
or     %ecx,%eax
mov    -0x4(%rbp),%ecx
and    $0x10,%ecx
shl    $0x7,%ecx
or     %ecx,%eax
mov    -0x4(%rbp),%ecx
and    $0x20,%ecx
shl    $0x5,%ecx
or     %ecx,%eax
mov    -0x4(%rbp),%ecx
and    $0x40,%ecx
shl    $0x3,%ecx
or     %ecx,%eax
mov    -0x4(%rbp),%ecx
and    $0x80,%ecx
shl    $0x1,%ecx
or     %ecx,%eax
mov    -0x4(%rbp),%ecx
and    $0x100,%ecx
sar    $0x1,%ecx
or     %ecx,%eax
mov    -0x4(%rbp),%ecx
and    $0x200,%ecx
sar    $0x3,%ecx
or     %ecx,%eax
mov    -0x4(%rbp),%ecx
and    $0x400,%ecx
sar    $0x5,%ecx
or     %ecx,%eax
mov    -0x4(%rbp),%ecx
and    $0x800,%ecx
sar    $0x7,%ecx
or     %ecx,%eax
mov    -0x4(%rbp),%ecx
and    $0x1000,%ecx
sar    $0x9,%ecx
or     %ecx,%eax
mov    -0x4(%rbp),%ecx
and    $0x2000,%ecx
sar    $0xb,%ecx
or     %ecx,%eax
mov    -0x4(%rbp),%ecx
and    $0x4000,%ecx
sar    $0xd,%ecx
or     %ecx,%eax
mov    -0x4(%rbp),%ecx
and    $0x8000,%ecx
sar    $0xf,%ecx
or     %ecx,%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<rev16>:
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
ret

LLVM IR (-O0):
define i32 @rev16(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = and i32 %3, 1
%5 = shl i32 %4, 15
%6 = load i32, i32* %2
%7 = and i32 %6, 2
%8 = shl i32 %7, 13
%9 = or i32 %5, %8
%10 = load i32, i32* %2
%11 = and i32 %10, 4
%12 = shl i32 %11, 11
%13 = or i32 %9, %12
%14 = load i32, i32* %2
%15 = and i32 %14, 8
%16 = shl i32 %15, 9
%17 = or i32 %13, %16
%18 = load i32, i32* %2
%19 = and i32 %18, 16
%20 = shl i32 %19, 7
%21 = or i32 %17, %20
%22 = load i32, i32* %2
%23 = and i32 %22, 32
%24 = shl i32 %23, 5
%25 = or i32 %21, %24
%26 = load i32, i32* %2
%27 = and i32 %26, 64
%28 = shl i32 %27, 3
%29 = or i32 %25, %28
%30 = load i32, i32* %2
%31 = and i32 %30, 128
%32 = shl i32 %31, 1
%33 = or i32 %29, %32
%34 = load i32, i32* %2
%35 = and i32 %34, 256
%36 = ashr i32 %35, 1
%37 = or i32 %33, %36
%38 = load i32, i32* %2
%39 = and i32 %38, 512
%40 = ashr i32 %39, 3
%41 = or i32 %37, %40
%42 = load i32, i32* %2
%43 = and i32 %42, 1024
%44 = ashr i32 %43, 5
%45 = or i32 %41, %44
%46 = load i32, i32* %2
%47 = and i32 %46, 2048
%48 = ashr i32 %47, 7
%49 = or i32 %45, %48
%50 = load i32, i32* %2
%51 = and i32 %50, 4096
%52 = ashr i32 %51, 9
%53 = or i32 %49, %52
%54 = load i32, i32* %2
%55 = and i32 %54, 8192
%56 = ashr i32 %55, 11
%57 = or i32 %53, %56
%58 = load i32, i32* %2
%59 = and i32 %58, 16384
%60 = ashr i32 %59, 13
%61 = or i32 %57, %60
%62 = load i32, i32* %2
%63 = and i32 %62, 32768
%64 = ashr i32 %63, 15
%65 = or i32 %61, %64
ret i32 %65
}

LLVM IR (-O2):
define i32 @rev16(i32 %0) {
%2 = trunc i32 %0 to i16
%3 = tail call i16 @llvm.bitreverse.i16(i16 %2)
%4 = zext i16 %3 to i32
ret i32 %4
}