#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*/ EXIT_FAILURE;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, ...);
int /*<<< orphan*/ gzclose(int /*<<< orphan*/ *);
scalar_t__ gzeof(int /*<<< orphan*/ *);
char *gzerror(int /*<<< orphan*/ *, int *);
int /*<<< orphan*/ *gzopen(char const *, char *);
int gzread(int /*<<< orphan*/ *, unsigned char *, int);
int /*<<< orphan*/ printf(char *, unsigned char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int gzcat(const char *file_name) {
  gzFile file;
  file = gzopen(file_name, "r");
  if (file == NULL) {
    fprintf(stderr, "Error gzopen of '%s' failed: %s.\n", file_name,
            strerror(errno));
    exit(EXIT_FAILURE);
  }
  while (1) {
    int err;
    int bytes_read;
    unsigned char buffer[0xFFFF];
    bytes_read = gzread(file, buffer, 0xFFFF - 1);
    buffer[bytes_read] = '\0';
    printf("%s", buffer);
    if (bytes_read < 0xFFFF - 1) {
      if (gzeof(file)) {
        break;
      } else {
        const char *error_string;
        error_string = gzerror(file, &err);
        if (err) {
          fprintf(stderr, "Error: %s.\n", error_string);
          exit(EXIT_FAILURE);
        }
      }
    }
  }
  gzclose(file);
  return (0);
}


x86 assembly (clang, -O0):
<gzcat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10040,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe56(%rip),%rsi
call   1090 <gzopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1212 <gzcat+0x82>
mov    0x2e1b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10034(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10030(%rbp)
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x10034(%rbp),%edi
mov    -0x10030(%rbp),%rdx
mov    %rax,%rcx
lea    0xe05(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
jmp    1217 <gzcat+0x87>
mov    -0x10(%rbp),%rdi
lea    -0x10020(%rbp),%rsi
mov    $0xfffe,%edx
call   1060 <gzread@plt>
mov    %eax,-0x18(%rbp)
movslq -0x18(%rbp),%rax
movb   $0x0,-0x10020(%rbp,%rax,1)
lea    -0x10020(%rbp),%rsi
lea    0xddb(%rip),%rdi
call   1040 <printf@plt>
cmpl   $0xfffe,-0x18(%rbp)
jge    12c7 <gzcat+0x137>
mov    -0x10(%rbp),%rdi
call   1050 <gzeof@plt>
cmp    $0x0,%rax
je     1273 <gzcat+0xe3>
jmp    12cc <gzcat+0x13c>
mov    -0x10(%rbp),%rdi
lea    -0x14(%rbp),%rsi
call   1080 <gzerror@plt>
mov    %rax,-0x10028(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     12bd <gzcat+0x12d>
mov    0x2d48(%rip),%rax
mov    (%rax),%edi
mov    -0x10028(%rbp),%rdx
lea    0xd7f(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2d1a(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
jmp    12c2 <gzcat+0x132>
jmp    12c7 <gzcat+0x137>
jmp    1217 <gzcat+0x87>
mov    -0x10(%rbp),%rdi
call   1030 <gzclose@plt>
xor    %eax,%eax
add    $0x10040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gzcat>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10010,%rsp
mov    %rdi,%r14
lea    0xe56(%rip),%rsi
call   1090 <gzopen@plt>
test   %rax,%rax
je     125d <gzcat+0xcd>
mov    %rax,%r13
lea    0x10(%rsp),%r14
lea    0xe5d(%rip),%r15
lea    0xc(%rsp),%r12
nopl   0x0(%rax)
mov    %r13,%rdi
mov    %r14,%rsi
mov    $0xfffe,%edx
call   1060 <gzread@plt>
movslq %eax,%rbx
movb   $0x0,0x10(%rsp,%rbx,1)
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
cmp    $0xfffd,%ebx
jg     11d0 <gzcat+0x40>
mov    %r13,%rdi
call   1050 <gzeof@plt>
test   %rax,%rax
jne    1242 <gzcat+0xb2>
mov    %r13,%rdi
mov    %r12,%rsi
call   1080 <gzerror@plt>
cmpl   $0x0,0xc(%rsp)
je     11d0 <gzcat+0x40>
mov    0x2dbf(%rip),%rcx
mov    (%rcx),%edi
lea    0xdfd(%rip),%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x2d95(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    %r13,%rdi
call   1030 <gzclose@plt>
xor    %eax,%eax
add    $0x10010,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    0x2d7c(%rip),%rax
mov    (%rax),%ebx
mov    0x2d6b(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xd87(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    1234 <gzcat+0xa4>

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

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [34 x i8] c"Error gzopen of '%s' failed: %s.\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [12 x i8] c"Error: %s.\0A\00"
define i32 @gzcat(i8* %0) {
%2 = alloca i32
%3 = alloca [65535 x i8]
%4 = tail call i32* @gzopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %9, label %6
6: ; preds = %1
%7 = bitcast i32* %2 to i8*
%8 = getelementptr inbounds [65535 x i8], [65535 x i8]* %3, i64 0, i64 0
br label %16
9: ; preds = %1
%10 = load i32, i32* @stderr
%11 = load i32, i32* @errno
%12 = tail call i8* @strerror(i32 %11)
%13 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %12)
%14 = load i32, i32* @EXIT_FAILURE
%15 = tail call i32 @exit(i32 %14)
unreachable
16: ; preds = %6, %34
%17 = call i32 @gzread(i32* %4, i8* %8, i32 65534)
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [65535 x i8], [65535 x i8]* %3, i64 0, i64 %18
store i8 0, i8* %19
%20 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %8)
%21 = icmp slt i32 %17, 65534
br i1 %21, label %22, label %34
22: ; preds = %16
%23 = call i64 @gzeof(i32* %4)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %35
25: ; preds = %22
%26 = call i8* @gzerror(i32* %4, i32* %2)
%27 = load i32, i32* %2
%28 = icmp eq i32 %27, 0
br i1 %28, label %34, label %29
29: ; preds = %25
%30 = load i32, i32* @stderr
%31 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %26)
%32 = load i32, i32* @EXIT_FAILURE
%33 = call i32 @exit(i32 %32)
unreachable
34: ; preds = %16, %25
br label %16
35: ; preds = %22
%36 = call i32 @gzclose(i32* %4)
ret i32 0
}