#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 /*<<< orphan*/ access_mode_string(char const *);
scalar_t__ errno;
int /*<<< orphan*/ fatal_error_with_errno(char *, char const *,
                                          int /*<<< orphan*/);
void *gzdopen(int, char const *);
int /*<<< orphan*/ mode_to_flags(char const *);
scalar_t__ xopen(char const *, int /*<<< orphan*/, int);
void *xgzopen(const char *path, const char *mode) {
  gzFile gzf;
  int fd;
  fd = (int)(intptr_t)xopen(path, mode_to_flags(mode), 0644);
  errno = 0;
  gzf = gzdopen(fd, mode);
  if (!gzf)
    fatal_error_with_errno("Failed to open \"%s\" for %s", path,
                           access_mode_string(mode));
  return gzf;
}


x86 assembly (clang, -O0):
<xgzopen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <mode_to_flags@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%esi
mov    $0x1a4,%edx
call   1040 <xopen@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e55(%rip),%rax
movq   $0x0,(%rax)
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <gzdopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11d0 <xgzopen+0x80>
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <access_mode_string@plt>
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
lea    0xe35(%rip),%rdi
call   1050 <fatal_error_with_errno@plt>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xgzopen>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsi,%rdi
call   1060 <mode_to_flags@plt>
mov    %r14,%rdi
mov    %eax,%esi
mov    $0x1a4,%edx
call   1040 <xopen@plt>
mov    0x2e67(%rip),%rcx
movq   $0x0,(%rcx)
mov    %eax,%edi
mov    %r15,%rsi
call   1030 <gzdopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11ab <xgzopen+0x5b>
mov    %r15,%rdi
call   1070 <access_mode_string@plt>
lea    0xe5f(%rip),%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1050 <fatal_error_with_errno@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@errno = global i64 0
@.str = [27 x i8] c"Failed to open \22%s\22 for %s\00"
define i8* @xgzopen(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %3
%8 = load i8*, i8** %4
%9 = call i32 @mode_to_flags(i8* %8)
%10 = call i64 @xopen(i8* %7, i32 %9, i32 420)
%11 = trunc i64 %10 to i32
store i32 %11, i32* %6
store i64 0, i64* @errno
%12 = load i32, i32* %6
%13 = load i8*, i8** %4
%14 = call i8* @gzdopen(i32 %12, i8* %13)
store i8* %14, i8** %5
%15 = load i8*, i8** %5
%16 = icmp ne i8* %15, null
br i1 %16, label %22, label %17
17: ; preds = %2
%18 = load i8*, i8** %3
%19 = load i8*, i8** %4
%20 = call i32 @access_mode_string(i8* %19)
%21 = call i32 @fatal_error_with_errno(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %18, i32 %20)
br label %22
22: ; preds = %17, %2
%23 = load i8*, i8** %5
ret i8* %23
}

LLVM IR (-O2):
@errno = global i64 0
@.str = [27 x i8] c"Failed to open \22%s\22 for %s\00"
define i8* @xgzopen(i8* %0, i8* %1) {
%3 = tail call i32 @mode_to_flags(i8* %1)
%4 = tail call i64 @xopen(i8* %0, i32 %3, i32 420)
%5 = trunc i64 %4 to i32
store i64 0, i64* @errno
%6 = tail call i8* @gzdopen(i32 %5, i8* %1)
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = tail call i32 @access_mode_string(i8* %1)
%10 = tail call i32 @fatal_error_with_errno(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %9)
br label %11
11: ; preds = %8, %2
ret i8* %6
}