#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__ {
  void *next_out;
  void *avail_out;
  void *next_in;
  void *avail_in;
};
typedef TYPE_1__ z_stream;
typedef void *uint32_t;

/* Variables and functions */
int /*<<< orphan*/ Z_FINISH;
int Z_OK;
int Z_STREAM_END;
int inflate(TYPE_1__ *, int /*<<< orphan*/);
int inflateEnd(TYPE_1__ *);
int inflateInit(TYPE_1__ *);
int /*<<< orphan*/ memset(TYPE_1__ *, int /*<<< orphan*/, int);
int inflate_buf(uint32_t msg_size, void *buf, uint32_t msg_size_inflated,
                void *inflated_buf) {
  z_stream strm;
  memset(&strm, 0, sizeof(z_stream));
  int ret = inflateInit(&strm);
  if (ret != Z_OK)
    return 13;
  strm.avail_in = msg_size;
  strm.next_in = buf;
  strm.avail_out = msg_size_inflated;
  strm.next_out = inflated_buf;
  ret = inflate(&strm, Z_FINISH);
  if (ret != Z_STREAM_END)
    return 13;
  if (inflateEnd(&strm) != Z_OK)
    return 13;
  return 0;
}


x86 assembly (clang, -O0):
<inflate_buf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
lea    -0x48(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1040 <memset@plt>
lea    -0x48(%rbp),%rdi
call   1050 <inflateInit@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
mov    0x2e72(%rip),%rcx
cmp    (%rcx),%eax
je     1192 <inflate_buf+0x52>
movl   $0xd,-0x4(%rbp)
jmp    1210 <inflate_buf+0xd0>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    0x2e17(%rip),%rax
mov    (%rax),%esi
lea    -0x48(%rbp),%rdi
call   1030 <inflate@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
mov    0x2e0f(%rip),%rcx
cmp    (%rcx),%eax
je     11e5 <inflate_buf+0xa5>
movl   $0xd,-0x4(%rbp)
jmp    1210 <inflate_buf+0xd0>
lea    -0x48(%rbp),%rdi
call   1060 <inflateEnd@plt>
mov    0x2dfb(%rip),%rcx
cmp    (%rcx),%eax
je     1209 <inflate_buf+0xc9>
movl   $0xd,-0x4(%rbp)
jmp    1210 <inflate_buf+0xd0>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inflate_buf>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%r13
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1040 <memset@plt>
mov    %rbx,%rdi
call   1050 <inflateInit@plt>
mov    0x2e73(%rip),%rbp
mov    $0xd,%ebx
cmp    0x0(%rbp),%eax
jne    11d0 <inflate_buf+0x90>
mov    %r13,0x20(%rsp)
mov    %r12,0x18(%rsp)
mov    %r15,0x10(%rsp)
mov    %r14,0x8(%rsp)
mov    0x2e2e(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdi
call   1030 <inflate@plt>
mov    0x2e2b(%rip),%rcx
cmp    (%rcx),%eax
jne    11d0 <inflate_buf+0x90>
lea    0x8(%rsp),%rdi
call   1060 <inflateEnd@plt>
xor    %ecx,%ecx
cmp    0x0(%rbp),%eax
mov    $0xd,%ebx
cmove  %ecx,%ebx
mov    %ebx,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_6__ = type { i8*, i8*, i8*, i8* }
@Z_OK = global i32 0
@Z_FINISH = global i32 0
@Z_STREAM_END = global i32 0
define i32 @inflate_buf(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca %struct.TYPE_6__
%11 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
%12 = call i32 @memset(%struct.TYPE_6__* %10, i32 0, i32 32)
%13 = call i32 @inflateInit(%struct.TYPE_6__* %10)
store i32 %13, i32* %11
%14 = load i32, i32* %11
%15 = load i32, i32* @Z_OK
%16 = icmp ne i32 %14, %15
br i1 %16, label %17, label %18
17: ; preds = %4
store i32 13, i32* %5
br label %39
18: ; preds = %4
%19 = load i8*, i8** %6
%20 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %10, i32 0, i32 3
store i8* %19, i8** %20
%21 = load i8*, i8** %7
%22 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %10, i32 0, i32 2
store i8* %21, i8** %22
%23 = load i8*, i8** %8
%24 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %10, i32 0, i32 1
store i8* %23, i8** %24
%25 = load i8*, i8** %9
%26 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %10, i32 0, i32 0
store i8* %25, i8** %26
%27 = load i32, i32* @Z_FINISH
%28 = call i32 @inflate(%struct.TYPE_6__* %10, i32 %27)
store i32 %28, i32* %11
%29 = load i32, i32* %11
%30 = load i32, i32* @Z_STREAM_END
%31 = icmp ne i32 %29, %30
br i1 %31, label %32, label %33
32: ; preds = %18
store i32 13, i32* %5
br label %39
33: ; preds = %18
%34 = call i32 @inflateEnd(%struct.TYPE_6__* %10)
%35 = load i32, i32* @Z_OK
%36 = icmp ne i32 %34, %35
br i1 %36, label %37, label %38
37: ; preds = %33
store i32 13, i32* %5
br label %39
38: ; preds = %33
store i32 0, i32* %5
br label %39
39: ; preds = %38, %37, %32, %17
%40 = load i32, i32* %5
ret i32 %40
}

LLVM IR (-O2):
%struct.TYPE_6__ = type { i8*, i8*, i8*, i8* }
@Z_OK = global i32 0
@Z_FINISH = global i32 0
@Z_STREAM_END = global i32 0
define i32 @inflate_buf(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca %struct.TYPE_6__
%6 = bitcast %struct.TYPE_6__* %5 to i8*
%7 = call i32 @memset(%struct.TYPE_6__* %5, i32 0, i32 32)
%8 = call i32 @inflateInit(%struct.TYPE_6__* %5)
%9 = load i32, i32* @Z_OK
%10 = icmp eq i32 %8, %9
br i1 %10, label %11, label %25
11: ; preds = %4
%12 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %5, i64 0, i32 3
store i8* %0, i8** %12
%13 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %5, i64 0, i32 2
store i8* %1, i8** %13
%14 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %5, i64 0, i32 1
store i8* %2, i8** %14
%15 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %5, i64 0, i32 0
store i8* %3, i8** %15
%16 = load i32, i32* @Z_FINISH
%17 = call i32 @inflate(%struct.TYPE_6__* %5, i32 %16)
%18 = load i32, i32* @Z_STREAM_END
%19 = icmp eq i32 %17, %18
br i1 %19, label %20, label %25
20: ; preds = %11
%21 = call i32 @inflateEnd(%struct.TYPE_6__* %5)
%22 = load i32, i32* @Z_OK
%23 = icmp eq i32 %21, %22
%24 = select i1 %23, i32 0, i32 13
br label %25
25: ; preds = %20, %11, %4
%26 = phi i32 [ 13, %4 ], [ 13, %11 ], [ %24, %20 ]
ret i32 %26
}