#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 inflate(unsigned char const *, long *, void (*)(unsigned char));
int read_bits(unsigned char const *, long *, int);
int unzip(const unsigned char *data, long *p,
          void (*callback)(unsigned char d)) {
  unsigned char cm, flg;
  if (read_bits(data, p, 8) != 0x1f || read_bits(data, p, 8) != 0x8b) {
    return -1;
  }
  cm = read_bits(data, p, 8);
  if (cm != 0x8) {
    return -1;
  }
  flg = read_bits(data, p, 8);
  if (flg & 0xe0)
    ;
  read_bits(data, p, 32);
  read_bits(data, p, 8);
  read_bits(data, p, 8);
  if (flg & 0x4) {
    unsigned int xlen;
    xlen = read_bits(data, p, 16);
    *p += ((long)xlen) * 8;
  }
  if (flg & 0x8) {
    while (read_bits(data, p, 8))
      ;
  }
  if (flg & 0x10) {
    while (read_bits(data, p, 8))
      ;
  }
  if (flg & 0x2)
    read_bits(data, p, 16);
  return inflate(data, p, callback);
}


x86 assembly (clang, -O0):
<unzip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x8,%edx
call   1040 <read_bits@plt>
cmp    $0x1f,%eax
jne    116c <unzip+0x4c>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x8,%edx
call   1040 <read_bits@plt>
cmp    $0x8b,%eax
je     1178 <unzip+0x58>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ea <unzip+0x1ca>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x8,%edx
call   1040 <read_bits@plt>
mov    %al,-0x21(%rbp)
movzbl -0x21(%rbp),%eax
cmp    $0x8,%eax
je     11a6 <unzip+0x86>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ea <unzip+0x1ca>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x8,%edx
call   1040 <read_bits@plt>
mov    %al,-0x22(%rbp)
movzbl -0x22(%rbp),%eax
and    $0xe0,%eax
cmp    $0x0,%eax
je     11d2 <unzip+0xb2>
jmp    11d2 <unzip+0xb2>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x20,%edx
call   1040 <read_bits@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x8,%edx
call   1040 <read_bits@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x8,%edx
call   1040 <read_bits@plt>
movzbl -0x22(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
je     1240 <unzip+0x120>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x10,%edx
call   1040 <read_bits@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,%ecx
shl    $0x3,%rcx
mov    -0x18(%rbp),%rax
add    (%rax),%rcx
mov    %rcx,(%rax)
movzbl -0x22(%rbp),%eax
and    $0x8,%eax
cmp    $0x0,%eax
je     127a <unzip+0x15a>
jmp    1255 <unzip+0x135>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x8,%edx
call   1040 <read_bits@plt>
cmp    $0x0,%eax
je     1275 <unzip+0x155>
jmp    1255 <unzip+0x135>
jmp    127a <unzip+0x15a>
movzbl -0x22(%rbp),%eax
and    $0x10,%eax
cmp    $0x0,%eax
je     12b4 <unzip+0x194>
jmp    128f <unzip+0x16f>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x8,%edx
call   1040 <read_bits@plt>
cmp    $0x0,%eax
je     12af <unzip+0x18f>
jmp    128f <unzip+0x16f>
jmp    12b4 <unzip+0x194>
movzbl -0x22(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     12d6 <unzip+0x1b6>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x10,%edx
call   1040 <read_bits@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <inflate@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unzip>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    $0x8,%edx
call   1040 <read_bits@plt>
cmp    $0x1f,%eax
jne    1242 <unzip+0x122>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x8,%edx
call   1040 <read_bits@plt>
cmp    $0x8b,%eax
jne    1242 <unzip+0x122>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x8,%edx
call   1040 <read_bits@plt>
cmp    $0x8,%al
jne    1242 <unzip+0x122>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x8,%edx
call   1040 <read_bits@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x20,%edx
call   1040 <read_bits@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x8,%edx
call   1040 <read_bits@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x8,%edx
call   1040 <read_bits@plt>
test   $0x4,%bpl
je     11d7 <unzip+0xb7>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x10,%edx
call   1040 <read_bits@plt>
mov    %eax,%eax
shl    $0x3,%rax
add    %rax,(%r15)
test   $0x8,%bpl
je     11f4 <unzip+0xd4>
nopl   (%rax)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x8,%edx
call   1040 <read_bits@plt>
test   %eax,%eax
jne    11e0 <unzip+0xc0>
test   $0x10,%bpl
je     1214 <unzip+0xf4>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x8,%edx
call   1040 <read_bits@plt>
test   %eax,%eax
jne    1200 <unzip+0xe0>
test   $0x2,%bpl
je     122a <unzip+0x10a>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x10,%edx
call   1040 <read_bits@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <inflate@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @unzip(i8* %0, i64* %1, void (i8)* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64*
%7 = alloca void (i8)*
%8 = alloca i8
%9 = alloca i8
%10 = alloca i32
store i8* %0, i8** %5
store i64* %1, i64** %6
store void (i8)* %2, void (i8)** %7
%11 = load i8*, i8** %5
%12 = load i64*, i64** %6
%13 = call i32 @read_bits(i8* %11, i64* %12, i32 8)
%14 = icmp ne i32 %13, 31
br i1 %14, label %20, label %15
15: ; preds = %3
%16 = load i8*, i8** %5
%17 = load i64*, i64** %6
%18 = call i32 @read_bits(i8* %16, i64* %17, i32 8)
%19 = icmp ne i32 %18, 139
br i1 %19, label %20, label %21
20: ; preds = %15, %3
store i32 -1, i32* %4
br label %104
21: ; preds = %15
%22 = load i8*, i8** %5
%23 = load i64*, i64** %6
%24 = call i32 @read_bits(i8* %22, i64* %23, i32 8)
%25 = trunc i32 %24 to i8
store i8 %25, i8* %8
%26 = load i8, i8* %8
%27 = zext i8 %26 to i32
%28 = icmp ne i32 %27, 8
br i1 %28, label %29, label %30
29: ; preds = %21
store i32 -1, i32* %4
br label %104
30: ; preds = %21
%31 = load i8*, i8** %5
%32 = load i64*, i64** %6
%33 = call i32 @read_bits(i8* %31, i64* %32, i32 8)
%34 = trunc i32 %33 to i8
store i8 %34, i8* %9
%35 = load i8, i8* %9
%36 = zext i8 %35 to i32
%37 = and i32 %36, 224
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %30
br label %40
40: ; preds = %39, %30
%41 = load i8*, i8** %5
%42 = load i64*, i64** %6
%43 = call i32 @read_bits(i8* %41, i64* %42, i32 32)
%44 = load i8*, i8** %5
%45 = load i64*, i64** %6
%46 = call i32 @read_bits(i8* %44, i64* %45, i32 8)
%47 = load i8*, i8** %5
%48 = load i64*, i64** %6
%49 = call i32 @read_bits(i8* %47, i64* %48, i32 8)
%50 = load i8, i8* %9
%51 = zext i8 %50 to i32
%52 = and i32 %51, 4
%53 = icmp ne i32 %52, 0
br i1 %53, label %54, label %64
54: ; preds = %40
%55 = load i8*, i8** %5
%56 = load i64*, i64** %6
%57 = call i32 @read_bits(i8* %55, i64* %56, i32 16)
store i32 %57, i32* %10
%58 = load i32, i32* %10
%59 = zext i32 %58 to i64
%60 = mul nsw i64 %59, 8
%61 = load i64*, i64** %6
%62 = load i64, i64* %61
%63 = add nsw i64 %62, %60
store i64 %63, i64* %61
br label %64
64: ; preds = %54, %40
%65 = load i8, i8* %9
%66 = zext i8 %65 to i32
%67 = and i32 %66, 8
%68 = icmp ne i32 %67, 0
br i1 %68, label %69, label %77
69: ; preds = %64
br label %70
70: ; preds = %75, %69
%71 = load i8*, i8** %5
%72 = load i64*, i64** %6
%73 = call i32 @read_bits(i8* %71, i64* %72, i32 8)
%74 = icmp ne i32 %73, 0
br i1 %74, label %75, label %76
75: ; preds = %70
br label %70
76: ; preds = %70
br label %77
77: ; preds = %76, %64
%78 = load i8, i8* %9
%79 = zext i8 %78 to i32
%80 = and i32 %79, 16
%81 = icmp ne i32 %80, 0
br i1 %81, label %82, label %90
82: ; preds = %77
br label %83
83: ; preds = %88, %82
%84 = load i8*, i8** %5
%85 = load i64*, i64** %6
%86 = call i32 @read_bits(i8* %84, i64* %85, i32 8)
%87 = icmp ne i32 %86, 0
br i1 %87, label %88, label %89
88: ; preds = %83
br label %83
89: ; preds = %83
br label %90
90: ; preds = %89, %77
%91 = load i8, i8* %9
%92 = zext i8 %91 to i32
%93 = and i32 %92, 2
%94 = icmp ne i32 %93, 0
br i1 %94, label %95, label %99
95: ; preds = %90
%96 = load i8*, i8** %5
%97 = load i64*, i64** %6
%98 = call i32 @read_bits(i8* %96, i64* %97, i32 16)
br label %99
99: ; preds = %95, %90
%100 = load i8*, i8** %5
%101 = load i64*, i64** %6
%102 = load void (i8)*, void (i8)** %7
%103 = call i32 @inflate(i8* %100, i64* %101, void (i8)* %102)
store i32 %103, i32* %4
br label %104
104: ; preds = %99, %29, %20
%105 = load i32, i32* %4
ret i32 %105
}

LLVM IR (-O2):
define i32 @unzip(i8* %0, i64* %1, void (i8)* %2) {
%4 = tail call i32 @read_bits(i8* %0, i64* %1, i32 8)
%5 = icmp eq i32 %4, 31
br i1 %5, label %6, label %45
6: ; preds = %3
%7 = tail call i32 @read_bits(i8* %0, i64* %1, i32 8)
%8 = icmp eq i32 %7, 139
br i1 %8, label %9, label %45
9: ; preds = %6
%10 = tail call i32 @read_bits(i8* %0, i64* %1, i32 8)
%11 = and i32 %10, 255
%12 = icmp eq i32 %11, 8
br i1 %12, label %13, label %45
13: ; preds = %9
%14 = tail call i32 @read_bits(i8* %0, i64* %1, i32 8)
%15 = tail call i32 @read_bits(i8* %0, i64* %1, i32 32)
%16 = tail call i32 @read_bits(i8* %0, i64* %1, i32 8)
%17 = tail call i32 @read_bits(i8* %0, i64* %1, i32 8)
%18 = and i32 %14, 4
%19 = icmp eq i32 %18, 0
br i1 %19, label %26, label %20
20: ; preds = %13
%21 = tail call i32 @read_bits(i8* %0, i64* %1, i32 16)
%22 = zext i32 %21 to i64
%23 = shl nuw nsw i64 %22, 3
%24 = load i64, i64* %1
%25 = add nsw i64 %23, %24
store i64 %25, i64* %1
br label %26
26: ; preds = %20, %13
%27 = and i32 %14, 8
%28 = icmp eq i32 %27, 0
br i1 %28, label %32, label %29
29: ; preds = %26, %29
%30 = tail call i32 @read_bits(i8* %0, i64* %1, i32 8)
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %29
32: ; preds = %29, %26
%33 = and i32 %14, 16
%34 = icmp eq i32 %33, 0
br i1 %34, label %38, label %35
35: ; preds = %32, %35
%36 = tail call i32 @read_bits(i8* %0, i64* %1, i32 8)
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %35
38: ; preds = %35, %32
%39 = and i32 %14, 2
%40 = icmp eq i32 %39, 0
br i1 %40, label %43, label %41
41: ; preds = %38
%42 = tail call i32 @read_bits(i8* %0, i64* %1, i32 16)
br label %43
43: ; preds = %41, %38
%44 = tail call i32 @inflate(i8* %0, i64* %1, void (i8)* %2)
br label %45
45: ; preds = %9, %3, %6, %43
%46 = phi i32 [ %44, %43 ], [ -1, %6 ], [ -1, %3 ], [ -1, %9 ]
ret i32 %46
}