#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 char *uLong;

/* Variables and functions */
scalar_t__ EISDIR;
int /*<<< orphan*/ STDIN_FILENO;
char *digest_bytestream(int /*<<< orphan*/);
char *digest_file(char *);
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
scalar_t__ strcmp(char *, char *);
char *strerror(scalar_t__);
int sum_file(char *filename) {
  uLong crc;
  errno = 0;
  if ((strcmp((filename), ("-")) == 0))
    crc = digest_bytestream(STDIN_FILENO);
  else
    crc = digest_file(filename);
  if (errno)
    if (errno == EISDIR)
      fprintf(stderr, "%s: %s: Is a directory\n", "crc32sum", filename);
    else
      fprintf(stderr, "%s: %s\n", filename, strerror(errno));
  else
    fprintf(stdout, "%08lX  %s\n", crc, filename);
  return 0;
}


x86 assembly (clang, -O0):
<sum_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e6d(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
lea    0xe8b(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    119b <sum_file+0x4b>
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
call   1030 <digest_bytestream@plt>
mov    %rax,-0x10(%rbp)
jmp    11a8 <sum_file+0x58>
mov    -0x8(%rbp),%rdi
call   1040 <digest_file@plt>
mov    %rax,-0x10(%rbp)
mov    0x2e21(%rip),%rax
cmpq   $0x0,(%rax)
je     1236 <sum_file+0xe6>
mov    0x2e10(%rip),%rax
mov    (%rax),%rax
mov    0x2e1e(%rip),%rcx
cmp    (%rcx),%rax
jne    11f8 <sum_file+0xa8>
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rcx
lea    0xe1b(%rip),%rsi
lea    0xe2c(%rip),%rdx
call   1060 <fprintf@plt>
jmp    1231 <sum_file+0xe1>
mov    0x2dd9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    0x2dbd(%rip),%rax
mov    (%rax),%rdi
call   1070 <strerror@plt>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rdx
mov    %rax,%rcx
lea    0xdf7(%rip),%rsi
call   1060 <fprintf@plt>
jmp    1253 <sum_file+0x103>
mov    0x2d8b(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x8(%rbp),%rcx
lea    0xddd(%rip),%rsi
call   1060 <fprintf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sum_file>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2e73(%rip),%rbp
movq   $0x0,0x0(%rbp)
lea    0xe94(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1180 <sum_file+0x30>
mov    %rbx,%rdi
call   1040 <digest_file@plt>
jmp    118e <sum_file+0x3e>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
call   1030 <digest_bytestream@plt>
mov    0x0(%rbp),%rdi
test   %rdi,%rdi
je     11be <sum_file+0x6e>
mov    0x2e4a(%rip),%rax
mov    0x2e33(%rip),%rcx
mov    (%rcx),%ebp
cmp    (%rax),%rdi
jne    11d6 <sum_file+0x86>
lea    0xe4f(%rip),%rsi
lea    0xe60(%rip),%rdx
mov    %ebp,%edi
jmp    11d1 <sum_file+0x81>
mov    0x2e03(%rip),%rcx
mov    (%rcx),%edi
lea    0xe5d(%rip),%rsi
mov    %rax,%rdx
mov    %rbx,%rcx
jmp    11ea <sum_file+0x9a>
call   1070 <strerror@plt>
lea    0xe41(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1060 <fprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
@.str = [2 x i8] c"-\00"
@STDIN_FILENO = global i32 0
@EISDIR = global i64 0
@stderr = global i32 0
@.str.1 = [24 x i8] c"%s: %s: Is a directory\0A\00"
@.str.2 = [9 x i8] c"crc32sum\00"
@.str.3 = [8 x i8] c"%s: %s\0A\00"
@stdout = global i32 0
@.str.4 = [11 x i8] c"%08lX %s\0A\00"
define i32 @sum_file(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
store i64 0, i64* @errno
%4 = load i8*, i8** %2
%5 = call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = load i32, i32* @STDIN_FILENO
%9 = call i8* @digest_bytestream(i32 %8)
store i8* %9, i8** %3
br label %13
10: ; preds = %1
%11 = load i8*, i8** %2
%12 = call i8* @digest_file(i8* %11)
store i8* %12, i8** %3
br label %13
13: ; preds = %10, %7
%14 = load i64, i64* @errno
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %31
16: ; preds = %13
%17 = load i64, i64* @errno
%18 = load i64, i64* @EISDIR
%19 = icmp eq i64 %17, %18
br i1 %19, label %20, label %24
20: ; preds = %16
%21 = load i32, i32* @stderr
%22 = load i8*, i8** %2
%23 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %22)
br label %30
24: ; preds = %16
%25 = load i32, i32* @stderr
%26 = load i8*, i8** %2
%27 = load i64, i64* @errno
%28 = call i8* @strerror(i64 %27)
%29 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %26, i8* %28)
br label %30
30: ; preds = %24, %20
br label %36
31: ; preds = %13
%32 = load i32, i32* @stdout
%33 = load i8*, i8** %3
%34 = load i8*, i8** %2
%35 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %33, i8* %34)
br label %36
36: ; preds = %31, %30
ret i32 0
}

LLVM IR (-O2):
@errno = global i64 0
@.str = [2 x i8] c"-\00"
@STDIN_FILENO = global i32 0
@EISDIR = global i64 0
@stderr = global i32 0
@.str.1 = [24 x i8] c"%s: %s: Is a directory\0A\00"
@.str.2 = [9 x i8] c"crc32sum\00"
@.str.3 = [8 x i8] c"%s: %s\0A\00"
@stdout = global i32 0
@.str.4 = [11 x i8] c"%08lX %s\0A\00"
define i32 @sum_file(i8* %0) {
store i64 0, i64* @errno
%2 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %7
4: ; preds = %1
%5 = load i32, i32* @STDIN_FILENO
%6 = tail call i8* @digest_bytestream(i32 %5)
br label %9
7: ; preds = %1
%8 = tail call i8* @digest_file(i8* %0)
br label %9
9: ; preds = %7, %4
%10 = phi i8* [ %6, %4 ], [ %8, %7 ]
%11 = load i64, i64* @errno
%12 = icmp eq i64 %11, 0
br i1 %12, label %22, label %13
13: ; preds = %9
%14 = load i64, i64* @EISDIR
%15 = icmp eq i64 %11, %14
%16 = load i32, i32* @stderr
br i1 %15, label %17, label %19
17: ; preds = %13
%18 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %25
19: ; preds = %13
%20 = tail call i8* @strerror(i64 %11)
%21 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %0, i8* %20)
br label %25
22: ; preds = %9
%23 = load i32, i32* @stdout
%24 = tail call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %10, i8* %0)
br label %25
25: ; preds = %17, %19, %22
ret i32 0
}