unsigned short ccitt_crc16(unsigned char *message, short length) {
  static unsigned short CRC16_Lookup[] = {
      0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf, 0x8c48,
      0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7, 0x1081, 0x0108,
      0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e, 0x9cc9, 0x8d40, 0xbfdb,
      0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876, 0x2102, 0x308b, 0x0210, 0x1399,
      0x6726, 0x76af, 0x4434, 0x55bd, 0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e,
      0xfae7, 0xc87c, 0xd9f5, 0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e,
      0x54b5, 0x453c, 0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd,
      0xc974, 0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb,
      0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3, 0x5285,
      0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a, 0xdecd, 0xcf44,
      0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72, 0x6306, 0x728f, 0x4014,
      0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9, 0xef4e, 0xfec7, 0xcc5c, 0xddd5,
      0xa96a, 0xb8e3, 0x8a78, 0x9bf1, 0x7387, 0x620e, 0x5095, 0x411c, 0x35a3,
      0x242a, 0x16b1, 0x0738, 0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862,
      0x9af9, 0x8b70, 0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e,
      0xf0b7, 0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff,
      0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036, 0x18c1,
      0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e, 0xa50a, 0xb483,
      0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5, 0x2942, 0x38cb, 0x0a50,
      0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd, 0xb58b, 0xa402, 0x9699, 0x8710,
      0xf3af, 0xe226, 0xd0bd, 0xc134, 0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7,
      0x6e6e, 0x5cf5, 0x4d7c, 0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1,
      0xa33a, 0xb2b3, 0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72,
      0x3efb, 0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232,
      0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a, 0xe70e,
      0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1, 0x6b46, 0x7acf,
      0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9, 0xf78f, 0xe606, 0xd49d,
      0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330, 0x7bc7, 0x6a4e, 0x58d5, 0x495c,
      0x3de3, 0x2c6a, 0x1ef1, 0x0f78};
  unsigned short crc16 = 0xFFFF;
  int i;
  for (i = 0; i < length; i++) {
    crc16 = ((crc16 >> 8) & 0xFF) ^ CRC16_Lookup[(crc16 ^ message[i]) & 0xFF];
  }
  crc16 &= 0xffff;
  return crc16;
}


