#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;
  char *msg;
  int avail_out;
  scalar_t__ 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_NO_FLUSH;
int Z_OK;
int deflate(TYPE_1__ *, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ png_write_bytes(int /*<<< orphan*/ *, scalar_t__, int);
int /*<<< orphan*/ stderr;
long compress_line(z_stream *zs, Bytef *line, int len, FILE *fi) {
  long size = 0;
  zs->next_in = line;
  zs->avail_in = len;
  while (1) {
    int ret = deflate(zs, Z_NO_FLUSH);
    if (ret != Z_OK) {
      fprintf(stderr, "error in deflate(): %s", zs->msg ? zs->msg : "unknown");
      return 0;
    }
    if (zs->avail_out != 16384) {
      int consumed = 16384 - zs->avail_out;
      size += consumed;
      png_write_bytes(fi, zs->next_out - consumed, consumed);
      zs->next_out = zs->next_out - consumed;
      zs->avail_out = 16384;
    }
    if (!zs->avail_in) {
      break;
    }
  }
  return size;
}


x86 assembly (clang, -O0):
<compress_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x20(%rax)
mov    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rdi
mov    0x2e61(%rip),%rax
mov    (%rax),%esi
call   1030 <deflate@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    0x2e6d(%rip),%rcx
cmp    (%rcx),%eax
je     11e7 <compress_line+0xb7>
mov    0x2e46(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
je     11b7 <compress_line+0x87>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x48(%rbp)
jmp    11c7 <compress_line+0x97>
lea    0xe59(%rip),%rax
mov    %rax,-0x48(%rbp)
jmp    11c7 <compress_line+0x97>
mov    -0x3c(%rbp),%edi
mov    -0x48(%rbp),%rdx
lea    0xe2b(%rip),%rsi
call   1040 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    126f <compress_line+0x13f>
mov    -0x10(%rbp),%rax
cmpl   $0x4000,0x10(%rax)
je     1250 <compress_line+0x120>
mov    -0x10(%rbp),%rcx
mov    $0x4000,%eax
sub    0x10(%rcx),%eax
mov    %eax,-0x38(%rbp)
movslq -0x38(%rbp),%rax
add    -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
movslq -0x38(%rbp),%rax
sub    %rax,%rsi
mov    -0x38(%rbp),%edx
call   1050 <png_write_bytes@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rcx
movslq -0x38(%rbp),%rax
sub    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x18(%rax)
mov    -0x10(%rbp),%rax
movl   $0x4000,0x10(%rax)
mov    -0x10(%rbp),%rax
cmpl   $0x0,(%rax)
jne    1262 <compress_line+0x132>
jmp    1267 <compress_line+0x137>
jmp    1164 <compress_line+0x34>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compress_line>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r15
mov    %rdi,%r12
mov    %rsi,0x20(%rdi)
mov    %edx,(%rdi)
xor    %r14d,%r14d
mov    0x2e7f(%rip),%r13
mov    0x2e98(%rip),%rbp
jmp    1167 <compress_line+0x37>
nopw   0x0(%rax,%rax,1)
cmpl   $0x0,(%r12)
je     11dd <compress_line+0xad>
mov    0x0(%r13),%esi
mov    %r12,%rdi
call   1030 <deflate@plt>
cmp    0x0(%rbp),%eax
jne    11b2 <compress_line+0x82>
movslq 0x10(%r12),%rax
cmp    $0x4000,%rax
je     1160 <compress_line+0x30>
mov    $0x4000,%ebx
sub    %rax,%rbx
add    %rbx,%r14
mov    0x18(%r12),%rsi
sub    %rbx,%rsi
mov    %r15,%rdi
mov    %ebx,%edx
call   1050 <png_write_bytes@plt>
sub    %rbx,0x18(%r12)
movl   $0x4000,0x10(%r12)
jmp    1160 <compress_line+0x30>
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r12),%rax
test   %rax,%rax
lea    0xe4d(%rip),%rdx
cmovne %rax,%rdx
lea    0xe2b(%rip),%rsi
call   1040 <fprintf@plt>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_4__ = type { i32, i8*, i32, i64, i32* }
@Z_NO_FLUSH = global i32 0
@Z_OK = global i32 0
@stderr = global i32 0
@.str = [23 x i8] c"error in deflate(): %s\00"
@.str.1 = [8 x i8] c"unknown\00"
define i64 @compress_line(%struct.TYPE_4__* %0, i32* %1, i32 %2, i32* %3) {
%5 = alloca i64
%6 = alloca %struct.TYPE_4__*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i64
%11 = alloca i32
%12 = alloca i32
store %struct.TYPE_4__* %0, %struct.TYPE_4__** %6
store i32* %1, i32** %7
store i32 %2, i32* %8
store i32* %3, i32** %9
store i64 0, i64* %10
%13 = load i32*, i32** %7
%14 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%15 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %14, i32 0, i32 4
store i32* %13, i32** %15
%16 = load i32, i32* %8
%17 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%18 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %17, i32 0, i32 0
store i32 %16, i32* %18
br label %19
19: ; preds = %4, %79
%20 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%21 = load i32, i32* @Z_NO_FLUSH
%22 = call i32 @deflate(%struct.TYPE_4__* %20, i32 %21)
store i32 %22, i32* %11
%23 = load i32, i32* %11
%24 = load i32, i32* @Z_OK
%25 = icmp ne i32 %23, %24
br i1 %25, label %26, label %40
26: ; preds = %19
%27 = load i32, i32* @stderr
%28 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%29 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %28, i32 0, i32 1
%30 = load i8*, i8** %29
%31 = icmp ne i8* %30, null
br i1 %31, label %32, label %36
32: ; preds = %26
%33 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%34 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %33, i32 0, i32 1
%35 = load i8*, i8** %34
br label %37
36: ; preds = %26
br label %37
37: ; preds = %36, %32
%38 = phi i8* [ %35, %32 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), %36 ]
%39 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %38)
store i64 0, i64* %5
br label %82
40: ; preds = %19
%41 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%42 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %41, i32 0, i32 2
%43 = load i32, i32* %42
%44 = icmp ne i32 %43, 16384
br i1 %44, label %45, label %73
45: ; preds = %40
%46 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%47 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %46, i32 0, i32 2
%48 = load i32, i32* %47
%49 = sub nsw i32 16384, %48
store i32 %49, i32* %12
%50 = load i32, i32* %12
%51 = sext i32 %50 to i64
%52 = load i64, i64* %10
%53 = add nsw i64 %52, %51
store i64 %53, i64* %10
%54 = load i32*, i32** %9
%55 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%56 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %55, i32 0, i32 3
%57 = load i64, i64* %56
%58 = load i32, i32* %12
%59 = sext i32 %58 to i64
%60 = sub nsw i64 %57, %59
%61 = load i32, i32* %12
%62 = call i32 @png_write_bytes(i32* %54, i64 %60, i32 %61)
%63 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%64 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %63, i32 0, i32 3
%65 = load i64, i64* %64
%66 = load i32, i32* %12
%67 = sext i32 %66 to i64
%68 = sub nsw i64 %65, %67
%69 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%70 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %69, i32 0, i32 3
store i64 %68, i64* %70
%71 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%72 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %71, i32 0, i32 2
store i32 16384, i32* %72
br label %73
73: ; preds = %45, %40
%74 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%75 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %74, i32 0, i32 0
%76 = load i32, i32* %75
%77 = icmp ne i32 %76, 0
br i1 %77, label %79, label %78
78: ; preds = %73
br label %80
79: ; preds = %73
br label %19
80: ; preds = %78
%81 = load i64, i64* %10
store i64 %81, i64* %5
br label %82
82: ; preds = %80, %37
%83 = load i64, i64* %5
ret i64 %83
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i32, i8*, i32, i64, i32* }
@Z_NO_FLUSH = global i32 0
@Z_OK = global i32 0
@stderr = global i32 0
@.str = [23 x i8] c"error in deflate(): %s\00"
@.str.1 = [8 x i8] c"unknown\00"
define i64 @compress_line(%struct.TYPE_4__* %0, i32* %1, i32 %2, i32* %3) {
%5 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %0, i64 0, i32 4
store i32* %1, i32** %5
%6 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %0, i64 0, i32 0
store i32 %2, i32* %6
%7 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %0, i64 0, i32 2
%8 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %0, i64 0, i32 3
br label %9
9: ; preds = %34, %4
%10 = phi i64 [ 0, %4 ], [ %35, %34 ]
%11 = load i32, i32* @Z_NO_FLUSH
%12 = tail call i32 @deflate(%struct.TYPE_4__* %0, i32 %11)
%13 = load i32, i32* @Z_OK
%14 = icmp eq i32 %12, %13
br i1 %14, label %22, label %15
15: ; preds = %9
%16 = load i32, i32* @stderr
%17 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %0, i64 0, i32 1
%18 = load i8*, i8** %17
%19 = icmp eq i8* %18, null
%20 = select i1 %19, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %18
%21 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %20)
br label %38
22: ; preds = %9
%23 = load i32, i32* %7
%24 = icmp eq i32 %23, 16384
br i1 %24, label %34, label %25
25: ; preds = %22
%26 = sub nsw i32 16384, %23
%27 = sext i32 %26 to i64
%28 = add nsw i64 %10, %27
%29 = load i64, i64* %8
%30 = sub nsw i64 %29, %27
%31 = tail call i32 @png_write_bytes(i32* %3, i64 %30, i32 %26)
%32 = load i64, i64* %8
%33 = sub nsw i64 %32, %27
store i64 %33, i64* %8
store i32 16384, i32* %7
br label %34
34: ; preds = %25, %22
%35 = phi i64 [ %28, %25 ], [ %10, %22 ]
%36 = load i32, i32* %6
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %9
38: ; preds = %34, %15
%39 = phi i64 [ 0, %15 ], [ %35, %34 ]
ret i64 %39
}