#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 CRCCompute(unsigned char *, unsigned int);
int /*<<< orphan*/ CRCPadding(unsigned int, unsigned int, unsigned int);
int /*<<< orphan*/ printf(char *, ...);
unsigned int strlen(char *);
unsigned int strtoul(char *, int /*<<< orphan*/, int);
int main(int argc, char **argv) {
  if (argc != 3) {
    printf("checksum requirement not fulfilled\n");
    printf("usage : %s 0xtargetcrc PayloadBytes\n", argv[0]);
    return 0;
  }
  unsigned int targetCRC;
  unsigned int length = strlen(argv[2]);
  unsigned int CheckSum;
  targetCRC = strtoul(argv[1], 0, 16);
  CheckSum = CRCCompute((unsigned char *)argv[2], length);
  printf("%s", argv[2]);
  CRCPadding(CheckSum, length, targetCRC);
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     119f <main+0x4f>
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe98(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1204 <main+0xb4>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1070 <strtoul@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    -0x18(%rbp),%esi
call   1050 <CRCCompute@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1060 <CRCPadding@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    11c1 <main+0x61>
mov    0x10(%rbx),%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    0x8(%rbx),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1080 <strtoul@plt>
mov    %eax,%r14d
mov    0x10(%rbx),%rdi
mov    %ebp,%esi
call   1060 <CRCCompute@plt>
mov    %eax,%r15d
mov    0x10(%rbx),%rsi
lea    0xe7f(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15d,%edi
mov    %ebp,%esi
mov    %r14d,%edx
call   1070 <CRCPadding@plt>
mov    $0x1,%ebx
jmp    11e0 <main+0x80>
lea    0xe60(%rip),%rdi
call   1030 <puts@plt>
mov    (%rbx),%rsi
lea    0xe29(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [36 x i8] c"checksum requirement not fulfilled\0A\00"
@.str.1 = [37 x i8] c"usage : %s 0xtargetcrc PayloadBytes\0A\00"
@.str.2 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 3
br i1 %10, label %11, label %17
11: ; preds = %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %15)
store i32 0, i32* %3
br label %39
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 2
%20 = load i8*, i8** %19
%21 = call i32 @strlen(i8* %20)
store i32 %21, i32* %7
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32 @strtoul(i8* %24, i32 0, i32 16)
store i32 %25, i32* %6
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 2
%28 = load i8*, i8** %27
%29 = load i32, i32* %7
%30 = call i32 @CRCCompute(i8* %28, i32 %29)
store i32 %30, i32* %8
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 2
%33 = load i8*, i8** %32
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %33)
%35 = load i32, i32* %8
%36 = load i32, i32* %7
%37 = load i32, i32* %6
%38 = call i32 @CRCPadding(i32 %35, i32 %36, i32 %37)
store i32 1, i32* %3
br label %39
39: ; preds = %17, %11
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
@.str.1 = [37 x i8] c"usage : %s 0xtargetcrc PayloadBytes\0A\00"
@.str.2 = [3 x i8] c"%s\00"
@str = [35 x i8] c"checksum requirement not fulfilled\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
%6 = load i8*, i8** %1
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %6)
br label %20
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 2
%10 = load i8*, i8** %9
%11 = tail call i32 @strlen(i8* %10)
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = tail call i32 @strtoul(i8* %13, i32 0, i32 16)
%15 = load i8*, i8** %9
%16 = tail call i32 @CRCCompute(i8* %15, i32 %11)
%17 = load i8*, i8** %9
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %17)
%19 = tail call i32 @CRCPadding(i32 %16, i32 %11, i32 %14)
br label %20
20: ; preds = %8, %4
%21 = phi i32 [ 0, %4 ], [ 1, %8 ]
ret i32 %21
}