#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 */
typedef int /*<<< orphan*/ zs;
struct TYPE_5__ {
  int avail_in;
  int avail_out;
  int total_out;
  int /*<<< orphan*/ *next_out;
  int /*<<< orphan*/ *next_in;
};
typedef TYPE_1__ z_stream;
typedef int /*<<< orphan*/ Bytef;

/* Variables and functions */
int /*<<< orphan*/ Z_BEST_COMPRESSION;
int /*<<< orphan*/ Z_FINISH;
int Z_OK;
int /*<<< orphan*/ __XALT_my_free_xalt_1_5(char *, int);
int deflate(TYPE_1__ *, int /*<<< orphan*/);
int deflateInit(TYPE_1__ *, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ memset(TYPE_1__ *, int /*<<< orphan*/, int);
int /*<<< orphan*/ stderr;
int strlen(char const *);
char *__XALT_compress_string_xalt_1_5(const char *str, int *lenOut) {
  z_stream zs;
  memset(&zs, 0, sizeof(zs));
  if (deflateInit(&zs, Z_BEST_COMPRESSION) != Z_OK) {
    fprintf(stderr, "Unable to set compression level with deflateInit\n");
    exit(1);
  }
  zs.next_in = (Bytef *)str;
  zs.avail_in = strlen(str);
  int ret, oldSz;
  char outbuffer[32768];
  int szOut = 0;
  int totalSz = zs.avail_in / 2;
  char *prev;
  char *out = (char *)malloc(totalSz + 1);
  do {
    zs.next_out = (Bytef *)outbuffer;
    zs.avail_out = 32768;
    ret = deflate(&zs, Z_FINISH);
    oldSz = szOut;
    szOut = zs.total_out;
    if (szOut > totalSz) {
      totalSz = ((2 * totalSz) > (2 * szOut) ? (2 * totalSz) : (2 * szOut));
      prev = out;
      out = (char *)malloc(totalSz + 1);
      memcpy(out, prev, oldSz);
      __XALT_my_free_xalt_1_5(prev, oldSz);
    }
    if (oldSz < szOut) {
      memcpy(&out[oldSz], outbuffer, zs.total_out - oldSz);
      out[szOut] = '\0';
    }
  } while (ret == Z_OK);
  *lenOut = szOut;
  return out;
}


x86 assembly (clang, -O0):
<__XALT_compress_string_xalt_1_5>:
push   %rbp
mov    %rsp,%rbp
sub    $0x8060,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1050 <memset@plt>
mov    0x2e26(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdi
call   1080 <deflateInit@plt>
mov    0x2e24(%rip),%rcx
cmp    (%rcx),%eax
je     11f3 <__XALT_compress_string_xalt_1_5+0x63>
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
lea    0xe1c(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x30(%rbp)
movl   $0x0,-0x8044(%rbp)
mov    -0x30(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8048(%rbp)
mov    -0x8048(%rbp),%edi
add    $0x1,%edi
call   1090 <malloc@plt>
mov    %rax,-0x8058(%rbp)
lea    -0x8040(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x8000,-0x2c(%rbp)
mov    0x2d78(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdi
call   1040 <deflate@plt>
mov    %eax,-0x34(%rbp)
mov    -0x8044(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x8044(%rbp)
mov    -0x8044(%rbp),%eax
cmp    -0x8048(%rbp),%eax
jle    1313 <__XALT_compress_string_xalt_1_5+0x183>
mov    -0x8048(%rbp),%eax
shl    $0x1,%eax
mov    -0x8044(%rbp),%ecx
shl    $0x1,%ecx
cmp    %ecx,%eax
jle    12b0 <__XALT_compress_string_xalt_1_5+0x120>
mov    -0x8048(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x805c(%rbp)
jmp    12bf <__XALT_compress_string_xalt_1_5+0x12f>
mov    -0x8044(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x805c(%rbp)
mov    -0x805c(%rbp),%eax
mov    %eax,-0x8048(%rbp)
mov    -0x8058(%rbp),%rax
mov    %rax,-0x8050(%rbp)
mov    -0x8048(%rbp),%edi
add    $0x1,%edi
call   1090 <malloc@plt>
mov    %rax,-0x8058(%rbp)
mov    -0x8058(%rbp),%rdi
mov    -0x8050(%rbp),%rsi
mov    -0x38(%rbp),%edx
call   1070 <memcpy@plt>
mov    -0x8050(%rbp),%rdi
mov    -0x38(%rbp),%esi
call   10a0 <__XALT_my_free_xalt_1_5@plt>
mov    -0x38(%rbp),%eax
cmp    -0x8044(%rbp),%eax
jge    1354 <__XALT_compress_string_xalt_1_5+0x1c4>
mov    -0x8058(%rbp),%rdi
movslq -0x38(%rbp),%rax
add    %rax,%rdi
lea    -0x8040(%rbp),%rsi
mov    -0x28(%rbp),%edx
sub    -0x38(%rbp),%edx
call   1070 <memcpy@plt>
mov    -0x8058(%rbp),%rax
movslq -0x8044(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1359 <__XALT_compress_string_xalt_1_5+0x1c9>
mov    -0x34(%rbp),%eax
mov    0x2c8d(%rip),%rcx
cmp    (%rcx),%eax
je     1237 <__XALT_compress_string_xalt_1_5+0xa7>
mov    -0x8044(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8058(%rbp),%rax
add    $0x8060,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__XALT_compress_string_xalt_1_5>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x8038,%rsp
mov    %rsi,0x8(%rsp)
mov    %rdi,%rbx
lea    0x10(%rsp),%r15
xor    %ebp,%ebp
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1050 <memset@plt>
mov    0x2e1a(%rip),%rax
mov    (%rax),%esi
mov    %r15,%rdi
call   1080 <deflateInit@plt>
mov    0x2e19(%rip),%rcx
cmp    (%rcx),%eax
jne    12cf <__XALT_compress_string_xalt_1_5+0x13f>
mov    %rbx,0x28(%rsp)
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,0x10(%rsp)
mov    %eax,%r12d
shr    $0x1f,%r12d
add    %eax,%r12d
sar    %r12d
lea    0x1(%r12),%edi
call   1090 <malloc@plt>
mov    %rax,%r14
jmp    1223 <__XALT_compress_string_xalt_1_5+0x93>
nopl   0x0(%rax)
mov    %r15d,%ebp
mov    0x2dd6(%rip),%rax
cmp    (%rax),%r13d
jne    12b2 <__XALT_compress_string_xalt_1_5+0x122>
lea    0x30(%rsp),%rax
mov    %rax,0x20(%rsp)
movl   $0x8000,0x14(%rsp)
mov    0x2d8c(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rdi
call   1040 <deflate@plt>
mov    %eax,%r13d
mov    0x18(%rsp),%r15d
cmp    %r12d,%r15d
jle    128a <__XALT_compress_string_xalt_1_5+0xfa>
add    %r12d,%r12d
lea    (%r15,%r15,1),%eax
cmp    %eax,%r12d
cmovle %eax,%r12d
lea    0x1(%r12),%edi
call   1090 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1070 <memcpy@plt>
mov    %r14,%rdi
mov    %ebp,%esi
call   10a0 <__XALT_my_free_xalt_1_5@plt>
mov    %rbx,%r14
cmp    %r15d,%ebp
jge    1210 <__XALT_compress_string_xalt_1_5+0x80>
movslq %r15d,%rbx
movslq %ebp,%rdi
add    %r14,%rdi
mov    0x18(%rsp),%edx
sub    %ebp,%edx
lea    0x30(%rsp),%rsi
call   1070 <memcpy@plt>
movb   $0x0,(%r14,%rbx,1)
jmp    1210 <__XALT_compress_string_xalt_1_5+0x80>
mov    0x8(%rsp),%rax
mov    %r15d,(%rax)
mov    %r14,%rax
add    $0x8038,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2cfa(%rip),%rax
mov    (%rax),%edi
lea    0xd21(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.TYPE_5__ = type { i32, i32, i32, i32*, i32* }
@Z_BEST_COMPRESSION = global i32 0
@Z_OK = global i32 0
@stderr = global i32 0
@.str = [50 x i8] c"Unable to set compression level with deflateInit\0A\00"
@Z_FINISH = global i32 0
define i8* @__XALT_compress_string_xalt_1_5(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca %struct.TYPE_5__
%6 = alloca i32
%7 = alloca i32
%8 = alloca [32768 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i8*
store i8* %0, i8** %3
store i32* %1, i32** %4
%13 = call i32 @memset(%struct.TYPE_5__* %5, i32 0, i32 32)
%14 = load i32, i32* @Z_BEST_COMPRESSION
%15 = call i32 @deflateInit(%struct.TYPE_5__* %5, i32 %14)
%16 = load i32, i32* @Z_OK
%17 = icmp ne i32 %15, %16
br i1 %17, label %18, label %22
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %2
%23 = load i8*, i8** %3
%24 = bitcast i8* %23 to i32*
%25 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %5, i32 0, i32 4
store i32* %24, i32** %25
%26 = load i8*, i8** %3
%27 = call i32 @strlen(i8* %26)
%28 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %5, i32 0, i32 0
store i32 %27, i32* %28
store i32 0, i32* %9
%29 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %5, i32 0, i32 0
%30 = load i32, i32* %29
%31 = sdiv i32 %30, 2
store i32 %31, i32* %10
%32 = load i32, i32* %10
%33 = add nsw i32 %32, 1
%34 = call i64 @malloc(i32 %33)
%35 = inttoptr i64 %34 to i8*
store i8* %35, i8** %12
br label %36
36: ; preds = %95, %22
%37 = getelementptr inbounds [32768 x i8], [32768 x i8]* %8, i64 0, i64 0
%38 = bitcast i8* %37 to i32*
%39 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %5, i32 0, i32 3
store i32* %38, i32** %39
%40 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %5, i32 0, i32 1
store i32 32768, i32* %40
%41 = load i32, i32* @Z_FINISH
%42 = call i32 @deflate(%struct.TYPE_5__* %5, i32 %41)
store i32 %42, i32* %6
%43 = load i32, i32* %9
store i32 %43, i32* %7
%44 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %5, i32 0, i32 2
%45 = load i32, i32* %44
store i32 %45, i32* %9
%46 = load i32, i32* %9
%47 = load i32, i32* %10
%48 = icmp sgt i32 %46, %47
br i1 %48, label %49, label %75
49: ; preds = %36
%50 = load i32, i32* %10
%51 = mul nsw i32 2, %50
%52 = load i32, i32* %9
%53 = mul nsw i32 2, %52
%54 = icmp sgt i32 %51, %53
br i1 %54, label %55, label %58
55: ; preds = %49
%56 = load i32, i32* %10
%57 = mul nsw i32 2, %56
br label %61
58: ; preds = %49
%59 = load i32, i32* %9
%60 = mul nsw i32 2, %59
br label %61
61: ; preds = %58, %55
%62 = phi i32 [ %57, %55 ], [ %60, %58 ]
store i32 %62, i32* %10
%63 = load i8*, i8** %12
store i8* %63, i8** %11
%64 = load i32, i32* %10
%65 = add nsw i32 %64, 1
%66 = call i64 @malloc(i32 %65)
%67 = inttoptr i64 %66 to i8*
store i8* %67, i8** %12
%68 = load i8*, i8** %12
%69 = load i8*, i8** %11
%70 = load i32, i32* %7
%71 = call i32 @memcpy(i8* %68, i8* %69, i32 %70)
%72 = load i8*, i8** %11
%73 = load i32, i32* %7
%74 = call i32 @__XALT_my_free_xalt_1_5(i8* %72, i32 %73)
br label %75
75: ; preds = %61, %36
%76 = load i32, i32* %7
%77 = load i32, i32* %9
%78 = icmp slt i32 %76, %77
br i1 %78, label %79, label %94
79: ; preds = %75
%80 = load i8*, i8** %12
%81 = load i32, i32* %7
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds i8, i8* %80, i64 %82
%84 = getelementptr inbounds [32768 x i8], [32768 x i8]* %8, i64 0, i64 0
%85 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %5, i32 0, i32 2
%86 = load i32, i32* %85
%87 = load i32, i32* %7
%88 = sub nsw i32 %86, %87
%89 = call i32 @memcpy(i8* %83, i8* %84, i32 %88)
%90 = load i8*, i8** %12
%91 = load i32, i32* %9
%92 = sext i32 %91 to i64
%93 = getelementptr inbounds i8, i8* %90, i64 %92
store i8 0, i8* %93
br label %94
94: ; preds = %79, %75
br label %95
95: ; preds = %94
%96 = load i32, i32* %6
%97 = load i32, i32* @Z_OK
%98 = icmp eq i32 %96, %97
br i1 %98, label %36, label %99
99: ; preds = %95
%100 = load i32, i32* %9
%101 = load i32*, i32** %4
store i32 %100, i32* %101
%102 = load i8*, i8** %12
ret i8* %102
}

LLVM IR (-O2):
%struct.TYPE_5__ = type { i32, i32, i32, i32*, i32* }
@Z_BEST_COMPRESSION = global i32 0
@Z_OK = global i32 0
@stderr = global i32 0
@.str = [50 x i8] c"Unable to set compression level with deflateInit\0A\00"
@Z_FINISH = global i32 0
define i8* @__XALT_compress_string_xalt_1_5(i8* %0, i32* nocapture writeonly %1) {
%3 = alloca %struct.TYPE_5__
%4 = alloca [32768 x i8]
%5 = bitcast %struct.TYPE_5__* %3 to i8*
%6 = call i32 @memset(%struct.TYPE_5__* %3, i32 0, i32 32)
%7 = load i32, i32* @Z_BEST_COMPRESSION
%8 = call i32 @deflateInit(%struct.TYPE_5__* %3, i32 %7)
%9 = load i32, i32* @Z_OK
%10 = icmp eq i32 %8, %9
br i1 %10, label %15, label %11
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %3, i64 0, i32 4
%17 = bitcast i32** %16 to i8**
store i8* %0, i8** %17
%18 = call i32 @strlen(i8* %0)
%19 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %3, i64 0, i32 0
store i32 %18, i32* %19
%20 = getelementptr inbounds [32768 x i8], [32768 x i8]* %4, i64 0, i64 0
%21 = sdiv i32 %18, 2
%22 = add nsw i32 %21, 1
%23 = call i64 @malloc(i32 %22)
%24 = inttoptr i64 %23 to i8*
%25 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %3, i64 0, i32 3
%26 = bitcast i32** %25 to [32768 x i8]**
%27 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %3, i64 0, i32 1
%28 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %3, i64 0, i32 2
br label %29
29: ; preds = %59, %15
%30 = phi i32 [ %21, %15 ], [ %48, %59 ]
%31 = phi i32 [ 0, %15 ], [ %35, %59 ]
%32 = phi i8* [ %24, %15 ], [ %49, %59 ]
store [32768 x i8]* %4, [32768 x i8]** %26
store i32 32768, i32* %27
%33 = load i32, i32* @Z_FINISH
%34 = call i32 @deflate(%struct.TYPE_5__* %3, i32 %33)
%35 = load i32, i32* %28
%36 = icmp sgt i32 %35, %30
br i1 %36, label %37, label %47
37: ; preds = %29
%38 = shl nsw i32 %30, 1
%39 = shl nsw i32 %35, 1
%40 = icmp sgt i32 %38, %39
%41 = select i1 %40, i32 %38, i32 %39
%42 = or i32 %41, 1
%43 = call i64 @malloc(i32 %42)
%44 = inttoptr i64 %43 to i8*
%45 = call i32 @memcpy(i8* %44, i8* %32, i32 %31)
%46 = call i32 @__XALT_my_free_xalt_1_5(i8* %32, i32 %31)
br label %47
47: ; preds = %37, %29
%48 = phi i32 [ %41, %37 ], [ %30, %29 ]
%49 = phi i8* [ %44, %37 ], [ %32, %29 ]
%50 = icmp slt i32 %31, %35
br i1 %50, label %51, label %59
51: ; preds = %47
%52 = sext i32 %31 to i64
%53 = getelementptr inbounds i8, i8* %49, i64 %52
%54 = load i32, i32* %28
%55 = sub nsw i32 %54, %31
%56 = call i32 @memcpy(i8* %53, i8* %20, i32 %55)
%57 = sext i32 %35 to i64
%58 = getelementptr inbounds i8, i8* %49, i64 %57
store i8 0, i8* %58
br label %59
59: ; preds = %47, %51
%60 = load i32, i32* @Z_OK
%61 = icmp eq i32 %34, %60
br i1 %61, label %29, label %62
62: ; preds = %59
store i32 %35, i32* %1
ret i8* %49
}