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

/* Variables and functions */
uint16_t compute_crc(uint16_t crc, uint8_t onech) {
  int idx;
  uint32_t ans = (crc ^ onech << 8);
  for (idx = 0; idx < 8; ++idx) {
    if (ans & 0x8000) {
      ans <<= 1;
      ans = ans ^ 4129;
    } else {
      ans <<= 1;
    }
  }
  return ans;
}


x86 assembly (clang, -O0):
<compute_crc>:
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,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x8,-0xc(%rbp)
jge    116f <compute_crc+0x6f>
mov    -0x10(%rbp),%eax
and    $0x8000,%eax
cmp    $0x0,%eax
je     1153 <compute_crc+0x53>
mov    -0x10(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
xor    $0x1021,%eax
mov    %eax,-0x10(%rbp)
jmp    115c <compute_crc+0x5c>
mov    -0x10(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1161 <compute_crc+0x61>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    111f <compute_crc+0x1f>
mov    -0x10(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<compute_crc>:
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 @compute_crc(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = load i32, i32* %3
%8 = load i32, i32* %4
%9 = shl i32 %8, 8
%10 = xor i32 %7, %9
store i32 %10, i32* %6
store i32 0, i32* %5
br label %11
11: ; preds = %27, %2
%12 = load i32, i32* %5
%13 = icmp slt i32 %12, 8
br i1 %13, label %14, label %30
14: ; preds = %11
%15 = load i32, i32* %6
%16 = and i32 %15, 32768
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %14
%19 = load i32, i32* %6
%20 = shl i32 %19, 1
store i32 %20, i32* %6
%21 = load i32, i32* %6
%22 = xor i32 %21, 4129
store i32 %22, i32* %6
br label %26
23: ; preds = %14
%24 = load i32, i32* %6
%25 = shl i32 %24, 1
store i32 %25, i32* %6
br label %26
26: ; preds = %23, %18
br label %27
27: ; preds = %26
%28 = load i32, i32* %5
%29 = add nsw i32 %28, 1
store i32 %29, i32* %5
br label %11
30: ; preds = %11
%31 = load i32, i32* %6
ret i32 %31
}

LLVM IR (-O2):
define i32 @compute_crc(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
}