#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 */

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(void *);
int lz77_inflate(unsigned char *, int, unsigned char *, int, unsigned char **);
unsigned char *malloc(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int lzpt_decompress_block(unsigned char *p_block_in, size_t sz_block_in,
                          int sz_mxdblk_in, unsigned char **pp_block_out,
                          size_t *psz_block_out) {
  unsigned char *p_block = NULL, *p_in, *p_out, *next_in;
  int remain_in, remain_out, this_declen;
  size_t total_decomp_size;
  *pp_block_out = NULL;
  *psz_block_out = 0;
  remain_out = sz_mxdblk_in;
  if (!(p_block = malloc(remain_out))) {
    fprintf(stderr, "lzpt_decompress_block(): allocation error!\n");
    return 1;
  }
  remain_in = sz_block_in;
  p_in = p_block_in;
  p_out = p_block;
  total_decomp_size = 0;
  while ((remain_in > (sizeof(unsigned int) - 1)) && (remain_out > 0)) {
    this_declen = lz77_inflate(p_in, remain_in, p_out, remain_out, &next_in);
    if (this_declen <= 0) {
      break;
    }
    p_out += this_declen;
    remain_out -= this_declen;
    total_decomp_size += this_declen;
    remain_in -= (next_in - p_in);
    p_in = next_in;
  }
  if ((remain_in > (sizeof(unsigned int) - 1)) || (remain_out < 0)) {
    fprintf(stderr, "lzpt_decompress_block(): decompress error! (%d %d %d)\n",
            remain_in, (sizeof(unsigned int) - 1), remain_out);
    free((void *)p_block);
    return 1;
  }
  *pp_block_out = p_block;
  *psz_block_out = total_decomp_size;
  if (total_decomp_size != sz_mxdblk_in) {
    printf("ERROR!\n");
    exit(1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<lzpt_decompress_block>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x28(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x30(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    -0x58(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    11d8 <lzpt_decompress_block+0x78>
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
lea    0xe3b(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    132b <lzpt_decompress_block+0x1cb>
mov    -0x18(%rbp),%rax
mov    %eax,-0x54(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x48(%rbp)
movq   $0x0,-0x68(%rbp)
movslq -0x54(%rbp),%rcx
xor    %eax,%eax
cmp    $0x3,%rcx
mov    %al,-0x69(%rbp)
jbe    1214 <lzpt_decompress_block+0xb4>
cmpl   $0x0,-0x58(%rbp)
setg   %al
mov    %al,-0x69(%rbp)
mov    -0x69(%rbp),%al
test   $0x1,%al
jne    1224 <lzpt_decompress_block+0xc4>
jmp    1297 <lzpt_decompress_block+0x137>
mov    -0x40(%rbp),%rdi
mov    -0x54(%rbp),%esi
mov    -0x48(%rbp),%rdx
mov    -0x58(%rbp),%ecx
lea    -0x50(%rbp),%r8
call   1080 <lz77_inflate@plt>
mov    %eax,-0x5c(%rbp)
cmpl   $0x0,-0x5c(%rbp)
jg     124d <lzpt_decompress_block+0xed>
jmp    1297 <lzpt_decompress_block+0x137>
mov    -0x5c(%rbp),%ecx
mov    -0x48(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x48(%rbp)
mov    -0x5c(%rbp),%ecx
mov    -0x58(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x58(%rbp)
movslq -0x5c(%rbp),%rax
add    -0x68(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x50(%rbp),%rcx
mov    -0x40(%rbp),%rax
sub    %rax,%rcx
movslq -0x54(%rbp),%rax
sub    %rcx,%rax
mov    %eax,-0x54(%rbp)
mov    -0x50(%rbp),%rax
mov    %rax,-0x40(%rbp)
jmp    11f7 <lzpt_decompress_block+0x97>
movslq -0x54(%rbp),%rax
cmp    $0x3,%rax
ja     12af <lzpt_decompress_block+0x14f>
cmpl   $0x0,-0x58(%rbp)
jge    12e7 <lzpt_decompress_block+0x187>
mov    0x2d2a(%rip),%rax
mov    (%rax),%edi
mov    -0x54(%rbp),%edx
mov    -0x58(%rbp),%r8d
lea    0xd66(%rip),%rsi
mov    $0x3,%ecx
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
jmp    132b <lzpt_decompress_block+0x1cb>
mov    -0x38(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x68(%rbp),%rcx
mov    -0x30(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x68(%rbp),%rax
movslq -0x1c(%rbp),%rcx
cmp    %rcx,%rax
je     1324 <lzpt_decompress_block+0x1c4>
lea    0xd4e(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lzpt_decompress_block>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r8,%rbx
mov    %rcx,%rbp
mov    %edx,%r14d
mov    %rsi,%r12
mov    %rdi,%r15
movq   $0x0,(%rcx)
movq   $0x0,(%r8)
mov    %edx,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     124c <lzpt_decompress_block+0xec>
mov    %rbp,0x10(%rsp)
mov    %rbx,0x18(%rsp)
movabs $0x300000000,%rcx
mov    %r12,%rbx
shl    $0x20,%rbx
xor    %r13d,%r13d
cmp    %rcx,%rbx
seta   %sil
mov    %rax,0x8(%rsp)
mov    %r14d,0x4(%rsp)
jbe    1265 <lzpt_decompress_block+0x105>
test   %r14d,%r14d
jle    126f <lzpt_decompress_block+0x10f>
xor    %r13d,%r13d
mov    %r14d,%ebp
mov    %rax,%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %r12d,%esi
mov    %r14,%rdx
mov    %ebp,%ecx
lea    0x20(%rsp),%r8
call   1080 <lz77_inflate@plt>
test   %eax,%eax
jle    12b2 <lzpt_decompress_block+0x152>
sar    $0x20,%rbx
mov    %eax,%edx
sub    %eax,%ebp
add    %rdx,%r13
mov    0x20(%rsp),%rcx
add    %r15,%rbx
mov    %rbx,%r12
sub    %rcx,%r12
mov    %r12,%rbx
shl    $0x20,%rbx
movabs $0x300000000,%rax
cmp    %rax,%rbx
seta   %sil
jbe    1268 <lzpt_decompress_block+0x108>
add    %rdx,%r14
mov    %rcx,%r15
test   %ebp,%ebp
jg     11f0 <lzpt_decompress_block+0x90>
jmp    1268 <lzpt_decompress_block+0x108>
mov    0x2d8d(%rip),%rax
mov    (%rax),%edi
lea    0xda4(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    12de <lzpt_decompress_block+0x17e>
mov    %r14d,%ebp
test   %sil,%sil
je     1277 <lzpt_decompress_block+0x117>
jmp    12b2 <lzpt_decompress_block+0x152>
mov    %r14d,%ebp
test   %sil,%sil
jne    12b2 <lzpt_decompress_block+0x152>
test   %ebp,%ebp
js     12b2 <lzpt_decompress_block+0x152>
mov    0x8(%rsp),%rax
mov    0x10(%rsp),%rcx
mov    %rax,(%rcx)
mov    0x18(%rsp),%rax
mov    %r13,(%rax)
movslq 0x4(%rsp),%rcx
xor    %eax,%eax
cmp    %rcx,%r13
je     12e3 <lzpt_decompress_block+0x183>
lea    0xdc0(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    0x2d27(%rip),%rax
mov    (%rax),%edi
lea    0xd6a(%rip),%rsi
mov    $0x3,%ecx
mov    %r12d,%edx
mov    %ebp,%r8d
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    $0x1,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [44 x i8] c"lzpt_decompress_block(): allocation error!\0A\00"
@.str.1 = [55 x i8] c"lzpt_decompress_block(): decompress error! (%d %d %d)\0A\00"
@.str.2 = [8 x i8] c"ERROR!\0A\00"
define i32 @lzpt_decompress_block(i8* %0, i64 %1, i32 %2, i8** %3, i64* %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
%10 = alloca i8**
%11 = alloca i64*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i64
store i8* %0, i8** %7
store i64 %1, i64* %8
store i32 %2, i32* %9
store i8** %3, i8*** %10
store i64* %4, i64** %11
store i8* null, i8** %12
%20 = load i8**, i8*** %10
store i8* null, i8** %20
%21 = load i64*, i64** %11
store i64 0, i64* %21
%22 = load i32, i32* %9
store i32 %22, i32* %17
%23 = load i32, i32* %17
%24 = call i8* @malloc(i32 %23)
store i8* %24, i8** %12
%25 = icmp ne i8* %24, null
br i1 %25, label %29, label %26
26: ; preds = %5
%27 = load i32, i32* @stderr
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %6
br label %101
29: ; preds = %5
%30 = load i64, i64* %8
%31 = trunc i64 %30 to i32
store i32 %31, i32* %16
%32 = load i8*, i8** %7
store i8* %32, i8** %13
%33 = load i8*, i8** %12
store i8* %33, i8** %14
store i64 0, i64* %19
br label %34
34: ; preds = %52, %29
%35 = load i32, i32* %16
%36 = sext i32 %35 to i64
%37 = icmp ugt i64 %36, 3
br i1 %37, label %38, label %41
38: ; preds = %34
%39 = load i32, i32* %17
%40 = icmp sgt i32 %39, 0
br label %41
41: ; preds = %38, %34
%42 = phi i1 [ false, %34 ], [ %40, %38 ]
br i1 %42, label %43, label %74
43: ; preds = %41
%44 = load i8*, i8** %13
%45 = load i32, i32* %16
%46 = load i8*, i8** %14
%47 = load i32, i32* %17
%48 = call i32 @lz77_inflate(i8* %44, i32 %45, i8* %46, i32 %47, i8** %15)
store i32 %48, i32* %18
%49 = load i32, i32* %18
%50 = icmp sle i32 %49, 0
br i1 %50, label %51, label %52
51: ; preds = %43
br label %74
52: ; preds = %43
%53 = load i32, i32* %18
%54 = load i8*, i8** %14
%55 = sext i32 %53 to i64
%56 = getelementptr inbounds i8, i8* %54, i64 %55
store i8* %56, i8** %14
%57 = load i32, i32* %18
%58 = load i32, i32* %17
%59 = sub nsw i32 %58, %57
store i32 %59, i32* %17
%60 = load i32, i32* %18
%61 = sext i32 %60 to i64
%62 = load i64, i64* %19
%63 = add i64 %62, %61
store i64 %63, i64* %19
%64 = load i8*, i8** %15
%65 = load i8*, i8** %13
%66 = ptrtoint i8* %64 to i64
%67 = ptrtoint i8* %65 to i64
%68 = sub i64 %66, %67
%69 = load i32, i32* %16
%70 = sext i32 %69 to i64
%71 = sub nsw i64 %70, %68
%72 = trunc i64 %71 to i32
store i32 %72, i32* %16
%73 = load i8*, i8** %15
store i8* %73, i8** %13
br label %34
74: ; preds = %51, %41
%75 = load i32, i32* %16
%76 = sext i32 %75 to i64
%77 = icmp ugt i64 %76, 3
br i1 %77, label %81, label %78
78: ; preds = %74
%79 = load i32, i32* %17
%80 = icmp slt i32 %79, 0
br i1 %80, label %81, label %88
81: ; preds = %78, %74
%82 = load i32, i32* @stderr
%83 = load i32, i32* %16
%84 = load i32, i32* %17
%85 = call i32 (i32, i8*, ...) @fprintf(i32 %82, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0), i32 %83, i64 3, i32 %84)
%86 = load i8*, i8** %12
%87 = call i32 @free(i8* %86)
store i32 1, i32* %6
br label %101
88: ; preds = %78
%89 = load i8*, i8** %12
%90 = load i8**, i8*** %10
store i8* %89, i8** %90
%91 = load i64, i64* %19
%92 = load i64*, i64** %11
store i64 %91, i64* %92
%93 = load i64, i64* %19
%94 = load i32, i32* %9
%95 = sext i32 %94 to i64
%96 = icmp ne i64 %93, %95
br i1 %96, label %97, label %100
97: ; preds = %88
%98 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%99 = call i32 @exit(i32 1)
unreachable
100: ; preds = %88
store i32 0, i32* %6
br label %101
101: ; preds = %100, %81, %26
%102 = load i32, i32* %6
ret i32 %102
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [44 x i8] c"lzpt_decompress_block(): allocation error!\0A\00"
@.str.1 = [55 x i8] c"lzpt_decompress_block(): decompress error! (%d %d %d)\0A\00"
@str = [7 x i8] c"ERROR!\00"
define i32 @lzpt_decompress_block(i8* %0, i64 %1, i32 %2, i8** nocapture writeonly %3, i64* nocapture writeonly %4) {
%6 = alloca i8*
%7 = bitcast i8** %6 to i8*
store i8* null, i8** %3
store i64 0, i64* %4
%8 = tail call i8* @malloc(i32 %2)
%9 = icmp eq i8* %8, null
br i1 %9, label %15, label %10
10: ; preds = %5
%11 = shl i64 %1, 32
%12 = icmp ugt i64 %11, 12884901888
%13 = icmp sgt i32 %2, 0
%14 = and i1 %12, %13
br i1 %14, label %18, label %43
15: ; preds = %5
%16 = load i32, i32* @stderr
%17 = tail call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
br label %63
18: ; preds = %10, %28
%19 = phi i64 [ %39, %28 ], [ %11, %10 ]
%20 = phi i64 [ %33, %28 ], [ 0, %10 ]
%21 = phi i32 [ %32, %28 ], [ %2, %10 ]
%22 = phi i64 [ %38, %28 ], [ %1, %10 ]
%23 = phi i8* [ %31, %28 ], [ %8, %10 ]
%24 = phi i8* [ %34, %28 ], [ %0, %10 ]
%25 = trunc i64 %22 to i32
%26 = call i32 @lz77_inflate(i8* %24, i32 %25, i8* %23, i32 %21, i8** %6)
%27 = icmp slt i32 %26, 1
br i1 %27, label %50, label %28
28: ; preds = %18
%29 = ashr exact i64 %19, 32
%30 = zext i32 %26 to i64
%31 = getelementptr inbounds i8, i8* %23, i64 %30
%32 = sub nsw i32 %21, %26
%33 = add i64 %20, %30
%34 = load i8*, i8** %6
%35 = ptrtoint i8* %34 to i64
%36 = ptrtoint i8* %24 to i64
%37 = add i64 %29, %36
%38 = sub i64 %37, %35
%39 = shl i64 %38, 32
%40 = icmp ugt i64 %39, 12884901888
%41 = icmp sgt i32 %32, 0
%42 = select i1 %40, i1 %41, i1 false
br i1 %42, label %18, label %43
43: ; preds = %28, %10
%44 = phi i64 [ %1, %10 ], [ %38, %28 ]
%45 = phi i32 [ %2, %10 ], [ %32, %28 ]
%46 = phi i64 [ 0, %10 ], [ %33, %28 ]
%47 = phi i1 [ %12, %10 ], [ %40, %28 ]
%48 = icmp slt i32 %45, 0
%49 = select i1 %47, i1 true, i1 %48
br i1 %49, label %50, label %57
50: ; preds = %18, %43
%51 = phi i32 [ %45, %43 ], [ %21, %18 ]
%52 = phi i64 [ %44, %43 ], [ %22, %18 ]
%53 = trunc i64 %52 to i32
%54 = load i32, i32* @stderr
%55 = call i32 (i32, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0), i32 %53, i64 3, i32 %51)
%56 = call i32 @free(i8* %8)
br label %63
57: ; preds = %43
store i8* %8, i8** %3
store i64 %46, i64* %4
%58 = sext i32 %2 to i64
%59 = icmp eq i64 %46, %58
br i1 %59, label %63, label %60
60: ; preds = %57
%61 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
%62 = call i32 @exit(i32 1)
unreachable
63: ; preds = %57, %50, %15
%64 = phi i32 [ 1, %50 ], [ 1, %15 ], [ 0, %57 ]
ret i32 %64
}