#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_4__ TYPE_1__;

/* Type definitions */
struct TYPE_4__ {
  int avail_in;
  int avail_out;
  int /*<<< orphan*/ *next_out;
  int /*<<< orphan*/ *next_in;
  void *opaque;
  void *zfree;
  void *zalloc;
};
typedef TYPE_1__ z_stream;
typedef int /*<<< orphan*/ outbuf;
typedef int /*<<< orphan*/ inbuf;
typedef int /*<<< orphan*/ Bytef;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ Z_NO_FLUSH;
void *Z_NULL;
int Z_OK;
int /*<<< orphan*/ abort();
int inflate(TYPE_1__ *, int /*<<< orphan*/);
int inflateInit2(TYPE_1__ *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int);
int read(int, char *, int);
int main(void) {
  int fd = open("/tmp/test2.in.gz", O_RDONLY);
  if (fd < 0) {
    abort();
  }
  char inbuf[4096];
  int inlen = read(fd, inbuf, sizeof(inbuf));
  if (inlen < 0) {
    abort();
  }
  printf("inlen=%d\n", inlen);
  char outbuf[104096];
  z_stream z;
  z.zalloc = Z_NULL;
  z.zfree = Z_NULL;
  z.opaque = Z_NULL;
  z.next_in = (Bytef *)inbuf;
  z.avail_in = inlen;
  z.next_out = (Bytef *)outbuf;
  z.avail_out = sizeof(outbuf);
  int ret = inflateInit2(&z, 32 + 15);
  if (ret != Z_OK) {
    abort();
  }
  ret = inflate(&z, Z_NO_FLUSH);
  printf("ret=%d\n", ret);
  printf("avail_in=%d\n", z.avail_in);
  printf("avail_out=%d\n", z.avail_out);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1a700,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e67(%rip),%rax
mov    (%rax),%esi
lea    0xe7e(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    119b <main+0x3b>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x8(%rbp),%edi
lea    -0x1010(%rbp),%rsi
mov    $0x1000,%edx
call   1070 <read@plt>
mov    %eax,-0x1014(%rbp)
cmpl   $0x0,-0x1014(%rbp)
jge    11c9 <main+0x69>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x1014(%rbp),%esi
lea    0xe3b(%rip),%rdi
call   1060 <printf@plt>
mov    0x2de6(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x1a6c8(%rbp)
mov    0x2dd5(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x1a6d0(%rbp)
mov    0x2dc4(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x1a6d8(%rbp)
lea    -0x1010(%rbp),%rax
mov    %rax,-0x1a6e0(%rbp)
mov    -0x1014(%rbp),%eax
mov    %eax,-0x1a6f0(%rbp)
lea    -0x1a6c0(%rbp),%rax
mov    %rax,-0x1a6e8(%rbp)
movl   $0x196a0,-0x1a6ec(%rbp)
lea    -0x1a6f0(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <inflateInit2@plt>
mov    %eax,-0x1a6f4(%rbp)
mov    -0x1a6f4(%rbp),%eax
mov    0x2d8c(%rip),%rcx
cmp    (%rcx),%eax
je     1273 <main+0x113>
mov    $0x0,%al
call   1030 <abort@plt>
mov    0x2d56(%rip),%rax
mov    (%rax),%esi
lea    -0x1a6f0(%rbp),%rdi
call   1040 <inflate@plt>
mov    %eax,-0x1a6f4(%rbp)
mov    -0x1a6f4(%rbp),%esi
lea    0xd80(%rip),%rdi
call   1060 <printf@plt>
mov    -0x1a6f0(%rbp),%esi
lea    0xd76(%rip),%rdi
call   1060 <printf@plt>
mov    -0x1a6ec(%rbp),%esi
lea    0xd71(%rip),%rdi
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x1a700,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x1a6d8,%rsp
mov    0x2e70(%rip),%rax
mov    (%rax),%esi
lea    0xe87(%rip),%rdi
call   1080 <open@plt>
test   %eax,%eax
js     124a <main+0xea>
lea    0x30(%rsp),%rbx
mov    %eax,%edi
mov    %rbx,%rsi
mov    $0x1000,%edx
call   1070 <read@plt>
test   %eax,%eax
js     124a <main+0xea>
mov    %eax,%ebp
lea    0xe66(%rip),%rdi
mov    %eax,%esi
call   1060 <printf@plt>
mov    0x2e0f(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x28(%rsp)
mov    %rax,0x20(%rsp)
mov    %rax,0x18(%rsp)
mov    %rbx,0x10(%rsp)
mov    %ebp,(%rsp)
lea    0x1030(%rsp),%rax
mov    %rax,0x8(%rsp)
movl   $0x196a0,0x4(%rsp)
mov    %rsp,%rdi
mov    $0x2f,%esi
call   1050 <inflateInit2@plt>
mov    0x2df4(%rip),%rcx
cmp    (%rcx),%eax
jne    124a <main+0xea>
mov    0x2dc9(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdi
call   1040 <inflate@plt>
lea    0xe03(%rip),%rdi
mov    %eax,%esi
call   1060 <printf@plt>
mov    (%rsp),%esi
lea    0xdfa(%rip),%rdi
call   1060 <printf@plt>
mov    0x4(%rsp),%esi
lea    0xdf7(%rip),%rdi
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x1a6d8,%rsp
pop    %rbx
pop    %rbp
ret
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
%struct.TYPE_4__ = type { i32, i32, i32*, i32*, i8*, i8*, i8* }
@.str = [17 x i8] c"/tmp/test2.in.gz\00"
@O_RDONLY = global i32 0
@.str.1 = [10 x i8] c"inlen=%d\0A\00"
@Z_NULL = global i8* null
@Z_OK = global i32 0
@Z_NO_FLUSH = global i32 0
@.str.2 = [8 x i8] c"ret=%d\0A\00"
@.str.3 = [13 x i8] c"avail_in=%d\0A\00"
@.str.4 = [14 x i8] c"avail_out=%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [4096 x i8]
%4 = alloca i32
%5 = alloca [104096 x i8]
%6 = alloca %struct.TYPE_4__
%7 = alloca i32
store i32 0, i32* %1
%8 = load i32, i32* @O_RDONLY
%9 = call i32 @open(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 %9, i32* %2
%10 = load i32, i32* %2
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = call i32 (...) @abort()
unreachable
14: ; preds = %0
%15 = load i32, i32* %2
%16 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%17 = call i32 @read(i32 %15, i8* %16, i32 4096)
store i32 %17, i32* %4
%18 = load i32, i32* %4
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %14
%21 = call i32 (...) @abort()
unreachable
22: ; preds = %14
%23 = load i32, i32* %4
%24 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %23)
%25 = load i8*, i8** @Z_NULL
%26 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %6, i32 0, i32 6
store i8* %25, i8** %26
%27 = load i8*, i8** @Z_NULL
%28 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %6, i32 0, i32 5
store i8* %27, i8** %28
%29 = load i8*, i8** @Z_NULL
%30 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %6, i32 0, i32 4
store i8* %29, i8** %30
%31 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%32 = bitcast i8* %31 to i32*
%33 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %6, i32 0, i32 3
store i32* %32, i32** %33
%34 = load i32, i32* %4
%35 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %6, i32 0, i32 0
store i32 %34, i32* %35
%36 = getelementptr inbounds [104096 x i8], [104096 x i8]* %5, i64 0, i64 0
%37 = bitcast i8* %36 to i32*
%38 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %6, i32 0, i32 2
store i32* %37, i32** %38
%39 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %6, i32 0, i32 1
store i32 104096, i32* %39
%40 = call i32 @inflateInit2(%struct.TYPE_4__* %6, i32 47)
store i32 %40, i32* %7
%41 = load i32, i32* %7
%42 = load i32, i32* @Z_OK
%43 = icmp ne i32 %41, %42
br i1 %43, label %44, label %46
44: ; preds = %22
%45 = call i32 (...) @abort()
unreachable
46: ; preds = %22
%47 = load i32, i32* @Z_NO_FLUSH
%48 = call i32 @inflate(%struct.TYPE_4__* %6, i32 %47)
store i32 %48, i32* %7
%49 = load i32, i32* %7
%50 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %49)
%51 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %6, i32 0, i32 0
%52 = load i32, i32* %51
%53 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %52)
%54 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %6, i32 0, i32 1
%55 = load i32, i32* %54
%56 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i32 %55)
ret i32 0
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i32, i32, i32*, i32*, i8*, i8*, i8* }
@.str = [17 x i8] c"/tmp/test2.in.gz\00"
@O_RDONLY = global i32 0
@.str.1 = [10 x i8] c"inlen=%d\0A\00"
@Z_NULL = global i8* null
@Z_OK = global i32 0
@Z_NO_FLUSH = global i32 0
@.str.2 = [8 x i8] c"ret=%d\0A\00"
@.str.3 = [13 x i8] c"avail_in=%d\0A\00"
@.str.4 = [14 x i8] c"avail_out=%d\0A\00"
define i32 @main() {
%1 = alloca [4096 x i8]
%2 = alloca [104096 x i8]
%3 = alloca %struct.TYPE_4__
%4 = load i32, i32* @O_RDONLY
%5 = tail call i32 @open(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = tail call i32 (...) @abort()
unreachable
9: ; preds = %0
%10 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 0
%11 = call i32 @read(i32 %5, i8* %10, i32 4096)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = tail call i32 (...) @abort()
unreachable
15: ; preds = %9
%16 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%17 = getelementptr inbounds [104096 x i8], [104096 x i8]* %2, i64 0, i64 0
%18 = bitcast %struct.TYPE_4__* %3 to i8*
%19 = load i8*, i8** @Z_NULL
%20 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %3, i64 0, i32 6
store i8* %19, i8** %20
%21 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %3, i64 0, i32 5
store i8* %19, i8** %21
%22 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %3, i64 0, i32 4
store i8* %19, i8** %22
%23 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %3, i64 0, i32 3
%24 = bitcast i32** %23 to [4096 x i8]**
store [4096 x i8]* %1, [4096 x i8]** %24
%25 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %3, i64 0, i32 0
store i32 %11, i32* %25
%26 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %3, i64 0, i32 2
%27 = bitcast i32** %26 to [104096 x i8]**
store [104096 x i8]* %2, [104096 x i8]** %27
%28 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %3, i64 0, i32 1
store i32 104096, i32* %28
%29 = call i32 @inflateInit2(%struct.TYPE_4__* %3, i32 47)
%30 = load i32, i32* @Z_OK
%31 = icmp eq i32 %29, %30
br i1 %31, label %34, label %32
32: ; preds = %15
%33 = call i32 (...) @abort()
unreachable
34: ; preds = %15
%35 = load i32, i32* @Z_NO_FLUSH
%36 = call i32 @inflate(%struct.TYPE_4__* %3, i32 %35)
%37 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %36)
%38 = load i32, i32* %25
%39 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %38)
%40 = load i32, i32* %28
%41 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i32 %40)
ret i32 0
}