#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 */
struct stat {
  int st_size;
};

/* Variables and functions */
int /*<<< orphan*/ MAP_SHARED;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ PROT_READ;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ fstat(int, struct stat *);
int /*<<< orphan*/ http_gunzip(char *, int);
char *mmap(int /*<<< orphan*/, int, int /*<<< orphan*/, int /*<<< orphan*/, int,
           int /*<<< orphan*/);
int /*<<< orphan*/ munmap(char *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  char *buf;
  int len;
  struct stat filestat;
  int fd;
  fd = open("/tmp/xyz", O_RDONLY);
  fstat(fd, &filestat);
  len = filestat.st_size;
  fprintf(stderr, "File has size: %d\n", len);
  buf = mmap(0, len, PROT_READ, MAP_SHARED, fd, 0);
  http_gunzip(buf, len);
  munmap(buf, len);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e4b(%rip),%rax
mov    (%rax),%esi
lea    0xe6a(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1080 <fstat@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
lea    0xe46(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x1c(%rbp),%esi
mov    0x2e26(%rip),%rax
mov    (%rax),%edx
mov    0x2e0d(%rip),%rax
mov    (%rax),%ecx
mov    -0x24(%rbp),%r8d
xor    %r9d,%r9d
mov    %r9d,%edi
call   1030 <mmap@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1090 <http_gunzip@plt>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1060 <munmap@plt>
mov    -0x24(%rbp),%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e59(%rip),%rax
mov    (%rax),%esi
lea    0xe78(%rip),%rdi
call   1070 <open@plt>
mov    %eax,%r14d
lea    0x8(%rsp),%rsi
mov    %eax,%edi
call   1080 <fstat@plt>
mov    0x8(%rsp),%ebp
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
lea    0xe59(%rip),%rsi
mov    %ebp,%edx
call   1050 <fprintf@plt>
mov    0x2e3a(%rip),%rax
mov    (%rax),%edx
mov    0x2e21(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %ebp,%esi
mov    %r14d,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %ebp,%esi
call   1090 <http_gunzip@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1060 <munmap@plt>
mov    %r14d,%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [9 x i8] c"/tmp/xyz\00"
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.1 = [19 x i8] c"File has size: %d\0A\00"
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca %struct.stat
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* @O_RDONLY
%11 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %10)
store i32 %11, i32* %9
%12 = load i32, i32* %9
%13 = call i32 @fstat(i32 %12, %struct.stat* %8)
%14 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%15 = load i32, i32* %14
store i32 %15, i32* %7
%16 = load i32, i32* @stderr
%17 = load i32, i32* %7
%18 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %17)
%19 = load i32, i32* %7
%20 = load i32, i32* @PROT_READ
%21 = load i32, i32* @MAP_SHARED
%22 = load i32, i32* %9
%23 = call i8* @mmap(i32 0, i32 %19, i32 %20, i32 %21, i32 %22, i32 0)
store i8* %23, i8** %6
%24 = load i8*, i8** %6
%25 = load i32, i32* %7
%26 = call i32 @http_gunzip(i8* %24, i32 %25)
%27 = load i8*, i8** %6
%28 = load i32, i32* %7
%29 = call i32 @munmap(i8* %27, i32 %28)
%30 = load i32, i32* %9
%31 = call i32 @close(i32 %30)
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [9 x i8] c"/tmp/xyz\00"
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.1 = [19 x i8] c"File has size: %d\0A\00"
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = load i32, i32* @O_RDONLY
%6 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = call i32 @fstat(i32 %6, %struct.stat* %3)
%8 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%9 = load i32, i32* %8
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%12 = load i32, i32* @PROT_READ
%13 = load i32, i32* @MAP_SHARED
%14 = tail call i8* @mmap(i32 0, i32 %9, i32 %12, i32 %13, i32 %6, i32 0)
%15 = tail call i32 @http_gunzip(i8* %14, i32 %9)
%16 = tail call i32 @munmap(i8* %14, i32 %9)
%17 = tail call i32 @close(i32 %6)
ret i32 0
}