#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 */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, unsigned long);
scalar_t__ pfdc4_read(int /*<<< orphan*/ *, unsigned char *, int,
                      unsigned long *);
scalar_t__ pfdc4_skip_chunk(int /*<<< orphan*/ *, unsigned long, unsigned long);
unsigned long psi_get_uint32_be(unsigned char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int pfdc4_load_header(FILE *fp, unsigned long size, unsigned long crc) {
  unsigned long vers;
  unsigned char buf[8];
  if (size < 4) {
    return (1);
  }
  if (pfdc4_read(fp, buf, 4, &crc)) {
    return (1);
  }
  vers = psi_get_uint32_be(buf, 0);
  if (vers != 0x00040000) {
    fprintf(stderr, "pfdc: unknown version (%lu)\n", vers);
    return (1);
  }
  if (pfdc4_skip_chunk(fp, size - 4, crc)) {
    return (1);
  }
  return (0);
}


x86 assembly (clang, -O0):
<pfdc4_load_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x4,-0x18(%rbp)
jae    116b <pfdc4_load_header+0x2b>
movl   $0x1,-0x4(%rbp)
jmp    120b <pfdc4_load_header+0xcb>
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    $0x4,%edx
lea    -0x20(%rbp),%rcx
call   1050 <pfdc4_read@plt>
cmp    $0x0,%rax
je     1197 <pfdc4_load_header+0x57>
movl   $0x1,-0x4(%rbp)
jmp    120b <pfdc4_load_header+0xcb>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
call   1030 <psi_get_uint32_be@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x40000,-0x28(%rbp)
je     11d9 <pfdc4_load_header+0x99>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xe38(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    120b <pfdc4_load_header+0xcb>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
sub    $0x4,%rsi
mov    -0x20(%rbp),%rdx
call   1060 <pfdc4_skip_chunk@plt>
cmp    $0x0,%rax
je     1204 <pfdc4_load_header+0xc4>
movl   $0x1,-0x4(%rbp)
jmp    120b <pfdc4_load_header+0xcb>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pfdc4_load_header>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,(%rsp)
mov    $0x1,%ebp
cmp    $0x4,%rsi
jb     11be <pfdc4_load_header+0x7e>
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0x8(%rsp),%rsi
mov    %rsp,%rcx
mov    $0x4,%edx
call   1050 <pfdc4_read@plt>
test   %rax,%rax
jne    11be <pfdc4_load_header+0x7e>
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1030 <psi_get_uint32_be@plt>
cmp    $0x40000,%rax
jne    11a6 <pfdc4_load_header+0x66>
add    $0xfffffffffffffffc,%rbx
mov    (%rsp),%rdx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <pfdc4_skip_chunk@plt>
xor    %ebp,%ebp
test   %rax,%rax
setne  %bpl
jmp    11be <pfdc4_load_header+0x7e>
mov    0x2e33(%rip),%rcx
mov    (%rcx),%edi
lea    0xe4a(%rip),%rsi
mov    %rax,%rdx
call   1040 <fprintf@plt>
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [29 x i8] c"pfdc: unknown version (%lu)\0A\00"
define i32 @pfdc4_load_header(i32* %0, i64 %1, i64 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca [8 x i8]
store i32* %0, i32** %5
store i64 %1, i64* %6
store i64 %2, i64* %7
%10 = load i64, i64* %6
%11 = icmp ult i64 %10, 4
br i1 %11, label %12, label %13
12: ; preds = %3
store i32 1, i32* %4
br label %37
13: ; preds = %3
%14 = load i32*, i32** %5
%15 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 0
%16 = call i64 @pfdc4_read(i32* %14, i8* %15, i32 4, i64* %7)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %13
store i32 1, i32* %4
br label %37
19: ; preds = %13
%20 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 0
%21 = call i64 @psi_get_uint32_be(i8* %20, i32 0)
store i64 %21, i64* %8
%22 = load i64, i64* %8
%23 = icmp ne i64 %22, 262144
br i1 %23, label %24, label %28
24: ; preds = %19
%25 = load i32, i32* @stderr
%26 = load i64, i64* %8
%27 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i64 %26)
store i32 1, i32* %4
br label %37
28: ; preds = %19
%29 = load i32*, i32** %5
%30 = load i64, i64* %6
%31 = sub i64 %30, 4
%32 = load i64, i64* %7
%33 = call i64 @pfdc4_skip_chunk(i32* %29, i64 %31, i64 %32)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %28
store i32 1, i32* %4
br label %37
36: ; preds = %28
store i32 0, i32* %4
br label %37
37: ; preds = %36, %35, %24, %18, %12
%38 = load i32, i32* %4
ret i32 %38
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [29 x i8] c"pfdc: unknown version (%lu)\0A\00"
define i32 @pfdc4_load_header(i32* %0, i64 %1, i64 %2) {
%4 = alloca i64
%5 = alloca [8 x i8]
store i64 %2, i64* %4
%6 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 0
%7 = icmp ult i64 %1, 4
br i1 %7, label %23, label %8
8: ; preds = %3
%9 = call i64 @pfdc4_read(i32* %0, i8* %6, i32 4, i64* %4)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %23
11: ; preds = %8
%12 = call i64 @psi_get_uint32_be(i8* %6, i32 0)
%13 = icmp eq i64 %12, 262144
br i1 %13, label %17, label %14
14: ; preds = %11
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i64 %12)
br label %23
17: ; preds = %11
%18 = add i64 %1, -4
%19 = load i64, i64* %4
%20 = call i64 @pfdc4_skip_chunk(i32* %0, i64 %18, i64 %19)
%21 = icmp ne i64 %20, 0
%22 = zext i1 %21 to i32
br label %23
23: ; preds = %17, %8, %3, %14
%24 = phi i32 [ 1, %14 ], [ 1, %3 ], [ 1, %8 ], [ %22, %17 ]
ret i32 %24
}