#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 /*<<< orphan*/ uint8_t;
typedef int uint32_t;
typedef int /*<<< orphan*/ uint16_t;

/* Variables and functions */
int crc32(int, int /*<<< orphan*/ *, int);
uint16_t get_crc16(uint8_t *buffer, uint32_t size, int init_flag) {
  static uint32_t crc = 0;
  if (buffer == NULL)
    return 0;
  if (init_flag == 1)
    crc = 0;
  crc = crc32(crc, buffer, size);
  return (uint16_t)(0xffff & crc);
}


x86 assembly (clang, -O0):
<get_crc16>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1139 <get_crc16+0x29>
movl   $0x0,-0x4(%rbp)
jmp    1173 <get_crc16+0x63>
cmpl   $0x1,-0x18(%rbp)
jne    114d <get_crc16+0x3d>
movl   $0x0,0x2edf(%rip)
mov    0x2ed9(%rip),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <crc32@plt>
mov    %eax,0x2ec7(%rip)
mov    0x2ec1(%rip),%eax
and    $0xffff,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_crc16>:
test   %rdi,%rdi
je     112e <get_crc16+0x1e>
push   %rax
mov    %esi,%eax
mov    %rdi,%rsi
cmp    $0x1,%edx
jne    1131 <get_crc16+0x21>
movl   $0x0,0x2f02(%rip)
xor    %edi,%edi
jmp    1137 <get_crc16+0x27>
xor    %eax,%eax
ret
mov    0x2ef5(%rip),%edi
mov    %eax,%edx
call   1030 <crc32@plt>
mov    %eax,0x2ee8(%rip)
movzwl %ax,%eax
add    $0x8,%rsp
ret

LLVM IR (-O0):
@get_crc16.crc = internal global i32 0
define i32 @get_crc16(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%8 = load i32*, i32** %5
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %11
10: ; preds = %3
store i32 0, i32* %4
br label %22
11: ; preds = %3
%12 = load i32, i32* %7
%13 = icmp eq i32 %12, 1
br i1 %13, label %14, label %15
14: ; preds = %11
store i32 0, i32* @get_crc16.crc
br label %15
15: ; preds = %14, %11
%16 = load i32, i32* @get_crc16.crc
%17 = load i32*, i32** %5
%18 = load i32, i32* %6
%19 = call i32 @crc32(i32 %16, i32* %17, i32 %18)
store i32 %19, i32* @get_crc16.crc
%20 = load i32, i32* @get_crc16.crc
%21 = and i32 65535, %20
store i32 %21, i32* %4
br label %22
22: ; preds = %15, %10
%23 = load i32, i32* %4
ret i32 %23
}

LLVM IR (-O2):
@get_crc16.crc = internal unnamed_addr global i32 0
define i32 @get_crc16(i32* %0, i32 %1, i32 %2) {
%4 = icmp eq i32* %0, null
br i1 %4, label %14, label %5
5: ; preds = %3
%6 = icmp eq i32 %2, 1
br i1 %6, label %9, label %7
7: ; preds = %5
%8 = load i32, i32* @get_crc16.crc
br label %10
9: ; preds = %5
store i32 0, i32* @get_crc16.crc
br label %10
10: ; preds = %7, %9
%11 = phi i32 [ %8, %7 ], [ 0, %9 ]
%12 = tail call i32 @crc32(i32 %11, i32* %0, i32 %1)
store i32 %12, i32* @get_crc16.crc
%13 = and i32 %12, 65535
br label %14
14: ; preds = %3, %10
%15 = phi i32 [ %13, %10 ], [ 0, %3 ]
ret i32 %15
}