#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 O_CREAT;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ gzclose(int /*<<< orphan*/ *);
scalar_t__ gzeof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *gzopen(char *, char *);
int gzread(int /*<<< orphan*/ *, char *, int);
int open(char *, int, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char *, int);
int degcompress(char *filein, char *fileout) {
  gzFile *gf;
  int wfd;
  unsigned char buf[1024];
  int r;
  gf = gzopen(filein, "rb");
  if (!gf) {
    fprintf(stderr, "decompress %s: %s.\n", filein, strerror(errno));
  }
  wfd = open(fileout, O_CREAT | O_WRONLY | O_TRUNC, 0666);
  if (wfd < 3) {
    fprintf(stderr, "open %s: %s\n", fileout, strerror(errno));
    exit(1);
  }
  while (1) {
    r = gzread(gf, (char *)&buf, 1024);
    if (r > 0) {
      write(wfd, (char *)&buf, r);
    } else {
      if (gzeof(gf))
        break;
      fprintf(stderr, "gzip error\n");
      break;
    }
  }
  gzclose(gf);
  close(wfd);
}


x86 assembly (clang, -O0):
<degcompress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x460,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe42(%rip),%rsi
call   1090 <gzopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1218 <degcompress+0x78>
mov    0x2df7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x444(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x440(%rbp)
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x444(%rbp),%edi
mov    -0x440(%rbp),%rdx
mov    %rax,%rcx
lea    0xdf2(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x18(%rbp),%rdi
mov    0x2dd5(%rip),%rax
mov    (%rax),%esi
mov    0x2d8c(%rip),%rax
or     (%rax),%esi
mov    0x2dbb(%rip),%rax
or     (%rax),%esi
mov    $0x1b6,%edx
call   10a0 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x3,-0x24(%rbp)
jge    129e <degcompress+0xfe>
mov    0x2d7b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x454(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x450(%rbp)
mov    0x2d59(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x454(%rbp),%edi
mov    -0x450(%rbp),%rdx
mov    %rax,%rcx
lea    0xd8a(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
jmp    12a3 <degcompress+0x103>
mov    -0x20(%rbp),%rdi
lea    -0x430(%rbp),%rsi
mov    $0x400,%edx
call   1070 <gzread@plt>
mov    %eax,-0x434(%rbp)
cmpl   $0x0,-0x434(%rbp)
jle    12e5 <degcompress+0x145>
mov    -0x24(%rbp),%edi
lea    -0x430(%rbp),%rsi
mov    -0x434(%rbp),%edx
call   1040 <write@plt>
jmp    1319 <degcompress+0x179>
mov    -0x20(%rbp),%rdi
call   1050 <gzeof@plt>
cmp    $0x0,%rax
je     12fd <degcompress+0x15d>
jmp    131e <degcompress+0x17e>
mov    0x2ccc(%rip),%rax
mov    (%rax),%edi
lea    0xd17(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    131e <degcompress+0x17e>
jmp    12a3 <degcompress+0x103>
mov    -0x20(%rbp),%rdi
call   1030 <gzclose@plt>
mov    -0x24(%rbp),%edi
call   1060 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x460,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<degcompress>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %rsi,%r14
mov    %rdi,%rbp
lea    0xe46(%rip),%rsi
call   1090 <gzopen@plt>
mov    %rax,%r15
test   %rax,%rax
jne    11f4 <degcompress+0x54>
mov    0x2e02(%rip),%rax
mov    (%rax),%ebx
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
lea    0xe1e(%rip),%rsi
mov    %ebx,%edi
mov    %rbp,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    0x2dfd(%rip),%rax
mov    0x2db6(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2de3(%rip),%rax
or     (%rax),%esi
mov    %r14,%rdi
mov    $0x1b6,%edx
call   10a0 <open@plt>
cmp    $0x3,%eax
jl     12a1 <degcompress+0x101>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    %r15,%rdi
mov    $0x400,%edx
call   1070 <gzread@plt>
test   %eax,%eax
jle    1260 <degcompress+0xc0>
mov    %rsp,%rbx
xchg   %ax,%ax
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1070 <gzread@plt>
test   %eax,%eax
jg     1240 <degcompress+0xa0>
mov    %r15,%rdi
call   1050 <gzeof@plt>
test   %rax,%rax
jne    1284 <degcompress+0xe4>
mov    0x2d5c(%rip),%rax
mov    (%rax),%edi
lea    0xda7(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    %r15,%rdi
call   1030 <gzclose@plt>
mov    %ebp,%edi
call   1060 <close@plt>
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d28(%rip),%rax
mov    (%rax),%ebx
mov    0x2d17(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
lea    0xd58(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [20 x i8] c"decompress %s: %s.\0A\00"
@errno = global i32 0
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@.str.2 = [13 x i8] c"open %s: %s\0A\00"
@.str.3 = [12 x i8] c"gzip error\0A\00"
define i32 @degcompress(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** %4
%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 %20, label %14
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %4
%17 = load i32, i32* @errno
%18 = call i8* @strerror(i32 %17)
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %16, i8* %18)
br label %20
20: ; preds = %14, %2
%21 = load i8*, i8** %5
%22 = load i32, i32* @O_CREAT
%23 = load i32, i32* @O_WRONLY
%24 = or i32 %22, %23
%25 = load i32, i32* @O_TRUNC
%26 = or i32 %24, %25
%27 = call i32 @open(i8* %21, i32 %26, i32 438)
store i32 %27, i32* %7
%28 = load i32, i32* %7
%29 = icmp slt i32 %28, 3
br i1 %29, label %30, label %37
30: ; preds = %20
%31 = load i32, i32* @stderr
%32 = load i8*, i8** %5
%33 = load i32, i32* @errno
%34 = call i8* @strerror(i32 %33)
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %32, i8* %34)
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %20
br label %38
38: ; preds = %37, %57
%39 = load i32*, i32** %6
%40 = bitcast [1024 x i8]* %8 to i8*
%41 = call i32 @gzread(i32* %39, i8* %40, i32 1024)
store i32 %41, i32* %9
%42 = load i32, i32* %9
%43 = icmp sgt i32 %42, 0
br i1 %43, label %44, label %49
44: ; preds = %38
%45 = load i32, i32* %7
%46 = bitcast [1024 x i8]* %8 to i8*
%47 = load i32, i32* %9
%48 = call i32 @write(i32 %45, i8* %46, i32 %47)
br label %57
49: ; preds = %38
%50 = load i32*, i32** %6
%51 = call i64 @gzeof(i32* %50)
%52 = icmp ne i64 %51, 0
br i1 %52, label %53, label %54
53: ; preds = %49
br label %58
54: ; preds = %49
%55 = load i32, i32* @stderr
%56 = call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
br label %58
57: ; preds = %44
br label %38
58: ; preds = %54, %53
%59 = load i32*, i32** %6
%60 = call i32 @gzclose(i32* %59)
%61 = load i32, i32* %7
%62 = call i32 @close(i32 %61)
%63 = load i32, i32* %3
ret i32 %63
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [20 x i8] c"decompress %s: %s.\0A\00"
@errno = global i32 0
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@.str.2 = [13 x i8] c"open %s: %s\0A\00"
@.str.3 = [12 x i8] c"gzip error\0A\00"
define i32 @degcompress(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* %0, 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 %12
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = load i32, i32* @errno
%10 = tail call i8* @strerror(i32 %9)
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %10)
br label %12
12: ; preds = %7, %2
%13 = load i32, i32* @O_CREAT
%14 = load i32, i32* @O_WRONLY
%15 = or i32 %14, %13
%16 = load i32, i32* @O_TRUNC
%17 = or i32 %15, %16
%18 = tail call i32 @open(i8* %1, i32 %17, i32 438)
%19 = icmp slt i32 %18, 3
br i1 %19, label %23, label %20
20: ; preds = %12
%21 = call i32 @gzread(i32* %5, i8* %4, i32 1024)
%22 = icmp sgt i32 %21, 0
br i1 %22, label %29, label %34
23: ; preds = %12
%24 = load i32, i32* @stderr
%25 = load i32, i32* @errno
%26 = tail call i8* @strerror(i32 %25)
%27 = tail call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %1, i8* %26)
%28 = tail call i32 @exit(i32 1)
unreachable
29: ; preds = %20, %29
%30 = phi i32 [ %32, %29 ], [ %21, %20 ]
%31 = call i32 @write(i32 %18, i8* %4, i32 %30)
%32 = call i32 @gzread(i32* %5, i8* %4, i32 1024)
%33 = icmp sgt i32 %32, 0
br i1 %33, label %29, label %34
34: ; preds = %29, %20
%35 = call i64 @gzeof(i32* %5)
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %34
%38 = load i32, i32* @stderr
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
br label %40
40: ; preds = %34, %37
%41 = call i32 @gzclose(i32* %5)
%42 = call i32 @close(i32 %18)
ret i32 undef
}