#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 fwrite(void const *, int, unsigned int, int /*<<< orphan*/ *);
unsigned long pfdc4_crc(unsigned long, void const *, unsigned int);
int pfdc4_write(FILE *fp, const void *buf, unsigned cnt, unsigned long *crc) {
  if (crc != NULL) {
    *crc = pfdc4_crc(*crc, buf, cnt);
  }
  if (fwrite(buf, 1, cnt, fp) != cnt) {
    return (1);
  }
  return (0);
}


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

x86 assembly (clang, -O2):
<pfdc4_write>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%r15
mov    %rdi,%r14
test   %rcx,%rcx
je     1147 <pfdc4_write+0x27>
mov    %rcx,%rbx
mov    (%rcx),%rdi
mov    %r15,%rsi
mov    %ebp,%edx
call   1030 <pfdc4_crc@plt>
mov    %rax,(%rbx)
mov    %r15,%rdi
mov    $0x1,%esi
mov    %ebp,%edx
mov    %r14,%rcx
call   1040 <fwrite@plt>
xor    %ecx,%ecx
cmp    %ebp,%eax
setne  %cl
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @pfdc4_write(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 i64*, i64** %9
%11 = icmp ne i64* %10, null
br i1 %11, label %12, label %19
12: ; preds = %4
%13 = load i64*, i64** %9
%14 = load i64, i64* %13
%15 = load i8*, i8** %7
%16 = load i32, i32* %8
%17 = call i64 @pfdc4_crc(i64 %14, i8* %15, i32 %16)
%18 = load i64*, i64** %9
store i64 %17, i64* %18
br label %19
19: ; preds = %12, %4
%20 = load i8*, i8** %7
%21 = load i32, i32* %8
%22 = load i32*, i32** %6
%23 = call i32 @fwrite(i8* %20, i32 1, i32 %21, i32* %22)
%24 = load i32, i32* %8
%25 = icmp ne i32 %23, %24
br i1 %25, label %26, label %27
26: ; preds = %19
store i32 1, i32* %5
br label %28
27: ; preds = %19
store i32 0, i32* %5
br label %28
28: ; preds = %27, %26
%29 = load i32, i32* %5
ret i32 %29
}

LLVM IR (-O2):
define i32 @pfdc4_write(i32* nocapture %0, i8* %1, i32 %2, i64* %3) {
%5 = icmp eq i64* %3, null
br i1 %5, label %9, label %6
6: ; preds = %4
%7 = load i64, i64* %3
%8 = tail call i64 @pfdc4_crc(i64 %7, i8* %1, i32 %2)
store i64 %8, i64* %3
br label %9
9: ; preds = %6, %4
%10 = tail call i32 @fwrite(i8* %1, i32 1, i32 %2, i32* %0)
%11 = icmp ne i32 %10, %2
%12 = zext i1 %11 to i32
ret i32 %12
}