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

/* Variables and functions */
int Z_OK;
int Z_STREAM_END;
int /*<<< orphan*/ __XALT_my_free_xalt_1_5(char *, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int inflate(TYPE_1__ *, int /*<<< orphan*/);
int /*<<< orphan*/ inflateEnd(TYPE_1__ *);
int inflateInit(TYPE_1__ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ memset(TYPE_1__ *, int /*<<< orphan*/, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char *);
char *uncompress_string(const char *str, int len) {
  z_stream zs;
  memset(&zs, 0, sizeof(zs));
  if (inflateInit(&zs) != Z_OK) {
    fprintf(stderr, "inflateInit failed while decompressing.\n");
    exit(1);
  }
  zs.next_in = (Bytef *)str;
  zs.avail_in = len;
  int ret, oldSz;
  char outbuffer[32768];
  int totalSz = 4 * len;
  int szOut = 0;
  char *prev;
  char *out = (char *)malloc(totalSz + 1);
  do {
    zs.next_out = (Bytef *)outbuffer;
    zs.avail_out = 32768;
    ret = inflate(&zs, 0);
    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, strlen(prev));
    }
    if (oldSz < szOut) {
      memcpy(&out[oldSz], outbuffer, zs.total_out - oldSz);
      out[szOut] = '\0';
    }
  } while (ret == Z_OK);
  inflateEnd(&zs);
  if (ret != Z_STREAM_END) {
    fprintf(stderr, "Exception during zlib decompression: (%d) %s\n", ret,
            zs.msg);
    exit(1);
  }
  return out;
}


