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

/* Variables and functions */
uint8_t crc8(uint8_t const msg[], size_t const msg_size) {
  static uint8_t const crc8_table[256] = {
      0x0,  0x9B, 0xAD, 0x36, 0xC1, 0x5A, 0x6C, 0xF7, 0x19, 0x82, 0xB4, 0x2F,
      0xD8, 0x43, 0x75, 0xEE, 0x32, 0xA9, 0x9F, 0x4,  0xF3, 0x68, 0x5E, 0xC5,
      0x2B, 0xB0, 0x86, 0x1D, 0xEA, 0x71, 0x47, 0xDC, 0x64, 0xFF, 0xC9, 0x52,
      0xA5, 0x3E, 0x8,  0x93, 0x7D, 0xE6, 0xD0, 0x4B, 0xBC, 0x27, 0x11, 0x8A,
      0x56, 0xCD, 0xFB, 0x60, 0x97, 0xC,  0x3A, 0xA1, 0x4F, 0xD4, 0xE2, 0x79,
      0x8E, 0x15, 0x23, 0xB8, 0xC8, 0x53, 0x65, 0xFE, 0x9,  0x92, 0xA4, 0x3F,
      0xD1, 0x4A, 0x7C, 0xE7, 0x10, 0x8B, 0xBD, 0x26, 0xFA, 0x61, 0x57, 0xCC,
      0x3B, 0xA0, 0x96, 0xD,  0xE3, 0x78, 0x4E, 0xD5, 0x22, 0xB9, 0x8F, 0x14,
      0xAC, 0x37, 0x1,  0x9A, 0x6D, 0xF6, 0xC0, 0x5B, 0xB5, 0x2E, 0x18, 0x83,
      0x74, 0xEF, 0xD9, 0x42, 0x9E, 0x5,  0x33, 0xA8, 0x5F, 0xC4, 0xF2, 0x69,
      0x87, 0x1C, 0x2A, 0xB1, 0x46, 0xDD, 0xEB, 0x70, 0xB,  0x90, 0xA6, 0x3D,
      0xCA, 0x51, 0x67, 0xFC, 0x12, 0x89, 0xBF, 0x24, 0xD3, 0x48, 0x7E, 0xE5,
      0x39, 0xA2, 0x94, 0xF,  0xF8, 0x63, 0x55, 0xCE, 0x20, 0xBB, 0x8D, 0x16,
      0xE1, 0x7A, 0x4C, 0xD7, 0x6F, 0xF4, 0xC2, 0x59, 0xAE, 0x35, 0x3,  0x98,
      0x76, 0xED, 0xDB, 0x40, 0xB7, 0x2C, 0x1A, 0x81, 0x5D, 0xC6, 0xF0, 0x6B,
      0x9C, 0x7,  0x31, 0xAA, 0x44, 0xDF, 0xE9, 0x72, 0x85, 0x1E, 0x28, 0xB3,
      0xC3, 0x58, 0x6E, 0xF5, 0x2,  0x99, 0xAF, 0x34, 0xDA, 0x41, 0x77, 0xEC,
      0x1B, 0x80, 0xB6, 0x2D, 0xF1, 0x6A, 0x5C, 0xC7, 0x30, 0xAB, 0x9D, 0x6,
      0xE8, 0x73, 0x45, 0xDE, 0x29, 0xB2, 0x84, 0x1F, 0xA7, 0x3C, 0xA,  0x91,
      0x66, 0xFD, 0xCB, 0x50, 0xBE, 0x25, 0x13, 0x88, 0x7F, 0xE4, 0xD2, 0x49,
      0x95, 0xE,  0x38, 0xA3, 0x54, 0xCF, 0xF9, 0x62, 0x8C, 0x17, 0x21, 0xBA,
      0x4D, 0xD6, 0xE0, 0x7B};
  uint8_t crc = 0;
  {
    uint8_t const *it = msg;
    for (; it != msg + msg_size; ++it) {
      crc = crc8_table[crc ^ *it];
    }
  }
  return crc;
}


