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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ SEEK_SET;
scalar_t__ WEXITSTATUS(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ error(int /*<<< orphan*/, int /*<<< orphan*/, char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
size_t fread(char *, int, size_t const, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
int /*<<< orphan*/ fwrite(char *, size_t, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char const *);
int /*<<< orphan*/ strcmp(char *, char *);
char *strrchr(char const *, char);
int /*<<< orphan*/ waitpid(int /*<<< orphan*/, int *, int /*<<< orphan*/);
char *xmalloc(size_t const);
int /*<<< orphan*/ *xopen_seekable(char const *, char const *);
int /*<<< orphan*/ *xpipe(char *, int /*<<< orphan*/ *, char *, char *,
                          char const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ *xtmpfile();
FILE *xopen_unzip(const char *name, const char *mode) {
  char *p, *zprog = NULL;
  FILE *fi, *fo;
  const size_t buflen = 64 * 1024;
  char *buffer;
  pid_t pid;
  int status;
  int any_data = 0;
  p = strrchr(name, '.');
  if (p != NULL) {
    if (!strcmp(p, ".bz2"))
      zprog = "bzcat";
    else if (!strcmp(p, ".gz"))
      zprog = "zcat";
  }
  if (zprog == NULL)
    return xopen_seekable(name, mode);
  buffer = xmalloc(buflen);
  fo = xtmpfile();
  fi = xpipe(zprog, &pid, "r", zprog, name, NULL);
  while (!feof(fi)) {
    size_t count = fread(buffer, 1, buflen, fi);
    if (ferror(fi)) {
      perror(name);
      exit(1);
    }
    if (count < 1)
      break;
    fwrite(buffer, count, 1, fo);
    if (ferror(fo))
      error(EXIT_FAILURE, errno, "writing temp file");
    any_data = 1;
  }
  free(buffer);
  fclose(fi);
  waitpid(pid, &status, 0);
  if (any_data == 0 && WEXITSTATUS(status) != 0) {
    fclose(fo);
    exit(1);
  }
  fseek(fo, 0L, SEEK_SET);
  return fo;
}


x86 assembly (clang, -O0):
<xopen_unzip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x10000,-0x40(%rbp)
movl   $0x0,-0x54(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2e,%esi
call   1070 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     12bb <xopen_unzip+0x9b>
mov    -0x20(%rbp),%rdi
lea    0xd91(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%eax
jne    128d <xopen_unzip+0x6d>
lea    0xd81(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    12b6 <xopen_unzip+0x96>
mov    -0x20(%rbp),%rdi
lea    0xd73(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%eax
jne    12b1 <xopen_unzip+0x91>
lea    0xd59(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    12b6 <xopen_unzip+0x96>
jmp    12bb <xopen_unzip+0x9b>
cmpq   $0x0,-0x28(%rbp)
jne    12dc <xopen_unzip+0xbc>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1110 <xopen_seekable@plt>
mov    %rax,-0x8(%rbp)
jmp    1449 <xopen_unzip+0x229>
mov    $0x10000,%edi
call   1090 <xmalloc@plt>
mov    %rax,-0x48(%rbp)
mov    $0x0,%al
call   1080 <xtmpfile@plt>
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x28(%rbp),%rcx
mov    -0x10(%rbp),%r8
lea    -0x4c(%rbp),%rsi
lea    0xd03(%rip),%rdx
xor    %eax,%eax
mov    %eax,%r9d
call   1120 <xpipe@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   10b0 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1338 <xopen_unzip+0x118>
jmp    13dc <xopen_unzip+0x1bc>
mov    -0x48(%rbp),%rdi
mov    -0x30(%rbp),%rcx
mov    $0x1,%esi
mov    $0x10000,%edx
call   1050 <fread@plt>
mov    %rax,-0x60(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <ferror@plt>
cmp    $0x0,%rax
je     1379 <xopen_unzip+0x159>
mov    -0x10(%rbp),%rdi
call   1100 <perror@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
cmpq   $0x1,-0x60(%rbp)
jae    1389 <xopen_unzip+0x169>
jmp    13dc <xopen_unzip+0x1bc>
mov    -0x48(%rbp),%rdi
mov    -0x60(%rbp),%rsi
mov    -0x38(%rbp),%rcx
mov    $0x1,%edx
call   1140 <fwrite@plt>
mov    -0x38(%rbp),%rdi
call   1040 <ferror@plt>
cmp    $0x0,%rax
je     13d0 <xopen_unzip+0x1b0>
mov    0x2c17(%rip),%rax
mov    (%rax),%edi
mov    0x2c1e(%rip),%rax
mov    (%rax),%esi
lea    0xc46(%rip),%rdx
call   10e0 <error@plt>
movl   $0x1,-0x54(%rbp)
jmp    131a <xopen_unzip+0xfa>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x4c(%rbp),%edi
lea    -0x50(%rbp),%rsi
xor    %edx,%edx
call   10f0 <waitpid@plt>
cmpl   $0x0,-0x54(%rbp)
jne    142b <xopen_unzip+0x20b>
mov    -0x50(%rbp),%edi
call   10d0 <WEXITSTATUS@plt>
cmp    $0x0,%rax
je     142b <xopen_unzip+0x20b>
mov    -0x38(%rbp),%rdi
call   1060 <fclose@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
mov    -0x38(%rbp),%rdi
mov    0x2ba2(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   10c0 <fseek@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xopen_unzip>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
mov    $0x2e,%esi
call   1070 <strrchr@plt>
test   %rax,%rax
je     1269 <xopen_unzip+0x49>
mov    %rax,%rbx
lea    0xdb6(%rip),%rsi
mov    %rax,%rdi
call   10a0 <strcmp@plt>
test   %eax,%eax
je     1282 <xopen_unzip+0x62>
lea    0xdae(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <strcmp@plt>
test   %eax,%eax
je     128b <xopen_unzip+0x6b>
mov    %r14,%rdi
mov    %r15,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1110 <xopen_seekable@plt>
lea    0xd7c(%rip),%rbx
jmp    1292 <xopen_unzip+0x72>
lea    0xd74(%rip),%rbx
mov    $0x10000,%edi
call   1090 <xmalloc@plt>
mov    %rax,%r12
xor    %eax,%eax
call   1080 <xtmpfile@plt>
mov    %rax,%r15
lea    0xd5f(%rip),%rdx
lea    0x4(%rsp),%rsi
mov    %rbx,%rdi
mov    %rbx,%rcx
mov    %r14,%r8
xor    %r9d,%r9d
call   1120 <xpipe@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   10b0 <feof@plt>
test   %eax,%eax
je     1316 <xopen_unzip+0xf6>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    0x4(%rsp),%edi
mov    %rsp,%rsi
xor    %edx,%edx
call   10f0 <waitpid@plt>
mov    (%rsp),%edi
call   10d0 <WEXITSTATUS@plt>
test   %rax,%rax
je     13ec <xopen_unzip+0x1cc>
mov    %r15,%rdi
call   1060 <fclose@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
mov    $0x1,%r13b
jmp    1333 <xopen_unzip+0x113>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   10b0 <feof@plt>
xor    %r13d,%r13d
test   %eax,%eax
jne    13ce <xopen_unzip+0x1ae>
mov    $0x10000,%edx
mov    %r12,%rdi
mov    $0x1,%esi
mov    %rbx,%rcx
call   1050 <fread@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1040 <ferror@plt>
test   %rax,%rax
jne    1411 <xopen_unzip+0x1f1>
test   %rbp,%rbp
je     13a4 <xopen_unzip+0x184>
mov    %r12,%rdi
mov    %rbp,%rsi
mov    $0x1,%edx
mov    %r15,%rcx
call   1140 <fwrite@plt>
mov    %r15,%rdi
call   1040 <ferror@plt>
test   %rax,%rax
je     1320 <xopen_unzip+0x100>
mov    0x2c48(%rip),%rax
mov    (%rax),%edi
mov    0x2c4f(%rip),%rax
mov    (%rax),%esi
lea    0xc77(%rip),%rdx
call   10e0 <error@plt>
jmp    1320 <xopen_unzip+0x100>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    0x4(%rsp),%edi
mov    %rsp,%rsi
xor    %edx,%edx
call   10f0 <waitpid@plt>
test   $0x1,%r13b
jne    12f3 <xopen_unzip+0xd3>
jmp    13ec <xopen_unzip+0x1cc>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    0x4(%rsp),%edi
mov    %rsp,%rsi
xor    %edx,%edx
call   10f0 <waitpid@plt>
mov    0x2be5(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
xor    %esi,%esi
call   10c0 <fseek@plt>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r14,%rdi
call   1100 <perror@plt>
mov    $0x1,%edi
call   1130 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c".bz2\00"
@.str.1 = [6 x i8] c"bzcat\00"
@.str.2 = [4 x i8] c".gz\00"
@.str.3 = [5 x i8] c"zcat\00"
@.str.4 = [2 x i8] c"r\00"
@EXIT_FAILURE = global i32 0
@errno = global i32 0
@.str.5 = [18 x i8] c"writing temp file\00"
@SEEK_SET = global i32 0
define i32* @xopen_unzip(i8* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i64
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* null, i8** %7
store i64 65536, i64* %10
store i32 0, i32* %14
%16 = load i8*, i8** %4
%17 = call i8* @strrchr(i8* %16, i8 signext 46)
store i8* %17, i8** %6
%18 = load i8*, i8** %6
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %32
20: ; preds = %2
%21 = load i8*, i8** %6
%22 = call i32 @strcmp(i8* %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%23 = icmp ne i32 %22, 0
br i1 %23, label %25, label %24
24: ; preds = %20
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8** %7
br label %31
25: ; preds = %20
%26 = load i8*, i8** %6
%27 = call i32 @strcmp(i8* %26, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%28 = icmp ne i32 %27, 0
br i1 %28, label %30, label %29
29: ; preds = %25
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8** %7
br label %30
30: ; preds = %29, %25
br label %31
31: ; preds = %30, %24
br label %32
32: ; preds = %31, %2
%33 = load i8*, i8** %7
%34 = icmp eq i8* %33, null
br i1 %34, label %35, label %39
35: ; preds = %32
%36 = load i8*, i8** %4
%37 = load i8*, i8** %5
%38 = call i32* @xopen_seekable(i8* %36, i8* %37)
store i32* %38, i32** %3
br label %101
39: ; preds = %32
%40 = call i8* @xmalloc(i64 65536)
store i8* %40, i8** %11
%41 = call i32* (...) @xtmpfile()
store i32* %41, i32** %9
%42 = load i8*, i8** %7
%43 = load i8*, i8** %7
%44 = load i8*, i8** %4
%45 = call i32* @xpipe(i8* %42, i32* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i8* %43, i8* %44, i32* null)
store i32* %45, i32** %8
br label %46
46: ; preds = %78, %39
%47 = load i32*, i32** %8
%48 = call i32 @feof(i32* %47)
%49 = icmp ne i32 %48, 0
%50 = xor i1 %49, true
br i1 %50, label %51, label %79
51: ; preds = %46
%52 = load i8*, i8** %11
%53 = load i32*, i32** %8
%54 = call i64 @fread(i8* %52, i32 1, i64 65536, i32* %53)
store i64 %54, i64* %15
%55 = load i32*, i32** %8
%56 = call i64 @ferror(i32* %55)
%57 = icmp ne i64 %56, 0
br i1 %57, label %58, label %62
58: ; preds = %51
%59 = load i8*, i8** %4
%60 = call i32 @perror(i8* %59)
%61 = call i32 @exit(i32 1)
unreachable
62: ; preds = %51
%63 = load i64, i64* %15
%64 = icmp ult i64 %63, 1
br i1 %64, label %65, label %66
65: ; preds = %62
br label %79
66: ; preds = %62
%67 = load i8*, i8** %11
%68 = load i64, i64* %15
%69 = load i32*, i32** %9
%70 = call i32 @fwrite(i8* %67, i64 %68, i32 1, i32* %69)
%71 = load i32*, i32** %9
%72 = call i64 @ferror(i32* %71)
%73 = icmp ne i64 %72, 0
br i1 %73, label %74, label %78
74: ; preds = %66
%75 = load i32, i32* @EXIT_FAILURE
%76 = load i32, i32* @errno
%77 = call i32 @error(i32 %75, i32 %76, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
br label %78
78: ; preds = %74, %66
store i32 1, i32* %14
br label %46
79: ; preds = %65, %46
%80 = load i8*, i8** %11
%81 = call i32 @free(i8* %80)
%82 = load i32*, i32** %8
%83 = call i32 @fclose(i32* %82)
%84 = load i32, i32* %12
%85 = call i32 @waitpid(i32 %84, i32* %13, i32 0)
%86 = load i32, i32* %14
%87 = icmp eq i32 %86, 0
br i1 %87, label %88, label %96
88: ; preds = %79
%89 = load i32, i32* %13
%90 = call i64 @WEXITSTATUS(i32 %89)
%91 = icmp ne i64 %90, 0
br i1 %91, label %92, label %96
92: ; preds = %88
%93 = load i32*, i32** %9
%94 = call i32 @fclose(i32* %93)
%95 = call i32 @exit(i32 1)
unreachable
96: ; preds = %88, %79
%97 = load i32*, i32** %9
%98 = load i32, i32* @SEEK_SET
%99 = call i32 @fseek(i32* %97, i64 0, i32 %98)
%100 = load i32*, i32** %9
store i32* %100, i32** %3
br label %101
101: ; preds = %96, %35
%102 = load i32*, i32** %3
ret i32* %102
}

LLVM IR (-O2):
@.str = [5 x i8] c".bz2\00"
@.str.1 = [6 x i8] c"bzcat\00"
@.str.2 = [4 x i8] c".gz\00"
@.str.3 = [5 x i8] c"zcat\00"
@.str.4 = [2 x i8] c"r\00"
@EXIT_FAILURE = global i32 0
@errno = global i32 0
@.str.5 = [18 x i8] c"writing temp file\00"
@SEEK_SET = global i32 0
define i32* @xopen_unzip(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 46)
%8 = icmp eq i8* %7, null
br i1 %8, label %15, label %9
9: ; preds = %2
%10 = tail call i32 @strcmp(i8* %7, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i32 %10, 0
br i1 %11, label %17, label %12
12: ; preds = %9
%13 = tail call i32 @strcmp(i8* %7, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%14 = icmp eq i32 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %2, %12
%16 = tail call i32* @xopen_seekable(i8* %0, i8* %1)
br label %70
17: ; preds = %9, %12
%18 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), %12 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), %9 ]
%19 = tail call i8* @xmalloc(i64 65536)
%20 = tail call i32* (...) @xtmpfile()
%21 = call i32* @xpipe(i8* %18, i32* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i8* %18, i8* %0, i32* null)
%22 = call i32 @feof(i32* %21)
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %50
24: ; preds = %17, %42
%25 = phi i1 [ false, %42 ], [ true, %17 ]
%26 = call i64 @fread(i8* %19, i32 1, i64 65536, i32* %21)
%27 = call i64 @ferror(i32* %21)
%28 = icmp eq i64 %27, 0
br i1 %28, label %32, label %29
29: ; preds = %24
%30 = call i32 @perror(i8* %0)
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %24
%33 = icmp eq i64 %26, 0
br i1 %33, label %45, label %34
34: ; preds = %32
%35 = call i32 @fwrite(i8* %19, i64 %26, i32 1, i32* %20)
%36 = call i64 @ferror(i32* %20)
%37 = icmp eq i64 %36, 0
br i1 %37, label %42, label %38
38: ; preds = %34
%39 = load i32, i32* @EXIT_FAILURE
%40 = load i32, i32* @errno
%41 = call i32 @error(i32 %39, i32 %40, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
br label %42
42: ; preds = %34, %38
%43 = call i32 @feof(i32* %21)
%44 = icmp eq i32 %43, 0
br i1 %44, label %24, label %62
45: ; preds = %32
%46 = call i32 @free(i8* %19)
%47 = call i32 @fclose(i32* %21)
%48 = load i32, i32* %3
%49 = call i32 @waitpid(i32 %48, i32* %4, i32 0)
br i1 %25, label %55, label %67
50: ; preds = %17
%51 = call i32 @free(i8* %19)
%52 = call i32 @fclose(i32* %21)
%53 = load i32, i32* %3
%54 = call i32 @waitpid(i32 %53, i32* %4, i32 0)
br label %55
55: ; preds = %50, %45
%56 = load i32, i32* %4
%57 = call i64 @WEXITSTATUS(i32 %56)
%58 = icmp eq i64 %57, 0
br i1 %58, label %67, label %59
59: ; preds = %55
%60 = call i32 @fclose(i32* %20)
%61 = call i32 @exit(i32 1)
unreachable
62: ; preds = %42
%63 = call i32 @free(i8* %19)
%64 = call i32 @fclose(i32* %21)
%65 = load i32, i32* %3
%66 = call i32 @waitpid(i32 %65, i32* %4, i32 0)
br label %67
67: ; preds = %62, %55, %45
%68 = load i32, i32* @SEEK_SET
%69 = call i32 @fseek(i32* %20, i64 0, i32 %68)
br label %70
70: ; preds = %67, %15
%71 = phi i32* [ %16, %15 ], [ %20, %67 ]
ret i32* %71
}