#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 TYPE_1__ *z_streamp;
struct TYPE_6__ {
  char *next_in;
  int avail_in;
  char *next_out;
  int avail_out;
  void *opaque;
  void *zfree;
  void *zalloc;
};
typedef TYPE_1__ z_stream;

/* Variables and functions */
int O_CREAT;
int O_WRONLY;
int /*<<< orphan*/ Z_NO_FLUSH;
void *Z_NULL;
int Z_OK;
int Z_STREAM_END;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, ...);
int inflate(TYPE_1__ *, int /*<<< orphan*/);
int inflateEnd(TYPE_1__ *);
int inflateInit2(TYPE_1__ *, int);
int open(char *, int, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ write(int, char *, int);
void http_gunzip(char *contents, int contentlength) {
  int rc;
  char buf[2048];
  z_stream gz_mgr_struct;
  z_streamp gz_mgr = &gz_mgr_struct;
  int fd;
  int have = 0;
  gz_mgr->zalloc = Z_NULL;
  gz_mgr->zfree = Z_NULL;
  gz_mgr->opaque = Z_NULL;
  gz_mgr->next_in = contents;
  gz_mgr->avail_in = contentlength;
  gz_mgr->next_out = buf;
  gz_mgr->avail_out = 2048;
  fd = open("/tmp/out", O_CREAT | O_WRONLY, 0666);
  if ((rc = inflateInit2(gz_mgr, 24)) != Z_OK) {
    fprintf(stderr, "[inflateInit]: error %d\n", rc);
  }
  do {
    rc = inflate(gz_mgr, Z_NO_FLUSH);
    if (rc < 0) {
      fprintf(stderr, "[inflate]: error %d\n", rc);
      break;
    }
    have += 2048 - gz_mgr->avail_out;
    fprintf(stderr, "[inflate]: rc: %d; have: %d\n", rc, have);
    write(fd, buf, 2048 - gz_mgr->avail_out);
    gz_mgr->next_out = buf;
    gz_mgr->avail_out = 2048;
  } while (rc != Z_STREAM_END);
  close(fd);
  if ((rc = inflateEnd(gz_mgr)) != Z_OK) {
    fprintf(stderr, "[inflateEnd]: error %d\n", rc);
  }
}


x86 assembly (clang, -O0):
<http_gunzip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x860,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x848(%rbp),%rax
mov    %rax,-0x850(%rbp)
movl   $0x0,-0x858(%rbp)
mov    0x2e17(%rip),%rax
mov    (%rax),%rcx
mov    -0x850(%rbp),%rax
mov    %rcx,0x30(%rax)
mov    0x2e02(%rip),%rax
mov    (%rax),%rcx
mov    -0x850(%rbp),%rax
mov    %rcx,0x28(%rax)
mov    0x2ded(%rip),%rax
mov    (%rax),%rcx
mov    -0x850(%rbp),%rax
mov    %rcx,0x20(%rax)
mov    -0x8(%rbp),%rcx
mov    -0x850(%rbp),%rax
mov    %rcx,(%rax)
mov    -0xc(%rbp),%ecx
mov    -0x850(%rbp),%rax
mov    %ecx,0x8(%rax)
lea    -0x810(%rbp),%rcx
mov    -0x850(%rbp),%rax
mov    %rcx,0x10(%rax)
mov    -0x850(%rbp),%rax
movl   $0x800,0x18(%rax)
mov    0x2ddd(%rip),%rax
mov    (%rax),%esi
mov    0x2d84(%rip),%rax
or     (%rax),%esi
lea    0xdd3(%rip),%rdi
mov    $0x1b6,%edx
call   1090 <open@plt>
mov    %eax,-0x854(%rbp)
mov    -0x850(%rbp),%rdi
mov    $0x18,%esi
call   1050 <inflateInit2@plt>
mov    %eax,-0x10(%rbp)
mov    0x2d90(%rip),%rcx
cmp    (%rcx),%eax
je     127a <http_gunzip+0x10a>
mov    0x2d61(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%edx
lea    0xd96(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    127f <http_gunzip+0x10f>
mov    -0x850(%rbp),%rdi
mov    0x2d33(%rip),%rax
mov    (%rax),%esi
call   1030 <inflate@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    12c0 <http_gunzip+0x150>
mov    0x2d20(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%edx
lea    0xd6e(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    134e <http_gunzip+0x1de>
mov    -0x850(%rbp),%rcx
mov    $0x800,%eax
sub    0x18(%rcx),%eax
add    -0x858(%rbp),%eax
mov    %eax,-0x858(%rbp)
mov    0x2ce6(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%edx
mov    -0x858(%rbp),%ecx
lea    0xd43(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x854(%rbp),%edi
lea    -0x810(%rbp),%rsi
mov    -0x850(%rbp),%rax
mov    $0x800,%edx
sub    0x18(%rax),%edx
call   1040 <write@plt>
lea    -0x810(%rbp),%rcx
mov    -0x850(%rbp),%rax
mov    %rcx,0x10(%rax)
mov    -0x850(%rbp),%rax
movl   $0x800,0x18(%rax)
mov    -0x10(%rbp),%eax
mov    0x2c92(%rip),%rcx
cmp    (%rcx),%eax
jne    127f <http_gunzip+0x10f>
mov    -0x854(%rbp),%edi
call   1060 <close@plt>
mov    -0x850(%rbp),%rdi
call   1080 <inflateEnd@plt>
mov    %eax,-0x10(%rbp)
mov    0x2c79(%rip),%rcx
cmp    (%rcx),%eax
je     1391 <http_gunzip+0x221>
mov    0x2c4a(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%edx
lea    0xcca(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
add    $0x860,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<http_gunzip>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x848,%rsp
mov    0x2e30(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x38(%rsp)
mov    %rax,0x30(%rsp)
mov    %rax,0x28(%rsp)
mov    %rdi,0x8(%rsp)
mov    %esi,0x10(%rsp)
lea    0x40(%rsp),%r12
mov    %r12,0x18(%rsp)
movl   $0x800,0x20(%rsp)
mov    0x2e3c(%rip),%rax
mov    0x2de5(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe32(%rip),%rdi
mov    $0x1b6,%edx
call   1090 <open@plt>
mov    %eax,%r13d
lea    0x8(%rsp),%rdi
mov    $0x18,%esi
call   1050 <inflateInit2@plt>
mov    0x2df7(%rip),%rcx
cmp    (%rcx),%eax
je     120e <http_gunzip+0x9e>
mov    0x2dcc(%rip),%rcx
mov    (%rcx),%edi
lea    0xe04(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    0x8(%rsp),%r14
mov    0x2dbe(%rip),%r15
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    0x2d99(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1030 <inflate@plt>
mov    %eax,%ebp
test   %eax,%eax
js     1284 <http_gunzip+0x114>
sub    0x20(%rsp),%ebx
add    $0x800,%ebx
mov    0x2d80(%rip),%rax
mov    (%rax),%edi
lea    0xde6(%rip),%rsi
mov    %ebp,%edx
mov    %ebx,%ecx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x800,%edx
sub    0x20(%rsp),%edx
mov    %r13d,%edi
mov    %r12,%rsi
call   1040 <write@plt>
mov    %r12,0x18(%rsp)
movl   $0x800,0x20(%rsp)
cmp    (%r15),%ebp
jne    1220 <http_gunzip+0xb0>
jmp    129d <http_gunzip+0x12d>
mov    0x2d3d(%rip),%rax
mov    (%rax),%edi
lea    0xd8e(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %r13d,%edi
call   1060 <close@plt>
lea    0x8(%rsp),%rdi
call   1080 <inflateEnd@plt>
mov    0x2d32(%rip),%rcx
cmp    (%rcx),%eax
je     12d3 <http_gunzip+0x163>
mov    0x2d07(%rip),%rcx
mov    (%rcx),%edi
lea    0xd8a(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
add    $0x848,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_6__ = type { i8*, i32, i8*, i32, i8*, i8*, i8* }
@Z_NULL = global i8* null
@.str = [9 x i8] c"/tmp/out\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@Z_OK = global i32 0
@stderr = global i32 0
@.str.1 = [25 x i8] c"[inflateInit]: error %d\0A\00"
@Z_NO_FLUSH = global i32 0
@.str.2 = [21 x i8] c"[inflate]: error %d\0A\00"
@.str.3 = [29 x i8] c"[inflate]: rc: %d; have: %d\0A\00"
@Z_STREAM_END = global i32 0
@.str.4 = [24 x i8] c"[inflateEnd]: error %d\0A\00"
define void @http_gunzip(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca [2048 x i8]
%7 = alloca %struct.TYPE_6__
%8 = alloca %struct.TYPE_6__*
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
store %struct.TYPE_6__* %7, %struct.TYPE_6__** %8
store i32 0, i32* %10
%11 = load i8*, i8** @Z_NULL
%12 = load %struct.TYPE_6__*, %struct.TYPE_6__** %8
%13 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %12, i32 0, i32 6
store i8* %11, i8** %13
%14 = load i8*, i8** @Z_NULL
%15 = load %struct.TYPE_6__*, %struct.TYPE_6__** %8
%16 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %15, i32 0, i32 5
store i8* %14, i8** %16
%17 = load i8*, i8** @Z_NULL
%18 = load %struct.TYPE_6__*, %struct.TYPE_6__** %8
%19 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %18, i32 0, i32 4
store i8* %17, i8** %19
%20 = load i8*, i8** %3
%21 = load %struct.TYPE_6__*, %struct.TYPE_6__** %8
%22 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %21, i32 0, i32 0
store i8* %20, i8** %22
%23 = load i32, i32* %4
%24 = load %struct.TYPE_6__*, %struct.TYPE_6__** %8
%25 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %24, i32 0, i32 1
store i32 %23, i32* %25
%26 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%27 = load %struct.TYPE_6__*, %struct.TYPE_6__** %8
%28 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %27, i32 0, i32 2
store i8* %26, i8** %28
%29 = load %struct.TYPE_6__*, %struct.TYPE_6__** %8
%30 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %29, i32 0, i32 3
store i32 2048, i32* %30
%31 = load i32, i32* @O_CREAT
%32 = load i32, i32* @O_WRONLY
%33 = or i32 %31, %32
%34 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %33, i32 438)
store i32 %34, i32* %9
%35 = load %struct.TYPE_6__*, %struct.TYPE_6__** %8
%36 = call i32 @inflateInit2(%struct.TYPE_6__* %35, i32 24)
store i32 %36, i32* %5
%37 = load i32, i32* @Z_OK
%38 = icmp ne i32 %36, %37
br i1 %38, label %39, label %43
39: ; preds = %2
%40 = load i32, i32* @stderr
%41 = load i32, i32* %5
%42 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %41)
br label %43
43: ; preds = %39, %2
br label %44
44: ; preds = %77, %43
%45 = load %struct.TYPE_6__*, %struct.TYPE_6__** %8
%46 = load i32, i32* @Z_NO_FLUSH
%47 = call i32 @inflate(%struct.TYPE_6__* %45, i32 %46)
store i32 %47, i32* %5
%48 = load i32, i32* %5
%49 = icmp slt i32 %48, 0
br i1 %49, label %50, label %54
50: ; preds = %44
%51 = load i32, i32* @stderr
%52 = load i32, i32* %5
%53 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %52)
br label %81
54: ; preds = %44
%55 = load %struct.TYPE_6__*, %struct.TYPE_6__** %8
%56 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %55, i32 0, i32 3
%57 = load i32, i32* %56
%58 = sub nsw i32 2048, %57
%59 = load i32, i32* %10
%60 = add nsw i32 %59, %58
store i32 %60, i32* %10
%61 = load i32, i32* @stderr
%62 = load i32, i32* %5
%63 = load i32, i32* %10
%64 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %61, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i32 %62, i32 %63)
%65 = load i32, i32* %9
%66 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%67 = load %struct.TYPE_6__*, %struct.TYPE_6__** %8
%68 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %67, i32 0, i32 3
%69 = load i32, i32* %68
%70 = sub nsw i32 2048, %69
%71 = call i32 @write(i32 %65, i8* %66, i32 %70)
%72 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%73 = load %struct.TYPE_6__*, %struct.TYPE_6__** %8
%74 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %73, i32 0, i32 2
store i8* %72, i8** %74
%75 = load %struct.TYPE_6__*, %struct.TYPE_6__** %8
%76 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %75, i32 0, i32 3
store i32 2048, i32* %76
br label %77
77: ; preds = %54
%78 = load i32, i32* %5
%79 = load i32, i32* @Z_STREAM_END
%80 = icmp ne i32 %78, %79
br i1 %80, label %44, label %81
81: ; preds = %77, %50
%82 = load i32, i32* %9
%83 = call i32 @close(i32 %82)
%84 = load %struct.TYPE_6__*, %struct.TYPE_6__** %8
%85 = call i32 @inflateEnd(%struct.TYPE_6__* %84)
store i32 %85, i32* %5
%86 = load i32, i32* @Z_OK
%87 = icmp ne i32 %85, %86
br i1 %87, label %88, label %92
88: ; preds = %81
%89 = load i32, i32* @stderr
%90 = load i32, i32* %5
%91 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %89, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i32 %90)
br label %92
92: ; preds = %88, %81
ret void
}

LLVM IR (-O2):
%struct.TYPE_6__ = type { i8*, i32, i8*, i32, i8*, i8*, i8* }
@Z_NULL = global i8* null
@.str = [9 x i8] c"/tmp/out\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@Z_OK = global i32 0
@stderr = global i32 0
@.str.1 = [25 x i8] c"[inflateInit]: error %d\0A\00"
@Z_NO_FLUSH = global i32 0
@.str.2 = [21 x i8] c"[inflate]: error %d\0A\00"
@.str.3 = [29 x i8] c"[inflate]: rc: %d; have: %d\0A\00"
@Z_STREAM_END = global i32 0
@.str.4 = [24 x i8] c"[inflateEnd]: error %d\0A\00"
define void @http_gunzip(i8* %0, i32 %1) {
%3 = alloca [2048 x i8]
%4 = alloca %struct.TYPE_6__
%5 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%6 = bitcast %struct.TYPE_6__* %4 to i8*
%7 = load i8*, i8** @Z_NULL
%8 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %4, i64 0, i32 6
store i8* %7, i8** %8
%9 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %4, i64 0, i32 5
store i8* %7, i8** %9
%10 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %4, i64 0, i32 4
store i8* %7, i8** %10
%11 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %4, i64 0, i32 0
store i8* %0, i8** %11
%12 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %4, i64 0, i32 1
store i32 %1, i32* %12
%13 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %4, i64 0, i32 2
store i8* %5, i8** %13
%14 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %4, i64 0, i32 3
store i32 2048, i32* %14
%15 = load i32, i32* @O_CREAT
%16 = load i32, i32* @O_WRONLY
%17 = or i32 %16, %15
%18 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %17, i32 438)
%19 = call i32 @inflateInit2(%struct.TYPE_6__* %4, i32 24)
%20 = load i32, i32* @Z_OK
%21 = icmp eq i32 %19, %20
br i1 %21, label %25, label %22
22: ; preds = %2
%23 = load i32, i32* @stderr
%24 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %19)
br label %25
25: ; preds = %22, %2
br label %26
26: ; preds = %25, %34
%27 = phi i32 [ %37, %34 ], [ 0, %25 ]
%28 = load i32, i32* @Z_NO_FLUSH
%29 = call i32 @inflate(%struct.TYPE_6__* %4, i32 %28)
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %26
%32 = load i32, i32* @stderr
%33 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %29)
br label %45
34: ; preds = %26
%35 = load i32, i32* %14
%36 = sub nsw i32 2048, %35
%37 = add nsw i32 %36, %27
%38 = load i32, i32* @stderr
%39 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i32 %29, i32 %37)
%40 = load i32, i32* %14
%41 = sub nsw i32 2048, %40
%42 = call i32 @write(i32 %18, i8* %5, i32 %41)
store i8* %5, i8** %13
store i32 2048, i32* %14
%43 = load i32, i32* @Z_STREAM_END
%44 = icmp eq i32 %29, %43
br i1 %44, label %45, label %26
45: ; preds = %34, %31
%46 = call i32 @close(i32 %18)
%47 = call i32 @inflateEnd(%struct.TYPE_6__* %4)
%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 (i32, i8*, i32, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i32 %47)
br label %53
53: ; preds = %50, %45
ret void
}