#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 __u8;
typedef int __u16;

/* Variables and functions */
int crc_ccitt_update(int, int);
int crc_xmodem_update(int, int);
void crc1(__u8 *buf) {
  __u16 crc16_xmodem;
  __u16 crc16_ccitt;
  crc16_xmodem = crc_xmodem_update(0, buf[0]);
  crc16_xmodem = crc_xmodem_update(crc16_xmodem, buf[1]);
  crc16_ccitt = crc_ccitt_update(crc16_xmodem, buf[2]);
  crc16_ccitt = crc_ccitt_update(crc16_xmodem, buf[3]);
  buf[0] = ((crc16_xmodem >> 0) & 0xff);
  buf[1] = ((crc16_ccitt >> 0) & 0xff);
  buf[2] = ((crc16_xmodem >> 8) & 0xff);
  buf[3] = ((crc16_ccitt >> 8) & 0xff);
}


x86 assembly (clang, -O0):
<crc1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%esi
xor    %edi,%edi
call   1040 <crc_xmodem_update@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%esi
call   1040 <crc_xmodem_update@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%esi
call   1030 <crc_ccitt_update@plt>
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%rax
mov    0xc(%rax),%esi
call   1030 <crc_ccitt_update@plt>
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%ecx
sar    $0x0,%ecx
and    $0xff,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%ecx
sar    $0x0,%ecx
and    $0xff,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0xc(%rbp),%ecx
sar    $0x8,%ecx
and    $0xff,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x10(%rbp),%ecx
sar    $0x8,%ecx
and    $0xff,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0xc(%rax)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<crc1>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    (%rdi),%esi
xor    %edi,%edi
call   1040 <crc_xmodem_update@plt>
mov    0x4(%rbx),%esi
mov    %eax,%edi
call   1040 <crc_xmodem_update@plt>
mov    %eax,%ebp
mov    0x8(%rbx),%esi
mov    %eax,%edi
call   1030 <crc_ccitt_update@plt>
mov    0xc(%rbx),%esi
mov    %ebp,%edi
call   1030 <crc_ccitt_update@plt>
mov    %ebp,%edx
movzbl %dl,%ecx
mov    %ecx,(%rbx)
movzbl %al,%ecx
mov    %ecx,0x4(%rbx)
movzbl %dh,%ecx
mov    %ecx,0x8(%rbx)
movzbl %ah,%eax
mov    %eax,0xc(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define void @crc1(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
store i32* %0, i32** %2
%5 = load i32*, i32** %2
%6 = getelementptr inbounds i32, i32* %5, i64 0
%7 = load i32, i32* %6
%8 = call i32 @crc_xmodem_update(i32 0, i32 %7)
store i32 %8, i32* %3
%9 = load i32, i32* %3
%10 = load i32*, i32** %2
%11 = getelementptr inbounds i32, i32* %10, i64 1
%12 = load i32, i32* %11
%13 = call i32 @crc_xmodem_update(i32 %9, i32 %12)
store i32 %13, i32* %3
%14 = load i32, i32* %3
%15 = load i32*, i32** %2
%16 = getelementptr inbounds i32, i32* %15, i64 2
%17 = load i32, i32* %16
%18 = call i32 @crc_ccitt_update(i32 %14, i32 %17)
store i32 %18, i32* %4
%19 = load i32, i32* %3
%20 = load i32*, i32** %2
%21 = getelementptr inbounds i32, i32* %20, i64 3
%22 = load i32, i32* %21
%23 = call i32 @crc_ccitt_update(i32 %19, i32 %22)
store i32 %23, i32* %4
%24 = load i32, i32* %3
%25 = ashr i32 %24, 0
%26 = and i32 %25, 255
%27 = load i32*, i32** %2
%28 = getelementptr inbounds i32, i32* %27, i64 0
store i32 %26, i32* %28
%29 = load i32, i32* %4
%30 = ashr i32 %29, 0
%31 = and i32 %30, 255
%32 = load i32*, i32** %2
%33 = getelementptr inbounds i32, i32* %32, i64 1
store i32 %31, i32* %33
%34 = load i32, i32* %3
%35 = ashr i32 %34, 8
%36 = and i32 %35, 255
%37 = load i32*, i32** %2
%38 = getelementptr inbounds i32, i32* %37, i64 2
store i32 %36, i32* %38
%39 = load i32, i32* %4
%40 = ashr i32 %39, 8
%41 = and i32 %40, 255
%42 = load i32*, i32** %2
%43 = getelementptr inbounds i32, i32* %42, i64 3
store i32 %41, i32* %43
ret void
}

LLVM IR (-O2):
define void @crc1(i32* nocapture %0) {
%2 = load i32, i32* %0
%3 = tail call i32 @crc_xmodem_update(i32 0, i32 %2)
%4 = getelementptr inbounds i32, i32* %0, i64 1
%5 = load i32, i32* %4
%6 = tail call i32 @crc_xmodem_update(i32 %3, i32 %5)
%7 = getelementptr inbounds i32, i32* %0, i64 2
%8 = load i32, i32* %7
%9 = tail call i32 @crc_ccitt_update(i32 %6, i32 %8)
%10 = getelementptr inbounds i32, i32* %0, i64 3
%11 = load i32, i32* %10
%12 = tail call i32 @crc_ccitt_update(i32 %6, i32 %11)
%13 = and i32 %6, 255
store i32 %13, i32* %0
%14 = and i32 %12, 255
store i32 %14, i32* %4
%15 = lshr i32 %6, 8
%16 = and i32 %15, 255
store i32 %16, i32* %7
%17 = lshr i32 %12, 8
%18 = and i32 %17, 255
store i32 %18, i32* %10
ret void
}