#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 psi_get_uint32_be(unsigned char *, int /*<<< orphan*/);
scalar_t__ psi_read_crc(int /*<<< orphan*/ *, unsigned char *, int,
                        unsigned long *);
int /*<<< orphan*/ stderr;
int psi_skip_chunk(FILE *fp, unsigned long cnt, unsigned long crc) {
  unsigned n;
  unsigned char buf[256];
  while (cnt > 0) {
    n = (cnt < 256) ? cnt : 256;
    if (psi_read_crc(fp, buf, n, &crc)) {
      return (1);
    }
    cnt -= n;
  }
  if (psi_read_crc(fp, buf, 4, NULL)) {
    return (1);
  }
  if (psi_get_uint32_be(buf, 0) != crc) {
    fprintf(stderr, "psi: crc error\n");
    return (1);
  }
  return (0);
}


x86 assembly (clang, -O0):
<psi_skip_chunk>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
jbe    11cd <psi_skip_chunk+0x9d>
cmpq   $0x100,-0x18(%rbp)
jae    1170 <psi_skip_chunk+0x40>
mov    -0x18(%rbp),%rax
mov    %rax,-0x138(%rbp)
jmp    1181 <psi_skip_chunk+0x51>
mov    $0x100,%eax
mov    %rax,-0x138(%rbp)
jmp    1181 <psi_skip_chunk+0x51>
mov    -0x138(%rbp),%rax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x130(%rbp),%rsi
mov    -0x24(%rbp),%edx
lea    -0x20(%rbp),%rcx
call   1050 <psi_read_crc@plt>
cmp    $0x0,%rax
je     11b8 <psi_skip_chunk+0x88>
movl   $0x1,-0x4(%rbp)
jmp    123c <psi_skip_chunk+0x10c>
mov    -0x24(%rbp),%eax
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x18(%rbp)
jmp    1147 <psi_skip_chunk+0x17>
mov    -0x10(%rbp),%rdi
lea    -0x130(%rbp),%rsi
mov    $0x4,%edx
xor    %eax,%eax
mov    %eax,%ecx
call   1050 <psi_read_crc@plt>
cmp    $0x0,%rax
je     11fc <psi_skip_chunk+0xcc>
movl   $0x1,-0x4(%rbp)
jmp    123c <psi_skip_chunk+0x10c>
lea    -0x130(%rbp),%rdi
xor    %esi,%esi
call   1030 <psi_get_uint32_be@plt>
cmp    -0x20(%rbp),%rax
je     1235 <psi_skip_chunk+0x105>
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
lea    0xddc(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    123c <psi_skip_chunk+0x10c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<psi_skip_chunk>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x110,%rsp
mov    %rdi,%r15
mov    %rdx,0x8(%rsp)
test   %rsi,%rsi
je     118a <psi_skip_chunk+0x5a>
mov    %rsi,%r13
lea    0x10(%rsp),%r14
lea    0x8(%rsp),%r12
nopw   0x0(%rax,%rax,1)
cmp    $0x100,%r13
mov    $0x100,%ebx
cmovb  %r13,%rbx
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
mov    %r12,%rcx
call   1050 <psi_read_crc@plt>
test   %rax,%rax
jne    11ce <psi_skip_chunk+0x9e>
sub    %rbx,%r13
jne    1160 <psi_skip_chunk+0x30>
xor    %r14d,%r14d
lea    0x10(%rsp),%rsi
mov    %r15,%rdi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1050 <psi_read_crc@plt>
test   %rax,%rax
jne    11ce <psi_skip_chunk+0x9e>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1030 <psi_get_uint32_be@plt>
cmp    0x8(%rsp),%rax
je     11d4 <psi_skip_chunk+0xa4>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
lea    0xe37(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x110,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@stderr = global i32 0
@.str = [16 x i8] c"psi: crc error\0A\00"
define i32 @psi_skip_chunk(i32* %0, i64 %1, i64 %2) {
%4 = alloca i64
%5 = alloca [256 x i8]
store i64 %2, i64* %4
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%7 = icmp eq i64 %1, 0
br i1 %7, label %18, label %10
8: ; preds = %10
%9 = icmp eq i64 %17, 0
br i1 %9, label %18, label %10
10: ; preds = %3, %8
%11 = phi i64 [ %17, %8 ], [ %1, %3 ]
%12 = icmp ult i64 %11, 256
%13 = select i1 %12, i64 %11, i64 256
%14 = trunc i64 %13 to i32
%15 = call i64 @psi_read_crc(i32* %0, i8* %6, i32 %14, i64* %4)
%16 = icmp eq i64 %15, 0
%17 = sub i64 %11, %13
br i1 %16, label %8, label %28
18: ; preds = %8, %3
%19 = call i64 @psi_read_crc(i32* %0, i8* %6, i32 4, i64* null)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %28
21: ; preds = %18
%22 = call i64 @psi_get_uint32_be(i8* %6, i32 0)
%23 = load i64, i64* %4
%24 = icmp eq i64 %22, %23
br i1 %24, label %28, label %25
25: ; preds = %21
%26 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %28
28: ; preds = %10, %21, %18, %25
%29 = phi i32 [ 1, %25 ], [ 1, %18 ], [ 0, %21 ], [ 1, %10 ]
ret i32 %29
}