#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 */
struct TYPE_5__ {
  int avail_in;
  scalar_t__ avail_out;
  unsigned char *next_out;
  unsigned char *next_in;
  int /*<<< orphan*/ *opaque;
  int /*<<< orphan*/ *zfree;
  int /*<<< orphan*/ *zalloc;
};
typedef TYPE_1__ z_stream;
typedef int ssize_t;

/* Variables and functions */
scalar_t__ MAX_WBITS;
int /*<<< orphan*/ Z_BEST_COMPRESSION;
int /*<<< orphan*/ Z_DEFAULT_STRATEGY;
int /*<<< orphan*/ Z_DEFLATED;
int /*<<< orphan*/ Z_FINISH;
scalar_t__ Z_OK;
int /*<<< orphan*/ deflate(TYPE_1__ *, int /*<<< orphan*/);
int /*<<< orphan*/ deflateEnd(TYPE_1__ *);
scalar_t__ deflateInit2(TYPE_1__ *, int /*<<< orphan*/, int /*<<< orphan*/,
                        scalar_t__, int, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int read(int /*<<< orphan*/, unsigned char *, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ write(int, unsigned char *, int);
int main(int argc, char *argv[]) {
  z_stream defstream;
  defstream.zalloc = NULL;
  defstream.zfree = NULL;
  defstream.opaque = NULL;
  defstream.avail_in = 0;
  defstream.avail_out = 0;
  if (deflateInit2(&defstream, Z_BEST_COMPRESSION, Z_DEFLATED, MAX_WBITS + 16,
                   8, Z_DEFAULT_STRATEGY) != Z_OK) {
    fprintf(stderr, "%s: deflateInit2 failed\n", argv[0]);
    return 1;
  };
  while (1) {
    unsigned char buffer[4096];
    ssize_t sz = read(0, buffer, 4096);
    if (sz == 0) {
      defstream.avail_out = 0;
      while (defstream.avail_out == 0) {
        defstream.next_out = buffer;
        defstream.avail_out = 4096;
        deflate(&defstream, Z_FINISH);
        write(1, buffer, 4096 - defstream.avail_out);
      };
      deflateEnd(&defstream);
      return 0;
    };
    if (sz == -1) {
      fprintf(stderr, "%s: read error: %s\n", argv[0], strerror(errno));
      return 1;
    };
    defstream.next_in = buffer;
    defstream.avail_in = sz;
    defstream.avail_out = 0;
    unsigned char outbuf[4096];
    while (defstream.avail_out == 0 && defstream.avail_in != 0) {
      defstream.next_out = outbuf;
      defstream.avail_out = 4096;
      deflate(&defstream, 0);
      write(1, outbuf, 4096 - defstream.avail_out);
    };
  };
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2070,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x48(%rbp)
movq   $0x0,-0x40(%rbp)
mov    0x2e29(%rip),%rax
mov    (%rax),%esi
mov    0x2e00(%rip),%rax
mov    (%rax),%edx
mov    0x2e0f(%rip),%rax
mov    (%rax),%rcx
add    $0x10,%rcx
mov    0x2dc9(%rip),%rax
mov    (%rax),%r9d
lea    -0x48(%rbp),%rdi
mov    $0x8,%r8d
call   1090 <deflateInit2@plt>
mov    0x2e00(%rip),%rcx
cmp    (%rcx),%rax
je     1223 <main+0xb3>
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdf0(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13b1 <main+0x241>
jmp    1228 <main+0xb8>
lea    -0x1050(%rbp),%rsi
xor    %edi,%edi
mov    $0x1000,%edx
call   1050 <read@plt>
mov    %eax,-0x1054(%rbp)
cmpl   $0x0,-0x1054(%rbp)
jne    12bc <main+0x14c>
movq   $0x0,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    12a7 <main+0x137>
lea    -0x1050(%rbp),%rax
mov    %rax,-0x38(%rbp)
movq   $0x1000,-0x40(%rbp)
mov    0x2d35(%rip),%rax
mov    (%rax),%esi
lea    -0x48(%rbp),%rdi
call   1040 <deflate@plt>
lea    -0x1050(%rbp),%rsi
mov    $0x1000,%eax
sub    -0x40(%rbp),%rax
mov    %eax,%edx
mov    $0x1,%edi
call   1030 <write@plt>
jmp    1256 <main+0xe6>
lea    -0x48(%rbp),%rdi
call   1070 <deflateEnd@plt>
movl   $0x0,-0x4(%rbp)
jmp    13b1 <main+0x241>
cmpl   $0xffffffff,-0x1054(%rbp)
jne    131e <main+0x1ae>
mov    0x2cf8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x206c(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x2068(%rbp)
mov    0x2ccb(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x206c(%rbp),%edi
mov    -0x2068(%rbp),%rdx
mov    %rax,%rcx
lea    0xd0e(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13b1 <main+0x241>
lea    -0x1050(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x1054(%rbp),%eax
mov    %eax,-0x48(%rbp)
movq   $0x0,-0x40(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x40(%rbp)
mov    %al,-0x206d(%rbp)
jne    135a <main+0x1ea>
cmpl   $0x0,-0x48(%rbp)
setne  %al
mov    %al,-0x206d(%rbp)
mov    -0x206d(%rbp),%al
test   $0x1,%al
jne    136d <main+0x1fd>
jmp    13ac <main+0x23c>
lea    -0x2060(%rbp),%rax
mov    %rax,-0x38(%rbp)
movq   $0x1000,-0x40(%rbp)
lea    -0x48(%rbp),%rdi
xor    %esi,%esi
call   1040 <deflate@plt>
lea    -0x2060(%rbp),%rsi
mov    $0x1000,%eax
sub    -0x40(%rbp),%rax
mov    %eax,%edx
mov    $0x1,%edi
call   1030 <write@plt>
jmp    133a <main+0x1ca>
jmp    1228 <main+0xb8>
mov    -0x4(%rbp),%eax
add    $0x2070,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x2048,%rsp
mov    %rsi,%r14
movl   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x28(%rsp)
movq   $0x0,0x38(%rsp)
mov    0x2e36(%rip),%rax
mov    (%rax),%esi
mov    0x2e0d(%rip),%rax
mov    (%rax),%edx
mov    0x2e1c(%rip),%rax
mov    (%rax),%rcx
add    $0x10,%rcx
mov    0x2dd6(%rip),%rax
mov    (%rax),%r9d
lea    0x8(%rsp),%rdi
mov    $0x8,%r8d
call   1090 <deflateInit2@plt>
mov    0x2e0c(%rip),%rcx
cmp    (%rcx),%rax
jne    126f <main+0xff>
lea    0x1040(%rsp),%r15
lea    0x40(%rsp),%rbx
lea    0x8(%rsp),%r12
nop
xor    %edi,%edi
mov    %r15,%rsi
mov    $0x1000,%edx
call   1050 <read@plt>
cmp    $0xffffffff,%eax
je     128b <main+0x11b>
test   %eax,%eax
je     12c2 <main+0x152>
mov    %r15,0x20(%rsp)
mov    %eax,0x8(%rsp)
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,0x18(%rsp)
movq   $0x1000,0x10(%rsp)
mov    %r12,%rdi
xor    %esi,%esi
call   1040 <deflate@plt>
mov    $0x1000,%edx
sub    0x10(%rsp),%edx
mov    $0x1,%edi
mov    %rbx,%rsi
call   1030 <write@plt>
cmpq   $0x0,0x10(%rsp)
jne    1200 <main+0x90>
cmpl   $0x0,0x8(%rsp)
jne    1230 <main+0xc0>
jmp    1200 <main+0x90>
mov    0x2d52(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xd7e(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    12bb <main+0x14b>
mov    0x2d36(%rip),%rax
mov    (%rax),%ebx
mov    (%r14),%r14
mov    0x2d1a(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xd6d(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%eax
jmp    1313 <main+0x1a3>
mov    0x2ce7(%rip),%r14
lea    0x8(%rsp),%rbx
xchg   %ax,%ax
mov    %r15,0x18(%rsp)
movq   $0x1000,0x10(%rsp)
mov    (%r14),%esi
mov    %rbx,%rdi
call   1040 <deflate@plt>
mov    $0x1000,%edx
sub    0x10(%rsp),%edx
mov    $0x1,%edi
mov    %r15,%rsi
call   1030 <write@plt>
cmpq   $0x0,0x10(%rsp)
je     12d0 <main+0x160>
lea    0x8(%rsp),%rdi
call   1070 <deflateEnd@plt>
xor    %eax,%eax
add    $0x2048,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.TYPE_5__ = type { i32, i64, i8*, i8*, i32*, i32*, i32* }
@Z_BEST_COMPRESSION = global i32 0
@Z_DEFLATED = global i32 0
@MAX_WBITS = global i64 0
@Z_DEFAULT_STRATEGY = global i32 0
@Z_OK = global i64 0
@stderr = global i32 0
@.str = [25 x i8] c"%s: deflateInit2 failed\0A\00"
@Z_FINISH = global i32 0
@.str.1 = [20 x i8] c"%s: read error: %s\0A\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.TYPE_5__
%7 = alloca [4096 x i8]
%8 = alloca i32
%9 = alloca [4096 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %6, i32 0, i32 6
store i32* null, i32** %10
%11 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %6, i32 0, i32 5
store i32* null, i32** %11
%12 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %6, i32 0, i32 4
store i32* null, i32** %12
%13 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %6, i32 0, i32 0
store i32 0, i32* %13
%14 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %6, i32 0, i32 1
store i64 0, i64* %14
%15 = load i32, i32* @Z_BEST_COMPRESSION
%16 = load i32, i32* @Z_DEFLATED
%17 = load i64, i64* @MAX_WBITS
%18 = add nsw i64 %17, 16
%19 = load i32, i32* @Z_DEFAULT_STRATEGY
%20 = call i64 @deflateInit2(%struct.TYPE_5__* %6, i32 %15, i32 %16, i64 %18, i32 8, i32 %19)
%21 = load i64, i64* @Z_OK
%22 = icmp ne i64 %20, %21
br i1 %22, label %23, label %29
23: ; preds = %2
%24 = load i32, i32* @stderr
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 0
%27 = load i8*, i8** %26
%28 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %27)
store i32 1, i32* %3
br label %94
29: ; preds = %2
br label %30
30: ; preds = %29, %93
%31 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%32 = call i32 @read(i32 0, i8* %31, i32 4096)
store i32 %32, i32* %8
%33 = load i32, i32* %8
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %55
35: ; preds = %30
%36 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %6, i32 0, i32 1
store i64 0, i64* %36
br label %37
37: ; preds = %41, %35
%38 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %6, i32 0, i32 1
%39 = load i64, i64* %38
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %53
41: ; preds = %37
%42 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%43 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %6, i32 0, i32 2
store i8* %42, i8** %43
%44 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %6, i32 0, i32 1
store i64 4096, i64* %44
%45 = load i32, i32* @Z_FINISH
%46 = call i32 @deflate(%struct.TYPE_5__* %6, i32 %45)
%47 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%48 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %6, i32 0, i32 1
%49 = load i64, i64* %48
%50 = sub nsw i64 4096, %49
%51 = trunc i64 %50 to i32
%52 = call i32 @write(i32 1, i8* %47, i32 %51)
br label %37
53: ; preds = %37
%54 = call i32 @deflateEnd(%struct.TYPE_5__* %6)
store i32 0, i32* %3
br label %94
55: ; preds = %30
%56 = load i32, i32* %8
%57 = icmp eq i32 %56, -1
br i1 %57, label %58, label %66
58: ; preds = %55
%59 = load i32, i32* @stderr
%60 = load i8**, i8*** %5
%61 = getelementptr inbounds i8*, i8** %60, i64 0
%62 = load i8*, i8** %61
%63 = load i32, i32* @errno
%64 = call i8* @strerror(i32 %63)
%65 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %62, i8* %64)
store i32 1, i32* %3
br label %94
66: ; preds = %55
%67 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%68 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %6, i32 0, i32 3
store i8* %67, i8** %68
%69 = load i32, i32* %8
%70 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %6, i32 0, i32 0
store i32 %69, i32* %70
%71 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %6, i32 0, i32 1
store i64 0, i64* %71
br label %72
72: ; preds = %82, %66
%73 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %6, i32 0, i32 1
%74 = load i64, i64* %73
%75 = icmp eq i64 %74, 0
br i1 %75, label %76, label %80
76: ; preds = %72
%77 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %6, i32 0, i32 0
%78 = load i32, i32* %77
%79 = icmp ne i32 %78, 0
br label %80
80: ; preds = %76, %72
%81 = phi i1 [ false, %72 ], [ %79, %76 ]
br i1 %81, label %82, label %93
82: ; preds = %80
%83 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%84 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %6, i32 0, i32 2
store i8* %83, i8** %84
%85 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %6, i32 0, i32 1
store i64 4096, i64* %85
%86 = call i32 @deflate(%struct.TYPE_5__* %6, i32 0)
%87 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%88 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %6, i32 0, i32 1
%89 = load i64, i64* %88
%90 = sub nsw i64 4096, %89
%91 = trunc i64 %90 to i32
%92 = call i32 @write(i32 1, i8* %87, i32 %91)
br label %72
93: ; preds = %80
br label %30
94: ; preds = %58, %53, %23
%95 = load i32, i32* %3
ret i32 %95
}

LLVM IR (-O2):
%struct.TYPE_5__ = type { i32, i64, i8*, i8*, i32*, i32*, i32* }
@Z_BEST_COMPRESSION = global i32 0
@Z_DEFLATED = global i32 0
@MAX_WBITS = global i64 0
@Z_DEFAULT_STRATEGY = global i32 0
@Z_OK = global i64 0
@stderr = global i32 0
@.str = [25 x i8] c"%s: deflateInit2 failed\0A\00"
@Z_FINISH = global i32 0
@.str.1 = [20 x i8] c"%s: read error: %s\0A\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.TYPE_5__
%4 = alloca [4096 x i8]
%5 = alloca [4096 x i8]
%6 = bitcast %struct.TYPE_5__* %3 to i8*
%7 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %3, i64 0, i32 4
%8 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %3, i64 0, i32 0
store i32 0, i32* %8
%9 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %3, i64 0, i32 1
store i64 0, i64* %9
%10 = bitcast i32** %7 to i8*
%11 = load i32, i32* @Z_BEST_COMPRESSION
%12 = load i32, i32* @Z_DEFLATED
%13 = load i64, i64* @MAX_WBITS
%14 = add nsw i64 %13, 16
%15 = load i32, i32* @Z_DEFAULT_STRATEGY
%16 = call i64 @deflateInit2(%struct.TYPE_5__* %3, i32 %11, i32 %12, i64 %14, i32 8, i32 %15)
%17 = load i64, i64* @Z_OK
%18 = icmp eq i64 %16, %17
br i1 %18, label %19, label %24
19: ; preds = %2
%20 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%21 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %3, i64 0, i32 3
%22 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%23 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %3, i64 0, i32 2
br label %28
24: ; preds = %2
%25 = load i32, i32* @stderr
%26 = load i8*, i8** %1
%27 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %26)
br label %62
28: ; preds = %19, %61
%29 = call i32 @read(i32 0, i8* %20, i32 4096)
switch i32 %29, label %47 [
i32 0, label %30
i32 -1, label %41
]
30: ; preds = %28, %30
store i8* %20, i8** %23
store i64 4096, i64* %9
%31 = load i32, i32* @Z_FINISH
%32 = call i32 @deflate(%struct.TYPE_5__* %3, i32 %31)
%33 = load i64, i64* %9
%34 = trunc i64 %33 to i32
%35 = sub i32 4096, %34
%36 = call i32 @write(i32 1, i8* %20, i32 %35)
%37 = load i64, i64* %9
%38 = icmp eq i64 %37, 0
br i1 %38, label %30, label %39
39: ; preds = %30
%40 = call i32 @deflateEnd(%struct.TYPE_5__* %3)
br label %59
41: ; preds = %28
%42 = load i32, i32* @stderr
%43 = load i8*, i8** %1
%44 = load i32, i32* @errno
%45 = call i8* @strerror(i32 %44)
%46 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %43, i8* %45)
br label %59
47: ; preds = %28
store i8* %20, i8** %21
store i32 %29, i32* %8
br label %48
48: ; preds = %47, %48
store i8* %22, i8** %23
store i64 4096, i64* %9
%49 = call i32 @deflate(%struct.TYPE_5__* %3, i32 0)
%50 = load i64, i64* %9
%51 = trunc i64 %50 to i32
%52 = sub i32 4096, %51
%53 = call i32 @write(i32 1, i8* %22, i32 %52)
%54 = load i64, i64* %9
%55 = icmp eq i64 %54, 0
%56 = load i32, i32* %8
%57 = icmp ne i32 %56, 0
%58 = select i1 %55, i1 %57, i1 false
br i1 %58, label %48, label %61
59: ; preds = %41, %39
%60 = phi i32 [ 0, %39 ], [ 1, %41 ]
br label %62
61: ; preds = %48
br label %28
62: ; preds = %59, %24
%63 = phi i32 [ 1, %24 ], [ %60, %59 ]
ret i32 %63
}