x86 assembly (clang, -O0):
<crc8>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%rdx
shl    $0x2,%rdx
add    %rdx,%rcx
cmp    %rcx,%rax
je     1161 <crc8+0x61>
mov    -0x14(%rbp),%eax
mov    -0x20(%rbp),%rcx
xor    (%rcx),%eax
movslq %eax,%rcx
lea    0xeb6(%rip),%rax
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x20(%rbp)
jmp    111b <crc8+0x1b>
mov    -0x14(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<crc8>:
test   %rsi,%rsi
je     1132 <crc8+0x32>
shl    $0x2,%rsi
xor    %ecx,%ecx
lea    0xeee(%rip),%rdx
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    (%rdi,%rcx,1),%eax
cltq
mov    (%rdx,%rax,4),%eax
add    $0x4,%rcx
cmp    %rcx,%rsi
jne    1120 <crc8+0x20>
ret
xor    %eax,%eax
ret

LLVM IR (-O0):
@crc8.crc8_table = internal constant [256 x i32] [i32 0, i32 155, i32 173, i32 54, i32 193, i32 90, i32 108, i32 247, i32 25, i32 130, i32 180, i32 47, i32 216, i32 67, i32 117, i32 238, i32 50, i32 169, i32 159, i32 4, i32 243, i32 104, i32 94, i32 197, i32 43, i32 176, i32 134, i32 29, i32 234, i32 113, i32 71, i32 220, i32 100, i32 255, i32 201, i32 82, i32 165, i32 62, i32 8, i32 147, i32 125, i32 230, i32 208, i32 75, i32 188, i32 39, i32 17, i32 138, i32 86, i32 205, i32 251, i32 96, i32 151, i32 12, i32 58, i32 161, i32 79, i32 212, i32 226, i32 121, i32 142, i32 21, i32 35, i32 184, i32 200, i32 83, i32 101, i32 254, i32 9, i32 146, i32 164, i32 63, i32 209, i32 74, i32 124, i32 231, i32 16, i32 139, i32 189, i32 38, i32 250, i32 97, i32 87, i32 204, i32 59, i32 160, i32 150, i32 13, i32 227, i32 120, i32 78, i32 213, i32 34, i32 185, i32 143, i32 20, i32 172, i32 55, i32 1, i32 154, i32 109, i32 246, i32 192, i32 91, i32 181, i32 46, i32 24, i32 131, i32 116, i32 239, i32 217, i32 66, i32 158, i32 5, i32 51, i32 168, i32 95, i32 196, i32 242, i32 105, i32 135, i32 28, i32 42, i32 177, i32 70, i32 221, i32 235, i32 112, i32 11, i32 144, i32 166, i32 61, i32 202, i32 81, i32 103, i32 252, i32 18, i32 137, i32 191, i32 36, i32 211, i32 72, i32 126, i32 229, i32 57, i32 162, i32 148, i32 15, i32 248, i32 99, i32 85, i32 206, i32 32, i32 187, i32 141, i32 22, i32 225, i32 122, i32 76, i32 215, i32 111, i32 244, i32 194, i32 89, i32 174, i32 53, i32 3, i32 152, i32 118, i32 237, i32 219, i32 64, i32 183, i32 44, i32 26, i32 129, i32 93, i32 198, i32 240, i32 107, i32 156, i32 7, i32 49, i32 170, i32 68, i32 223, i32 233, i32 114, i32 133, i32 30, i32 40, i32 179, i32 195, i32 88, i32 110, i32 245, i32 2, i32 153, i32 175, i32 52, i32 218, i32 65, i32 119, i32 236, i32 27, i32 128, i32 182, i32 45, i32 241, i32 106, i32 92, i32 199, i32 48, i32 171, i32 157, i32 6, i32 232, i32 115, i32 69, i32 222, i32 41, i32 178, i32 132, i32 31, i32 167, i32 60, i32 10, i32 145, i32 102, i32 253, i32 203, i32 80, i32 190, i32 37, i32 19, i32 136, i32 127, i32 228, i32 210, i32 73, i32 149, i32 14, i32 56, i32 163, i32 84, i32 207, i32 249, i32 98, i32 140, i32 23, i32 33, i32 186, i32 77, i32 214, i32 224, i32 123]
define i32 @crc8(i32* %0, i64 %1) {
%3 = alloca i32*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32*
store i32* %0, i32** %3
store i64 %1, i64* %4
store i32 0, i32* %5
%7 = load i32*, i32** %3
store i32* %7, i32** %6
br label %8
8: ; preds = %22, %2
%9 = load i32*, i32** %6
%10 = load i32*, i32** %3
%11 = load i64, i64* %4
%12 = getelementptr inbounds i32, i32* %10, i64 %11
%13 = icmp ne i32* %9, %12
br i1 %13, label %14, label %25
14: ; preds = %8
%15 = load i32, i32* %5
%16 = load i32*, i32** %6
%17 = load i32, i32* %16
%18 = xor i32 %15, %17
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [256 x i32], [256 x i32]* @crc8.crc8_table, i64 0, i64 %19
%21 = load i32, i32* %20
store i32 %21, i32* %5
br label %22
22: ; preds = %14
%23 = load i32*, i32** %6
%24 = getelementptr inbounds i32, i32* %23, i32 1
store i32* %24, i32** %6
br label %8
25: ; preds = %8
%26 = load i32, i32* %5
ret i32 %26
}

LLVM IR (-O2):
@crc8.crc8_table = internal unnamed_addr constant [256 x i32] [i32 0, i32 155, i32 173, i32 54, i32 193, i32 90, i32 108, i32 247, i32 25, i32 130, i32 180, i32 47, i32 216, i32 67, i32 117, i32 238, i32 50, i32 169, i32 159, i32 4, i32 243, i32 104, i32 94, i32 197, i32 43, i32 176, i32 134, i32 29, i32 234, i32 113, i32 71, i32 220, i32 100, i32 255, i32 201, i32 82, i32 165, i32 62, i32 8, i32 147, i32 125, i32 230, i32 208, i32 75, i32 188, i32 39, i32 17, i32 138, i32 86, i32 205, i32 251, i32 96, i32 151, i32 12, i32 58, i32 161, i32 79, i32 212, i32 226, i32 121, i32 142, i32 21, i32 35, i32 184, i32 200, i32 83, i32 101, i32 254, i32 9, i32 146, i32 164, i32 63, i32 209, i32 74, i32 124, i32 231, i32 16, i32 139, i32 189, i32 38, i32 250, i32 97, i32 87, i32 204, i32 59, i32 160, i32 150, i32 13, i32 227, i32 120, i32 78, i32 213, i32 34, i32 185, i32 143, i32 20, i32 172, i32 55, i32 1, i32 154, i32 109, i32 246, i32 192, i32 91, i32 181, i32 46, i32 24, i32 131, i32 116, i32 239, i32 217, i32 66, i32 158, i32 5, i32 51, i32 168, i32 95, i32 196, i32 242, i32 105, i32 135, i32 28, i32 42, i32 177, i32 70, i32 221, i32 235, i32 112, i32 11, i32 144, i32 166, i32 61, i32 202, i32 81, i32 103, i32 252, i32 18, i32 137, i32 191, i32 36, i32 211, i32 72, i32 126, i32 229, i32 57, i32 162, i32 148, i32 15, i32 248, i32 99, i32 85, i32 206, i32 32, i32 187, i32 141, i32 22, i32 225, i32 122, i32 76, i32 215, i32 111, i32 244, i32 194, i32 89, i32 174, i32 53, i32 3, i32 152, i32 118, i32 237, i32 219, i32 64, i32 183, i32 44, i32 26, i32 129, i32 93, i32 198, i32 240, i32 107, i32 156, i32 7, i32 49, i32 170, i32 68, i32 223, i32 233, i32 114, i32 133, i32 30, i32 40, i32 179, i32 195, i32 88, i32 110, i32 245, i32 2, i32 153, i32 175, i32 52, i32 218, i32 65, i32 119, i32 236, i32 27, i32 128, i32 182, i32 45, i32 241, i32 106, i32 92, i32 199, i32 48, i32 171, i32 157, i32 6, i32 232, i32 115, i32 69, i32 222, i32 41, i32 178, i32 132, i32 31, i32 167, i32 60, i32 10, i32 145, i32 102, i32 253, i32 203, i32 80, i32 190, i32 37, i32 19, i32 136, i32 127, i32 228, i32 210, i32 73, i32 149, i32 14, i32 56, i32 163, i32 84, i32 207, i32 249, i32 98, i32 140, i32 23, i32 33, i32 186, i32 77, i32 214, i32 224, i32 123]
define i32 @crc8(i32* %0, i64 %1) {
%3 = getelementptr inbounds i32, i32* %0, i64 %1
%4 = icmp eq i64 %1, 0
br i1 %4, label %15, label %5
5: ; preds = %2, %5
%6 = phi i32* [ %13, %5 ], [ %0, %2 ]
%7 = phi i32 [ %12, %5 ], [ 0, %2 ]
%8 = load i32, i32* %6
%9 = xor i32 %8, %7
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [256 x i32], [256 x i32]* @crc8.crc8_table, i64 0, i64 %10
%12 = load i32, i32* %11
%13 = getelementptr inbounds i32, i32* %6, i64 1
%14 = icmp eq i32* %13, %3
br i1 %14, label %15, label %5
15: ; preds = %5, %2
%16 = phi i32 [ 0, %2 ], [ %12, %5 ]
ret i32 %16
}