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

/* Variables and functions */
unsigned int fread(void *, int, unsigned int, int /*<<< orphan*/ *);
unsigned long psi_crc(unsigned long, void *, unsigned int);
int psi_read_crc(FILE *fp, void *buf, unsigned cnt, unsigned long *crc) {
  if (fread(buf, 1, cnt, fp) != cnt) {
    return (1);
  }
  if (crc != NULL) {
    *crc = psi_crc(*crc, buf, cnt);
  }
  return (0);
}


x86 assembly (clang, -O0):
<psi_read_crc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
cmp    -0x1c(%rbp),%eax
je     1161 <psi_read_crc+0x41>
movl   $0x1,-0x4(%rbp)
jmp    1190 <psi_read_crc+0x70>
cmpq   $0x0,-0x28(%rbp)
je     1189 <psi_read_crc+0x69>
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <psi_crc@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<psi_read_crc>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%rcx
mov    $0x1,%r15d
mov    %rsi,%rdi
mov    $0x1,%esi
call   1030 <fread@plt>
cmp    %ebp,%eax
jne    1161 <psi_read_crc+0x41>
xor    %r15d,%r15d
test   %r14,%r14
je     1161 <psi_read_crc+0x41>
mov    (%r14),%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1040 <psi_crc@plt>
mov    %rax,(%r14)
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @psi_read_crc(i32* %0, i8* %1, i32 %2, i64* %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i64*
store i32* %0, i32** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i64* %3, i64** %9
%10 = load i8*, i8** %7
%11 = load i32, i32* %8
%12 = load i32*, i32** %6
%13 = call i32 @fread(i8* %10, i32 1, i32 %11, i32* %12)
%14 = load i32, i32* %8
%15 = icmp ne i32 %13, %14
br i1 %15, label %16, label %17
16: ; preds = %4
store i32 1, i32* %5
br label %28
17: ; preds = %4
%18 = load i64*, i64** %9
%19 = icmp ne i64* %18, null
br i1 %19, label %20, label %27
20: ; preds = %17
%21 = load i64*, i64** %9
%22 = load i64, i64* %21
%23 = load i8*, i8** %7
%24 = load i32, i32* %8
%25 = call i64 @psi_crc(i64 %22, i8* %23, i32 %24)
%26 = load i64*, i64** %9
store i64 %25, i64* %26
br label %27
27: ; preds = %20, %17
store i32 0, i32* %5
br label %28
28: ; preds = %27, %16
%29 = load i32, i32* %5
ret i32 %29
}

LLVM IR (-O2):
define i32 @psi_read_crc(i32* nocapture %0, i8* %1, i32 %2, i64* %3) {
%5 = tail call i32 @fread(i8* %1, i32 1, i32 %2, i32* %0)
%6 = icmp eq i32 %5, %2
br i1 %6, label %7, label %12
7: ; preds = %4
%8 = icmp eq i64* %3, null
br i1 %8, label %12, label %9
9: ; preds = %7
%10 = load i64, i64* %3
%11 = tail call i64 @psi_crc(i64 %10, i8* %1, i32 %2)
store i64 %11, i64* %3
br label %12
12: ; preds = %7, %9, %4
%13 = phi i32 [ 1, %4 ], [ 0, %9 ], [ 0, %7 ]
ret i32 %13
}