#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 long pfdc2_crc(unsigned long, unsigned char *, unsigned int);
scalar_t__ pfdc2_read(int /*<<< orphan*/ *, unsigned char *, int);
unsigned long psi_get_uint32_be(unsigned char *, int /*<<< orphan*/);
int pfdc2_skip_chunk(FILE *fp, unsigned cnt, unsigned long crc) {
  unsigned n;
  unsigned char buf[256];
  while (cnt > 0) {
    n = (cnt < 256) ? cnt : 256;
    if (pfdc2_read(fp, buf, n)) {
      return (1);
    }
    crc = pfdc2_crc(crc, buf, n);
    cnt -= n;
  }
  if (pfdc2_read(fp, buf, 4)) {
    return (1);
  }
  if (psi_get_uint32_be(buf, 0) != crc) {
    return (1);
  }
  return (0);
}


x86 assembly (clang, -O0):
<pfdc2_skip_chunk>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
cmpl   $0x0,-0x14(%rbp)
jbe    11d4 <pfdc2_skip_chunk+0xa4>
cmpl   $0x100,-0x14(%rbp)
jae    116b <pfdc2_skip_chunk+0x3b>
mov    -0x14(%rbp),%eax
mov    %eax,-0x134(%rbp)
jmp    117b <pfdc2_skip_chunk+0x4b>
mov    $0x100,%eax
mov    %eax,-0x134(%rbp)
jmp    117b <pfdc2_skip_chunk+0x4b>
mov    -0x134(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x130(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1050 <pfdc2_read@plt>
cmp    $0x0,%rax
je     11ad <pfdc2_skip_chunk+0x7d>
movl   $0x1,-0x4(%rbp)
jmp    122a <pfdc2_skip_chunk+0xfa>
mov    -0x20(%rbp),%rdi
lea    -0x130(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1040 <pfdc2_crc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x24(%rbp),%ecx
mov    -0x14(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
jmp    1146 <pfdc2_skip_chunk+0x16>
mov    -0x10(%rbp),%rdi
lea    -0x130(%rbp),%rsi
mov    $0x4,%edx
call   1050 <pfdc2_read@plt>
cmp    $0x0,%rax
je     11ff <pfdc2_skip_chunk+0xcf>
movl   $0x1,-0x4(%rbp)
jmp    122a <pfdc2_skip_chunk+0xfa>
lea    -0x130(%rbp),%rdi
xor    %esi,%esi
call   1030 <psi_get_uint32_be@plt>
cmp    -0x20(%rbp),%rax
je     1223 <pfdc2_skip_chunk+0xf3>
movl   $0x1,-0x4(%rbp)
jmp    122a <pfdc2_skip_chunk+0xfa>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pfdc2_skip_chunk>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x100,%rsp
mov    %rdx,%r12
mov    %rdi,%r14
test   %esi,%esi
je     1184 <pfdc2_skip_chunk+0x54>
mov    %esi,%ebp
mov    %rsp,%r15
xchg   %ax,%ax
cmp    $0x100,%ebp
mov    $0x100,%ebx
cmovb  %ebp,%ebx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1050 <pfdc2_read@plt>
test   %rax,%rax
jne    11b8 <pfdc2_skip_chunk+0x88>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1040 <pfdc2_crc@plt>
mov    %rax,%r12
sub    %ebx,%ebp
jne    1150 <pfdc2_skip_chunk+0x20>
mov    %rsp,%rsi
mov    %r14,%rdi
mov    $0x4,%edx
call   1050 <pfdc2_read@plt>
mov    %rax,%rcx
mov    $0x1,%eax
test   %rcx,%rcx
jne    11bd <pfdc2_skip_chunk+0x8d>
mov    %rsp,%rdi
xor    %esi,%esi
call   1030 <psi_get_uint32_be@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %r12,%rcx
setne  %al
jmp    11bd <pfdc2_skip_chunk+0x8d>
mov    $0x1,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @pfdc2_skip_chunk(i32* %0, i32 %1, i64 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i64
%8 = alloca i32
%9 = alloca [256 x i8]
store i32* %0, i32** %5
store i32 %1, i32* %6
store i64 %2, i64* %7
br label %10
10: ; preds = %27, %3
%11 = load i32, i32* %6
%12 = icmp ugt i32 %11, 0
br i1 %12, label %13, label %35
13: ; preds = %10
%14 = load i32, i32* %6
%15 = icmp ult i32 %14, 256
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = load i32, i32* %6
br label %19
18: ; preds = %13
br label %19
19: ; preds = %18, %16
%20 = phi i32 [ %17, %16 ], [ 256, %18 ]
store i32 %20, i32* %8
%21 = load i32*, i32** %5
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%23 = load i32, i32* %8
%24 = call i64 @pfdc2_read(i32* %21, i8* %22, i32 %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %19
store i32 1, i32* %4
br label %48
27: ; preds = %19
%28 = load i64, i64* %7
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%30 = load i32, i32* %8
%31 = call i64 @pfdc2_crc(i64 %28, i8* %29, i32 %30)
store i64 %31, i64* %7
%32 = load i32, i32* %8
%33 = load i32, i32* %6
%34 = sub i32 %33, %32
store i32 %34, i32* %6
br label %10
35: ; preds = %10
%36 = load i32*, i32** %5
%37 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%38 = call i64 @pfdc2_read(i32* %36, i8* %37, i32 4)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %35
store i32 1, i32* %4
br label %48
41: ; preds = %35
%42 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%43 = call i64 @psi_get_uint32_be(i8* %42, i32 0)
%44 = load i64, i64* %7
%45 = icmp ne i64 %43, %44
br i1 %45, label %46, label %47
46: ; preds = %41
store i32 1, i32* %4
br label %48
47: ; preds = %41
store i32 0, i32* %4
br label %48
48: ; preds = %47, %46, %40, %26
%49 = load i32, i32* %4
ret i32 %49
}

LLVM IR (-O2):
define i32 @pfdc2_skip_chunk(i32* %0, i32 %1, i64 %2) {
%4 = alloca [256 x i8]
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%6 = icmp eq i32 %1, 0
br i1 %6, label %18, label %7
7: ; preds = %3, %14
%8 = phi i64 [ %15, %14 ], [ %2, %3 ]
%9 = phi i32 [ %16, %14 ], [ %1, %3 ]
%10 = icmp ult i32 %9, 256
%11 = select i1 %10, i32 %9, i32 256
%12 = call i64 @pfdc2_read(i32* %0, i8* %5, i32 %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %26
14: ; preds = %7
%15 = call i64 @pfdc2_crc(i64 %8, i8* %5, i32 %11)
%16 = sub i32 %9, %11
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %7
18: ; preds = %14, %3
%19 = phi i64 [ %2, %3 ], [ %15, %14 ]
%20 = call i64 @pfdc2_read(i32* %0, i8* %5, i32 4)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %18
%23 = call i64 @psi_get_uint32_be(i8* %5, i32 0)
%24 = icmp ne i64 %23, %19
%25 = zext i1 %24 to i32
br label %26
26: ; preds = %7, %22, %18
%27 = phi i32 [ 1, %18 ], [ %25, %22 ], [ 1, %7 ]
ret i32 %27
}