#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;
typedef int /*<<< orphan*/ buf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ Z_OK;
scalar_t__ fclose(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
scalar_t__ fread(char *, int, int, int /*<<< orphan*/ *);
scalar_t__ gzclose(int /*<<< orphan*/);
char *gzerror(int /*<<< orphan*/, int *);
int gzwrite(int /*<<< orphan*/, char *, unsigned int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdout;
int gz_compress(FILE *in, gzFile out) {
  char buf[16384];
  int len;
  int err;
  for (;;) {
    memset(buf, 0, 16384);
    len = (int)fread(buf, 1, sizeof(buf), in);
    if (ferror(in)) {
      printf("Error: fread failed in gz_compress\n");
      fflush(stdout);
      return -1;
    }
    if (len == 0) {
      break;
    }
    if (gzwrite(out, buf, (unsigned int)len) != len) {
      printf("Error: %s\n", gzerror(out, &err));
      fflush(stdout);
      return -1;
    }
  }
  if (gzclose(out) != Z_OK) {
    printf("Error: gzclose failed in gz_compress\n");
    fflush(stdout);
    return -1;
  }
  if (fclose(in)) {
    printf("Error: fclose failed in gz_compress\n");
    fflush(stdout);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<gz_compress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4030,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
lea    -0x4020(%rbp),%rdi
xor    %esi,%esi
mov    $0x4000,%edx
call   1080 <memset@plt>
lea    -0x4020(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x4000,%edx
call   1050 <fread@plt>
mov    %eax,-0x4024(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <ferror@plt>
cmp    $0x0,%rax
je     1210 <gz_compress+0x80>
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    0x2ddb(%rip),%rax
mov    (%rax),%edi
call   1090 <fflush@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1304 <gz_compress+0x174>
cmpl   $0x0,-0x4024(%rbp)
jne    1222 <gz_compress+0x92>
jmp    1282 <gz_compress+0xf2>
mov    -0x14(%rbp),%edi
lea    -0x4020(%rbp),%rsi
mov    -0x4024(%rbp),%edx
call   10b0 <gzwrite@plt>
cmp    -0x4024(%rbp),%eax
je     127d <gz_compress+0xed>
mov    -0x14(%rbp),%edi
lea    -0x4028(%rbp),%rsi
call   10a0 <gzerror@plt>
mov    %rax,%rsi
lea    0xdc8(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    0x2d6e(%rip),%rax
mov    (%rax),%edi
call   1090 <fflush@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1304 <gz_compress+0x174>
jmp    11a2 <gz_compress+0x12>
mov    -0x14(%rbp),%edi
call   1030 <gzclose@plt>
mov    0x2d5f(%rip),%rcx
cmp    (%rcx),%rax
je     12c2 <gz_compress+0x132>
lea    0xd8e(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    0x2d29(%rip),%rax
mov    (%rax),%edi
call   1090 <fflush@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1304 <gz_compress+0x174>
mov    -0x10(%rbp),%rdi
call   1060 <fclose@plt>
cmp    $0x0,%rax
je     12fd <gz_compress+0x16d>
lea    0xd79(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    0x2cee(%rip),%rax
mov    (%rax),%edi
call   1090 <fflush@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1304 <gz_compress+0x174>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x4030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gz_compress>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x4018,%rsp
mov    %esi,%r14d
mov    %rdi,%rbx
lea    0x10(%rsp),%r15
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x4000,%edx
call   1090 <memset@plt>
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x4000,%edx
mov    %rbx,%rcx
call   1060 <fread@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1050 <ferror@plt>
test   %rax,%rax
jne    1229 <gz_compress+0x89>
test   %ebp,%ebp
je     1232 <gz_compress+0x92>
mov    %r14d,%edi
mov    %r15,%rsi
mov    %ebp,%edx
call   10c0 <gzwrite@plt>
cmp    %ebp,%eax
je     11c0 <gz_compress+0x20>
lea    0xc(%rsp),%rsi
mov    %r14d,%edi
call   10b0 <gzerror@plt>
lea    0xde3(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
jmp    1268 <gz_compress+0xc8>
lea    0xe24(%rip),%rdi
jmp    1263 <gz_compress+0xc3>
mov    %r14d,%edi
call   1030 <gzclose@plt>
mov    0x2daf(%rip),%rcx
cmp    (%rcx),%rax
jne    125c <gz_compress+0xbc>
mov    %rbx,%rdi
call   1070 <fclose@plt>
test   %rax,%rax
je     1289 <gz_compress+0xe9>
lea    0xdb1(%rip),%rdi
jmp    1263 <gz_compress+0xc3>
lea    0xdcc(%rip),%rdi
call   1040 <puts@plt>
mov    0x2d69(%rip),%rax
mov    (%rax),%edi
call   10a0 <fflush@plt>
mov    $0xffffffff,%eax
add    $0x4018,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
jmp    127b <gz_compress+0xdb>

LLVM IR (-O0):
@.str = [36 x i8] c"Error: fread failed in gz_compress\0A\00"
@stdout = global i32 0
@.str.1 = [11 x i8] c"Error: %s\0A\00"
@Z_OK = global i64 0
@.str.2 = [38 x i8] c"Error: gzclose failed in gz_compress\0A\00"
@.str.3 = [37 x i8] c"Error: fclose failed in gz_compress\0A\00"
define i32 @gz_compress(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca [16384 x i8]
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
br label %9
9: ; preds = %40, %2
%10 = getelementptr inbounds [16384 x i8], [16384 x i8]* %6, i64 0, i64 0
%11 = call i32 @memset(i8* %10, i32 0, i32 16384)
%12 = getelementptr inbounds [16384 x i8], [16384 x i8]* %6, i64 0, i64 0
%13 = load i32*, i32** %4
%14 = call i64 @fread(i8* %12, i32 1, i32 16384, i32* %13)
%15 = trunc i64 %14 to i32
store i32 %15, i32* %7
%16 = load i32*, i32** %4
%17 = call i64 @ferror(i32* %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %9
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%21 = load i32, i32* @stdout
%22 = call i32 @fflush(i32 %21)
store i32 -1, i32* %3
br label %59
23: ; preds = %9
%24 = load i32, i32* %7
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %23
br label %41
27: ; preds = %23
%28 = load i32, i32* %5
%29 = getelementptr inbounds [16384 x i8], [16384 x i8]* %6, i64 0, i64 0
%30 = load i32, i32* %7
%31 = call i32 @gzwrite(i32 %28, i8* %29, i32 %30)
%32 = load i32, i32* %7
%33 = icmp ne i32 %31, %32
br i1 %33, label %34, label %40
34: ; preds = %27
%35 = load i32, i32* %5
%36 = call i8* @gzerror(i32 %35, i32* %8)
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %36)
%38 = load i32, i32* @stdout
%39 = call i32 @fflush(i32 %38)
store i32 -1, i32* %3
br label %59
40: ; preds = %27
br label %9
41: ; preds = %26
%42 = load i32, i32* %5
%43 = call i64 @gzclose(i32 %42)
%44 = load i64, i64* @Z_OK
%45 = icmp ne i64 %43, %44
br i1 %45, label %46, label %50
46: ; preds = %41
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
%48 = load i32, i32* @stdout
%49 = call i32 @fflush(i32 %48)
store i32 -1, i32* %3
br label %59
50: ; preds = %41
%51 = load i32*, i32** %4
%52 = call i64 @fclose(i32* %51)
%53 = icmp ne i64 %52, 0
br i1 %53, label %54, label %58
54: ; preds = %50
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0))
%56 = load i32, i32* @stdout
%57 = call i32 @fflush(i32 %56)
store i32 -1, i32* %3
br label %59
58: ; preds = %50
store i32 0, i32* %3
br label %59
59: ; preds = %58, %54, %46, %34, %19
%60 = load i32, i32* %3
ret i32 %60
}

LLVM IR (-O2):
@stdout = global i32 0
@.str.1 = [11 x i8] c"Error: %s\0A\00"
@Z_OK = global i64 0
@str = [36 x i8] c"Error: fclose failed in gz_compress\00"
@str.4 = [37 x i8] c"Error: gzclose failed in gz_compress\00"
@str.5 = [35 x i8] c"Error: fread failed in gz_compress\00"
define i32 @gz_compress(i32* nocapture %0, i32 %1) {
%3 = alloca [16384 x i8]
%4 = alloca i32
%5 = getelementptr inbounds [16384 x i8], [16384 x i8]* %3, i64 0, i64 0
%6 = bitcast i32* %4 to i8*
br label %7
7: ; preds = %17, %2
%8 = call i32 @memset(i8* %5, i32 0, i32 16384)
%9 = call i64 @fread(i8* %5, i32 1, i32 16384, i32* %0)
%10 = trunc i64 %9 to i32
%11 = call i64 @ferror(i32* %0)
%12 = icmp eq i64 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %7
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.5, i64 0, i64 0))
br label %34
15: ; preds = %7
%16 = icmp eq i32 %10, 0
br i1 %16, label %23, label %17
17: ; preds = %15
%18 = call i32 @gzwrite(i32 %1, i8* %5, i32 %10)
%19 = icmp eq i32 %18, %10
br i1 %19, label %7, label %20
20: ; preds = %17
%21 = call i8* @gzerror(i32 %1, i32* %4)
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %21)
br label %34
23: ; preds = %15
%24 = call i64 @gzclose(i32 %1)
%25 = load i64, i64* @Z_OK
%26 = icmp eq i64 %24, %25
br i1 %26, label %29, label %27
27: ; preds = %23
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.4, i64 0, i64 0))
br label %34
29: ; preds = %23
%30 = call i64 @fclose(i32* %0)
%31 = icmp eq i64 %30, 0
br i1 %31, label %37, label %32
32: ; preds = %29
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
br label %34
34: ; preds = %13, %20, %27, %32
%35 = load i32, i32* @stdout
%36 = call i32 @fflush(i32 %35)
br label %37
37: ; preds = %34, %29
%38 = phi i32 [ 0, %29 ], [ -1, %34 ]
ret i32 %38
}