#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 */

/* Type definitions */
typedef int /*<<< orphan*/ uLong;
struct stat {
  int /*<<< orphan*/ st_size;
};
typedef int /*<<< orphan*/ dest_file;
typedef int /*<<< orphan*/ Bytef;

/* Variables and functions */
int /*<<< orphan*/ *MAP_FAILED;
int /*<<< orphan*/ MAP_PRIVATE;
int /*<<< orphan*/ O_RDONLY;
int PATH_MAX;
int /*<<< orphan*/ PROT_READ;
int S_IRUSR;
int S_IWUSR;
scalar_t__ Z_OK;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ close(int);
scalar_t__ compress(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                    int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ compressBound(int /*<<< orphan*/);
int creat(char *, int);
int /*<<< orphan*/ free(int /*<<< orphan*/ *);
int fstat(int, struct stat *);
int /*<<< orphan*/ *malloc(int /*<<< orphan*/);
int /*<<< orphan*/ *mmap(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/, int /*<<< orphan*/, int,
                         int /*<<< orphan*/);
int /*<<< orphan*/ munmap(int /*<<< orphan*/ *, int /*<<< orphan*/);
int open(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *);
int /*<<< orphan*/ write(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
int compress_file(const char *filename) {
  int src_fd, dest_fd;
  struct stat sb;
  Bytef *src, *dest;
  uLong dest_len;
  char dest_file[PATH_MAX];
  src_fd = open(filename, O_RDONLY);
  assert(dest_fd != -1);
  assert(fstat(src_fd, &sb) != -1);
  src = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, src_fd, 0);
  assert(src != MAP_FAILED);
  dest_len = compressBound(sb.st_size);
  dest = malloc(dest_len);
  assert(dest);
  assert(compress(dest, &dest_len, src, sb.st_size) == Z_OK);
  munmap(src, sb.st_size);
  close(src_fd);
  snprintf(dest_file, sizeof(dest_file), "%s.z", filename);
  dest_fd = creat(dest_file, S_IRUSR | S_IWUSR);
  assert(dest_fd != -1);
  write(dest_fd, dest, dest_len);
  close(dest_fd);
  free(dest);
  return 0;
}


x86 assembly (clang, -O0):
<compress_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e05(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x50(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2db9(%rip),%rax
mov    (%rax),%esi
call   10d0 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
mov    -0xc(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   10f0 <fstat@plt>
cmp    $0xffffffff,%eax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
mov    -0x18(%rbp),%esi
mov    0x2da0(%rip),%rax
mov    (%rax),%edx
mov    0x2d4f(%rip),%rax
mov    (%rax),%ecx
mov    -0xc(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1060 <mmap@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    0x2d26(%rip),%rcx
cmp    (%rcx),%rax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
mov    -0x18(%rbp),%edi
call   1080 <compressBound@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%edi
call   10b0 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %eax,%edi
call   10a0 <assert@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x18(%rbp),%ecx
lea    -0x2c(%rbp),%rsi
call   1040 <compress@plt>
mov    0x2d11(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   10c0 <munmap@plt>
mov    -0xc(%rbp),%edi
call   1090 <close@plt>
mov    -0x48(%rbp),%rdi
mov    -0x50(%rbp),%rax
mov    %eax,%esi
mov    -0x8(%rbp),%rcx
lea    0xcf8(%rip),%rdx
call   1070 <snprintf@plt>
mov    -0x48(%rbp),%rdi
mov    0x2ca0(%rip),%rax
mov    (%rax),%esi
mov    0x2ca7(%rip),%rax
or     (%rax),%esi
call   10e0 <creat@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
mov    -0x10(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1050 <write@plt>
mov    -0x10(%rbp),%edi
call   1090 <close@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rax
mov    %rax,%rsp
xor    %eax,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compress_file>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdi,-0x38(%rbp)
mov    %rsp,-0x48(%rbp)
mov    0x2df8(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x40(%rbp)
mov    %rsp,%r13
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
mov    0x2dc2(%rip),%rax
mov    (%rax),%esi
call   10d0 <open@plt>
mov    %eax,%ebx
xor    %edi,%edi
call   10a0 <assert@plt>
lea    -0x30(%rbp),%rsi
mov    %ebx,%edi
call   10f0 <fstat@plt>
xor    %edi,%edi
cmp    $0xffffffff,%eax
setne  %dil
call   10a0 <assert@plt>
mov    -0x30(%rbp),%r14d
mov    0x2db6(%rip),%rax
mov    (%rax),%edx
mov    0x2d65(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %r14d,%esi
mov    %ebx,%r8d
xor    %r9d,%r9d
call   1060 <mmap@plt>
mov    %rax,%r15
mov    0x2d41(%rip),%rax
xor    %edi,%edi
cmp    (%rax),%r15
setne  %dil
call   10a0 <assert@plt>
mov    %r14d,%edi
call   1080 <compressBound@plt>
mov    %eax,-0x2c(%rbp)
mov    %eax,%edi
call   10b0 <malloc@plt>
mov    %rax,%r12
mov    %r12d,%edi
call   10a0 <assert@plt>
lea    -0x2c(%rbp),%rsi
mov    %r12,%rdi
mov    %r15,%rdx
mov    %r14d,%ecx
call   1040 <compress@plt>
mov    0x2d35(%rip),%rcx
xor    %edi,%edi
cmp    (%rcx),%rax
sete   %dil
call   10a0 <assert@plt>
mov    %r15,%rdi
mov    %r14d,%esi
call   10c0 <munmap@plt>
mov    %ebx,%edi
call   1090 <close@plt>
lea    0xd2e(%rip),%rdx
mov    %r13,%rdi
mov    -0x40(%rbp),%rsi
mov    -0x38(%rbp),%rcx
call   1070 <snprintf@plt>
mov    0x2ccf(%rip),%rax
mov    0x2cd8(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %r13,%rdi
call   10e0 <creat@plt>
mov    %eax,%ebx
xor    %edi,%edi
cmp    $0xffffffff,%eax
setne  %dil
call   10a0 <assert@plt>
mov    -0x2c(%rbp),%edx
mov    %ebx,%edi
mov    %r12,%rsi
call   1050 <write@plt>
mov    %ebx,%edi
call   1090 <close@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    -0x48(%rbp),%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@PATH_MAX = global i32 0
@O_RDONLY = global i32 0
@PROT_READ = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_FAILED = global i32* null
@Z_OK = global i64 0
@.str = [5 x i8] c"%s.z\00"
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
define i32 @compress_file(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.stat
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i64
store i8* %0, i8** %2
%11 = load i32, i32* @PATH_MAX
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %9
%14 = alloca i8, i64 %12
store i64 %12, i64* %10
%15 = load i8*, i8** %2
%16 = load i32, i32* @O_RDONLY
%17 = call i32 @open(i8* %15, i32 %16)
store i32 %17, i32* %3
%18 = load i32, i32* %4
%19 = icmp ne i32 %18, -1
%20 = zext i1 %19 to i32
%21 = call i32 @assert(i32 %20)
%22 = load i32, i32* %3
%23 = call i32 @fstat(i32 %22, %struct.stat* %5)
%24 = icmp ne i32 %23, -1
%25 = zext i1 %24 to i32
%26 = call i32 @assert(i32 %25)
%27 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%28 = load i32, i32* %27
%29 = load i32, i32* @PROT_READ
%30 = load i32, i32* @MAP_PRIVATE
%31 = load i32, i32* %3
%32 = call i32* @mmap(i32* null, i32 %28, i32 %29, i32 %30, i32 %31, i32 0)
store i32* %32, i32** %6
%33 = load i32*, i32** %6
%34 = load i32*, i32** @MAP_FAILED
%35 = icmp ne i32* %33, %34
%36 = zext i1 %35 to i32
%37 = call i32 @assert(i32 %36)
%38 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%39 = load i32, i32* %38
%40 = call i32 @compressBound(i32 %39)
store i32 %40, i32* %8
%41 = load i32, i32* %8
%42 = call i32* @malloc(i32 %41)
store i32* %42, i32** %7
%43 = load i32*, i32** %7
%44 = ptrtoint i32* %43 to i32
%45 = call i32 @assert(i32 %44)
%46 = load i32*, i32** %7
%47 = load i32*, i32** %6
%48 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%49 = load i32, i32* %48
%50 = call i64 @compress(i32* %46, i32* %8, i32* %47, i32 %49)
%51 = load i64, i64* @Z_OK
%52 = icmp eq i64 %50, %51
%53 = zext i1 %52 to i32
%54 = call i32 @assert(i32 %53)
%55 = load i32*, i32** %6
%56 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%57 = load i32, i32* %56
%58 = call i32 @munmap(i32* %55, i32 %57)
%59 = load i32, i32* %3
%60 = call i32 @close(i32 %59)
%61 = trunc i64 %12 to i32
%62 = load i8*, i8** %2
%63 = call i32 @snprintf(i8* %14, i32 %61, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %62)
%64 = load i32, i32* @S_IRUSR
%65 = load i32, i32* @S_IWUSR
%66 = or i32 %64, %65
%67 = call i32 @creat(i8* %14, i32 %66)
store i32 %67, i32* %4
%68 = load i32, i32* %4
%69 = icmp ne i32 %68, -1
%70 = zext i1 %69 to i32
%71 = call i32 @assert(i32 %70)
%72 = load i32, i32* %4
%73 = load i32*, i32** %7
%74 = load i32, i32* %8
%75 = call i32 @write(i32 %72, i32* %73, i32 %74)
%76 = load i32, i32* %4
%77 = call i32 @close(i32 %76)
%78 = load i32*, i32** %7
%79 = call i32 @free(i32* %78)
%80 = load i8*, i8** %9
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@PATH_MAX = global i32 0
@O_RDONLY = global i32 0
@PROT_READ = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_FAILED = global i32* null
@Z_OK = global i64 0
@.str = [5 x i8] c"%s.z\00"
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
define i32 @compress_file(i8* %0) {
%2 = alloca %struct.stat
%3 = alloca i32
%4 = bitcast %struct.stat* %2 to i8*
%5 = bitcast i32* %3 to i8*
%6 = load i32, i32* @PATH_MAX
%7 = zext i32 %6 to i64
%8 = tail call i8* @llvm.stacksave()
%9 = alloca i8, i64 %7
%10 = load i32, i32* @O_RDONLY
%11 = tail call i32 @open(i8* %0, i32 %10)
%12 = tail call i32 @assert(i32 0)
%13 = call i32 @fstat(i32 %11, %struct.stat* %2)
%14 = icmp ne i32 %13, -1
%15 = zext i1 %14 to i32
%16 = tail call i32 @assert(i32 %15)
%17 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%18 = load i32, i32* %17
%19 = load i32, i32* @PROT_READ
%20 = load i32, i32* @MAP_PRIVATE
%21 = tail call i32* @mmap(i32* null, i32 %18, i32 %19, i32 %20, i32 %11, i32 0)
%22 = load i32*, i32** @MAP_FAILED
%23 = icmp ne i32* %21, %22
%24 = zext i1 %23 to i32
%25 = tail call i32 @assert(i32 %24)
%26 = tail call i32 @compressBound(i32 %18)
store i32 %26, i32* %3
%27 = tail call i32* @malloc(i32 %26)
%28 = ptrtoint i32* %27 to i64
%29 = trunc i64 %28 to i32
%30 = tail call i32 @assert(i32 %29)
%31 = call i64 @compress(i32* %27, i32* %3, i32* %21, i32 %18)
%32 = load i64, i64* @Z_OK
%33 = icmp eq i64 %31, %32
%34 = zext i1 %33 to i32
%35 = call i32 @assert(i32 %34)
%36 = call i32 @munmap(i32* %21, i32 %18)
%37 = call i32 @close(i32 %11)
%38 = call i32 @snprintf(i8* %9, i32 %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %0)
%39 = load i32, i32* @S_IRUSR
%40 = load i32, i32* @S_IWUSR
%41 = or i32 %40, %39
%42 = call i32 @creat(i8* %9, i32 %41)
%43 = icmp ne i32 %42, -1
%44 = zext i1 %43 to i32
%45 = call i32 @assert(i32 %44)
%46 = load i32, i32* %3
%47 = call i32 @write(i32 %42, i32* %27, i32 %46)
%48 = call i32 @close(i32 %42)
%49 = call i32 @free(i32* %27)
ret i32 0
}