#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 */
typedef struct TYPE_5__ TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ zstrm;
struct TYPE_5__ {
  int avail_in;
  int avail_out;
  scalar_t__ total_out;
  int /*<<< orphan*/ *next_out;
  int /*<<< orphan*/ *next_in;
};
typedef TYPE_1__ z_stream;
typedef int /*<<< orphan*/ FILE;
typedef int /*<<< orphan*/ Bytef;

/* Variables and functions */
int /*<<< orphan*/ Z_FINISH;
int Z_OK;
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int inflate(TYPE_1__ *, int /*<<< orphan*/);
int inflateInit(TYPE_1__ *);
int /*<<< orphan*/ memset(TYPE_1__ *, int /*<<< orphan*/, int);
int pdf_numpages_1(char *, int);
int /*<<< orphan*/ willus_mem_alloc_warn(void **, int, char *, int);
int /*<<< orphan*/ willus_mem_free(double **, char *);
int decodecheck(FILE *f, int np) {
  char *inbuf, *outbuf;
  z_stream zstrm;
  int i0, status, obsize, extra;
  static char *funcname = "decodecheck";
  extra = 4;
  willus_mem_alloc_warn((void **)&inbuf, np + extra, funcname, 10);
  obsize = np * 10;
  if (obsize < 1024)
    obsize = 1024;
  willus_mem_alloc_warn((void **)&outbuf, obsize, funcname, 10);
  fread(inbuf, 1, np + extra, f);
  i0 = 0;
  if (inbuf[i0] == '\n' || inbuf[i0] == '\r')
    i0++;
  memset(&zstrm, 0, sizeof(zstrm));
  zstrm.avail_in = np + extra - i0;
  zstrm.avail_out = obsize;
  zstrm.next_in = (Bytef *)&inbuf[i0];
  zstrm.next_out = (Bytef *)outbuf;
  status = inflateInit(&zstrm);
  if (status != Z_OK) {
    willus_mem_free((double **)&outbuf, funcname);
    willus_mem_free((double **)&inbuf, funcname);
    return (0);
  }
  status = inflate(&zstrm, Z_FINISH);
  if (zstrm.total_out > 0)
    np = pdf_numpages_1(outbuf, (int)zstrm.total_out);
  else
    np = 0;
  willus_mem_free((double **)&outbuf, funcname);
  willus_mem_free((double **)&inbuf, funcname);
  return (np);
}


