#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 /*<<< orphan*/ uint8_t;
typedef int /*<<< orphan*/ uint32_t;
typedef int uint16_t;

/* Variables and functions */
uint16_t crc16_ccitt(uint8_t *data, uint32_t len, uint16_t crc_init) {
  static uint16_t const crctable[256] = {
      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};
  uint16_t crc = crc_init;
  while (len-- > 0) {
    crc = (crc >> 8) ^ crctable[(crc ^ *data++) & 0xff];
  }
  return crc;
}


x86 assembly (clang, -O0):
<crc16_ccitt>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0xc(%rbp)
cmp    $0x0,%eax
jle    115d <crc16_ccitt+0x5d>
mov    -0x14(%rbp),%eax
sar    $0x8,%eax
mov    -0x14(%rbp),%ecx
mov    -0x8(%rbp),%rdx
mov    %rdx,%rsi
add    $0x4,%rsi
mov    %rsi,-0x8(%rbp)
xor    (%rdx),%ecx
and    $0xff,%ecx
movslq %ecx,%rdx
lea    0xeae(%rip),%rcx
xor    (%rcx,%rdx,4),%eax
mov    %eax,-0x14(%rbp)
jmp    1114 <crc16_ccitt+0x14>
mov    -0x14(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<crc16_ccitt>:
test   %esi,%esi
jle    1113 <crc16_ccitt+0x13>
test   $0x1,%sil
jne    1116 <crc16_ccitt+0x16>
mov    %esi,%ecx
cmp    $0x1,%esi
jne    113a <crc16_ccitt+0x3a>
jmp    1174 <crc16_ccitt+0x74>
mov    %edx,%eax
ret
lea    -0x1(%rsi),%ecx
mov    %edx,%eax
sar    $0x8,%eax
xor    (%rdi),%edx
add    $0x4,%rdi
movzbl %dl,%r8d
lea    0xed1(%rip),%rdx
xor    (%rdx,%r8,4),%eax
mov    %eax,%edx
cmp    $0x1,%esi
je     1174 <crc16_ccitt+0x74>
add    $0xffffffff,%ecx
lea    0xebc(%rip),%rsi
mov    %edx,%eax
cs nopw 0x0(%rax,%rax,1)
mov    %eax,%edx
xor    (%rdi),%eax
sar    $0x8,%edx
movzbl %al,%eax
xor    (%rsi,%rax,4),%edx
mov    %edx,%eax
sar    $0x8,%eax
xor    0x4(%rdi),%edx
movzbl %dl,%edx
xor    (%rsi,%rdx,4),%eax
add    $0x8,%rdi
add    $0xfffffffe,%ecx
jb     1150 <crc16_ccitt+0x50>
ret

LLVM IR (-O0):
@crc16_ccitt.crctable = internal constant [256 x i32] [i32 0, i32 4489, i32 8978, i32 12955, i32 17956, i32 22445, i32 25910, i32 29887, i32 35912, i32 40385, i32 44890, i32 48851, i32 51820, i32 56293, i32 59774, i32 63735, i32 4225, i32 264, i32 13203, i32 8730, i32 22181, i32 18220, i32 30135, i32 25662, i32 40137, i32 36160, i32 49115, i32 44626, i32 56045, i32 52068, i32 63999, i32 59510, i32 8450, i32 12427, i32 528, i32 5017, i32 26406, i32 30383, i32 17460, i32 21949, i32 44362, i32 48323, i32 36440, i32 40913, i32 60270, i32 64231, i32 51324, i32 55797, i32 12675, i32 8202, i32 4753, i32 792, i32 30631, i32 26158, i32 21685, i32 17724, i32 48587, i32 44098, i32 40665, i32 36688, i32 64495, i32 60006, i32 55549, i32 51572, i32 16900, i32 21389, i32 24854, i32 28831, i32 1056, i32 5545, i32 10034, i32 14011, i32 52812, i32 57285, i32 60766, i32 64727, i32 34920, i32 39393, i32 43898, i32 47859, i32 21125, i32 17164, i32 29079, i32 24606, i32 5281, i32 1320, i32 14259, i32 9786, i32 57037, i32 53060, i32 64991, i32 60502, i32 39145, i32 35168, i32 48123, i32 43634, i32 25350, i32 29327, i32 16404, i32 20893, i32 9506, i32 13483, i32 1584, i32 6073, i32 61262, i32 65223, i32 52316, i32 56789, i32 43370, i32 47331, i32 35448, i32 39921, i32 29575, i32 25102, i32 20629, i32 16668, i32 13731, i32 9258, i32 5809, i32 1848, i32 65487, i32 60998, i32 56541, i32 52564, i32 47595, i32 43106, i32 39673, i32 35696, i32 33800, i32 38273, i32 42778, i32 46739, i32 49708, i32 54181, i32 57662, i32 61623, i32 2112, i32 6601, i32 11090, i32 15067, i32 20068, i32 24557, i32 28022, i32 31999, i32 38025, i32 34048, i32 47003, i32 42514, i32 53933, i32 49956, i32 61887, i32 57398, i32 6337, i32 2376, i32 15315, i32 10842, i32 24293, i32 20332, i32 32247, i32 27774, i32 42250, i32 46211, i32 34328, i32 38801, i32 58158, i32 62119, i32 49212, i32 53685, i32 10562, i32 14539, i32 2640, i32 7129, i32 28518, i32 32495, i32 19572, i32 24061, i32 46475, i32 41986, i32 38553, i32 34576, i32 62383, i32 57894, i32 53437, i32 49460, i32 14787, i32 10314, i32 6865, i32 2904, i32 32743, i32 28270, i32 23797, i32 19836, i32 50700, i32 55173, i32 58654, i32 62615, i32 32808, i32 37281, i32 41786, i32 45747, i32 19012, i32 23501, i32 26966, i32 30943, i32 3168, i32 7657, i32 12146, i32 16123, i32 54925, i32 50948, i32 62879, i32 58390, i32 37033, i32 33056, i32 46011, i32 41522, i32 23237, i32 19276, i32 31191, i32 26718, i32 7393, i32 3432, i32 16371, i32 11898, i32 59150, i32 63111, i32 50204, i32 54677, i32 41258, i32 45219, i32 33336, i32 37809, i32 27462, i32 31439, i32 18516, i32 23005, i32 11618, i32 15595, i32 3696, i32 8185, i32 63375, i32 58886, i32 54429, i32 50452, i32 45483, i32 40994, i32 37561, i32 33584, i32 31687, i32 27214, i32 22741, i32 18780, i32 15843, i32 11370, i32 7921, i32 3960]
define i32 @crc16_ccitt(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = load i32, i32* %6
store i32 %8, i32* %7
br label %9
9: ; preds = %13, %3
%10 = load i32, i32* %5
%11 = add nsw i32 %10, -1
store i32 %11, i32* %5
%12 = icmp sgt i32 %10, 0
br i1 %12, label %13, label %26
13: ; preds = %9
%14 = load i32, i32* %7
%15 = ashr i32 %14, 8
%16 = load i32, i32* %7
%17 = load i32*, i32** %4
%18 = getelementptr inbounds i32, i32* %17, i32 1
store i32* %18, i32** %4
%19 = load i32, i32* %17
%20 = xor i32 %16, %19
%21 = and i32 %20, 255
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [256 x i32], [256 x i32]* @crc16_ccitt.crctable, i64 0, i64 %22
%24 = load i32, i32* %23
%25 = xor i32 %15, %24
store i32 %25, i32* %7
br label %9
26: ; preds = %9
%27 = load i32, i32* %7
ret i32 %27
}

LLVM IR (-O2):
@crc16_ccitt.crctable = internal unnamed_addr constant [256 x i32] [i32 0, i32 4489, i32 8978, i32 12955, i32 17956, i32 22445, i32 25910, i32 29887, i32 35912, i32 40385, i32 44890, i32 48851, i32 51820, i32 56293, i32 59774, i32 63735, i32 4225, i32 264, i32 13203, i32 8730, i32 22181, i32 18220, i32 30135, i32 25662, i32 40137, i32 36160, i32 49115, i32 44626, i32 56045, i32 52068, i32 63999, i32 59510, i32 8450, i32 12427, i32 528, i32 5017, i32 26406, i32 30383, i32 17460, i32 21949, i32 44362, i32 48323, i32 36440, i32 40913, i32 60270, i32 64231, i32 51324, i32 55797, i32 12675, i32 8202, i32 4753, i32 792, i32 30631, i32 26158, i32 21685, i32 17724, i32 48587, i32 44098, i32 40665, i32 36688, i32 64495, i32 60006, i32 55549, i32 51572, i32 16900, i32 21389, i32 24854, i32 28831, i32 1056, i32 5545, i32 10034, i32 14011, i32 52812, i32 57285, i32 60766, i32 64727, i32 34920, i32 39393, i32 43898, i32 47859, i32 21125, i32 17164, i32 29079, i32 24606, i32 5281, i32 1320, i32 14259, i32 9786, i32 57037, i32 53060, i32 64991, i32 60502, i32 39145, i32 35168, i32 48123, i32 43634, i32 25350, i32 29327, i32 16404, i32 20893, i32 9506, i32 13483, i32 1584, i32 6073, i32 61262, i32 65223, i32 52316, i32 56789, i32 43370, i32 47331, i32 35448, i32 39921, i32 29575, i32 25102, i32 20629, i32 16668, i32 13731, i32 9258, i32 5809, i32 1848, i32 65487, i32 60998, i32 56541, i32 52564, i32 47595, i32 43106, i32 39673, i32 35696, i32 33800, i32 38273, i32 42778, i32 46739, i32 49708, i32 54181, i32 57662, i32 61623, i32 2112, i32 6601, i32 11090, i32 15067, i32 20068, i32 24557, i32 28022, i32 31999, i32 38025, i32 34048, i32 47003, i32 42514, i32 53933, i32 49956, i32 61887, i32 57398, i32 6337, i32 2376, i32 15315, i32 10842, i32 24293, i32 20332, i32 32247, i32 27774, i32 42250, i32 46211, i32 34328, i32 38801, i32 58158, i32 62119, i32 49212, i32 53685, i32 10562, i32 14539, i32 2640, i32 7129, i32 28518, i32 32495, i32 19572, i32 24061, i32 46475, i32 41986, i32 38553, i32 34576, i32 62383, i32 57894, i32 53437, i32 49460, i32 14787, i32 10314, i32 6865, i32 2904, i32 32743, i32 28270, i32 23797, i32 19836, i32 50700, i32 55173, i32 58654, i32 62615, i32 32808, i32 37281, i32 41786, i32 45747, i32 19012, i32 23501, i32 26966, i32 30943, i32 3168, i32 7657, i32 12146, i32 16123, i32 54925, i32 50948, i32 62879, i32 58390, i32 37033, i32 33056, i32 46011, i32 41522, i32 23237, i32 19276, i32 31191, i32 26718, i32 7393, i32 3432, i32 16371, i32 11898, i32 59150, i32 63111, i32 50204, i32 54677, i32 41258, i32 45219, i32 33336, i32 37809, i32 27462, i32 31439, i32 18516, i32 23005, i32 11618, i32 15595, i32 3696, i32 8185, i32 63375, i32 58886, i32 54429, i32 50452, i32 45483, i32 40994, i32 37561, i32 33584, i32 31687, i32 27214, i32 22741, i32 18780, i32 15843, i32 11370, i32 7921, i32 3960]
define i32 @crc16_ccitt(i32* nocapture %0, i32 %1, i32 %2) {
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %50
5: ; preds = %3
%6 = and i32 %1, 1
%7 = icmp eq i32 %6, 0
br i1 %7, label %19, label %8
8: ; preds = %5
%9 = add nsw i32 %1, -1
%10 = ashr i32 %2, 8
%11 = getelementptr inbounds i32, i32* %0, i64 1
%12 = load i32, i32* %0
%13 = xor i32 %12, %2
%14 = and i32 %13, 255
%15 = zext i32 %14 to i64
%16 = getelementptr inbounds [256 x i32], [256 x i32]* @crc16_ccitt.crctable, i64 0, i64 %15
%17 = load i32, i32* %16
%18 = xor i32 %17, %10
br label %19
19: ; preds = %8, %5
%20 = phi i32 [ %2, %5 ], [ %18, %8 ]
%21 = phi i32* [ %0, %5 ], [ %11, %8 ]
%22 = phi i32 [ %1, %5 ], [ %9, %8 ]
%23 = phi i32 [ undef, %5 ], [ %18, %8 ]
%24 = icmp eq i32 %1, 1
br i1 %24, label %50, label %25
25: ; preds = %19, %25
%26 = phi i32 [ %47, %25 ], [ %20, %19 ]
%27 = phi i32* [ %40, %25 ], [ %21, %19 ]
%28 = phi i32 [ %38, %25 ], [ %22, %19 ]
%29 = ashr i32 %26, 8
%30 = getelementptr inbounds i32, i32* %27, i64 1
%31 = load i32, i32* %27
%32 = xor i32 %31, %26
%33 = and i32 %32, 255
%34 = zext i32 %33 to i64
%35 = getelementptr inbounds [256 x i32], [256 x i32]* @crc16_ccitt.crctable, i64 0, i64 %34
%36 = load i32, i32* %35
%37 = xor i32 %36, %29
%38 = add nsw i32 %28, -2
%39 = ashr i32 %37, 8
%40 = getelementptr inbounds i32, i32* %27, i64 2
%41 = load i32, i32* %30
%42 = xor i32 %41, %37
%43 = and i32 %42, 255
%44 = zext i32 %43 to i64
%45 = getelementptr inbounds [256 x i32], [256 x i32]* @crc16_ccitt.crctable, i64 0, i64 %44
%46 = load i32, i32* %45
%47 = xor i32 %46, %39
%48 = add i32 %28, -3
%49 = icmp ult i32 %48, -2
br i1 %49, label %25, label %50
50: ; preds = %19, %25, %3
%51 = phi i32 [ %2, %3 ], [ %23, %19 ], [ %47, %25 ]
ret i32 %51
}