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

/* Type definitions */
struct TYPE_6__ {
  unsigned char *next_out;
  scalar_t__ total_in;
  scalar_t__ total_out;
  int avail_in;
  int avail_out;
  int /*<<< orphan*/ *next_in;
  scalar_t__ opaque;
  scalar_t__ zfree;
  scalar_t__ zalloc;
};
typedef TYPE_1__ z_stream;
typedef scalar_t__ voidpf;
typedef scalar_t__ uLong;
typedef scalar_t__ free_func;
typedef scalar_t__ alloc_func;
typedef int /*<<< orphan*/ Bytef;

/* Variables and functions */
int /*<<< orphan*/ Z_DEFLATED;
int /*<<< orphan*/ Z_FINISH;
int /*<<< orphan*/ Z_FIXED;
int /*<<< orphan*/ Z_NO_FLUSH;
int Z_OK;
int Z_STREAM_END;
int deflate(TYPE_1__ *, int /*<<< orphan*/);
int deflateEnd(TYPE_1__ *);
int deflateInit2(TYPE_1__ *, int, int /*<<< orphan*/, int, int,
                 int /*<<< orphan*/);
int deflateSetDictionary(TYPE_1__ *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
scalar_t__ strlen(char *);
int test_deflate(char *str, unsigned char *compr, uLong comprLen) {
  z_stream c_stream;
  int err;
  uLong len = (uLong)strlen(str) + 1;
  c_stream.zalloc = (alloc_func)0;
  c_stream.zfree = (free_func)0;
  c_stream.opaque = (voidpf)0;
  err = deflateInit2(&c_stream, 9, Z_DEFLATED, -15, 8, Z_FIXED);
  if (err != Z_OK) {
    fprintf(stderr, "deflateInit\n");
  }
  err = deflateSetDictionary(&c_stream, (Bytef *)"", 0);
  if (err != Z_OK) {
    fprintf(stderr, "deflateSetDictionary\n");
  }
  c_stream.next_in = (Bytef *)str;
  c_stream.next_out = compr;
  while (c_stream.total_in != len && c_stream.total_out < comprLen) {
    c_stream.avail_in = c_stream.avail_out = 1;
    err = deflate(&c_stream, Z_NO_FLUSH);
    if (err != Z_OK) {
      fprintf(stderr, "deflate\n");
    }
  }
  for (;;) {
    c_stream.avail_out = 1;
    err = deflate(&c_stream, Z_FINISH);
    if (err == Z_STREAM_END)
      break;
    if (err != Z_OK) {
      fprintf(stderr, "deflate\n");
    }
  }
  err = deflateEnd(&c_stream);
  if (err != Z_OK) {
    fprintf(stderr, "deflateEnd\n");
  }
  return c_stream.total_out;
}


x86 assembly (clang, -O0):
<test_deflate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x1,%rax
mov    %rax,-0x68(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    0x2e1c(%rip),%rax
mov    (%rax),%edx
mov    0x2e2b(%rip),%rax
mov    (%rax),%r9d
lea    -0x58(%rbp),%rdi
mov    $0x9,%esi
mov    $0xfffffff1,%ecx
mov    $0x8,%r8d
call   1080 <deflateInit2@plt>
mov    %eax,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
mov    0x2e1a(%rip),%rcx
cmp    (%rcx),%eax
je     11f3 <test_deflate+0x93>
mov    0x2de3(%rip),%rax
mov    (%rax),%edi
lea    0xe12(%rip),%rsi
call   1050 <fprintf@plt>
lea    -0x58(%rbp),%rdi
lea    0xe39(%rip),%rsi
xor    %edx,%edx
call   1070 <deflateSetDictionary@plt>
mov    %eax,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
mov    0x2dde(%rip),%rcx
cmp    (%rcx),%eax
je     122f <test_deflate+0xcf>
mov    0x2da7(%rip),%rax
mov    (%rax),%edi
lea    0xde3(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x50(%rbp),%rcx
xor    %eax,%eax
cmp    -0x68(%rbp),%rcx
mov    %al,-0x69(%rbp)
je     1260 <test_deflate+0x100>
mov    -0x48(%rbp),%rax
cmp    -0x18(%rbp),%rax
setl   %al
mov    %al,-0x69(%rbp)
mov    -0x69(%rbp),%al
test   $0x1,%al
jne    1270 <test_deflate+0x110>
jmp    12bf <test_deflate+0x15f>
movl   $0x1,-0x3c(%rbp)
movl   $0x1,-0x40(%rbp)
mov    0x2d33(%rip),%rax
mov    (%rax),%esi
lea    -0x58(%rbp),%rdi
call   1040 <deflate@plt>
mov    %eax,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
mov    0x2d53(%rip),%rcx
cmp    (%rcx),%eax
je     12ba <test_deflate+0x15a>
mov    0x2d1c(%rip),%rax
mov    (%rax),%edi
lea    0xd6e(%rip),%rsi
call   1050 <fprintf@plt>
jmp    123f <test_deflate+0xdf>
jmp    12c4 <test_deflate+0x164>
movl   $0x1,-0x3c(%rbp)
mov    0x2cde(%rip),%rax
mov    (%rax),%esi
lea    -0x58(%rbp),%rdi
call   1040 <deflate@plt>
mov    %eax,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
mov    0x2cf6(%rip),%rcx
cmp    (%rcx),%eax
jne    12f7 <test_deflate+0x197>
jmp    1323 <test_deflate+0x1c3>
mov    -0x5c(%rbp),%eax
mov    0x2cef(%rip),%rcx
cmp    (%rcx),%eax
je     131e <test_deflate+0x1be>
mov    0x2cb8(%rip),%rax
mov    (%rax),%edi
lea    0xd0a(%rip),%rsi
call   1050 <fprintf@plt>
jmp    12c4 <test_deflate+0x164>
lea    -0x58(%rbp),%rdi
call   1060 <deflateEnd@plt>
mov    %eax,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
mov    0x2cb7(%rip),%rcx
cmp    (%rcx),%eax
je     1356 <test_deflate+0x1f6>
mov    0x2c80(%rip),%rax
mov    (%rax),%edi
lea    0xcdb(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x48(%rbp),%rax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_deflate>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
call   1030 <strlen@plt>
mov    %rax,%rbx
xorps  %xmm0,%xmm0
movups %xmm0,0x30(%rsp)
movq   $0x0,0x40(%rsp)
mov    0x2e29(%rip),%rax
mov    (%rax),%edx
mov    0x2e38(%rip),%rax
mov    (%rax),%r9d
lea    0x8(%rsp),%rdi
mov    $0x9,%esi
mov    $0xfffffff1,%ecx
mov    $0x8,%r8d
call   1080 <deflateInit2@plt>
mov    0x2e2c(%rip),%r13
cmp    0x0(%r13),%eax
je     11df <test_deflate+0x7f>
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
lea    0xe26(%rip),%rsi
call   1050 <fprintf@plt>
add    $0x1,%rbx
lea    0xe4d(%rip),%rsi
lea    0x8(%rsp),%rdi
xor    %edx,%edx
call   1070 <deflateSetDictionary@plt>
cmp    0x0(%r13),%eax
je     1211 <test_deflate+0xb1>
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
lea    0xe01(%rip),%rsi
call   1050 <fprintf@plt>
mov    %r12,0x28(%rsp)
mov    %r15,0x8(%rsp)
cmp    %rbx,0x10(%rsp)
je     127a <test_deflate+0x11a>
cmp    %r14,0x18(%rsp)
jge    127a <test_deflate+0x11a>
movabs $0x100000001,%rbp
mov    0x2d7e(%rip),%r12
lea    0x8(%rsp),%r15
nop
mov    %rbp,0x20(%rsp)
mov    (%r12),%esi
mov    %r15,%rdi
call   1040 <deflate@plt>
cmp    0x0(%r13),%eax
je     126c <test_deflate+0x10c>
mov    0x2d6a(%rip),%rax
mov    (%rax),%edi
lea    0xdbc(%rip),%rsi
call   1050 <fprintf@plt>
cmp    %rbx,0x10(%rsp)
je     127a <test_deflate+0x11a>
cmp    %r14,0x18(%rsp)
jl     1240 <test_deflate+0xe0>
movl   $0x1,0x24(%rsp)
mov    0x2d27(%rip),%r15
mov    (%r15),%esi
lea    0x8(%rsp),%rdi
call   1040 <deflate@plt>
mov    0x2d43(%rip),%r12
cmp    (%r12),%eax
jne    12db <test_deflate+0x17b>
lea    0x8(%rsp),%rdi
call   1060 <deflateEnd@plt>
cmp    0x0(%r13),%eax
je     12c8 <test_deflate+0x168>
mov    0x2d0e(%rip),%rax
mov    (%rax),%edi
lea    0xd69(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x18(%rsp),%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x8(%rsp),%rbx
mov    0x2ce1(%rip),%rbp
lea    0xd35(%rip),%r14
jmp    1309 <test_deflate+0x1a9>
movl   $0x1,0x24(%rsp)
mov    (%r15),%esi
mov    %rbx,%rdi
call   1040 <deflate@plt>
cmp    (%r12),%eax
je     12a3 <test_deflate+0x143>
cmp    0x0(%r13),%eax
je     12f0 <test_deflate+0x190>
mov    0x0(%rbp),%edi
mov    %r14,%rsi
call   1050 <fprintf@plt>
jmp    12f0 <test_deflate+0x190>

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

LLVM IR (-O2):
%struct.TYPE_6__ = type { i8*, i64, i64, i32, i32, i32*, i64, i64, i64 }
@Z_DEFLATED = global i32 0
@Z_FIXED = global i32 0
@Z_OK = global i32 0
@stderr = global i32 0
@.str = [13 x i8] c"deflateInit\0A\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [22 x i8] c"deflateSetDictionary\0A\00"
@Z_NO_FLUSH = global i32 0
@.str.3 = [9 x i8] c"deflate\0A\00"
@Z_FINISH = global i32 0
@Z_STREAM_END = global i32 0
@.str.4 = [12 x i8] c"deflateEnd\0A\00"
define i32 @test_deflate(i8* %0, i8* %1, i64 %2) {
%4 = alloca %struct.TYPE_6__
%5 = bitcast %struct.TYPE_6__* %4 to i8*
%6 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%7 = add nsw i64 %6, 1
%8 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %4, i64 0, i32 6
%9 = bitcast i64* %8 to i8*
%10 = load i32, i32* @Z_DEFLATED
%11 = load i32, i32* @Z_FIXED
%12 = call i32 @deflateInit2(%struct.TYPE_6__* %4, i32 9, i32 %10, i32 -15, i32 8, i32 %11)
%13 = load i32, i32* @Z_OK
%14 = icmp eq i32 %12, %13
br i1 %14, label %18, label %15
15: ; preds = %3
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %15, %3
%19 = call i32 @deflateSetDictionary(%struct.TYPE_6__* %4, i32* bitcast ([1 x i8]* @.str.1 to i32*), i32 0)
%20 = load i32, i32* @Z_OK
%21 = icmp eq i32 %19, %20
br i1 %21, label %25, label %22
22: ; preds = %18
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
br label %25
25: ; preds = %22, %18
%26 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %4, i64 0, i32 5
%27 = bitcast i32** %26 to i8**
store i8* %0, i8** %27
%28 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %4, i64 0, i32 0
store i8* %1, i8** %28
%29 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %4, i64 0, i32 1
%30 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %4, i64 0, i32 2
%31 = load i64, i64* %29
%32 = icmp ne i64 %31, %7
%33 = load i64, i64* %30
%34 = icmp slt i64 %33, %2
%35 = select i1 %32, i1 %34, i1 false
br i1 %35, label %36, label %39
36: ; preds = %25
%37 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %4, i64 0, i32 4
%38 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %4, i64 0, i32 3
br label %45
39: ; preds = %53, %25
%40 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %4, i64 0, i32 4
store i32 1, i32* %40
%41 = load i32, i32* @Z_FINISH
%42 = call i32 @deflate(%struct.TYPE_6__* %4, i32 %41)
%43 = load i32, i32* @Z_STREAM_END
%44 = icmp eq i32 %42, %43
br i1 %44, label %71, label %59
45: ; preds = %36, %53
store i32 1, i32* %37
store i32 1, i32* %38
%46 = load i32, i32* @Z_NO_FLUSH
%47 = call i32 @deflate(%struct.TYPE_6__* %4, i32 %46)
%48 = load i32, i32* @Z_OK
%49 = icmp eq i32 %47, %48
br i1 %49, label %53, label %50
50: ; preds = %45
%51 = load i32, i32* @stderr
%52 = call i32 @fprintf(i32 %51, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
br label %53
53: ; preds = %50, %45
%54 = load i64, i64* %29
%55 = icmp ne i64 %54, %7
%56 = load i64, i64* %30
%57 = icmp slt i64 %56, %2
%58 = select i1 %55, i1 %57, i1 false
br i1 %58, label %45, label %39
59: ; preds = %39, %66
%60 = phi i32 [ %68, %66 ], [ %42, %39 ]
%61 = load i32, i32* @Z_OK
%62 = icmp eq i32 %60, %61
br i1 %62, label %66, label %63
63: ; preds = %59
%64 = load i32, i32* @stderr
%65 = call i32 @fprintf(i32 %64, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
br label %66
66: ; preds = %63, %59
store i32 1, i32* %40
%67 = load i32, i32* @Z_FINISH
%68 = call i32 @deflate(%struct.TYPE_6__* %4, i32 %67)
%69 = load i32, i32* @Z_STREAM_END
%70 = icmp eq i32 %68, %69
br i1 %70, label %71, label %59
71: ; preds = %66, %39
%72 = call i32 @deflateEnd(%struct.TYPE_6__* %4)
%73 = load i32, i32* @Z_OK
%74 = icmp eq i32 %72, %73
br i1 %74, label %78, label %75
75: ; preds = %71
%76 = load i32, i32* @stderr
%77 = call i32 @fprintf(i32 %76, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
br label %78
78: ; preds = %75, %71
%79 = load i64, i64* %30
%80 = trunc i64 %79 to i32
ret i32 %80
}