#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_DEFAULT_COMPRESSION;
int /*<<< orphan*/ Z_DEFAULT_STRATEGY;
int /*<<< orphan*/ Z_DEFLATED;
int /*<<< orphan*/ Z_FINISH;
void *Z_NULL;
int Z_OK;
int Z_STREAM_END;
int /*<<< orphan*/ close(int);
int deflate(TYPE_1__ *, int /*<<< orphan*/);
int deflateEnd(TYPE_1__ *);
int deflateInit2(TYPE_1__ *, int /*<<< orphan*/, int /*<<< orphan*/, int, int,
                 int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int open(char *, int, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ write(int, char *, int);
void http_gzip(char *contents, int contentlength) {
  int rc;
  char buf[16384];
  z_stream gz_mgr_struct;
  z_streamp gz_mgr = &gz_mgr_struct;
  int fd;
  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 = 16384;
  fd = open("/tmp/xyz", O_CREAT | O_WRONLY, 0666);
  if ((rc = deflateInit2(gz_mgr, Z_DEFAULT_COMPRESSION, Z_DEFLATED, 24, 8,
                         Z_DEFAULT_STRATEGY)) != Z_OK) {
    fprintf(stderr, "[deflateInit2]: error %d\n", rc);
  }
  rc = deflate(gz_mgr, Z_FINISH);
  if (rc != Z_STREAM_END) {
    fprintf(stderr, "[deflate]: error %d\n", rc);
  }
  write(fd, buf, 16384 - gz_mgr->avail_out);
  close(fd);
  if ((rc = deflateEnd(gz_mgr)) != Z_OK) {
    fprintf(stderr, "[deflateEnd]: error %d\n", rc);
  }
}


x86 assembly (clang, -O0):
<http_gzip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4060,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x4048(%rbp),%rax
mov    %rax,-0x4050(%rbp)
mov    0x2e19(%rip),%rax
mov    (%rax),%rcx
mov    -0x4050(%rbp),%rax
mov    %rcx,0x30(%rax)
mov    0x2e04(%rip),%rax
mov    (%rax),%rcx
mov    -0x4050(%rbp),%rax
mov    %rcx,0x28(%rax)
mov    0x2def(%rip),%rax
mov    (%rax),%rcx
mov    -0x4050(%rbp),%rax
mov    %rcx,0x20(%rax)
mov    -0x8(%rbp),%rcx
mov    -0x4050(%rbp),%rax
mov    %rcx,(%rax)
mov    -0xc(%rbp),%ecx
mov    -0x4050(%rbp),%rax
mov    %ecx,0x8(%rax)
lea    -0x4010(%rbp),%rcx
mov    -0x4050(%rbp),%rax
mov    %rcx,0x10(%rax)
mov    -0x4050(%rbp),%rax
movl   $0x4000,0x18(%rax)
mov    0x2de7(%rip),%rax
mov    (%rax),%esi
mov    0x2d76(%rip),%rax
or     (%rax),%esi
lea    0xddd(%rip),%rdi
mov    $0x1b6,%edx
call   1080 <open@plt>
mov    %eax,-0x4054(%rbp)
mov    -0x4050(%rbp),%rdi
mov    0x2d77(%rip),%rax
mov    (%rax),%esi
mov    0x2d76(%rip),%rax
mov    (%rax),%edx
mov    0x2d45(%rip),%rax
mov    (%rax),%r9d
mov    $0x18,%ecx
mov    $0x8,%r8d
call   1090 <deflateInit2@plt>
mov    %eax,-0x10(%rbp)
mov    0x2d78(%rip),%rcx
cmp    (%rcx),%eax
je     1290 <http_gzip+0x120>
mov    0x2d49(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%edx
lea    0xd7e(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x4050(%rbp),%rdi
mov    0x2d0a(%rip),%rax
mov    (%rax),%esi
call   1040 <deflate@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    0x2d26(%rip),%rcx
cmp    (%rcx),%eax
je     12d2 <http_gzip+0x162>
mov    0x2d07(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%edx
lea    0xd56(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x4054(%rbp),%edi
lea    -0x4010(%rbp),%rsi
mov    -0x4050(%rbp),%rax
mov    $0x4000,%edx
sub    0x18(%rax),%edx
call   1030 <write@plt>
mov    -0x4054(%rbp),%edi
call   1050 <close@plt>
mov    -0x4050(%rbp),%rdi
call   1070 <deflateEnd@plt>
mov    %eax,-0x10(%rbp)
mov    0x2cd4(%rip),%rcx
cmp    (%rcx),%eax
je     1334 <http_gzip+0x1c4>
mov    0x2ca5(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%edx
lea    0xd09(%rip),%rsi
call   1060 <fprintf@plt>
add    $0x4060,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<http_gzip>:
push   %r14
push   %rbx
sub    $0x4048,%rsp
mov    0x2e2f(%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),%rax
mov    %rax,0x18(%rsp)
movl   $0x4000,0x20(%rsp)
mov    0x2e43(%rip),%rax
mov    0x2dd4(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe39(%rip),%rdi
mov    $0x1b6,%edx
call   1080 <open@plt>
mov    %eax,%ebx
mov    0x2dde(%rip),%rax
mov    (%rax),%esi
mov    0x2ddd(%rip),%rax
mov    (%rax),%edx
mov    0x2dac(%rip),%rax
mov    (%rax),%r9d
lea    0x8(%rsp),%rdi
mov    $0x18,%ecx
mov    $0x8,%r8d
call   1090 <deflateInit2@plt>
mov    0x2ddd(%rip),%r14
cmp    (%r14),%eax
je     1227 <http_gzip+0xb7>
mov    0x2db1(%rip),%rcx
mov    (%rcx),%edi
lea    0xde9(%rip),%rsi
mov    %eax,%edx
call   1060 <fprintf@plt>
mov    0x2d7a(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdi
call   1040 <deflate@plt>
mov    0x2d97(%rip),%rcx
cmp    (%rcx),%eax
je     125c <http_gzip+0xec>
mov    0x2d7c(%rip),%rcx
mov    (%rcx),%edi
lea    0xdce(%rip),%rsi
mov    %eax,%edx
call   1060 <fprintf@plt>
mov    $0x4000,%edx
sub    0x20(%rsp),%edx
lea    0x40(%rsp),%rsi
mov    %ebx,%edi
call   1030 <write@plt>
mov    %ebx,%edi
call   1050 <close@plt>
lea    0x8(%rsp),%rdi
call   1070 <deflateEnd@plt>
cmp    (%r14),%eax
je     129e <http_gzip+0x12e>
mov    0x2d3a(%rip),%rcx
mov    (%rcx),%edi
lea    0xda1(%rip),%rsi
mov    %eax,%edx
call   1060 <fprintf@plt>
add    $0x4048,%rsp
pop    %rbx
pop    %r14
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/xyz\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@Z_DEFAULT_COMPRESSION = global i32 0
@Z_DEFLATED = global i32 0
@Z_DEFAULT_STRATEGY = global i32 0
@Z_OK = global i32 0
@stderr = global i32 0
@.str.1 = [26 x i8] c"[deflateInit2]: error %d\0A\00"
@Z_FINISH = global i32 0
@Z_STREAM_END = global i32 0
@.str.2 = [21 x i8] c"[deflate]: error %d\0A\00"
@.str.3 = [24 x i8] c"[deflateEnd]: error %d\0A\00"
define void @http_gzip(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca [16384 x i8]
%7 = alloca %struct.TYPE_6__
%8 = alloca %struct.TYPE_6__*
%9 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
store %struct.TYPE_6__* %7, %struct.TYPE_6__** %8
%10 = load i8*, i8** @Z_NULL
%11 = load %struct.TYPE_6__*, %struct.TYPE_6__** %8
%12 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %11, i32 0, i32 6
store i8* %10, i8** %12
%13 = load i8*, i8** @Z_NULL
%14 = load %struct.TYPE_6__*, %struct.TYPE_6__** %8
%15 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %14, i32 0, i32 5
store i8* %13, i8** %15
%16 = load i8*, i8** @Z_NULL
%17 = load %struct.TYPE_6__*, %struct.TYPE_6__** %8
%18 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %17, i32 0, i32 4
store i8* %16, i8** %18
%19 = load i8*, i8** %3
%20 = load %struct.TYPE_6__*, %struct.TYPE_6__** %8
%21 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %20, i32 0, i32 0
store i8* %19, i8** %21
%22 = load i32, i32* %4
%23 = load %struct.TYPE_6__*, %struct.TYPE_6__** %8
%24 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %23, i32 0, i32 1
store i32 %22, i32* %24
%25 = getelementptr inbounds [16384 x i8], [16384 x i8]* %6, i64 0, i64 0
%26 = load %struct.TYPE_6__*, %struct.TYPE_6__** %8
%27 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %26, i32 0, i32 2
store i8* %25, i8** %27
%28 = load %struct.TYPE_6__*, %struct.TYPE_6__** %8
%29 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %28, i32 0, i32 3
store i32 16384, i32* %29
%30 = load i32, i32* @O_CREAT
%31 = load i32, i32* @O_WRONLY
%32 = or i32 %30, %31
%33 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %32, i32 438)
store i32 %33, i32* %9
%34 = load %struct.TYPE_6__*, %struct.TYPE_6__** %8
%35 = load i32, i32* @Z_DEFAULT_COMPRESSION
%36 = load i32, i32* @Z_DEFLATED
%37 = load i32, i32* @Z_DEFAULT_STRATEGY
%38 = call i32 @deflateInit2(%struct.TYPE_6__* %34, i32 %35, i32 %36, i32 24, i32 8, i32 %37)
store i32 %38, i32* %5
%39 = load i32, i32* @Z_OK
%40 = icmp ne i32 %38, %39
br i1 %40, label %41, label %45
41: ; preds = %2
%42 = load i32, i32* @stderr
%43 = load i32, i32* %5
%44 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %43)
br label %45
45: ; preds = %41, %2
%46 = load %struct.TYPE_6__*, %struct.TYPE_6__** %8
%47 = load i32, i32* @Z_FINISH
%48 = call i32 @deflate(%struct.TYPE_6__* %46, i32 %47)
store i32 %48, i32* %5
%49 = load i32, i32* %5
%50 = load i32, i32* @Z_STREAM_END
%51 = icmp ne i32 %49, %50
br i1 %51, label %52, label %56
52: ; preds = %45
%53 = load i32, i32* @stderr
%54 = load i32, i32* %5
%55 = call i32 @fprintf(i32 %53, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %54)
br label %56
56: ; preds = %52, %45
%57 = load i32, i32* %9
%58 = getelementptr inbounds [16384 x i8], [16384 x i8]* %6, i64 0, i64 0
%59 = load %struct.TYPE_6__*, %struct.TYPE_6__** %8
%60 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %59, i32 0, i32 3
%61 = load i32, i32* %60
%62 = sub nsw i32 16384, %61
%63 = call i32 @write(i32 %57, i8* %58, i32 %62)
%64 = load i32, i32* %9
%65 = call i32 @close(i32 %64)
%66 = load %struct.TYPE_6__*, %struct.TYPE_6__** %8
%67 = call i32 @deflateEnd(%struct.TYPE_6__* %66)
store i32 %67, i32* %5
%68 = load i32, i32* @Z_OK
%69 = icmp ne i32 %67, %68
br i1 %69, label %70, label %74
70: ; preds = %56
%71 = load i32, i32* @stderr
%72 = load i32, i32* %5
%73 = call i32 @fprintf(i32 %71, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %72)
br label %74
74: ; preds = %70, %56
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/xyz\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@Z_DEFAULT_COMPRESSION = global i32 0
@Z_DEFLATED = global i32 0
@Z_DEFAULT_STRATEGY = global i32 0
@Z_OK = global i32 0
@stderr = global i32 0
@.str.1 = [26 x i8] c"[deflateInit2]: error %d\0A\00"
@Z_FINISH = global i32 0
@Z_STREAM_END = global i32 0
@.str.2 = [21 x i8] c"[deflate]: error %d\0A\00"
@.str.3 = [24 x i8] c"[deflateEnd]: error %d\0A\00"
define void @http_gzip(i8* %0, i32 %1) {
%3 = alloca [16384 x i8]
%4 = alloca %struct.TYPE_6__
%5 = getelementptr inbounds [16384 x i8], [16384 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 16384, 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 = load i32, i32* @Z_DEFAULT_COMPRESSION
%20 = load i32, i32* @Z_DEFLATED
%21 = load i32, i32* @Z_DEFAULT_STRATEGY
%22 = call i32 @deflateInit2(%struct.TYPE_6__* %4, i32 %19, i32 %20, i32 24, i32 8, i32 %21)
%23 = load i32, i32* @Z_OK
%24 = icmp eq i32 %22, %23
br i1 %24, label %28, label %25
25: ; preds = %2
%26 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %22)
br label %28
28: ; preds = %25, %2
%29 = load i32, i32* @Z_FINISH
%30 = call i32 @deflate(%struct.TYPE_6__* %4, i32 %29)
%31 = load i32, i32* @Z_STREAM_END
%32 = icmp eq i32 %30, %31
br i1 %32, label %36, label %33
33: ; preds = %28
%34 = load i32, i32* @stderr
%35 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %30)
br label %36
36: ; preds = %33, %28
%37 = load i32, i32* %14
%38 = sub nsw i32 16384, %37
%39 = call i32 @write(i32 %18, i8* %5, i32 %38)
%40 = call i32 @close(i32 %18)
%41 = call i32 @deflateEnd(%struct.TYPE_6__* %4)
%42 = load i32, i32* @Z_OK
%43 = icmp eq i32 %41, %42
br i1 %43, label %47, label %44
44: ; preds = %36
%45 = load i32, i32* @stderr
%46 = call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %41)
br label %47
47: ; preds = %44, %36
ret void
}