#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fileno(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, ...);
int /*<<< orphan*/ gzdopen(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ *stdout;
scalar_t__ strcmp(char *, char *);
char *strerror(int /*<<< orphan*/);
gzFile gzFile_create(const char *filename, char *mode) {
  FILE *stream = NULL;
  if (filename == NULL) {
    if (strcmp(mode, "r") == 0) {
      stream = stdin;
    } else if (strcmp(mode, "w") == 0) {
      stream = stdout;
    } else {
      fprintf(stderr, "Unknown file mode='%s'\n", mode);
      exit(EXIT_FAILURE);
    }
  } else {
    stream = fopen(filename, mode);
    if (!stream) {
      fprintf(stderr, "file:%s, error: %s", filename, strerror(errno));
      exit(EXIT_FAILURE);
    }
  }
  return gzdopen(fileno(stream), mode);
}


x86 assembly (clang, -O0):
<gzFile_create>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1220 <gzFile_create+0xb0>
mov    -0x10(%rbp),%rdi
lea    0xe62(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11c0 <gzFile_create+0x50>
mov    0x2e34(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    121b <gzFile_create+0xab>
mov    -0x10(%rbp),%rdi
lea    0xe37(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11ed <gzFile_create+0x7d>
mov    0x2ddf(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    1216 <gzFile_create+0xa6>
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe03(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2db9(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    121b <gzFile_create+0xab>
jmp    1289 <gzFile_create+0x119>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1284 <gzFile_create+0x114>
mov    0x2d95(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2d79(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rdx
mov    %rax,%rcx
lea    0xdad(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2d4b(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    1289 <gzFile_create+0x119>
mov    -0x18(%rbp),%rdi
call   1060 <fileno@plt>
mov    %eax,%edi
mov    -0x10(%rbp),%rsi
call   1030 <gzdopen@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gzFile_create>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
test   %rdi,%rdi
je     11be <gzFile_create+0x4e>
mov    %rdi,%rbx
mov    %r14,%rsi
call   1070 <fopen@plt>
mov    %rax,%rdi
test   %rax,%rax
jne    11f9 <gzFile_create+0x89>
mov    0x2e42(%rip),%rax
mov    (%rax),%ebp
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xe6f(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    1226 <gzFile_create+0xb6>
lea    0xe3b(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11ef <gzFile_create+0x7f>
lea    0xe29(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    120c <gzFile_create+0x9c>
mov    0x2dd3(%rip),%rax
jmp    11f6 <gzFile_create+0x86>
mov    0x2df2(%rip),%rax
mov    (%rax),%rdi
call   1060 <fileno@plt>
mov    %eax,%edi
mov    %r14,%rsi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <gzdopen@plt>
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
lea    0xde8(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stdin = global i32* null
@.str.1 = [2 x i8] c"w\00"
@stdout = global i32* null
@stderr = global i32 0
@.str.2 = [24 x i8] c"Unknown file mode='%s'\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [19 x i8] c"file:%s, error: %s\00"
@errno = global i32 0
define i32 @gzFile_create(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32* null, i32** %5
%6 = load i8*, i8** %3
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %28
8: ; preds = %2
%9 = load i8*, i8** %4
%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 %14
12: ; preds = %8
%13 = load i32*, i32** @stdin
store i32* %13, i32** %5
br label %27
14: ; preds = %8
%15 = load i8*, i8** %4
%16 = call i64 @strcmp(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = load i32*, i32** @stdout
store i32* %19, i32** %5
br label %26
20: ; preds = %14
%21 = load i32, i32* @stderr
%22 = load i8*, i8** %4
%23 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %22)
%24 = load i32, i32* @EXIT_FAILURE
%25 = call i32 @exit(i32 %24)
unreachable
26: ; preds = %18
br label %27
27: ; preds = %26, %12
br label %43
28: ; preds = %2
%29 = load i8*, i8** %3
%30 = load i8*, i8** %4
%31 = call i32* @fopen(i8* %29, i8* %30)
store i32* %31, i32** %5
%32 = load i32*, i32** %5
%33 = icmp ne i32* %32, null
br i1 %33, label %42, label %34
34: ; preds = %28
%35 = load i32, i32* @stderr
%36 = load i8*, i8** %3
%37 = load i32, i32* @errno
%38 = call i8* @strerror(i32 %37)
%39 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %36, i8* %38)
%40 = load i32, i32* @EXIT_FAILURE
%41 = call i32 @exit(i32 %40)
unreachable
42: ; preds = %28
br label %43
43: ; preds = %42, %27
%44 = load i32*, i32** %5
%45 = call i32 @fileno(i32* %44)
%46 = load i8*, i8** %4
%47 = call i32 @gzdopen(i32 %45, i8* %46)
ret i32 %47
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stdin = global i32* null
@.str.1 = [2 x i8] c"w\00"
@stdout = global i32* null
@stderr = global i32 0
@.str.2 = [24 x i8] c"Unknown file mode='%s'\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [19 x i8] c"file:%s, error: %s\00"
@errno = global i32 0
define i32 @gzFile_create(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %4, label %19
4: ; preds = %2
%5 = tail call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = load i32*, i32** @stdin
br label %29
9: ; preds = %4
%10 = tail call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = load i32*, i32** @stdout
br label %29
14: ; preds = %9
%15 = load i32, i32* @stderr
%16 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %1)
%17 = load i32, i32* @EXIT_FAILURE
%18 = tail call i32 @exit(i32 %17)
unreachable
19: ; preds = %2
%20 = tail call i32* @fopen(i8* %0, i8* %1)
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %29
22: ; preds = %19
%23 = load i32, i32* @stderr
%24 = load i32, i32* @errno
%25 = tail call i8* @strerror(i32 %24)
%26 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %0, i8* %25)
%27 = load i32, i32* @EXIT_FAILURE
%28 = tail call i32 @exit(i32 %27)
unreachable
29: ; preds = %19, %7, %12
%30 = phi i32* [ %8, %7 ], [ %13, %12 ], [ %20, %19 ]
%31 = tail call i32 @fileno(i32* %30)
%32 = tail call i32 @gzdopen(i32 %31, i8* %1)
ret i32 %32
}