#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*/ argv;

/* Variables and functions */
unsigned short CRCCCITT(unsigned char *, int const, int, int /*<<< orphan*/);
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int main(int argc, char **argv) {
  size_t how_many;
  unsigned short the_crc;
  if (argc < 2) {
    puts("usage: enter string to check");
    return EXIT_FAILURE;
  }
  unsigned char *buff = argv[1];
  const int TEST_SIZE = sizeof(argv[1]) - 1;
  how_many = TEST_SIZE;
  printf("msg: %s \ntestsize: %i\n", buff, TEST_SIZE);
  if (how_many != TEST_SIZE) {
    printf("how_many %i\n", how_many);
    printf("crcccitt: error reading %s\n", argv[1]);
    return EXIT_FAILURE;
  }
  the_crc = CRCCCITT(buff, TEST_SIZE, 0xffff, 0);
  printf("Initial CRC value is 0x%04X\n", the_crc);
  buff[TEST_SIZE] = (unsigned char)((the_crc >> 8) & 0xff);
  buff[TEST_SIZE + 1] = (unsigned char)(the_crc & 0xff);
  the_crc = CRCCCITT(buff, TEST_SIZE + 2, 0xffff, 0);
  printf("Final CRC value is 0x%04X\n", the_crc);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    116d <main+0x3d>
lea    0xea9(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e7d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    126c <main+0x13c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
movl   $0x7,-0x2c(%rbp)
movq   $0x7,-0x18(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xe8a(%rip),%rdi
mov    $0x7,%edx
mov    $0x0,%al
call   1040 <printf@plt>
cmpq   $0x7,-0x18(%rbp)
je     11e3 <main+0xb3>
mov    -0x18(%rbp),%rsi
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2e07(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    126c <main+0x13c>
mov    -0x28(%rbp),%rdi
mov    $0x7,%esi
mov    $0xffff,%edx
xor    %ecx,%ecx
call   1050 <CRCCCITT@plt>
mov    %ax,-0x1a(%rbp)
movzwl -0x1a(%rbp),%esi
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movzwl -0x1a(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x28(%rbp),%rax
mov    %cl,0x7(%rax)
movzwl -0x1a(%rbp),%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x28(%rbp),%rax
mov    %cl,0x8(%rax)
mov    -0x28(%rbp),%rdi
mov    $0x9,%esi
mov    $0xffff,%edx
xor    %ecx,%ecx
call   1050 <CRCCCITT@plt>
mov    %ax,-0x1a(%rbp)
movzwl -0x1a(%rbp),%esi
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2d71(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
cmp    $0x1,%edi
jg     114d <main+0x1d>
lea    0xec1(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e95(%rip),%rax
jmp    11c2 <main+0x92>
mov    0x8(%rsi),%rbx
lea    0xec5(%rip),%rdi
mov    %rbx,%rsi
mov    $0x7,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x7,%esi
mov    $0xffff,%edx
xor    %ecx,%ecx
call   1050 <CRCCCITT@plt>
movzwl %ax,%ebp
lea    0xeaf(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
rol    $0x8,%bp
mov    %bp,0x7(%rbx)
mov    %rbx,%rdi
mov    $0x9,%esi
mov    $0xffff,%edx
xor    %ecx,%ecx
call   1050 <CRCCCITT@plt>
movzwl %ax,%esi
lea    0xe9d(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e16(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [29 x i8] c"usage: enter string to check\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [23 x i8] c"msg: %s \0Atestsize: %i\0A\00"
@.str.2 = [13 x i8] c"how_many %i\0A\00"
@.str.3 = [28 x i8] c"crcccitt: error reading %s\0A\00"
@.str.4 = [29 x i8] c"Initial CRC value is 0x%04X\0A\00"
@.str.5 = [27 x i8] c"Final CRC value is 0x%04X\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i16
%8 = alloca i8*
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 2
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = call i32 @puts(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
store i32 %14, i32* %3
br label %56
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
store i8* %18, i8** %8
store i32 7, i32* %9
store i64 7, i64* %6
%19 = load i8*, i8** %8
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %19, i32 7)
%21 = load i64, i64* %6
%22 = icmp ne i64 %21, 7
br i1 %22, label %23, label %31
23: ; preds = %15
%24 = load i64, i64* %6
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i64 %24)
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %28)
%30 = load i32, i32* @EXIT_FAILURE
store i32 %30, i32* %3
br label %56
31: ; preds = %15
%32 = load i8*, i8** %8
%33 = call zeroext i16 @CRCCCITT(i8* %32, i32 7, i32 65535, i32 0)
store i16 %33, i16* %7
%34 = load i16, i16* %7
%35 = zext i16 %34 to i32
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i32 %35)
%37 = load i16, i16* %7
%38 = zext i16 %37 to i32
%39 = ashr i32 %38, 8
%40 = and i32 %39, 255
%41 = trunc i32 %40 to i8
%42 = load i8*, i8** %8
%43 = getelementptr inbounds i8, i8* %42, i64 7
store i8 %41, i8* %43
%44 = load i16, i16* %7
%45 = zext i16 %44 to i32
%46 = and i32 %45, 255
%47 = trunc i32 %46 to i8
%48 = load i8*, i8** %8
%49 = getelementptr inbounds i8, i8* %48, i64 8
store i8 %47, i8* %49
%50 = load i8*, i8** %8
%51 = call zeroext i16 @CRCCCITT(i8* %50, i32 9, i32 65535, i32 0)
store i16 %51, i16* %7
%52 = load i16, i16* %7
%53 = zext i16 %52 to i32
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i32 %53)
%55 = load i32, i32* @EXIT_SUCCESS
store i32 %55, i32* %3
br label %56
56: ; preds = %31, %23, %12
%57 = load i32, i32* %3
ret i32 %57
}

LLVM IR (-O2):
@.str = [29 x i8] c"usage: enter string to check\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [23 x i8] c"msg: %s \0Atestsize: %i\0A\00"
@.str.4 = [29 x i8] c"Initial CRC value is 0x%04X\0A\00"
@.str.5 = [27 x i8] c"Final CRC value is 0x%04X\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %21
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %8, i32 7)
%10 = tail call zeroext i16 @CRCCCITT(i8* %8, i32 7, i32 65535, i32 0)
%11 = zext i16 %10 to i32
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i32 %11)
%13 = lshr i16 %10, 8
%14 = trunc i16 %13 to i8
%15 = getelementptr inbounds i8, i8* %8, i64 7
store i8 %14, i8* %15
%16 = trunc i16 %10 to i8
%17 = getelementptr inbounds i8, i8* %8, i64 8
store i8 %16, i8* %17
%18 = tail call zeroext i16 @CRCCCITT(i8* %8, i32 9, i32 65535, i32 0)
%19 = zext i16 %18 to i32
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i32 %19)
br label %21
21: ; preds = %6, %4
%22 = phi i32* [ @EXIT_FAILURE, %4 ], [ @EXIT_SUCCESS, %6 ]
%23 = load i32, i32* %22
ret i32 %23
}