#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 uint8_t;

/* Variables and functions */
int crc16_update(int, int);
int /*<<< orphan*/ printf(char *, int, int);
int main(int argc, char **argv) {
  uint8_t msg[] = {0x01, 0x03, 0x01, 0x00, 0x01, 0x00};
  int crc;
  crc = 0xFFFF;
  for (int i = 0; i < sizeof msg; i++) {
    crc = crc16_update(crc, msg[i]);
  }
  printf("%x %x\n", (uint8_t)(crc & 0xFF), (uint8_t)(crc >> 8));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xec3(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xec0(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xebd(%rip),%rax
mov    %rax,-0x20(%rbp)
movl   $0xffff,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
movslq -0x38(%rbp),%rax
cmp    $0x18,%rax
jae    1194 <main+0x74>
mov    -0x34(%rbp),%edi
movslq -0x38(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%esi
call   1040 <crc16_update@plt>
mov    %eax,-0x34(%rbp)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1165 <main+0x45>
mov    -0x34(%rbp),%esi
and    $0xff,%esi
mov    -0x34(%rbp),%edx
sar    $0x8,%edx
lea    0xe6e(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    $0xffff,%edi
mov    $0x1,%esi
call   1040 <crc16_update@plt>
mov    %eax,%edi
mov    $0x3,%esi
call   1040 <crc16_update@plt>
mov    %eax,%edi
mov    $0x1,%esi
call   1040 <crc16_update@plt>
mov    %eax,%edi
xor    %esi,%esi
call   1040 <crc16_update@plt>
mov    %eax,%edi
mov    $0x1,%esi
call   1040 <crc16_update@plt>
mov    %eax,%edi
xor    %esi,%esi
call   1040 <crc16_update@plt>
mov    %eax,%edi
call   1040 <crc16_update@plt>
mov    %eax,%edi
call   1040 <crc16_update@plt>
mov    %eax,%edi
call   1040 <crc16_update@plt>
mov    %eax,%edi
call   1040 <crc16_update@plt>
mov    %eax,%edi
call   1040 <crc16_update@plt>
mov    %eax,%edi
call   1040 <crc16_update@plt>
mov    %eax,%edi
call   1040 <crc16_update@plt>
mov    %eax,%edi
call   1040 <crc16_update@plt>
mov    %eax,%edi
call   1040 <crc16_update@plt>
mov    %eax,%edi
call   1040 <crc16_update@plt>
mov    %eax,%edi
call   1040 <crc16_update@plt>
mov    %eax,%edi
call   1040 <crc16_update@plt>
mov    %eax,%edi
call   1040 <crc16_update@plt>
mov    %eax,%edi
call   1040 <crc16_update@plt>
mov    %eax,%edi
call   1040 <crc16_update@plt>
mov    %eax,%edi
call   1040 <crc16_update@plt>
mov    %eax,%edi
call   1040 <crc16_update@plt>
mov    %eax,%edi
call   1040 <crc16_update@plt>
movzbl %al,%esi
sar    $0x8,%eax
lea    0xe0f(%rip),%rdi
mov    %eax,%edx
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@__const.main.msg = [6 x i32] [i32 1, i32 3, i32 1, i32 0, i32 1, i32 0]
@.str = [7 x i8] c"%x %x\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [6 x i32]
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = bitcast [6 x i32]* %6 to i8*
store i32 65535, i32* %7
store i32 0, i32* %8
br label %10
10: ; preds = %21, %2
%11 = load i32, i32* %8
%12 = sext i32 %11 to i64
%13 = icmp ult i64 %12, 24
br i1 %13, label %14, label %24
14: ; preds = %10
%15 = load i32, i32* %7
%16 = load i32, i32* %8
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [6 x i32], [6 x i32]* %6, i64 0, i64 %17
%19 = load i32, i32* %18
%20 = call i32 @crc16_update(i32 %15, i32 %19)
store i32 %20, i32* %7
br label %21
21: ; preds = %14
%22 = load i32, i32* %8
%23 = add nsw i32 %22, 1
store i32 %23, i32* %8
br label %10
24: ; preds = %10
%25 = load i32, i32* %7
%26 = and i32 %25, 255
%27 = load i32, i32* %7
%28 = ashr i32 %27, 8
%29 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %26, i32 %28)
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"%x %x\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @crc16_update(i32 65535, i32 1)
%4 = tail call i32 @crc16_update(i32 %3, i32 3)
%5 = tail call i32 @crc16_update(i32 %4, i32 1)
%6 = tail call i32 @crc16_update(i32 %5, i32 0)
%7 = tail call i32 @crc16_update(i32 %6, i32 1)
%8 = tail call i32 @crc16_update(i32 %7, i32 0)
%9 = tail call i32 @crc16_update(i32 %8, i32 undef)
%10 = tail call i32 @crc16_update(i32 %9, i32 undef)
%11 = tail call i32 @crc16_update(i32 %10, i32 undef)
%12 = tail call i32 @crc16_update(i32 %11, i32 undef)
%13 = tail call i32 @crc16_update(i32 %12, i32 undef)
%14 = tail call i32 @crc16_update(i32 %13, i32 undef)
%15 = tail call i32 @crc16_update(i32 %14, i32 undef)
%16 = tail call i32 @crc16_update(i32 %15, i32 undef)
%17 = tail call i32 @crc16_update(i32 %16, i32 undef)
%18 = tail call i32 @crc16_update(i32 %17, i32 undef)
%19 = tail call i32 @crc16_update(i32 %18, i32 undef)
%20 = tail call i32 @crc16_update(i32 %19, i32 undef)
%21 = tail call i32 @crc16_update(i32 %20, i32 undef)
%22 = tail call i32 @crc16_update(i32 %21, i32 undef)
%23 = tail call i32 @crc16_update(i32 %22, i32 undef)
%24 = tail call i32 @crc16_update(i32 %23, i32 undef)
%25 = tail call i32 @crc16_update(i32 %24, i32 undef)
%26 = tail call i32 @crc16_update(i32 %25, i32 undef)
%27 = and i32 %26, 255
%28 = ashr i32 %26, 8
%29 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %27, i32 %28)
ret i32 0
}