#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 int UpdateCRC16(unsigned int, int /*<<< orphan*/);
unsigned short Cal_CRC16(const unsigned char *data, unsigned int size) {
  unsigned int crc = 0;
  const unsigned char *dataEnd = data + size;
  while (data < dataEnd)
    crc = UpdateCRC16(crc, *data++);
  crc = UpdateCRC16(crc, 0);
  crc = UpdateCRC16(crc, 0);
  return crc & 0xffffu;
}


x86 assembly (clang, -O0):
<Cal_CRC16>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1164 <Cal_CRC16+0x54>
mov    -0x10(%rbp),%edi
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movzbl (%rax),%esi
call   1030 <UpdateCRC16@plt>
mov    %eax,-0x10(%rbp)
jmp    1134 <Cal_CRC16+0x24>
mov    -0x10(%rbp),%edi
xor    %esi,%esi
call   1030 <UpdateCRC16@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
xor    %esi,%esi
call   1030 <UpdateCRC16@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
and    $0xffff,%eax
movzwl %ax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Cal_CRC16>:
push   %r14
push   %rbx
push   %rax
test   %esi,%esi
je     1145 <Cal_CRC16+0x35>
mov    %rdi,%rbx
mov    %esi,%r14d
add    %rdi,%r14
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl (%rbx),%esi
add    $0x1,%rbx
mov    %eax,%edi
call   1030 <UpdateCRC16@plt>
cmp    %r14,%rbx
jb     1130 <Cal_CRC16+0x20>
jmp    1147 <Cal_CRC16+0x37>
xor    %eax,%eax
mov    %eax,%edi
xor    %esi,%esi
call   1030 <UpdateCRC16@plt>
mov    %eax,%edi
xor    %esi,%esi
call   1030 <UpdateCRC16@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define zeroext i16 @Cal_CRC16(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 0, i32* %5
%7 = load i8*, i8** %3
%8 = load i32, i32* %4
%9 = zext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %7, i64 %9
store i8* %10, i8** %6
br label %11
11: ; preds = %15, %2
%12 = load i8*, i8** %3
%13 = load i8*, i8** %6
%14 = icmp ult i8* %12, %13
br i1 %14, label %15, label %22
15: ; preds = %11
%16 = load i32, i32* %5
%17 = load i8*, i8** %3
%18 = getelementptr inbounds i8, i8* %17, i32 1
store i8* %18, i8** %3
%19 = load i8, i8* %17
%20 = zext i8 %19 to i32
%21 = call i32 @UpdateCRC16(i32 %16, i32 %20)
store i32 %21, i32* %5
br label %11
22: ; preds = %11
%23 = load i32, i32* %5
%24 = call i32 @UpdateCRC16(i32 %23, i32 0)
store i32 %24, i32* %5
%25 = load i32, i32* %5
%26 = call i32 @UpdateCRC16(i32 %25, i32 0)
store i32 %26, i32* %5
%27 = load i32, i32* %5
%28 = and i32 %27, 65535
%29 = trunc i32 %28 to i16
ret i16 %29
}

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