x86 assembly (clang, -O0):
<ccitt_crc16>:
push   %rbp
mov    %rsp,%rbp
mov    %si,%ax
mov    %rdi,-0x8(%rbp)
mov    %ax,-0xa(%rbp)
movw   $0xffff,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
movswl -0xa(%rbp),%ecx
cmp    %ecx,%eax
jge    1171 <ccitt_crc16+0x71>
movzwl -0xc(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
movzwl -0xc(%rbp),%ecx
mov    -0x8(%rbp),%rdx
movslq -0x10(%rbp),%rsi
movzbl (%rdx,%rsi,1),%edx
xor    %edx,%ecx
and    $0xff,%ecx
movslq %ecx,%rdx
lea    0x2ed7(%rip),%rcx
movzwl (%rcx,%rdx,2),%ecx
xor    %ecx,%eax
mov    %ax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    111c <ccitt_crc16+0x1c>
movzwl -0xc(%rbp),%eax
and    $0xffff,%eax
mov    %ax,-0xc(%rbp)
movzwl -0xc(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<ccitt_crc16>:
test   %si,%si
jle    1118 <ccitt_crc16+0x18>
movzwl %si,%r8d
cmp    $0x1,%si
jne    111d <ccitt_crc16+0x1d>
mov    $0xffff,%eax
xor    %edx,%edx
jmp    1170 <ccitt_crc16+0x70>
mov    $0xffff,%ax
ret
mov    %r8d,%r9d
and    $0xfffffffe,%r9d
mov    $0xffff,%eax
xor    %edx,%edx
lea    0xece(%rip),%r10
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl %al,%esi
shr    $0x8,%eax
movzbl (%rdi,%rdx,1),%ecx
xor    %ecx,%esi
movzwl (%r10,%rsi,2),%ecx
xor    %ecx,%eax
shr    $0x8,%ecx
movzbl 0x1(%rdi,%rdx,1),%esi
movzbl %al,%eax
xor    %esi,%eax
movzwl (%r10,%rax,2),%eax
xor    %ecx,%eax
add    $0x2,%rdx
cmp    %rdx,%r9
jne    1140 <ccitt_crc16+0x40>
test   $0x1,%r8b
je     1191 <ccitt_crc16+0x91>
mov    %eax,%ecx
shr    $0x8,%ecx
movzbl (%rdi,%rdx,1),%edx
movzbl %al,%eax
xor    %edx,%eax
lea    0xe75(%rip),%rdx
movzwl (%rdx,%rax,2),%eax
xor    %ecx,%eax
ret

LLVM IR (-O0):
@ccitt_crc16.CRC16_Lookup = internal global [256 x i16] [i16 0, i16 4489, i16 8978, i16 12955, i16 17956, i16 22445, i16 25910, i16 29887, i16 -29624, i16 -25151, i16 -20646, i16 -16685, i16 -13716, i16 -9243, i16 -5762, i16 -1801, i16 4225, i16 264, i16 13203, i16 8730, i16 22181, i16 18220, i16 30135, i16 25662, i16 -25399, i16 -29376, i16 -16421, i16 -20910, i16 -9491, i16 -13468, i16 -1537, i16 -6026, i16 8450, i16 12427, i16 528, i16 5017, i16 26406, i16 30383, i16 17460, i16 21949, i16 -21174, i16 -17213, i16 -29096, i16 -24623, i16 -5266, i16 -1305, i16 -14212, i16 -9739, i16 12675, i16 8202, i16 4753, i16 792, i16 30631, i16 26158, i16 21685, i16 17724, i16 -16949, i16 -21438, i16 -24871, i16 -28848, i16 -1041, i16 -5530, i16 -9987, i16 -13964, i16 16900, i16 21389, i16 24854, i16 28831, i16 1056, i16 5545, i16 10034, i16 14011, i16 -12724, i16 -8251, i16 -4770, i16 -809, i16 -30616, i16 -26143, i16 -21638, i16 -17677, i16 21125, i16 17164, i16 29079, i16 24606, i16 5281, i16 1320, i16 14259, i16 9786, i16 -8499, i16 -12476, i16 -545, i16 -5034, i16 -26391, i16 -30368, i16 -17413, i16 -21902, i16 25350, i16 29327, i16 16404, i16 20893, i16 9506, i16 13483, i16 1584, i16 6073, i16 -4274, i16 -313, i16 -13220, i16 -8747, i16 -22166, i16 -18205, i16 -30088, i16 -25615, i16 29575, i16 25102, i16 20629, i16 16668, i16 13731, i16 9258, i16 5809, i16 1848, i16 -49, i16 -4538, i16 -8995, i16 -12972, i16 -17941, i16 -22430, i16 -25863, i16 -29840, i16 -31736, i16 -27263, i16 -22758, i16 -18797, i16 -15828, i16 -11355, i16 -7874, i16 -3913, i16 2112, i16 6601, i16 11090, i16 15067, i16 20068, i16 24557, i16 28022, i16 31999, i16 -27511, i16 -31488, i16 -18533, i16 -23022, i16 -11603, i16 -15580, i16 -3649, i16 -8138, i16 6337, i16 2376, i16 15315, i16 10842, i16 24293, i16 20332, i16 32247, i16 27774, i16 -23286, i16 -19325, i16 -31208, i16 -26735, i16 -7378, i16 -3417, i16 -16324, i16 -11851, i16 10562, i16 14539, i16 2640, i16 7129, i16 28518, i16 32495, i16 19572, i16 24061, i16 -19061, i16 -23550, i16 -26983, i16 -30960, i16 -3153, i16 -7642, i16 -12099, i16 -16076, i16 14787, i16 10314, i16 6865, i16 2904, i16 32743, i16 28270, i16 23797, i16 19836, i16 -14836, i16 -10363, i16 -6882, i16 -2921, i16 -32728, i16 -28255, i16 -23750, i16 -19789, i16 19012, i16 23501, i16 26966, i16 30943, i16 3168, i16 7657, i16 12146, i16 16123, i16 -10611, i16 -14588, i16 -2657, i16 -7146, i16 -28503, i16 -32480, i16 -19525, i16 -24014, i16 23237, i16 19276, i16 31191, i16 26718, i16 7393, i16 3432, i16 16371, i16 11898, i16 -6386, i16 -2425, i16 -15332, i16 -10859, i16 -24278, i16 -20317, i16 -32200, i16 -27727, i16 27462, i16 31439, i16 18516, i16 23005, i16 11618, i16 15595, i16 3696, i16 8185, i16 -2161, i16 -6650, i16 -11107, i16 -15084, i16 -20053, i16 -24542, i16 -27975, i16 -31952, i16 31687, i16 27214, i16 22741, i16 18780, i16 15843, i16 11370, i16 7921, i16 3960]
define zeroext i16 @ccitt_crc16(i8* %0, i16 signext %1) {
%3 = alloca i8*
%4 = alloca i16
%5 = alloca i16
%6 = alloca i32
store i8* %0, i8** %3
store i16 %1, i16* %4
store i16 -1, i16* %5
store i32 0, i32* %6
br label %7
7: ; preds = %33, %2
%8 = load i32, i32* %6
%9 = load i16, i16* %4
%10 = sext i16 %9 to i32
%11 = icmp slt i32 %8, %10
br i1 %11, label %12, label %36
12: ; preds = %7
%13 = load i16, i16* %5
%14 = zext i16 %13 to i32
%15 = ashr i32 %14, 8
%16 = and i32 %15, 255
%17 = load i16, i16* %5
%18 = zext i16 %17 to i32
%19 = load i8*, i8** %3
%20 = load i32, i32* %6
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
%23 = load i8, i8* %22
%24 = zext i8 %23 to i32
%25 = xor i32 %18, %24
%26 = and i32 %25, 255
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [256 x i16], [256 x i16]* @ccitt_crc16.CRC16_Lookup, i64 0, i64 %27
%29 = load i16, i16* %28
%30 = zext i16 %29 to i32
%31 = xor i32 %16, %30
%32 = trunc i32 %31 to i16
store i16 %32, i16* %5
br label %33
33: ; preds = %12
%34 = load i32, i32* %6
%35 = add nsw i32 %34, 1
store i32 %35, i32* %6
br label %7
36: ; preds = %7
%37 = load i16, i16* %5
%38 = zext i16 %37 to i32
%39 = and i32 %38, 65535
%40 = trunc i32 %39 to i16
store i16 %40, i16* %5
%41 = load i16, i16* %5
ret i16 %41
}

LLVM IR (-O2):
@ccitt_crc16.CRC16_Lookup = internal unnamed_addr constant [256 x i16] [i16 0, i16 4489, i16 8978, i16 12955, i16 17956, i16 22445, i16 25910, i16 29887, i16 -29624, i16 -25151, i16 -20646, i16 -16685, i16 -13716, i16 -9243, i16 -5762, i16 -1801, i16 4225, i16 264, i16 13203, i16 8730, i16 22181, i16 18220, i16 30135, i16 25662, i16 -25399, i16 -29376, i16 -16421, i16 -20910, i16 -9491, i16 -13468, i16 -1537, i16 -6026, i16 8450, i16 12427, i16 528, i16 5017, i16 26406, i16 30383, i16 17460, i16 21949, i16 -21174, i16 -17213, i16 -29096, i16 -24623, i16 -5266, i16 -1305, i16 -14212, i16 -9739, i16 12675, i16 8202, i16 4753, i16 792, i16 30631, i16 26158, i16 21685, i16 17724, i16 -16949, i16 -21438, i16 -24871, i16 -28848, i16 -1041, i16 -5530, i16 -9987, i16 -13964, i16 16900, i16 21389, i16 24854, i16 28831, i16 1056, i16 5545, i16 10034, i16 14011, i16 -12724, i16 -8251, i16 -4770, i16 -809, i16 -30616, i16 -26143, i16 -21638, i16 -17677, i16 21125, i16 17164, i16 29079, i16 24606, i16 5281, i16 1320, i16 14259, i16 9786, i16 -8499, i16 -12476, i16 -545, i16 -5034, i16 -26391, i16 -30368, i16 -17413, i16 -21902, i16 25350, i16 29327, i16 16404, i16 20893, i16 9506, i16 13483, i16 1584, i16 6073, i16 -4274, i16 -313, i16 -13220, i16 -8747, i16 -22166, i16 -18205, i16 -30088, i16 -25615, i16 29575, i16 25102, i16 20629, i16 16668, i16 13731, i16 9258, i16 5809, i16 1848, i16 -49, i16 -4538, i16 -8995, i16 -12972, i16 -17941, i16 -22430, i16 -25863, i16 -29840, i16 -31736, i16 -27263, i16 -22758, i16 -18797, i16 -15828, i16 -11355, i16 -7874, i16 -3913, i16 2112, i16 6601, i16 11090, i16 15067, i16 20068, i16 24557, i16 28022, i16 31999, i16 -27511, i16 -31488, i16 -18533, i16 -23022, i16 -11603, i16 -15580, i16 -3649, i16 -8138, i16 6337, i16 2376, i16 15315, i16 10842, i16 24293, i16 20332, i16 32247, i16 27774, i16 -23286, i16 -19325, i16 -31208, i16 -26735, i16 -7378, i16 -3417, i16 -16324, i16 -11851, i16 10562, i16 14539, i16 2640, i16 7129, i16 28518, i16 32495, i16 19572, i16 24061, i16 -19061, i16 -23550, i16 -26983, i16 -30960, i16 -3153, i16 -7642, i16 -12099, i16 -16076, i16 14787, i16 10314, i16 6865, i16 2904, i16 32743, i16 28270, i16 23797, i16 19836, i16 -14836, i16 -10363, i16 -6882, i16 -2921, i16 -32728, i16 -28255, i16 -23750, i16 -19789, i16 19012, i16 23501, i16 26966, i16 30943, i16 3168, i16 7657, i16 12146, i16 16123, i16 -10611, i16 -14588, i16 -2657, i16 -7146, i16 -28503, i16 -32480, i16 -19525, i16 -24014, i16 23237, i16 19276, i16 31191, i16 26718, i16 7393, i16 3432, i16 16371, i16 11898, i16 -6386, i16 -2425, i16 -15332, i16 -10859, i16 -24278, i16 -20317, i16 -32200, i16 -27727, i16 27462, i16 31439, i16 18516, i16 23005, i16 11618, i16 15595, i16 3696, i16 8185, i16 -2161, i16 -6650, i16 -11107, i16 -15084, i16 -20053, i16 -24542, i16 -27975, i16 -31952, i16 31687, i16 27214, i16 22741, i16 18780, i16 15843, i16 11370, i16 7921, i16 3960]
define zeroext i16 @ccitt_crc16(i8* nocapture %0, i16 signext %1) {
%3 = icmp sgt i16 %1, 0
br i1 %3, label %4, label %61
4: ; preds = %2
%5 = zext i16 %1 to i64
%6 = and i64 %5, 1
%7 = icmp eq i16 %1, 1
br i1 %7, label %40, label %8
8: ; preds = %4
%9 = and i64 %5, 65534
br label %10
10: ; preds = %10, %8
%11 = phi i64 [ 0, %8 ], [ %37, %10 ]
%12 = phi i32 [ 65535, %8 ], [ %36, %10 ]
%13 = phi i64 [ 0, %8 ], [ %38, %10 ]
%14 = lshr i32 %12, 8
%15 = getelementptr inbounds i8, i8* %0, i64 %11
%16 = load i8, i8* %15
%17 = zext i8 %16 to i32
%18 = and i32 %12, 255
%19 = xor i32 %18, %17
%20 = zext i32 %19 to i64
%21 = getelementptr inbounds [256 x i16], [256 x i16]* @ccitt_crc16.CRC16_Lookup, i64 0, i64 %20
%22 = load i16, i16* %21
%23 = zext i16 %22 to i32
%24 = xor i32 %14, %23
%25 = or i64 %11, 1
%26 = lshr i32 %23, 8
%27 = getelementptr inbounds i8, i8* %0, i64 %25
%28 = load i8, i8* %27
%29 = zext i8 %28 to i32
%30 = and i32 %24, 255
%31 = xor i32 %30, %29
%32 = zext i32 %31 to i64
%33 = getelementptr inbounds [256 x i16], [256 x i16]* @ccitt_crc16.CRC16_Lookup, i64 0, i64 %32
%34 = load i16, i16* %33
%35 = zext i16 %34 to i32
%36 = xor i32 %26, %35
%37 = add nuw nsw i64 %11, 2
%38 = add i64 %13, 2
%39 = icmp eq i64 %38, %9
br i1 %39, label %40, label %10
40: ; preds = %10, %4
%41 = phi i32 [ undef, %4 ], [ %36, %10 ]
%42 = phi i64 [ 0, %4 ], [ %37, %10 ]
%43 = phi i32 [ 65535, %4 ], [ %36, %10 ]
%44 = icmp eq i64 %6, 0
br i1 %44, label %58, label %45
45: ; preds = %40
%46 = lshr i32 %43, 8
%47 = and i32 %46, 255
%48 = getelementptr inbounds i8, i8* %0, i64 %42
%49 = load i8, i8* %48
%50 = zext i8 %49 to i32
%51 = and i32 %43, 255
%52 = xor i32 %51, %50
%53 = zext i32 %52 to i64
%54 = getelementptr inbounds [256 x i16], [256 x i16]* @ccitt_crc16.CRC16_Lookup, i64 0, i64 %53
%55 = load i16, i16* %54
%56 = zext i16 %55 to i32
%57 = xor i32 %47, %56
br label %58
58: ; preds = %40, %45
%59 = phi i32 [ %41, %40 ], [ %57, %45 ]
%60 = trunc i32 %59 to i16
br label %61
61: ; preds = %58, %2
%62 = phi i16 [ -1, %2 ], [ %60, %58 ]
ret i16 %62
}