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

/* Type definitions */
typedef TYPE_1__ *z_streamp;
typedef int /*<<< orphan*/ z_stream;
typedef int uLong;
typedef scalar_t__ int32_t;
struct TYPE_10__ {
  unsigned char *next_in;
  unsigned int avail_in;
  int total_out;
  unsigned int avail_out;
  struct TYPE_10__ *next_out;
};
typedef TYPE_1__ Bytef;

/* Variables and functions */
int Z_OK;
int Z_STREAM_END;
int /*<<< orphan*/ Z_SYNC_FLUSH;
int /*<<< orphan*/ assert(int);
TYPE_1__ *calloc(int, int);
int /*<<< orphan*/ free(TYPE_1__ *);
int inflate(TYPE_1__ *, int /*<<< orphan*/);
int inflateEnd(TYPE_1__ *);
int inflateInit(TYPE_1__ *);
void *mat_element_load(char const **, char const **);
TYPE_1__ *realloc(TYPE_1__ *, int);
void *mat_element_load_compressed(int32_t size, const char *data) {
  z_streamp strm = calloc(sizeof(z_stream), 1);
  strm->next_in = (unsigned char *)data;
  strm->avail_in = (unsigned int)size;
  int z = inflateInit(strm);
  assert(z == Z_OK);
  uLong n = (uLong)size * 2;
  Bytef *p = calloc(n, 1);
  for (;;) {
    strm->next_out = p + strm->total_out;
    strm->avail_out = (unsigned int)(n - strm->total_out);
    z = inflate(strm, Z_SYNC_FLUSH);
    if (z != Z_OK)
      break;
    n *= 2;
    p = realloc(p, n);
  }
  assert(z == Z_STREAM_END);
  Bytef *begin = p;
  Bytef *end = p + strm->total_out;
  z = inflateEnd(strm);
  assert(z == Z_OK);
  void *self = mat_element_load((const char **)&begin, (const char **)&end);
  assert(begin == end);
  free(p);
  free(strm);
  return self;
}


