#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 */

/* Variables and functions */
unsigned short shitfer(int /*<<< orphan*/, unsigned short);
unsigned short crc16(const unsigned char *buffer, int len) {
  unsigned short crc;
  unsigned char *p = (unsigned char *)buffer;
  crc = 0;
  while (len-- > 0)
    crc = shitfer(*p++, crc);
  crc = shitfer(0, crc);
  crc = shitfer(0, crc);
  return crc;
}


x86 assembly (clang, -O0):
<crc16>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movw   $0x0,-0xe(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0xc(%rbp)
cmp    $0x0,%eax
jle    1165 <crc16+0x55>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movzbl (%rax),%edi
movzwl -0xe(%rbp),%esi
call   1030 <shitfer@plt>
mov    %ax,-0xe(%rbp)
jmp    112d <crc16+0x1d>
xor    %edi,%edi
movzwl -0xe(%rbp),%esi
call   1030 <shitfer@plt>
mov    %ax,-0xe(%rbp)
xor    %edi,%edi
movzwl -0xe(%rbp),%esi
call   1030 <shitfer@plt>
mov    %ax,-0xe(%rbp)
movzwl -0xe(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<crc16>:
push   %rbp
push   %rbx
push   %rax
test   %esi,%esi
jle    1149 <crc16+0x39>
mov    %esi,%ebp
mov    %rdi,%rbx
add    $0x1,%ebp
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl (%rbx),%edi
add    $0x1,%rbx
movzwl %ax,%esi
call   1030 <shitfer@plt>
add    $0xffffffff,%ebp
cmp    $0x1,%ebp
ja     1130 <crc16+0x20>
jmp    114b <crc16+0x3b>
xor    %eax,%eax
movzwl %ax,%esi
xor    %edi,%edi
call   1030 <shitfer@plt>
movzwl %ax,%esi
xor    %edi,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <shitfer@plt>

LLVM IR (-O0):
define zeroext i16 @crc16(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i16
%6 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = load i8*, i8** %3
store i8* %7, i8** %6
store i16 0, i16* %5
br label %8
8: ; preds = %12, %2
%9 = load i32, i32* %4
%10 = add nsw i32 %9, -1
store i32 %10, i32* %4
%11 = icmp sgt i32 %9, 0
br i1 %11, label %12, label %19
12: ; preds = %8
%13 = load i8*, i8** %6
%14 = getelementptr inbounds i8, i8* %13, i32 1
store i8* %14, i8** %6
%15 = load i8, i8* %13
%16 = zext i8 %15 to i32
%17 = load i16, i16* %5
%18 = call zeroext i16 @shitfer(i32 %16, i16 zeroext %17)
store i16 %18, i16* %5
br label %8
19: ; preds = %8
%20 = load i16, i16* %5
%21 = call zeroext i16 @shitfer(i32 0, i16 zeroext %20)
store i16 %21, i16* %5
%22 = load i16, i16* %5
%23 = call zeroext i16 @shitfer(i32 0, i16 zeroext %22)
store i16 %23, i16* %5
%24 = load i16, i16* %5
ret i16 %24
}

LLVM IR (-O2):
define zeroext i16 @crc16(i8* nocapture %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %14
4: ; preds = %2, %4
%5 = phi i8* [ %9, %4 ], [ %0, %2 ]
%6 = phi i16 [ %12, %4 ], [ 0, %2 ]
%7 = phi i32 [ %8, %4 ], [ %1, %2 ]
%8 = add nsw i32 %7, -1
%9 = getelementptr inbounds i8, i8* %5, i64 1
%10 = load i8, i8* %5
%11 = zext i8 %10 to i32
%12 = tail call zeroext i16 @shitfer(i32 %11, i16 zeroext %6)
%13 = icmp ugt i32 %7, 1
br i1 %13, label %4, label %14
14: ; preds = %4, %2
%15 = phi i16 [ 0, %2 ], [ %12, %4 ]
%16 = tail call zeroext i16 @shitfer(i32 0, i16 zeroext %15)
%17 = tail call zeroext i16 @shitfer(i32 0, i16 zeroext %16)
ret i16 %17
}