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

/* Variables and functions */
int STDIN_FILENO;
int STDOUT_FILENO;
int Z_ERRNO;
int /*<<< orphan*/ fatal_error(char *, char const *, char const *);
int /*<<< orphan*/ fatal_error_with_errno(char *, char const *);
void *gzdopen(int, char const *);
char *gzerror(void *, int *);
void *gzopen(char const *, char const *);
scalar_t__ strchr(char const *, char);
scalar_t__ strcmp(char const *, char *);
void *xgzopen(const char *filename, const char *mode) {
  gzFile f;
  if (strcmp(filename, "-") == 0) {
    int fd;
    if (strchr(mode, 'w'))
      fd = STDOUT_FILENO;
    else
      fd = STDIN_FILENO;
    f = gzdopen(fd, mode);
  } else {
    f = gzopen(filename, mode);
  }
  if (!f) {
    const char *err_str;
    int errnum;
    err_str = gzerror(f, &errnum);
    if (errnum == Z_ERRNO)
      fatal_error_with_errno("Failed to open the file \"%s\"", filename);
    else
      fatal_error("zlib error opening \"%s\": %s", filename, err_str);
  }
  return f;
}


x86 assembly (clang, -O0):
<xgzopen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe75(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11e4 <xgzopen+0x74>
mov    -0x10(%rbp),%rdi
mov    $0x77,%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
je     11c3 <xgzopen+0x53>
mov    0x2e37(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
jmp    11cf <xgzopen+0x5f>
mov    0x2e06(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <gzdopen@plt>
mov    %rax,-0x18(%rbp)
jmp    11f5 <xgzopen+0x85>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1090 <gzopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1251 <xgzopen+0xe1>
mov    -0x18(%rbp),%rdi
lea    -0x2c(%rbp),%rsi
call   1080 <gzerror@plt>
mov    %rax,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
mov    0x2dc5(%rip),%rcx
cmp    (%rcx),%eax
jne    1238 <xgzopen+0xc8>
mov    -0x8(%rbp),%rsi
lea    0xdd4(%rip),%rdi
call   1050 <fatal_error_with_errno@plt>
jmp    124c <xgzopen+0xdc>
mov    -0x8(%rbp),%rsi
mov    -0x28(%rbp),%rdx
lea    0xdd8(%rip),%rdi
call   1070 <fatal_error@plt>
jmp    1251 <xgzopen+0xe1>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xgzopen>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xe7f(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1198 <xgzopen+0x28>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1090 <gzopen@plt>
jmp    11c4 <xgzopen+0x54>
mov    %rbx,%rdi
mov    $0x77,%esi
call   1040 <strchr@plt>
test   %rax,%rax
jne    11b3 <xgzopen+0x43>
mov    0x2e1f(%rip),%rax
jmp    11ba <xgzopen+0x4a>
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
call   1030 <gzdopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    120a <xgzopen+0x9a>
lea    0x4(%rsp),%rsi
xor    %edi,%edi
call   1080 <gzerror@plt>
mov    0x4(%rsp),%ecx
mov    0x2dfd(%rip),%rdx
cmp    (%rdx),%ecx
jne    11f8 <xgzopen+0x88>
lea    0xe14(%rip),%rdi
mov    %r14,%rsi
call   1050 <fatal_error_with_errno@plt>
jmp    120a <xgzopen+0x9a>
lea    0xe20(%rip),%rdi
mov    %r14,%rsi
mov    %rax,%rdx
call   1070 <fatal_error@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"-\00"
@STDOUT_FILENO = global i32 0
@STDIN_FILENO = global i32 0
@Z_ERRNO = global i32 0
@.str.1 = [29 x i8] c"Failed to open the file \22%s\22\00"
@.str.2 = [28 x i8] c"zlib error opening \22%s\22: %s\00"
define i8* @xgzopen(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%9 = load i8*, i8** %3
%10 = call i64 @strcmp(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %24
12: ; preds = %2
%13 = load i8*, i8** %4
%14 = call i64 @strchr(i8* %13, i8 signext 119)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = load i32, i32* @STDOUT_FILENO
store i32 %17, i32* %6
br label %20
18: ; preds = %12
%19 = load i32, i32* @STDIN_FILENO
store i32 %19, i32* %6
br label %20
20: ; preds = %18, %16
%21 = load i32, i32* %6
%22 = load i8*, i8** %4
%23 = call i8* @gzdopen(i32 %21, i8* %22)
store i8* %23, i8** %5
br label %28
24: ; preds = %2
%25 = load i8*, i8** %3
%26 = load i8*, i8** %4
%27 = call i8* @gzopen(i8* %25, i8* %26)
store i8* %27, i8** %5
br label %28
28: ; preds = %24, %20
%29 = load i8*, i8** %5
%30 = icmp ne i8* %29, null
br i1 %30, label %45, label %31
31: ; preds = %28
%32 = load i8*, i8** %5
%33 = call i8* @gzerror(i8* %32, i32* %8)
store i8* %33, i8** %7
%34 = load i32, i32* %8
%35 = load i32, i32* @Z_ERRNO
%36 = icmp eq i32 %34, %35
br i1 %36, label %37, label %40
37: ; preds = %31
%38 = load i8*, i8** %3
%39 = call i32 @fatal_error_with_errno(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %38)
br label %44
40: ; preds = %31
%41 = load i8*, i8** %3
%42 = load i8*, i8** %7
%43 = call i32 @fatal_error(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %41, i8* %42)
br label %44
44: ; preds = %40, %37
br label %45
45: ; preds = %44, %28
%46 = load i8*, i8** %5
ret i8* %46
}

LLVM IR (-O2):
@.str = [2 x i8] c"-\00"
@STDOUT_FILENO = global i32 0
@STDIN_FILENO = global i32 0
@Z_ERRNO = global i32 0
@.str.1 = [29 x i8] c"Failed to open the file \22%s\22\00"
@.str.2 = [28 x i8] c"zlib error opening \22%s\22: %s\00"
define i8* @xgzopen(i8* %0, i8* %1) {
%3 = alloca i32
%4 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %13
6: ; preds = %2
%7 = tail call i64 @strchr(i8* %1, i8 signext 119)
%8 = icmp eq i64 %7, 0
%9 = load i32, i32* @STDIN_FILENO
%10 = load i32, i32* @STDOUT_FILENO
%11 = select i1 %8, i32 %9, i32 %10
%12 = tail call i8* @gzdopen(i32 %11, i8* %1)
br label %15
13: ; preds = %2
%14 = tail call i8* @gzopen(i8* %0, i8* %1)
br label %15
15: ; preds = %13, %6
%16 = phi i8* [ %12, %6 ], [ %14, %13 ]
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %29
18: ; preds = %15
%19 = bitcast i32* %3 to i8*
%20 = call i8* @gzerror(i8* null, i32* %3)
%21 = load i32, i32* %3
%22 = load i32, i32* @Z_ERRNO
%23 = icmp eq i32 %21, %22
br i1 %23, label %24, label %26
24: ; preds = %18
%25 = call i32 @fatal_error_with_errno(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %28
26: ; preds = %18
%27 = call i32 @fatal_error(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* %20)
br label %28
28: ; preds = %26, %24
br label %29
29: ; preds = %28, %15
ret i8* %16
}