#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;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int cel_crc32(int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ printf(char *, char const *);
int /*<<< orphan*/ strlen(char *);
extern void cel_crc32_file(const char *_file, uint32_t *file_crc32) {
  FILE *stream;
  char buffer[2048];
  uint32_t crc = 0xffffffff;
  if ((stream = fopen(_file, "r")) == NULL) {
    printf("Error: unable to open file %s\n", _file);
    *file_crc32 = crc;
    return;
  }
  while (fgets(buffer, 2048, stream) != NULL) {
    crc = cel_crc32(crc, buffer, strlen(buffer));
  }
  *file_crc32 = crc;
  fclose(stream);
}


x86 assembly (clang, -O0):
<cel_crc32_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x840,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x824(%rbp)
ff ff ff
mov    -0x8(%rbp),%rdi
lea    0xe78(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11bc <cel_crc32_file+0x5c>
mov    -0x8(%rbp),%rsi
lea    0xe5c(%rip),%rdi
call   1050 <printf@plt>
mov    -0x824(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
jmp    123a <cel_crc32_file+0xda>
jmp    11c1 <cel_crc32_file+0x61>
lea    -0x820(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x800,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     1225 <cel_crc32_file+0xc5>
mov    -0x824(%rbp),%eax
mov    %eax,-0x834(%rbp)
lea    -0x820(%rbp),%rax
mov    %rax,-0x830(%rbp)
lea    -0x820(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x834(%rbp),%edi
mov    -0x830(%rbp),%rsi
mov    %eax,%edx
call   1080 <cel_crc32@plt>
mov    %eax,-0x824(%rbp)
jmp    11c1 <cel_crc32_file+0x61>
mov    -0x824(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x840,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cel_crc32_file>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x808,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xe86(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11e8 <cel_crc32_file+0x88>
mov    %rax,%r15
mov    %rsp,%rdi
mov    $0x800,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
je     11db <cel_crc32_file+0x7b>
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1080 <cel_crc32@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    $0x800,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
jne    11b0 <cel_crc32_file+0x50>
mov    %ebp,(%r14)
mov    %r15,%rdi
call   1030 <fclose@plt>
jmp    11fe <cel_crc32_file+0x9e>
lea    0xe13(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
movl   $0xffffffff,(%r14)
add    $0x808,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [31 x i8] c"Error: unable to open file %s\0A\00"
define void @cel_crc32_file(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca [2048 x i8]
%7 = alloca i32
store i8* %0, i8** %3
store i32* %1, i32** %4
store i32 -1, i32* %7
%8 = load i8*, i8** %3
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %5
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load i8*, i8** %3
%13 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = load i32, i32* %7
%15 = load i32*, i32** %4
store i32 %14, i32* %15
br label %33
16: ; preds = %2
br label %17
17: ; preds = %22, %16
%18 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%19 = load i32*, i32** %5
%20 = call i32* @fgets(i8* %18, i32 2048, i32* %19)
%21 = icmp ne i32* %20, null
br i1 %21, label %22, label %28
22: ; preds = %17
%23 = load i32, i32* %7
%24 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%25 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%26 = call i32 @strlen(i8* %25)
%27 = call i32 @cel_crc32(i32 %23, i8* %24, i32 %26)
store i32 %27, i32* %7
br label %17
28: ; preds = %17
%29 = load i32, i32* %7
%30 = load i32*, i32** %4
store i32 %29, i32* %30
%31 = load i32*, i32** %5
%32 = call i32 @fclose(i32* %31)
br label %33
33: ; preds = %28, %11
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [31 x i8] c"Error: unable to open file %s\0A\00"
define void @cel_crc32_file(i8* %0, i32* nocapture writeonly %1) {
%3 = alloca [2048 x i8]
%4 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = call i32* @fgets(i8* %4, i32 2048, i32* %5)
%9 = icmp eq i32* %8, null
br i1 %9, label %18, label %12
10: ; preds = %2
%11 = tail call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %0)
store i32 -1, i32* %1
br label %21
12: ; preds = %7, %12
%13 = phi i32 [ %15, %12 ], [ -1, %7 ]
%14 = call i32 @strlen(i8* %4)
%15 = call i32 @cel_crc32(i32 %13, i8* %4, i32 %14)
%16 = call i32* @fgets(i8* %4, i32 2048, i32* %5)
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %12
18: ; preds = %12, %7
%19 = phi i32 [ -1, %7 ], [ %15, %12 ]
store i32 %19, i32* %1
%20 = call i32 @fclose(i32* %5)
br label %21
21: ; preds = %18, %10
ret void
}