#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;
typedef int uint16_t;
typedef int int16_t;

/* Variables and functions */
uint16_t CRC16(uint16_t crc, uint8_t value) {
  uint8_t i;
  crc = crc ^ (int16_t)value << 8;
  for (i = 0; i < 8; i++) {
    if (crc & 0x8000)
      crc = (crc << 1) ^ 0x1021;
    else
      crc = (crc << 1);
  }
  return crc;
}


x86 assembly (clang, -O0):
<CRC16>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    -0x8(%rbp),%ecx
shl    $0x8,%ecx
xor    %ecx,%eax
mov    %eax,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x8,-0xc(%rbp)
jge    1169 <CRC16+0x69>
mov    -0x4(%rbp),%eax
and    $0x8000,%eax
cmp    $0x0,%eax
je     114d <CRC16+0x4d>
mov    -0x4(%rbp),%eax
shl    $0x1,%eax
xor    $0x1021,%eax
mov    %eax,-0x4(%rbp)
jmp    1156 <CRC16+0x56>
mov    -0x4(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    115b <CRC16+0x5b>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    111f <CRC16+0x1f>
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<CRC16>:
shl    $0x8,%esi
xor    %edi,%esi
lea    (%rsi,%rsi,1),%eax
mov    %eax,%ecx
xor    $0x1021,%ecx
test   $0x8000,%esi
cmove  %eax,%ecx
lea    (%rcx,%rcx,1),%eax
mov    %eax,%edx
xor    $0x1021,%edx
test   $0x8000,%ecx
cmove  %eax,%edx
lea    (%rdx,%rdx,1),%eax
mov    %eax,%ecx
xor    $0x1021,%ecx
test   $0x8000,%edx
cmove  %eax,%ecx
lea    (%rcx,%rcx,1),%eax
mov    %eax,%edx
xor    $0x1021,%edx
test   $0x8000,%ecx
cmove  %eax,%edx
lea    (%rdx,%rdx,1),%eax
mov    %eax,%ecx
xor    $0x1021,%ecx
test   $0x8000,%edx
cmove  %eax,%ecx
lea    (%rcx,%rcx,1),%eax
mov    %eax,%edx
xor    $0x1021,%edx
test   $0x8000,%ecx
cmove  %eax,%edx
lea    (%rdx,%rdx,1),%eax
mov    %eax,%ecx
xor    $0x1021,%ecx
test   $0x8000,%edx
cmove  %eax,%ecx
lea    (%rcx,%rcx,1),%edx
mov    %edx,%eax
xor    $0x1021,%eax
test   $0x8000,%ecx
cmove  %edx,%eax
ret

LLVM IR (-O0):
define i32 @CRC16(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = load i32, i32* %3
%7 = load i32, i32* %4
%8 = shl i32 %7, 8
%9 = xor i32 %6, %8
store i32 %9, i32* %3
store i32 0, i32* %5
br label %10
10: ; preds = %25, %2
%11 = load i32, i32* %5
%12 = icmp slt i32 %11, 8
br i1 %12, label %13, label %28
13: ; preds = %10
%14 = load i32, i32* %3
%15 = and i32 %14, 32768
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %13
%18 = load i32, i32* %3
%19 = shl i32 %18, 1
%20 = xor i32 %19, 4129
store i32 %20, i32* %3
br label %24
21: ; preds = %13
%22 = load i32, i32* %3
%23 = shl i32 %22, 1
store i32 %23, i32* %3
br label %24
24: ; preds = %21, %17
br label %25
25: ; preds = %24
%26 = load i32, i32* %5
%27 = add nsw i32 %26, 1
store i32 %27, i32* %5
br label %10
28: ; preds = %10
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
define i32 @CRC16(i32 %0, i32 %1) {
%3 = shl i32 %1, 8
%4 = xor i32 %3, %0
%5 = and i32 %4, 32768
%6 = icmp eq i32 %5, 0
%7 = shl i32 %4, 1
%8 = xor i32 %7, 4129
%9 = select i1 %6, i32 %7, i32 %8
%10 = and i32 %9, 32768
%11 = icmp eq i32 %10, 0
%12 = shl i32 %9, 1
%13 = xor i32 %12, 4129
%14 = select i1 %11, i32 %12, i32 %13
%15 = and i32 %14, 32768
%16 = icmp eq i32 %15, 0
%17 = shl i32 %14, 1
%18 = xor i32 %17, 4129
%19 = select i1 %16, i32 %17, i32 %18
%20 = and i32 %19, 32768
%21 = icmp eq i32 %20, 0
%22 = shl i32 %19, 1
%23 = xor i32 %22, 4129
%24 = select i1 %21, i32 %22, i32 %23
%25 = and i32 %24, 32768
%26 = icmp eq i32 %25, 0
%27 = shl i32 %24, 1
%28 = xor i32 %27, 4129
%29 = select i1 %26, i32 %27, i32 %28
%30 = and i32 %29, 32768
%31 = icmp eq i32 %30, 0
%32 = shl i32 %29, 1
%33 = xor i32 %32, 4129
%34 = select i1 %31, i32 %32, i32 %33
%35 = and i32 %34, 32768
%36 = icmp eq i32 %35, 0
%37 = shl i32 %34, 1
%38 = xor i32 %37, 4129
%39 = select i1 %36, i32 %37, i32 %38
%40 = and i32 %39, 32768
%41 = icmp eq i32 %40, 0
%42 = shl i32 %39, 1
%43 = xor i32 %42, 4129
%44 = select i1 %41, i32 %42, i32 %43
ret i32 %44
}