x86 assembly (clang, -O0):
<decodecheck>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x4,-0x58(%rbp)
mov    -0x14(%rbp),%esi
add    -0x58(%rbp),%esi
mov    0x2ec5(%rip),%rdx
lea    -0x20(%rbp),%rdi
mov    $0xa,%ecx
call   1030 <willus_mem_alloc_warn@plt>
imul   $0xa,-0x14(%rbp),%eax
mov    %eax,-0x54(%rbp)
cmpl   $0x400,-0x54(%rbp)
jge    11bc <decodecheck+0x4c>
movl   $0x400,-0x54(%rbp)
mov    -0x54(%rbp),%esi
mov    0x2e92(%rip),%rdx
lea    -0x28(%rbp),%rdi
mov    $0xa,%ecx
call   1030 <willus_mem_alloc_warn@plt>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%edx
add    -0x58(%rbp),%edx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1050 <fread@plt>
movl   $0x0,-0x4c(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x4c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
je     121d <decodecheck+0xad>
mov    -0x20(%rbp),%rax
movslq -0x4c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xd,%eax
jne    1226 <decodecheck+0xb6>
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
lea    -0x48(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1060 <memset@plt>
mov    -0x14(%rbp),%eax
add    -0x58(%rbp),%eax
sub    -0x4c(%rbp),%eax
mov    %eax,-0x48(%rbp)
mov    -0x54(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x4c(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    -0x48(%rbp),%rdi
call   1070 <inflateInit@plt>
mov    %eax,-0x50(%rbp)
mov    -0x50(%rbp),%eax
mov    0x2d7b(%rip),%rcx
cmp    (%rcx),%eax
je     12a9 <decodecheck+0x139>
lea    -0x28(%rbp),%rdi
mov    0x2dd0(%rip),%rsi
call   1080 <willus_mem_free@plt>
lea    -0x20(%rbp),%rdi
mov    0x2dc0(%rip),%rsi
call   1080 <willus_mem_free@plt>
movl   $0x0,-0x4(%rbp)
jmp    130d <decodecheck+0x19d>
mov    0x2d28(%rip),%rax
mov    (%rax),%esi
lea    -0x48(%rbp),%rdi
call   1040 <inflate@plt>
mov    %eax,-0x50(%rbp)
cmpq   $0x0,-0x40(%rbp)
jle    12e0 <decodecheck+0x170>
mov    -0x28(%rbp),%rdi
mov    -0x40(%rbp),%rax
mov    %eax,%esi
call   1090 <pdf_numpages_1@plt>
mov    %eax,-0x14(%rbp)
jmp    12e7 <decodecheck+0x177>
movl   $0x0,-0x14(%rbp)
lea    -0x28(%rbp),%rdi
mov    0x2d66(%rip),%rsi
call   1080 <willus_mem_free@plt>
lea    -0x20(%rbp),%rdi
mov    0x2d56(%rip),%rsi
call   1080 <willus_mem_free@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decodecheck>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x30,%rsp
mov    %esi,%r15d
mov    %rdi,%r14
lea    0x4(%r15),%ebx
lea    0xe73(%rip),%r12
mov    %rsp,%rdi
mov    %ebx,%esi
mov    %r12,%rdx
mov    $0xa,%ecx
call   1030 <willus_mem_alloc_warn@plt>
lea    (%r15,%r15,1),%eax
lea    (%rax,%rax,4),%eax
cmp    $0x401,%eax
mov    $0x400,%ebp
cmovge %eax,%ebp
lea    0x8(%rsp),%rdi
mov    %ebp,%esi
mov    %r12,%rdx
mov    $0xa,%ecx
call   1030 <willus_mem_alloc_warn@plt>
mov    (%rsp),%rdi
mov    $0x1,%esi
mov    %ebx,%edx
mov    %r14,%rcx
call   1050 <fread@plt>
mov    (%rsp),%rax
mov    (%rax),%al
cmp    $0xa,%al
sete   %cl
cmp    $0xd,%al
sete   %bl
or     %cl,%bl
lea    0x10(%rsp),%r12
xor    %r14d,%r14d
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1060 <memset@plt>
movzbl %bl,%eax
mov    %eax,%ecx
neg    %ecx
add    %r15d,%ecx
add    $0x4,%ecx
mov    %ecx,0x10(%rsp)
add    (%rsp),%rax
mov    %ebp,0x14(%rsp)
mov    %rax,0x28(%rsp)
mov    0x8(%rsp),%rax
mov    %rax,0x20(%rsp)
mov    %r12,%rdi
call   1070 <inflateInit@plt>
mov    0x2db6(%rip),%rcx
cmp    (%rcx),%eax
jne    1268 <decodecheck+0xf8>
mov    0x2d93(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rdi
call   1040 <inflate@plt>
mov    0x18(%rsp),%rsi
test   %rsi,%rsi
jle    1268 <decodecheck+0xf8>
mov    0x8(%rsp),%rdi
call   1090 <pdf_numpages_1@plt>
mov    %eax,%r14d
lea    0xd91(%rip),%rbx
lea    0x8(%rsp),%rdi
mov    %rbx,%rsi
call   1080 <willus_mem_free@plt>
mov    %rsp,%rdi
mov    %rbx,%rsi
call   1080 <willus_mem_free@plt>
mov    %r14d,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_5__ = type { i32, i32, i64, i32*, i32* }
@decodecheck.funcname = internal global i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i32 0, i32 0)
@.str = [12 x i8] c"decodecheck\00"
@Z_OK = global i32 0
@Z_FINISH = global i32 0
define i32 @decodecheck(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca %struct.TYPE_5__
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 4, i32* %12
%13 = load i32, i32* %5
%14 = load i32, i32* %12
%15 = add nsw i32 %13, %14
%16 = load i8*, i8** @decodecheck.funcname
%17 = call i32 @willus_mem_alloc_warn(i8** %6, i32 %15, i8* %16, i32 10)
%18 = load i32, i32* %5
%19 = mul nsw i32 %18, 10
store i32 %19, i32* %11
%20 = load i32, i32* %11
%21 = icmp slt i32 %20, 1024
br i1 %21, label %22, label %23
22: ; preds = %2
store i32 1024, i32* %11
br label %23
23: ; preds = %22, %2
%24 = load i32, i32* %11
%25 = load i8*, i8** @decodecheck.funcname
%26 = call i32 @willus_mem_alloc_warn(i8** %7, i32 %24, i8* %25, i32 10)
%27 = load i8*, i8** %6
%28 = load i32, i32* %5
%29 = load i32, i32* %12
%30 = add nsw i32 %28, %29
%31 = load i32*, i32** %4
%32 = call i32 @fread(i8* %27, i32 1, i32 %30, i32* %31)
store i32 0, i32* %9
%33 = load i8*, i8** %6
%34 = load i32, i32* %9
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp eq i32 %38, 10
br i1 %39, label %48, label %40
40: ; preds = %23
%41 = load i8*, i8** %6
%42 = load i32, i32* %9
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %41, i64 %43
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = icmp eq i32 %46, 13
br i1 %47, label %48, label %51
48: ; preds = %40, %23
%49 = load i32, i32* %9
%50 = add nsw i32 %49, 1
store i32 %50, i32* %9
br label %51
51: ; preds = %48, %40
%52 = call i32 @memset(%struct.TYPE_5__* %8, i32 0, i32 32)
%53 = load i32, i32* %5
%54 = load i32, i32* %12
%55 = add nsw i32 %53, %54
%56 = load i32, i32* %9
%57 = sub nsw i32 %55, %56
%58 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %8, i32 0, i32 0
store i32 %57, i32* %58
%59 = load i32, i32* %11
%60 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %8, i32 0, i32 1
store i32 %59, i32* %60
%61 = load i8*, i8** %6
%62 = load i32, i32* %9
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8, i8* %61, i64 %63
%65 = bitcast i8* %64 to i32*
%66 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %8, i32 0, i32 4
store i32* %65, i32** %66
%67 = load i8*, i8** %7
%68 = bitcast i8* %67 to i32*
%69 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %8, i32 0, i32 3
store i32* %68, i32** %69
%70 = call i32 @inflateInit(%struct.TYPE_5__* %8)
store i32 %70, i32* %10
%71 = load i32, i32* %10
%72 = load i32, i32* @Z_OK
%73 = icmp ne i32 %71, %72
br i1 %73, label %74, label %81
74: ; preds = %51
%75 = bitcast i8** %7 to double**
%76 = load i8*, i8** @decodecheck.funcname
%77 = call i32 @willus_mem_free(double** %75, i8* %76)
%78 = bitcast i8** %6 to double**
%79 = load i8*, i8** @decodecheck.funcname
%80 = call i32 @willus_mem_free(double** %78, i8* %79)
store i32 0, i32* %3
br label %102
81: ; preds = %51
%82 = load i32, i32* @Z_FINISH
%83 = call i32 @inflate(%struct.TYPE_5__* %8, i32 %82)
store i32 %83, i32* %10
%84 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %8, i32 0, i32 2
%85 = load i64, i64* %84
%86 = icmp sgt i64 %85, 0
br i1 %86, label %87, label %93
87: ; preds = %81
%88 = load i8*, i8** %7
%89 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %8, i32 0, i32 2
%90 = load i64, i64* %89
%91 = trunc i64 %90 to i32
%92 = call i32 @pdf_numpages_1(i8* %88, i32 %91)
store i32 %92, i32* %5
br label %94
93: ; preds = %81
store i32 0, i32* %5
br label %94
94: ; preds = %93, %87
%95 = bitcast i8** %7 to double**
%96 = load i8*, i8** @decodecheck.funcname
%97 = call i32 @willus_mem_free(double** %95, i8* %96)
%98 = bitcast i8** %6 to double**
%99 = load i8*, i8** @decodecheck.funcname
%100 = call i32 @willus_mem_free(double** %98, i8* %99)
%101 = load i32, i32* %5
store i32 %101, i32* %3
br label %102
102: ; preds = %94, %74
%103 = load i32, i32* %3
ret i32 %103
}

LLVM IR (-O2):
%struct.TYPE_5__ = type { i32, i32, i64, i32*, i32* }
@.str = [12 x i8] c"decodecheck\00"
@Z_OK = global i32 0
@Z_FINISH = global i32 0
define i32 @decodecheck(i32* nocapture %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca %struct.TYPE_5__
%6 = bitcast i8** %3 to i8*
%7 = bitcast i8** %4 to i8*
%8 = bitcast %struct.TYPE_5__* %5 to i8*
%9 = add nsw i32 %1, 4
%10 = call i32 @willus_mem_alloc_warn(i8** %3, i32 %9, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 10)
%11 = mul nsw i32 %1, 10
%12 = icmp sgt i32 %11, 1024
%13 = select i1 %12, i32 %11, i32 1024
%14 = call i32 @willus_mem_alloc_warn(i8** %4, i32 %13, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 10)
%15 = load i8*, i8** %3
%16 = call i32 @fread(i8* %15, i32 1, i32 %9, i32* %0)
%17 = load i8*, i8** %3
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 10
%20 = icmp eq i8 %18, 13
%21 = or i1 %19, %20
%22 = sext i1 %21 to i32
%23 = call i32 @memset(%struct.TYPE_5__* %5, i32 0, i32 32)
%24 = add nsw i32 %9, %22
%25 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %5, i64 0, i32 0
store i32 %24, i32* %25
%26 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %5, i64 0, i32 1
store i32 %13, i32* %26
%27 = load i8*, i8** %3
%28 = zext i1 %21 to i64
%29 = getelementptr inbounds i8, i8* %27, i64 %28
%30 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %5, i64 0, i32 4
%31 = bitcast i32** %30 to i8**
store i8* %29, i8** %31
%32 = bitcast i8** %4 to i32**
%33 = load i32*, i32** %32
%34 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %5, i64 0, i32 3
store i32* %33, i32** %34
%35 = call i32 @inflateInit(%struct.TYPE_5__* %5)
%36 = load i32, i32* @Z_OK
%37 = icmp eq i32 %35, %36
br i1 %37, label %38, label %48
38: ; preds = %2
%39 = load i32, i32* @Z_FINISH
%40 = call i32 @inflate(%struct.TYPE_5__* %5, i32 %39)
%41 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %5, i64 0, i32 2
%42 = load i64, i64* %41
%43 = icmp sgt i64 %42, 0
br i1 %43, label %44, label %48
44: ; preds = %38
%45 = load i8*, i8** %4
%46 = trunc i64 %42 to i32
%47 = call i32 @pdf_numpages_1(i8* %45, i32 %46)
br label %48
48: ; preds = %44, %38, %2
%49 = phi i32 [ 0, %2 ], [ %47, %44 ], [ 0, %38 ]
%50 = bitcast i8** %4 to double**
%51 = call i32 @willus_mem_free(double** %50, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%52 = bitcast i8** %3 to double**
%53 = call i32 @willus_mem_free(double** %52, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
ret i32 %49
}