#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*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
scalar_t__ fwrite(char *, int, unsigned int, int /*<<< orphan*/ *);
scalar_t__ gzclose(int /*<<< orphan*/);
char *gzerror(int /*<<< orphan*/ *, int *);
int gzread(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdout;
int gz_uncompress(gzFile in, FILE *out) {
  char buf[16384];
  int len;
  int err;
  for (;;) {
    len = gzread(in, buf, sizeof(buf));
    if (len < 0) {
      printf("Error: %s\n", gzerror(out, &err));
      fflush(stdout);
      return -1;
    }
    if (len == 0) {
      break;
    }
    if ((int)fwrite(buf, 1, (unsigned int)len, out) != len) {
      printf("Error: fwrite failed in gz_compress\n");
      fflush(stdout);
      return -1;
    }
  }
  if (fclose(out)) {
    printf("Error: fclose failed in gz_compress\n");
    fflush(stdout);
    return -1;
  }
  if (gzclose(in) != Z_OK) {
    printf("Error: gzclose failed in gz_compress\n");
    fflush(stdout);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<gz_uncompress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4020,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x4010(%rbp),%rsi
mov    $0x4000,%edx
call   1060 <gzread@plt>
mov    %eax,-0x4014(%rbp)
cmpl   $0x0,-0x4014(%rbp)
jge    11e4 <gz_uncompress+0x74>
mov    -0x10(%rbp),%rdi
lea    -0x4018(%rbp),%rsi
call   1080 <gzerror@plt>
mov    %rax,%rsi
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12cc <gz_uncompress+0x15c>
cmpl   $0x0,-0x4014(%rbp)
jne    11f6 <gz_uncompress+0x86>
jmp    124a <gz_uncompress+0xda>
lea    -0x4010(%rbp),%rdi
mov    -0x4014(%rbp),%edx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1090 <fwrite@plt>
cmp    -0x4014(%rbp),%eax
je     1245 <gz_uncompress+0xd5>
lea    0xde7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2da6(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12cc <gz_uncompress+0x15c>
jmp    1182 <gz_uncompress+0x12>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
cmp    $0x0,%rax
je     1285 <gz_uncompress+0x115>
lea    0xdcc(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2d66(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12cc <gz_uncompress+0x15c>
mov    -0x8(%rbp),%edi
call   1030 <gzclose@plt>
mov    0x2d5c(%rip),%rcx
cmp    (%rcx),%rax
je     12c5 <gz_uncompress+0x155>
lea    0xdb1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2d26(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12cc <gz_uncompress+0x15c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x4020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gz_uncompress>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x4018,%rsp
mov    %rsi,%r15
mov    %edi,%r14d
lea    0x10(%rsp),%rbp
nopl   0x0(%rax,%rax,1)
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0x4000,%edx
call   1070 <gzread@plt>
test   %eax,%eax
js     11d7 <gz_uncompress+0x57>
je     11f7 <gz_uncompress+0x77>
mov    %eax,%ebx
mov    %rbp,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    %r15,%rcx
call   10a0 <fwrite@plt>
cmp    %eax,%ebx
je     11a0 <gz_uncompress+0x20>
lea    0xe36(%rip),%rdi
jmp    122d <gz_uncompress+0xad>
lea    0xc(%rsp),%rsi
mov    %r15,%rdi
call   1090 <gzerror@plt>
lea    0xe15(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1232 <gz_uncompress+0xb2>
mov    %r15,%rdi
call   1050 <fclose@plt>
test   %rax,%rax
je     120d <gz_uncompress+0x8d>
lea    0xe49(%rip),%rdi
jmp    122d <gz_uncompress+0xad>
mov    %r14d,%edi
call   1030 <gzclose@plt>
mov    %rax,%rcx
mov    0x2dd1(%rip),%rdx
xor    %eax,%eax
cmp    (%rdx),%rcx
je     1245 <gz_uncompress+0xc5>
lea    0xe02(%rip),%rdi
call   1040 <puts@plt>
mov    0x2d9f(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
mov    $0xffffffff,%eax
add    $0x4018,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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