x86 assembly (clang, -O0):
<uncompress_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x8070,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1050 <memset@plt>
lea    -0x38(%rbp),%rdi
call   1060 <inflateInit@plt>
mov    0x2e1e(%rip),%rcx
cmp    (%rcx),%eax
je     11fb <uncompress_string+0x5b>
mov    0x2def(%rip),%rax
mov    (%rax),%edi
lea    0xe16(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0xc(%rbp),%eax
shl    $0x2,%eax
mov    %eax,-0x8044(%rbp)
movl   $0x0,-0x8048(%rbp)
mov    -0x8044(%rbp),%edi
add    $0x1,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x8058(%rbp)
lea    -0x8040(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x8000,-0x34(%rbp)
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
call   1030 <inflate@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x8048(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x8048(%rbp)
mov    -0x8048(%rbp),%eax
cmp    -0x8044(%rbp),%eax
jle    1322 <uncompress_string+0x182>
mov    -0x8044(%rbp),%eax
shl    $0x1,%eax
mov    -0x8048(%rbp),%ecx
shl    $0x1,%ecx
cmp    %ecx,%eax
jle    12a6 <uncompress_string+0x106>
mov    -0x8044(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x805c(%rbp)
jmp    12b5 <uncompress_string+0x115>
mov    -0x8048(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x805c(%rbp)
mov    -0x805c(%rbp),%eax
mov    %eax,-0x8044(%rbp)
mov    -0x8058(%rbp),%rax
mov    %rax,-0x8050(%rbp)
mov    -0x8044(%rbp),%edi
add    $0x1,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x8058(%rbp)
mov    -0x8058(%rbp),%rdi
mov    -0x8050(%rbp),%rsi
mov    -0x40(%rbp),%edx
call   1080 <memcpy@plt>
mov    -0x8050(%rbp),%rax
mov    %rax,-0x8068(%rbp)
mov    -0x8050(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x8068(%rbp),%rdi
mov    %eax,%esi
call   10b0 <__XALT_my_free_xalt_1_5@plt>
mov    -0x40(%rbp),%eax
cmp    -0x8048(%rbp),%eax
jge    1363 <uncompress_string+0x1c3>
mov    -0x8058(%rbp),%rdi
movslq -0x40(%rbp),%rax
add    %rax,%rdi
lea    -0x8040(%rbp),%rsi
mov    -0x30(%rbp),%edx
sub    -0x40(%rbp),%edx
call   1080 <memcpy@plt>
mov    -0x8058(%rbp),%rax
movslq -0x8048(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1368 <uncompress_string+0x1c8>
mov    -0x3c(%rbp),%eax
mov    0x2c7e(%rip),%rcx
cmp    (%rcx),%eax
je     1234 <uncompress_string+0x94>
lea    -0x38(%rbp),%rdi
call   1090 <inflateEnd@plt>
mov    -0x3c(%rbp),%eax
mov    0x2c53(%rip),%rcx
cmp    (%rcx),%eax
je     13bd <uncompress_string+0x21d>
mov    0x2c34(%rip),%rax
mov    (%rax),%edi
mov    -0x3c(%rbp),%edx
mov    -0x28(%rbp),%rcx
lea    0xc7d(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x8058(%rbp),%rax
add    $0x8070,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<uncompress_string>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x8038,%rsp
mov    %esi,%ebp
mov    %rdi,%r14
lea    0x8(%rsp),%r15
xor    %ebx,%ebx
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1050 <memset@plt>
mov    %r15,%rdi
call   1060 <inflateInit@plt>
mov    0x2e15(%rip),%rcx
cmp    (%rcx),%eax
jne    12de <uncompress_string+0x13e>
mov    %r14,0x28(%rsp)
mov    %ebp,0x8(%rsp)
mov    %ebp,%r12d
shl    $0x2,%r12d
lea    0x1(,%rbp,4),%edi
call   10a0 <malloc@plt>
mov    %rax,%r14
jmp    1223 <uncompress_string+0x83>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15d,%ebx
mov    0x2dd6(%rip),%rax
cmp    (%rax),%r13d
jne    12b3 <uncompress_string+0x113>
lea    0x30(%rsp),%rax
mov    %rax,0x20(%rsp)
movl   $0x8000,0xc(%rsp)
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1030 <inflate@plt>
mov    %eax,%r13d
mov    0x10(%rsp),%r15d
cmp    %r12d,%r15d
jle    128b <uncompress_string+0xeb>
add    %r12d,%r12d
lea    (%r15,%r15,1),%eax
cmp    %eax,%r12d
cmovle %eax,%r12d
lea    0x1(%r12),%edi
call   10a0 <malloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1080 <memcpy@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   10b0 <__XALT_my_free_xalt_1_5@plt>
mov    %rbp,%r14
cmp    %r15d,%ebx
jge    1210 <uncompress_string+0x70>
movslq %r15d,%rbp
movslq %ebx,%rdi
add    %r14,%rdi
mov    0x10(%rsp),%edx
sub    %ebx,%edx
lea    0x30(%rsp),%rsi
call   1080 <memcpy@plt>
movb   $0x0,(%r14,%rbp,1)
jmp    1210 <uncompress_string+0x70>
lea    0x8(%rsp),%rdi
call   1090 <inflateEnd@plt>
mov    0x2d1c(%rip),%rax
cmp    (%rax),%r13d
jne    12ff <uncompress_string+0x15f>
mov    %r14,%rax
add    $0x8038,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2ceb(%rip),%rax
mov    (%rax),%edi
lea    0xd12(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    0x2cca(%rip),%rax
mov    (%rax),%edi
mov    0x18(%rsp),%rcx
lea    0xd15(%rip),%rsi
mov    %r13d,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
%struct.TYPE_6__ = type { i32, i32, i32, i8*, i32*, i32* }
@Z_OK = global i32 0
@stderr = global i32 0
@.str = [41 x i8] c"inflateInit failed while decompressing.\0A\00"
@Z_STREAM_END = global i32 0
@.str.1 = [46 x i8] c"Exception during zlib decompression: (%d) %s\0A\00"
define i8* @uncompress_string(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.TYPE_6__
%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_6__* %5, i32 0, i32 40)
%14 = call i32 @inflateInit(%struct.TYPE_6__* %5)
%15 = load i32, i32* @Z_OK
%16 = icmp ne i32 %14, %15
br i1 %16, label %17, label %21
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %2
%22 = load i8*, i8** %3
%23 = bitcast i8* %22 to i32*
%24 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %5, i32 0, i32 5
store i32* %23, i32** %24
%25 = load i32, i32* %4
%26 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %5, i32 0, i32 0
store i32 %25, i32* %26
%27 = load i32, i32* %4
%28 = mul nsw i32 4, %27
store i32 %28, i32* %9
store i32 0, i32* %10
%29 = load i32, i32* %9
%30 = add nsw i32 %29, 1
%31 = call i64 @malloc(i32 %30)
%32 = inttoptr i64 %31 to i8*
store i8* %32, i8** %12
br label %33
33: ; preds = %92, %21
%34 = getelementptr inbounds [32768 x i8], [32768 x i8]* %8, i64 0, i64 0
%35 = bitcast i8* %34 to i32*
%36 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %5, i32 0, i32 4
store i32* %35, i32** %36
%37 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %5, i32 0, i32 1
store i32 32768, i32* %37
%38 = call i32 @inflate(%struct.TYPE_6__* %5, i32 0)
store i32 %38, i32* %6
%39 = load i32, i32* %10
store i32 %39, i32* %7
%40 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %5, i32 0, i32 2
%41 = load i32, i32* %40
store i32 %41, i32* %10
%42 = load i32, i32* %10
%43 = load i32, i32* %9
%44 = icmp sgt i32 %42, %43
br i1 %44, label %45, label %72
45: ; preds = %33
%46 = load i32, i32* %9
%47 = mul nsw i32 2, %46
%48 = load i32, i32* %10
%49 = mul nsw i32 2, %48
%50 = icmp sgt i32 %47, %49
br i1 %50, label %51, label %54
51: ; preds = %45
%52 = load i32, i32* %9
%53 = mul nsw i32 2, %52
br label %57
54: ; preds = %45
%55 = load i32, i32* %10
%56 = mul nsw i32 2, %55
br label %57
57: ; preds = %54, %51
%58 = phi i32 [ %53, %51 ], [ %56, %54 ]
store i32 %58, i32* %9
%59 = load i8*, i8** %12
store i8* %59, i8** %11
%60 = load i32, i32* %9
%61 = add nsw i32 %60, 1
%62 = call i64 @malloc(i32 %61)
%63 = inttoptr i64 %62 to i8*
store i8* %63, i8** %12
%64 = load i8*, i8** %12
%65 = load i8*, i8** %11
%66 = load i32, i32* %7
%67 = call i32 @memcpy(i8* %64, i8* %65, i32 %66)
%68 = load i8*, i8** %11
%69 = load i8*, i8** %11
%70 = call i32 @strlen(i8* %69)
%71 = call i32 @__XALT_my_free_xalt_1_5(i8* %68, i32 %70)
br label %72
72: ; preds = %57, %33
%73 = load i32, i32* %7
%74 = load i32, i32* %10
%75 = icmp slt i32 %73, %74
br i1 %75, label %76, label %91
76: ; preds = %72
%77 = load i8*, i8** %12
%78 = load i32, i32* %7
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds i8, i8* %77, i64 %79
%81 = getelementptr inbounds [32768 x i8], [32768 x i8]* %8, i64 0, i64 0
%82 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %5, i32 0, i32 2
%83 = load i32, i32* %82
%84 = load i32, i32* %7
%85 = sub nsw i32 %83, %84
%86 = call i32 @memcpy(i8* %80, i8* %81, i32 %85)
%87 = load i8*, i8** %12
%88 = load i32, i32* %10
%89 = sext i32 %88 to i64
%90 = getelementptr inbounds i8, i8* %87, i64 %89
store i8 0, i8* %90
br label %91
91: ; preds = %76, %72
br label %92
92: ; preds = %91
%93 = load i32, i32* %6
%94 = load i32, i32* @Z_OK
%95 = icmp eq i32 %93, %94
br i1 %95, label %33, label %96
96: ; preds = %92
%97 = call i32 @inflateEnd(%struct.TYPE_6__* %5)
%98 = load i32, i32* %6
%99 = load i32, i32* @Z_STREAM_END
%100 = icmp ne i32 %98, %99
br i1 %100, label %101, label %108
101: ; preds = %96
%102 = load i32, i32* @stderr
%103 = load i32, i32* %6
%104 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %5, i32 0, i32 3
%105 = load i8*, i8** %104
%106 = call i32 (i32, i8*, ...) @fprintf(i32 %102, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i32 %103, i8* %105)
%107 = call i32 @exit(i32 1)
unreachable
108: ; preds = %96
%109 = load i8*, i8** %12
ret i8* %109
}

LLVM IR (-O2):
%struct.TYPE_6__ = type { i32, i32, i32, i8*, i32*, i32* }
@Z_OK = global i32 0
@stderr = global i32 0
@.str = [41 x i8] c"inflateInit failed while decompressing.\0A\00"
@Z_STREAM_END = global i32 0
@.str.1 = [46 x i8] c"Exception during zlib decompression: (%d) %s\0A\00"
define i8* @uncompress_string(i8* %0, i32 %1) {
%3 = alloca %struct.TYPE_6__
%4 = alloca [32768 x i8]
%5 = bitcast %struct.TYPE_6__* %3 to i8*
%6 = call i32 @memset(%struct.TYPE_6__* %3, i32 0, i32 40)
%7 = call i32 @inflateInit(%struct.TYPE_6__* %3)
%8 = load i32, i32* @Z_OK
%9 = icmp eq i32 %7, %8
br i1 %9, label %14, label %10
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %3, i64 0, i32 5
%16 = bitcast i32** %15 to i8**
store i8* %0, i8** %16
%17 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %3, i64 0, i32 0
store i32 %1, i32* %17
%18 = getelementptr inbounds [32768 x i8], [32768 x i8]* %4, i64 0, i64 0
%19 = shl nsw i32 %1, 2
%20 = or i32 %19, 1
%21 = call i64 @malloc(i32 %20)
%22 = inttoptr i64 %21 to i8*
%23 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %3, i64 0, i32 4
%24 = bitcast i32** %23 to [32768 x i8]**
%25 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %3, i64 0, i32 1
%26 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %3, i64 0, i32 2
br label %27
27: ; preds = %57, %14
%28 = phi i32 [ 0, %14 ], [ %32, %57 ]
%29 = phi i32 [ %19, %14 ], [ %46, %57 ]
%30 = phi i8* [ %22, %14 ], [ %47, %57 ]
store [32768 x i8]* %4, [32768 x i8]** %24
store i32 32768, i32* %25
%31 = call i32 @inflate(%struct.TYPE_6__* %3, i32 0)
%32 = load i32, i32* %26
%33 = icmp sgt i32 %32, %29
br i1 %33, label %34, label %45
34: ; preds = %27
%35 = shl nsw i32 %29, 1
%36 = shl nsw i32 %32, 1
%37 = icmp sgt i32 %35, %36
%38 = select i1 %37, i32 %35, i32 %36
%39 = or i32 %38, 1
%40 = call i64 @malloc(i32 %39)
%41 = inttoptr i64 %40 to i8*
%42 = call i32 @memcpy(i8* %41, i8* %30, i32 %28)
%43 = call i32 @strlen(i8* %30)
%44 = call i32 @__XALT_my_free_xalt_1_5(i8* %30, i32 %43)
br label %45
45: ; preds = %34, %27
%46 = phi i32 [ %38, %34 ], [ %29, %27 ]
%47 = phi i8* [ %41, %34 ], [ %30, %27 ]
%48 = icmp slt i32 %28, %32
br i1 %48, label %49, label %57
49: ; preds = %45
%50 = sext i32 %28 to i64
%51 = getelementptr inbounds i8, i8* %47, i64 %50
%52 = load i32, i32* %26
%53 = sub nsw i32 %52, %28
%54 = call i32 @memcpy(i8* %51, i8* %18, i32 %53)
%55 = sext i32 %32 to i64
%56 = getelementptr inbounds i8, i8* %47, i64 %55
store i8 0, i8* %56
br label %57
57: ; preds = %45, %49
%58 = load i32, i32* @Z_OK
%59 = icmp eq i32 %31, %58
br i1 %59, label %27, label %60
60: ; preds = %57
%61 = call i32 @inflateEnd(%struct.TYPE_6__* %3)
%62 = load i32, i32* @Z_STREAM_END
%63 = icmp eq i32 %31, %62
br i1 %63, label %70, label %64
64: ; preds = %60
%65 = load i32, i32* @stderr
%66 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %3, i64 0, i32 3
%67 = load i8*, i8** %66
%68 = call i32 (i32, i8*, ...) @fprintf(i32 %65, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i32 %31, i8* %67)
%69 = call i32 @exit(i32 1)
unreachable
70: ; preds = %60
ret i8* %47
}