#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*/ uint8_t;
typedef scalar_t__ uint32_t;
typedef scalar_t__ ssize_t;
typedef scalar_t__ off_t;

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
scalar_t__ crc32part(int /*<<< orphan*/ *, size_t, scalar_t__);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ memset(int /*<<< orphan*/ *, int /*<<< orphan*/, int);
scalar_t__ read(int, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
uint32_t infilecrc32(int infd, size_t len, size_t padlen) {
  off_t offset;
  uint8_t buffer[1024];
  ssize_t nbytes;
  size_t bytesread;
  uint32_t crc;
  offset = lseek(infd, 0, SEEK_SET);
  if (offset == (off_t)-1) {
    fprintf(stderr, "lseek failed: %s\n", strerror(errno));
    exit(4);
  }
  crc = 0;
  for (bytesread = 0; bytesread < len; bytesread += nbytes) {
    nbytes = read(infd, buffer, 1024);
    if (nbytes < 0) {
      fprintf(stderr, "read failed: %s\n", strerror(errno));
      exit(4);
    } else if (nbytes == 0) {
      fprintf(stderr, "Unexpected end-of-file: %s\n", strerror(errno));
      exit(4);
    } else {
      crc = crc32part(buffer, nbytes, crc);
    }
  }
  memset(buffer, 0, 1024);
  return crc32part(buffer, padlen, crc);
}


x86 assembly (clang, -O0):
<infilecrc32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1050,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e40(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1030 <lseek@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0xffffffffffffffff,-0x20(%rbp)
jne    11e4 <infilecrc32+0x74>
mov    0x2e31(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x103c(%rbp)
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x103c(%rbp),%edi
mov    %rax,%rdx
lea    0xe2b(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x4,%edi
call   1070 <exit@plt>
movq   $0x0,-0x1038(%rbp)
movq   $0x0,-0x1030(%rbp)
mov    -0x1030(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    12ff <infilecrc32+0x18f>
mov    -0x4(%rbp),%edi
lea    -0x1020(%rbp),%rsi
mov    $0x400,%edx
call   1050 <read@plt>
mov    %rax,-0x1028(%rbp)
cmpq   $0x0,-0x1028(%rbp)
jge    1270 <infilecrc32+0x100>
mov    0x2da5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1040(%rbp)
mov    0x2d8e(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x1040(%rbp),%edi
mov    %rax,%rdx
lea    0xdb1(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x4,%edi
call   1070 <exit@plt>
cmpq   $0x0,-0x1028(%rbp)
jne    12ba <infilecrc32+0x14a>
mov    0x2d5b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1044(%rbp)
mov    0x2d44(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x1044(%rbp),%edi
mov    %rax,%rdx
lea    0xd78(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x4,%edi
call   1070 <exit@plt>
lea    -0x1020(%rbp),%rdi
mov    -0x1028(%rbp),%rsi
mov    -0x1038(%rbp),%rdx
call   1080 <crc32part@plt>
mov    %rax,-0x1038(%rbp)
jmp    12e0 <infilecrc32+0x170>
jmp    12e5 <infilecrc32+0x175>
mov    -0x1028(%rbp),%rax
add    -0x1030(%rbp),%rax
mov    %rax,-0x1030(%rbp)
jmp    11fa <infilecrc32+0x8a>
lea    -0x1020(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
lea    -0x1020(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1038(%rbp),%rdx
call   1080 <crc32part@plt>
add    $0x1050,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<infilecrc32>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1018,%rsp
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %edi,%r12d
mov    0x2e3f(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1030 <lseek@plt>
cmp    $0xffffffffffffffff,%rax
je     127f <infilecrc32+0x10f>
test   %r15,%r15
mov    %rbx,0x8(%rsp)
je     11f5 <infilecrc32+0x85>
xor    %ebx,%ebx
lea    0x10(%rsp),%r13
xor    %r14d,%r14d
nopl   0x0(%rax,%rax,1)
mov    %r12d,%edi
mov    %r13,%rsi
mov    $0x400,%edx
call   1050 <read@plt>
test   %rax,%rax
js     122d <infilecrc32+0xbd>
je     124d <infilecrc32+0xdd>
mov    %rax,%rbp
mov    %r13,%rdi
mov    %rax,%rsi
mov    %rbx,%rdx
call   1080 <crc32part@plt>
mov    %rax,%rbx
add    %rbp,%r14
cmp    %r15,%r14
jb     11c0 <infilecrc32+0x50>
jmp    11f7 <infilecrc32+0x87>
xor    %ebx,%ebx
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
mov    %rbp,%rdi
mov    0x8(%rsp),%rsi
mov    %rbx,%rdx
call   1080 <crc32part@plt>
add    $0x1018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dac(%rip),%rax
mov    (%rax),%ebx
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xdc7(%rip),%rsi
jmp    126b <infilecrc32+0xfb>
mov    0x2d8c(%rip),%rax
mov    (%rax),%ebx
mov    0x2d7b(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xdb8(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1060 <fprintf@plt>
mov    $0x4,%edi
call   1070 <exit@plt>
mov    0x2d5a(%rip),%rax
mov    (%rax),%ebx
mov    0x2d49(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xd63(%rip),%rsi
jmp    126b <infilecrc32+0xfb>

LLVM IR (-O0):
@SEEK_SET = global i32 0
@stderr = global i32 0
@.str = [18 x i8] c"lseek failed: %s\0A\00"
@errno = global i32 0
@.str.1 = [17 x i8] c"read failed: %s\0A\00"
@.str.2 = [28 x i8] c"Unexpected end-of-file: %s\0A\00"
define i64 @infilecrc32(i32 %0, i64 %1, i64 %2) {
%4 = alloca i32
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca [1024 x i32]
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
store i32 %0, i32* %4
store i64 %1, i64* %5
store i64 %2, i64* %6
%12 = load i32, i32* %4
%13 = load i32, i32* @SEEK_SET
%14 = call i64 @lseek(i32 %12, i32 0, i32 %13)
store i64 %14, i64* %7
%15 = load i64, i64* %7
%16 = icmp eq i64 %15, -1
br i1 %16, label %17, label %23
17: ; preds = %3
%18 = load i32, i32* @stderr
%19 = load i32, i32* @errno
%20 = call i8* @strerror(i32 %19)
%21 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = call i32 @exit(i32 4)
unreachable
23: ; preds = %3
store i64 0, i64* %11
store i64 0, i64* %10
br label %24
24: ; preds = %56, %23
%25 = load i64, i64* %10
%26 = load i64, i64* %5
%27 = icmp ult i64 %25, %26
br i1 %27, label %28, label %60
28: ; preds = %24
%29 = load i32, i32* %4
%30 = getelementptr inbounds [1024 x i32], [1024 x i32]* %8, i64 0, i64 0
%31 = call i64 @read(i32 %29, i32* %30, i32 1024)
store i64 %31, i64* %9
%32 = load i64, i64* %9
%33 = icmp slt i64 %32, 0
br i1 %33, label %34, label %40
34: ; preds = %28
%35 = load i32, i32* @stderr
%36 = load i32, i32* @errno
%37 = call i8* @strerror(i32 %36)
%38 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %37)
%39 = call i32 @exit(i32 4)
unreachable
40: ; preds = %28
%41 = load i64, i64* %9
%42 = icmp eq i64 %41, 0
br i1 %42, label %43, label %49
43: ; preds = %40
%44 = load i32, i32* @stderr
%45 = load i32, i32* @errno
%46 = call i8* @strerror(i32 %45)
%47 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %46)
%48 = call i32 @exit(i32 4)
unreachable
49: ; preds = %40
%50 = getelementptr inbounds [1024 x i32], [1024 x i32]* %8, i64 0, i64 0
%51 = load i64, i64* %9
%52 = load i64, i64* %11
%53 = call i64 @crc32part(i32* %50, i64 %51, i64 %52)
store i64 %53, i64* %11
br label %54
54: ; preds = %49
br label %55
55: ; preds = %54
br label %56
56: ; preds = %55
%57 = load i64, i64* %9
%58 = load i64, i64* %10
%59 = add i64 %58, %57
store i64 %59, i64* %10
br label %24
60: ; preds = %24
%61 = getelementptr inbounds [1024 x i32], [1024 x i32]* %8, i64 0, i64 0
%62 = call i32 @memset(i32* %61, i32 0, i32 1024)
%63 = getelementptr inbounds [1024 x i32], [1024 x i32]* %8, i64 0, i64 0
%64 = load i64, i64* %6
%65 = load i64, i64* %11
%66 = call i64 @crc32part(i32* %63, i64 %64, i64 %65)
ret i64 %66
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
@stderr = global i32 0
@.str = [18 x i8] c"lseek failed: %s\0A\00"
@errno = global i32 0
@.str.1 = [17 x i8] c"read failed: %s\0A\00"
@.str.2 = [28 x i8] c"Unexpected end-of-file: %s\0A\00"
define i64 @infilecrc32(i32 %0, i64 %1, i64 %2) {
%4 = alloca [1024 x i32]
%5 = bitcast [1024 x i32]* %4 to i8*
%6 = load i32, i32* @SEEK_SET
%7 = tail call i64 @lseek(i32 %0, i32 0, i32 %6)
%8 = icmp eq i64 %7, -1
br i1 %8, label %13, label %9
9: ; preds = %3
%10 = icmp eq i64 %1, 0
br i1 %10, label %42, label %11
11: ; preds = %9
%12 = getelementptr inbounds [1024 x i32], [1024 x i32]* %4, i64 0, i64 0
br label %19
13: ; preds = %3
%14 = load i32, i32* @stderr
%15 = load i32, i32* @errno
%16 = tail call i8* @strerror(i32 %15)
%17 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = tail call i32 @exit(i32 4)
unreachable
19: ; preds = %11, %38
%20 = phi i64 [ 0, %11 ], [ %39, %38 ]
%21 = phi i64 [ 0, %11 ], [ %40, %38 ]
%22 = call i64 @read(i32 %0, i32* %12, i32 1024)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %30
24: ; preds = %19
%25 = load i32, i32* @stderr
%26 = load i32, i32* @errno
%27 = call i8* @strerror(i32 %26)
%28 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %27)
%29 = call i32 @exit(i32 4)
unreachable
30: ; preds = %19
%31 = icmp eq i64 %22, 0
br i1 %31, label %32, label %38
32: ; preds = %30
%33 = load i32, i32* @stderr
%34 = load i32, i32* @errno
%35 = call i8* @strerror(i32 %34)
%36 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %35)
%37 = call i32 @exit(i32 4)
unreachable
38: ; preds = %30
%39 = call i64 @crc32part(i32* %12, i64 %22, i64 %20)
%40 = add i64 %22, %21
%41 = icmp ult i64 %40, %1
br i1 %41, label %19, label %42
42: ; preds = %38, %9
%43 = phi i64 [ 0, %9 ], [ %39, %38 ]
%44 = getelementptr inbounds [1024 x i32], [1024 x i32]* %4, i64 0, i64 0
%45 = call i32 @memset(i32* %44, i32 0, i32 1024)
%46 = call i64 @crc32part(i32* %44, i64 %2, i64 %43)
ret i64 %46
}