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

/* Variables and functions */
int cel_crc32(int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ cel_crc32_file(char *, int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ strlen(char *);
int main(int argc, char **args) {
  uint32_t file_crc32;
  uint32_t str_crc32;
  if (argc != 2) {
    printf("Usage: crc32 file path\n");
    return 0;
  }
  printf("+---test cel_crc32_hash: \n");
  str_crc32 = cel_crc32(-1, "chenxin619315@gmail.com",
                        strlen("chenxin619315@gmail.com"));
  printf("string crc32: 0x%x\n", str_crc32);
  putchar('\n');
  printf("+---test cel_crc32_file: \n");
  cel_crc32_file(args[1], &file_crc32);
  printf("file crc32: 0x%x\n", file_crc32);
  return 0;
}


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   $0x2,-0x8(%rbp)
je     118a <main+0x3a>
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    120c <main+0xbc>
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe94(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%edx
mov    $0xffffffff,%edi
lea    0xe81(%rip),%rsi
call   1070 <cel_crc32@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x14(%rbp),%rsi
call   1060 <cel_crc32_file@plt>
mov    -0x14(%rbp),%esi
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    11de <main+0x7e>
mov    %rsi,%r14
lea    0xecb(%rip),%rdi
call   1040 <puts@plt>
lea    0xe81(%rip),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    $0xffffffff,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1080 <cel_crc32@plt>
lea    0xe7b(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xea1(%rip),%rdi
call   1040 <puts@plt>
mov    0x8(%r14),%rdi
lea    0x4(%rsp),%rsi
call   1070 <cel_crc32_file@plt>
mov    0x4(%rsp),%esi
lea    0xe57(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    11ea <main+0x8a>
lea    0xe8d(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [24 x i8] c"Usage: crc32 file path\0A\00"
@.str.1 = [27 x i8] c"+---test cel_crc32_hash: \0A\00"
@.str.2 = [24 x i8] c"chenxin619315@gmail.com\00"
@.str.3 = [20 x i8] c"string crc32: 0x%x\0A\00"
@.str.4 = [27 x i8] c"+---test cel_crc32_file: \0A\00"
@.str.5 = [18 x i8] c"file crc32: 0x%x\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %26
12: ; preds = %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @strlen(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%15 = call i32 @cel_crc32(i32 -1, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %14)
store i32 %15, i32* %7
%16 = load i32, i32* %7
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %16)
%18 = call i32 @putchar(i8 signext 10)
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32 @cel_crc32_file(i8* %22, i32* %6)
%24 = load i32, i32* %6
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i32 %24)
store i32 0, i32* %3
br label %26
26: ; preds = %12, %10
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
@.str.2 = [24 x i8] c"chenxin619315@gmail.com\00"
@.str.3 = [20 x i8] c"string crc32: 0x%x\0A\00"
@.str.5 = [18 x i8] c"file crc32: 0x%x\0A\00"
@str = [26 x i8] c"+---test cel_crc32_hash: \00"
@str.6 = [26 x i8] c"+---test cel_crc32_file: \00"
@str.7 = [23 x i8] c"Usage: crc32 file path\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.7, i64 0, i64 0))
br label %20
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
%10 = tail call i32 @strlen(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%11 = tail call i32 @cel_crc32(i32 -1, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %10)
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %11)
%13 = tail call i32 @putchar(i8 signext 10)
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.6, i64 0, i64 0))
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = call i32 @cel_crc32_file(i8* %16, i32* %3)
%18 = load i32, i32* %3
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i32 %18)
br label %20
20: ; preds = %8, %6
ret i32 0
}