#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 mboot_crc16(unsigned short crc_init, unsigned char *buffer,
                           int len) {
  unsigned short crc;
  unsigned char *p = (unsigned char *)buffer;
  crc = crc_init;
  while (len-- > 0)
    crc = shitfer(*p++, crc);
  crc = shitfer(0, crc);
  crc = shitfer(0, crc);
  return crc;
}


x86 assembly (clang, -O0):
<mboot_crc16>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %di,%ax
mov    %ax,-0x2(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x2(%rbp),%ax
mov    %ax,-0x16(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
cmp    $0x0,%eax
jle    116e <mboot_crc16+0x5e>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movzbl (%rax),%edi
movzwl -0x16(%rbp),%esi
call   1030 <shitfer@plt>
mov    %ax,-0x16(%rbp)
jmp    1136 <mboot_crc16+0x26>
xor    %edi,%edi
movzwl -0x16(%rbp),%esi
call   1030 <shitfer@plt>
mov    %ax,-0x16(%rbp)
xor    %edi,%edi
movzwl -0x16(%rbp),%esi
call   1030 <shitfer@plt>
mov    %ax,-0x16(%rbp)
movzwl -0x16(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mboot_crc16>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%eax
test   %edx,%edx
jle    1147 <mboot_crc16+0x37>
mov    %edx,%ebp
mov    %rsi,%rbx
add    $0x1,%ebp
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 <mboot_crc16+0x20>
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 @mboot_crc16(i16 zeroext %0, i8* %1, i32 %2) {
%4 = alloca i16
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i16
%8 = alloca i8*
store i16 %0, i16* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = load i8*, i8** %5
store i8* %9, i8** %8
%10 = load i16, i16* %4
store i16 %10, i16* %7
br label %11
11: ; preds = %15, %3
%12 = load i32, i32* %6
%13 = add nsw i32 %12, -1
store i32 %13, i32* %6
%14 = icmp sgt i32 %12, 0
br i1 %14, label %15, label %22
15: ; preds = %11
%16 = load i8*, i8** %8
%17 = getelementptr inbounds i8, i8* %16, i32 1
store i8* %17, i8** %8
%18 = load i8, i8* %16
%19 = zext i8 %18 to i32
%20 = load i16, i16* %7
%21 = call zeroext i16 @shitfer(i32 %19, i16 zeroext %20)
store i16 %21, i16* %7
br label %11
22: ; preds = %11
%23 = load i16, i16* %7
%24 = call zeroext i16 @shitfer(i32 0, i16 zeroext %23)
store i16 %24, i16* %7
%25 = load i16, i16* %7
%26 = call zeroext i16 @shitfer(i32 0, i16 zeroext %25)
store i16 %26, i16* %7
%27 = load i16, i16* %7
ret i16 %27
}

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