x86 assembly (clang, -O0):
<mat_element_load_compressed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x4,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x18(%rbp),%rdi
call   1050 <inflateInit@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2e1f(%rip),%rcx
cmp    (%rcx),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x8(%rbp),%rax
shl    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%rax
movslq 0xc(%rax),%rax
shl    $0x5,%rax
add    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x18(%rax)
mov    -0x20(%rbp),%ecx
mov    -0x18(%rbp),%rax
sub    0xc(%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x10(%rax)
mov    -0x18(%rbp),%rdi
mov    0x2da6(%rip),%rax
mov    (%rax),%esi
call   1040 <inflate@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2daa(%rip),%rcx
cmp    (%rcx),%eax
je     1253 <mat_element_load_compressed+0xd3>
jmp    1271 <mat_element_load_compressed+0xf1>
mov    -0x20(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%esi
call   1090 <realloc@plt>
mov    %rax,-0x28(%rbp)
jmp    11fb <mat_element_load_compressed+0x7b>
mov    -0x1c(%rbp),%eax
mov    0x2d65(%rip),%rcx
cmp    (%rcx),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
movslq 0xc(%rcx),%rcx
shl    $0x5,%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1080 <inflateEnd@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2d31(%rip),%rcx
cmp    (%rcx),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
lea    -0x30(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   10a0 <mat_element_load@plt>
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x38(%rbp),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mat_element_load_compressed>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r15
mov    %rdi,%rbx
mov    $0x4,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,%r14
mov    %r15,(%rax)
mov    %ebx,0x8(%rax)
mov    %rax,%rdi
call   1050 <inflateInit@plt>
mov    0x2e36(%rip),%r12
xor    %edi,%edi
cmp    (%r12),%eax
sete   %dil
call   1070 <assert@plt>
add    %ebx,%ebx
mov    %ebx,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,%r15
movslq 0xc(%r14),%rax
mov    %ebx,%ecx
sub    %eax,%ecx
shl    $0x5,%rax
add    %r15,%rax
mov    %rax,0x18(%r14)
mov    %ecx,0x10(%r14)
mov    0x2de0(%rip),%r13
nopl   0x0(%rax,%rax,1)
mov    0x0(%r13),%esi
mov    %r14,%rdi
call   1040 <inflate@plt>
cmp    (%r12),%eax
jne    123a <mat_element_load_compressed+0xba>
add    %ebx,%ebx
mov    %r15,%rdi
mov    %ebx,%esi
call   1090 <realloc@plt>
mov    %rax,%r15
movslq 0xc(%r14),%rax
mov    %ebx,%ecx
sub    %eax,%ecx
shl    $0x5,%rax
add    %r15,%rax
mov    %rax,0x18(%r14)
mov    %ecx,0x10(%r14)
jmp    1200 <mat_element_load_compressed+0x80>
mov    0x2d9f(%rip),%rcx
xor    %edi,%edi
cmp    (%rcx),%eax
sete   %dil
call   1070 <assert@plt>
mov    %r15,0x8(%rsp)
movslq 0xc(%r14),%rax
shl    $0x5,%rax
add    %r15,%rax
mov    %rax,(%rsp)
mov    %r14,%rdi
call   1080 <inflateEnd@plt>
xor    %edi,%edi
cmp    (%r12),%eax
sete   %dil
call   1070 <assert@plt>
lea    0x8(%rsp),%rdi
mov    %rsp,%rsi
call   10a0 <mat_element_load@plt>
mov    %rax,%rbx
mov    0x8(%rsp),%rax
xor    %edi,%edi
cmp    (%rsp),%rax
sete   %dil
call   1070 <assert@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.TYPE_10__ = type { i8*, i32, i32, i32, %struct.TYPE_10__* }
@Z_OK = global i32 0
@Z_SYNC_FLUSH = global i32 0
@Z_STREAM_END = global i32 0
define i8* @mat_element_load_compressed(i64 %0, i8* %1) {
%3 = alloca i64
%4 = alloca i8*
%5 = alloca %struct.TYPE_10__*
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.TYPE_10__*
%9 = alloca %struct.TYPE_10__*
%10 = alloca %struct.TYPE_10__*
%11 = alloca i8*
store i64 %0, i64* %3
store i8* %1, i8** %4
%12 = call %struct.TYPE_10__* @calloc(i32 4, i32 1)
store %struct.TYPE_10__* %12, %struct.TYPE_10__** %5
%13 = load i8*, i8** %4
%14 = load %struct.TYPE_10__*, %struct.TYPE_10__** %5
%15 = getelementptr inbounds %struct.TYPE_10__, %struct.TYPE_10__* %14, i32 0, i32 0
store i8* %13, i8** %15
%16 = load i64, i64* %3
%17 = trunc i64 %16 to i32
%18 = load %struct.TYPE_10__*, %struct.TYPE_10__** %5
%19 = getelementptr inbounds %struct.TYPE_10__, %struct.TYPE_10__* %18, i32 0, i32 1
store i32 %17, i32* %19
%20 = load %struct.TYPE_10__*, %struct.TYPE_10__** %5
%21 = call i32 @inflateInit(%struct.TYPE_10__* %20)
store i32 %21, i32* %6
%22 = load i32, i32* %6
%23 = load i32, i32* @Z_OK
%24 = icmp eq i32 %22, %23
%25 = zext i1 %24 to i32
%26 = call i32 @assert(i32 %25)
%27 = load i64, i64* %3
%28 = trunc i64 %27 to i32
%29 = mul nsw i32 %28, 2
store i32 %29, i32* %7
%30 = load i32, i32* %7
%31 = call %struct.TYPE_10__* @calloc(i32 %30, i32 1)
store %struct.TYPE_10__* %31, %struct.TYPE_10__** %8
br label %32
32: ; preds = %55, %2
%33 = load %struct.TYPE_10__*, %struct.TYPE_10__** %8
%34 = load %struct.TYPE_10__*, %struct.TYPE_10__** %5
%35 = getelementptr inbounds %struct.TYPE_10__, %struct.TYPE_10__* %34, i32 0, i32 2
%36 = load i32, i32* %35
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds %struct.TYPE_10__, %struct.TYPE_10__* %33, i64 %37
%39 = load %struct.TYPE_10__*, %struct.TYPE_10__** %5
%40 = getelementptr inbounds %struct.TYPE_10__, %struct.TYPE_10__* %39, i32 0, i32 4
store %struct.TYPE_10__* %38, %struct.TYPE_10__** %40
%41 = load i32, i32* %7
%42 = load %struct.TYPE_10__*, %struct.TYPE_10__** %5
%43 = getelementptr inbounds %struct.TYPE_10__, %struct.TYPE_10__* %42, i32 0, i32 2
%44 = load i32, i32* %43
%45 = sub nsw i32 %41, %44
%46 = load %struct.TYPE_10__*, %struct.TYPE_10__** %5
%47 = getelementptr inbounds %struct.TYPE_10__, %struct.TYPE_10__* %46, i32 0, i32 3
store i32 %45, i32* %47
%48 = load %struct.TYPE_10__*, %struct.TYPE_10__** %5
%49 = load i32, i32* @Z_SYNC_FLUSH
%50 = call i32 @inflate(%struct.TYPE_10__* %48, i32 %49)
store i32 %50, i32* %6
%51 = load i32, i32* %6
%52 = load i32, i32* @Z_OK
%53 = icmp ne i32 %51, %52
br i1 %53, label %54, label %55
54: ; preds = %32
br label %61
55: ; preds = %32
%56 = load i32, i32* %7
%57 = mul nsw i32 %56, 2
store i32 %57, i32* %7
%58 = load %struct.TYPE_10__*, %struct.TYPE_10__** %8
%59 = load i32, i32* %7
%60 = call %struct.TYPE_10__* @realloc(%struct.TYPE_10__* %58, i32 %59)
store %struct.TYPE_10__* %60, %struct.TYPE_10__** %8
br label %32
61: ; preds = %54
%62 = load i32, i32* %6
%63 = load i32, i32* @Z_STREAM_END
%64 = icmp eq i32 %62, %63
%65 = zext i1 %64 to i32
%66 = call i32 @assert(i32 %65)
%67 = load %struct.TYPE_10__*, %struct.TYPE_10__** %8
store %struct.TYPE_10__* %67, %struct.TYPE_10__** %9
%68 = load %struct.TYPE_10__*, %struct.TYPE_10__** %8
%69 = load %struct.TYPE_10__*, %struct.TYPE_10__** %5
%70 = getelementptr inbounds %struct.TYPE_10__, %struct.TYPE_10__* %69, i32 0, i32 2
%71 = load i32, i32* %70
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds %struct.TYPE_10__, %struct.TYPE_10__* %68, i64 %72
store %struct.TYPE_10__* %73, %struct.TYPE_10__** %10
%74 = load %struct.TYPE_10__*, %struct.TYPE_10__** %5
%75 = call i32 @inflateEnd(%struct.TYPE_10__* %74)
store i32 %75, i32* %6
%76 = load i32, i32* %6
%77 = load i32, i32* @Z_OK
%78 = icmp eq i32 %76, %77
%79 = zext i1 %78 to i32
%80 = call i32 @assert(i32 %79)
%81 = bitcast %struct.TYPE_10__** %9 to i8**
%82 = bitcast %struct.TYPE_10__** %10 to i8**
%83 = call i8* @mat_element_load(i8** %81, i8** %82)
store i8* %83, i8** %11
%84 = load %struct.TYPE_10__*, %struct.TYPE_10__** %9
%85 = load %struct.TYPE_10__*, %struct.TYPE_10__** %10
%86 = icmp eq %struct.TYPE_10__* %84, %85
%87 = zext i1 %86 to i32
%88 = call i32 @assert(i32 %87)
%89 = load %struct.TYPE_10__*, %struct.TYPE_10__** %8
%90 = call i32 @free(%struct.TYPE_10__* %89)
%91 = load %struct.TYPE_10__*, %struct.TYPE_10__** %5
%92 = call i32 @free(%struct.TYPE_10__* %91)
%93 = load i8*, i8** %11
ret i8* %93
}

LLVM IR (-O2):
%struct.TYPE_10__ = type { i8*, i32, i32, i32, %struct.TYPE_10__* }
@Z_OK = global i32 0
@Z_SYNC_FLUSH = global i32 0
@Z_STREAM_END = global i32 0
define i8* @mat_element_load_compressed(i64 %0, i8* %1) {
%3 = alloca %struct.TYPE_10__*
%4 = alloca %struct.TYPE_10__*
%5 = tail call %struct.TYPE_10__* @calloc(i32 4, i32 1)
%6 = getelementptr inbounds %struct.TYPE_10__, %struct.TYPE_10__* %5, i64 0, i32 0
store i8* %1, i8** %6
%7 = trunc i64 %0 to i32
%8 = getelementptr inbounds %struct.TYPE_10__, %struct.TYPE_10__* %5, i64 0, i32 1
store i32 %7, i32* %8
%9 = tail call i32 @inflateInit(%struct.TYPE_10__* %5)
%10 = load i32, i32* @Z_OK
%11 = icmp eq i32 %9, %10
%12 = zext i1 %11 to i32
%13 = tail call i32 @assert(i32 %12)
%14 = shl nsw i32 %7, 1
%15 = tail call %struct.TYPE_10__* @calloc(i32 %14, i32 1)
%16 = getelementptr inbounds %struct.TYPE_10__, %struct.TYPE_10__* %5, i64 0, i32 2
%17 = getelementptr inbounds %struct.TYPE_10__, %struct.TYPE_10__* %5, i64 0, i32 4
%18 = getelementptr inbounds %struct.TYPE_10__, %struct.TYPE_10__* %5, i64 0, i32 3
%19 = load i32, i32* %16
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds %struct.TYPE_10__, %struct.TYPE_10__* %15, i64 %20
store %struct.TYPE_10__* %21, %struct.TYPE_10__** %17
%22 = sub nsw i32 %14, %19
store i32 %22, i32* %18
%23 = load i32, i32* @Z_SYNC_FLUSH
%24 = tail call i32 @inflate(%struct.TYPE_10__* %5, i32 %23)
%25 = load i32, i32* @Z_OK
%26 = icmp eq i32 %24, %25
br i1 %26, label %27, label %40
27: ; preds = %2, %27
%28 = phi %struct.TYPE_10__* [ %31, %27 ], [ %15, %2 ]
%29 = phi i32 [ %30, %27 ], [ %14, %2 ]
%30 = shl nsw i32 %29, 1
%31 = tail call %struct.TYPE_10__* @realloc(%struct.TYPE_10__* %28, i32 %30)
%32 = load i32, i32* %16
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds %struct.TYPE_10__, %struct.TYPE_10__* %31, i64 %33
store %struct.TYPE_10__* %34, %struct.TYPE_10__** %17
%35 = sub nsw i32 %30, %32
store i32 %35, i32* %18
%36 = load i32, i32* @Z_SYNC_FLUSH
%37 = tail call i32 @inflate(%struct.TYPE_10__* %5, i32 %36)
%38 = load i32, i32* @Z_OK
%39 = icmp eq i32 %37, %38
br i1 %39, label %27, label %40
40: ; preds = %27, %2
%41 = phi %struct.TYPE_10__* [ %15, %2 ], [ %31, %27 ]
%42 = phi i32 [ %24, %2 ], [ %37, %27 ]
%43 = load i32, i32* @Z_STREAM_END
%44 = icmp eq i32 %42, %43
%45 = zext i1 %44 to i32
%46 = tail call i32 @assert(i32 %45)
%47 = bitcast %struct.TYPE_10__** %3 to i8*
store %struct.TYPE_10__* %41, %struct.TYPE_10__** %3
%48 = bitcast %struct.TYPE_10__** %4 to i8*
%49 = load i32, i32* %16
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds %struct.TYPE_10__, %struct.TYPE_10__* %41, i64 %50
store %struct.TYPE_10__* %51, %struct.TYPE_10__** %4
%52 = tail call i32 @inflateEnd(%struct.TYPE_10__* %5)
%53 = load i32, i32* @Z_OK
%54 = icmp eq i32 %52, %53
%55 = zext i1 %54 to i32
%56 = tail call i32 @assert(i32 %55)
%57 = bitcast %struct.TYPE_10__** %3 to i8**
%58 = bitcast %struct.TYPE_10__** %4 to i8**
%59 = call i8* @mat_element_load(i8** %57, i8** %58)
%60 = load %struct.TYPE_10__*, %struct.TYPE_10__** %3
%61 = load %struct.TYPE_10__*, %struct.TYPE_10__** %4
%62 = icmp eq %struct.TYPE_10__* %60, %61
%63 = zext i1 %62 to i32
%64 = call i32 @assert(i32 %63)
%65 = call i32 @free(%struct.TYPE_10__* %41)
%66 = call i32 @free(%struct.TYPE_10__* %5)
ret i8* %59
}