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

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int /*<<< orphan*/ gzclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *gzopen(char *, char *);
int /*<<< orphan*/ gzwrite(int /*<<< orphan*/ *, char *, int);
int open(char *, int /*<<< orphan*/);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int gcompress(char *filein, char *fileout) {
  gzFile *gf;
  int rfd;
  unsigned char buf[1024];
  int r;
  gf = gzopen(fileout, "wb");
  if (!gf) {
    fprintf(stderr, "decompress %s: %s.\n", fileout, strerror(errno));
    exit(1);
  }
  rfd = open(filein, O_RDONLY);
  if (rfd < 3) {
    fprintf(stderr, "open %s: %s\n", filein, strerror(errno));
    exit(1);
  }
  while (1) {
    r = read(rfd, (char *)&buf, 1024);
    if (r > 0) {
      gzwrite(gf, (char *)&buf, r);
    } else {
      break;
    }
  }
  gzclose(gf);
  close(rfd);
}


x86 assembly (clang, -O0):
<gcompress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x460,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe52(%rip),%rsi
call   1080 <gzopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1210 <gcompress+0x80>
mov    0x2e0f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x444(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x440(%rbp)
mov    0x2ded(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x444(%rbp),%edi
mov    -0x440(%rbp),%rdx
mov    %rax,%rcx
lea    0xe02(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rdi
mov    0x2dcd(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x3,-0x24(%rbp)
jge    127d <gcompress+0xed>
mov    0x2da2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x454(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x450(%rbp)
mov    0x2d80(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x454(%rbp),%edi
mov    -0x450(%rbp),%rdx
mov    %rax,%rcx
lea    0xda9(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    1282 <gcompress+0xf2>
mov    -0x24(%rbp),%edi
lea    -0x430(%rbp),%rsi
mov    $0x400,%edx
call   1050 <read@plt>
mov    %eax,-0x434(%rbp)
cmpl   $0x0,-0x434(%rbp)
jle    12c4 <gcompress+0x134>
mov    -0x20(%rbp),%rdi
lea    -0x430(%rbp),%rsi
mov    -0x434(%rbp),%edx
call   1070 <gzwrite@plt>
jmp    12c9 <gcompress+0x139>
jmp    12ce <gcompress+0x13e>
jmp    1282 <gcompress+0xf2>
mov    -0x20(%rbp),%rdi
call   1030 <gzclose@plt>
mov    -0x24(%rbp),%edi
call   1040 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x460,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gcompress>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %rsi,%rbp
mov    %rdi,%r14
lea    0xe56(%rip),%rsi
mov    %rbp,%rdi
call   1080 <gzopen@plt>
test   %rax,%rax
je     122d <gcompress+0x9d>
mov    %rax,%r15
mov    0x2e27(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1090 <open@plt>
cmp    $0x3,%eax
jl     1252 <gcompress+0xc2>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x400,%edx
call   1050 <read@plt>
test   %eax,%eax
jle    1210 <gcompress+0x80>
mov    %rsp,%rbx
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1070 <gzwrite@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1050 <read@plt>
test   %eax,%eax
jg     11f0 <gcompress+0x60>
mov    %r15,%rdi
call   1030 <gzclose@plt>
mov    %ebp,%edi
call   1040 <close@plt>
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2da4(%rip),%rax
mov    (%rax),%ebx
mov    0x2d93(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xdb8(%rip),%rsi
mov    %ebx,%edi
mov    %rbp,%rdx
jmp    1275 <gcompress+0xe5>
mov    0x2d7f(%rip),%rax
mov    (%rax),%ebx
mov    0x2d6e(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xda7(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %rax,%rcx
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"wb\00"
@stderr = global i32 0
@.str.1 = [20 x i8] c"decompress %s: %s.\0A\00"
@errno = global i32 0
@O_RDONLY = global i32 0
@.str.2 = [13 x i8] c"open %s: %s\0A\00"
define i32 @gcompress(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca [1024 x i8]
%9 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%10 = load i8*, i8** %5
%11 = call i32* @gzopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %6
%12 = load i32*, i32** %6
%13 = icmp ne i32* %12, null
br i1 %13, label %21, label %14
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %5
%17 = load i32, i32* @errno
%18 = call i8* @strerror(i32 %17)
%19 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %16, i8* %18)
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %2
%22 = load i8*, i8** %4
%23 = load i32, i32* @O_RDONLY
%24 = call i32 @open(i8* %22, i32 %23)
store i32 %24, i32* %7
%25 = load i32, i32* %7
%26 = icmp slt i32 %25, 3
br i1 %26, label %27, label %34
27: ; preds = %21
%28 = load i32, i32* @stderr
%29 = load i8*, i8** %4
%30 = load i32, i32* @errno
%31 = call i8* @strerror(i32 %30)
%32 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %29, i8* %31)
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %21
br label %35
35: ; preds = %34, %47
%36 = load i32, i32* %7
%37 = bitcast [1024 x i8]* %8 to i8*
%38 = call i32 @read(i32 %36, i8* %37, i32 1024)
store i32 %38, i32* %9
%39 = load i32, i32* %9
%40 = icmp sgt i32 %39, 0
br i1 %40, label %41, label %46
41: ; preds = %35
%42 = load i32*, i32** %6
%43 = bitcast [1024 x i8]* %8 to i8*
%44 = load i32, i32* %9
%45 = call i32 @gzwrite(i32* %42, i8* %43, i32 %44)
br label %47
46: ; preds = %35
br label %48
47: ; preds = %41
br label %35
48: ; preds = %46
%49 = load i32*, i32** %6
%50 = call i32 @gzclose(i32* %49)
%51 = load i32, i32* %7
%52 = call i32 @close(i32 %51)
%53 = load i32, i32* %3
ret i32 %53
}

LLVM IR (-O2):
@.str = [3 x i8] c"wb\00"
@stderr = global i32 0
@.str.1 = [20 x i8] c"decompress %s: %s.\0A\00"
@errno = global i32 0
@O_RDONLY = global i32 0
@.str.2 = [13 x i8] c"open %s: %s\0A\00"
define i32 @gcompress(i8* %0, i8* %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @gzopen(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %13
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = load i32, i32* @errno
%10 = tail call i8* @strerror(i32 %9)
%11 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %1, i8* %10)
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = load i32, i32* @O_RDONLY
%15 = tail call i32 @open(i8* %0, i32 %14)
%16 = icmp slt i32 %15, 3
br i1 %16, label %20, label %17
17: ; preds = %13
%18 = call i32 @read(i32 %15, i8* %4, i32 1024)
%19 = icmp sgt i32 %18, 0
br i1 %19, label %26, label %31
20: ; preds = %13
%21 = load i32, i32* @stderr
%22 = load i32, i32* @errno
%23 = tail call i8* @strerror(i32 %22)
%24 = tail call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* %23)
%25 = tail call i32 @exit(i32 1)
unreachable
26: ; preds = %17, %26
%27 = phi i32 [ %29, %26 ], [ %18, %17 ]
%28 = call i32 @gzwrite(i32* %5, i8* %4, i32 %27)
%29 = call i32 @read(i32 %15, i8* %4, i32 1024)
%30 = icmp sgt i32 %29, 0
br i1 %30, label %26, label %31
31: ; preds = %26, %17
%32 = call i32 @gzclose(i32* %5)
%33 = call i32 @close(i32 %15)
ret i32 undef
}