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

/* Variables and functions */
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ strcat(char *, char const *);
int /*<<< orphan*/ strcmp(char const *, char const *const);
int /*<<< orphan*/ strcpy(char *, char const *const);
int strlen(char const *const);
FILE *open_input(const char *filename) {
  const char *const tab[][2] = {
      {".gz", "zcat"},
      {".Z", "zcat"},
      {".bz2", "bzcat"},
      {".xz", "xzcat"},
  };
  int i;
  int flen = strlen(filename);
  for (i = 0; i < sizeof tab / sizeof tab[0]; i++) {
    int elen = strlen(tab[i][0]);
    if (flen > elen && !strcmp(filename + flen - elen, tab[i][0])) {
      char *cmd = malloc(flen + strlen(tab[i][1]) + 2);
      FILE *res;
      strcpy(cmd, tab[i][1]);
      strcat(cmd, " ");
      strcat(cmd, filename);
      res = popen(cmd, "r");
      free(cmd);
      return res;
    }
  }
  return fopen(filename, "r");
}


x86 assembly (clang, -O0):
<open_input>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x50(%rbp),%rdi
lea    0x2c36(%rip),%rsi
mov    $0x40,%edx
call   1070 <memcpy@plt>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x58(%rbp)
movl   $0x0,-0x54(%rbp)
movslq -0x54(%rbp),%rax
cmp    $0x4,%rax
jae    12d7 <open_input+0x147>
movslq -0x54(%rbp),%rcx
lea    -0x50(%rbp),%rax
shl    $0x4,%rcx
add    %rcx,%rax
mov    (%rax),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x5c(%rbp)
mov    -0x58(%rbp),%eax
cmp    -0x5c(%rbp),%eax
jle    12c4 <open_input+0x134>
mov    -0x10(%rbp),%rdi
movslq -0x58(%rbp),%rax
add    %rax,%rdi
movslq -0x5c(%rbp),%rcx
xor    %eax,%eax
sub    %rcx,%rax
add    %rax,%rdi
movslq -0x54(%rbp),%rcx
lea    -0x50(%rbp),%rax
shl    $0x4,%rcx
add    %rcx,%rax
mov    (%rax),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    12c4 <open_input+0x134>
mov    -0x58(%rbp),%eax
mov    %eax,-0x74(%rbp)
movslq -0x54(%rbp),%rcx
lea    -0x50(%rbp),%rax
shl    $0x4,%rcx
add    %rcx,%rax
mov    0x8(%rax),%rdi
call   1050 <strlen@plt>
mov    -0x74(%rbp),%edi
add    %eax,%edi
add    $0x2,%edi
call   1080 <malloc@plt>
mov    %rax,-0x68(%rbp)
mov    -0x68(%rbp),%rdi
movslq -0x54(%rbp),%rcx
lea    -0x50(%rbp),%rax
shl    $0x4,%rcx
add    %rcx,%rax
mov    0x8(%rax),%rsi
call   1040 <strcpy@plt>
mov    -0x68(%rbp),%rdi
lea    0xd94(%rip),%rsi
call   10b0 <strcat@plt>
mov    -0x68(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   10b0 <strcat@plt>
mov    -0x68(%rbp),%rdi
lea    0xd79(%rip),%rsi
call   1090 <popen@plt>
mov    %rax,-0x70(%rbp)
mov    -0x68(%rbp),%rdi
call   1030 <free@plt>
mov    -0x70(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12eb <open_input+0x15b>
jmp    12c9 <open_input+0x139>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    11c7 <open_input+0x37>
mov    -0x10(%rbp),%rdi
lea    0xd3c(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_input>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
call   1050 <strlen@plt>
mov    %eax,%r12d
movslq %eax,%rbx
lea    (%r14,%rbx,1),%r15
lea    0xe5f(%rip),%rdi
call   1050 <strlen@plt>
cmp    %eax,%ebx
jle    11c6 <open_input+0x46>
cltq
mov    %r15,%rdi
sub    %rax,%rdi
lea    0xe47(%rip),%rsi
call   1060 <strcmp@plt>
test   %eax,%eax
je     125b <open_input+0xdb>
lea    0xe37(%rip),%rdi
call   1050 <strlen@plt>
cmp    %eax,%r12d
jle    11ef <open_input+0x6f>
cltq
mov    %r15,%rdi
sub    %rax,%rdi
lea    0xe1e(%rip),%rsi
call   1060 <strcmp@plt>
test   %eax,%eax
je     125f <open_input+0xdf>
lea    0xe11(%rip),%rdi
call   1050 <strlen@plt>
cmp    %eax,%r12d
jle    1218 <open_input+0x98>
cltq
mov    %r15,%rdi
sub    %rax,%rdi
lea    0xdf8(%rip),%rsi
call   1060 <strcmp@plt>
test   %eax,%eax
je     1266 <open_input+0xe6>
lea    0xdf3(%rip),%rdi
call   1050 <strlen@plt>
cmp    %eax,%r12d
jle    1241 <open_input+0xc1>
cltq
sub    %rax,%r15
lea    0xddd(%rip),%rsi
mov    %r15,%rdi
call   1060 <strcmp@plt>
test   %eax,%eax
je     126d <open_input+0xed>
lea    0xdd6(%rip),%rsi
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1090 <fopen@plt>
xor    %eax,%eax
jmp    1272 <open_input+0xf2>
mov    $0x1,%eax
jmp    1272 <open_input+0xf2>
mov    $0x2,%eax
jmp    1272 <open_input+0xf2>
mov    $0x3,%eax
shl    $0x4,%rax
lea    0x2b63(%rip),%rcx
mov    0x8(%rax,%rcx,1),%r15
mov    %r15,%rdi
call   1050 <strlen@plt>
lea    (%r12,%rax,1),%edi
add    $0x2,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
call   1040 <strcpy@plt>
lea    0xd71(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   10a0 <strcat@plt>
lea    0xd59(%rip),%rsi
mov    %rbx,%rdi
call   1080 <popen@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c".gz\00"
@.str.1 = [5 x i8] c"zcat\00"
@.str.2 = [3 x i8] c".Z\00"
@.str.3 = [5 x i8] c".bz2\00"
@.str.4 = [6 x i8] c"bzcat\00"
@.str.5 = [4 x i8] c".xz\00"
@.str.6 = [6 x i8] c"xzcat\00"
@__const.open_input.tab = [4 x [2 x i8*]] [[2 x i8*] [i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i32 0, i32 0)], [2 x i8*] [i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i32 0, i32 0)], [2 x i8*] [i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i32 0, i32 0)], [2 x i8*] [i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i32 0, i32 0)]]
@.str.7 = [2 x i8] c" \00"
@.str.8 = [2 x i8] c"r\00"
define i32* @open_input(i8* %0) {
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca [4 x [2 x i8*]]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32*
store i8* %0, i8** %3
%10 = bitcast [4 x [2 x i8*]]* %4 to i8*
%11 = load i8*, i8** %3
%12 = call i32 @strlen(i8* %11)
store i32 %12, i32* %6
store i32 0, i32* %5
br label %13
13: ; preds = %72, %1
%14 = load i32, i32* %5
%15 = sext i32 %14 to i64
%16 = icmp ult i64 %15, 4
br i1 %16, label %17, label %75
17: ; preds = %13
%18 = load i32, i32* %5
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [4 x [2 x i8*]], [4 x [2 x i8*]]* %4, i64 0, i64 %19
%21 = getelementptr inbounds [2 x i8*], [2 x i8*]* %20, i64 0, i64 0
%22 = load i8*, i8** %21
%23 = call i32 @strlen(i8* %22)
store i32 %23, i32* %7
%24 = load i32, i32* %6
%25 = load i32, i32* %7
%26 = icmp sgt i32 %24, %25
br i1 %26, label %27, label %71
27: ; preds = %17
%28 = load i8*, i8** %3
%29 = load i32, i32* %6
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
%32 = load i32, i32* %7
%33 = sext i32 %32 to i64
%34 = sub i64 0, %33
%35 = getelementptr inbounds i8, i8* %31, i64 %34
%36 = load i32, i32* %5
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [4 x [2 x i8*]], [4 x [2 x i8*]]* %4, i64 0, i64 %37
%39 = getelementptr inbounds [2 x i8*], [2 x i8*]* %38, i64 0, i64 0
%40 = load i8*, i8** %39
%41 = call i32 @strcmp(i8* %35, i8* %40)
%42 = icmp ne i32 %41, 0
br i1 %42, label %71, label %43
43: ; preds = %27
%44 = load i32, i32* %6
%45 = load i32, i32* %5
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [4 x [2 x i8*]], [4 x [2 x i8*]]* %4, i64 0, i64 %46
%48 = getelementptr inbounds [2 x i8*], [2 x i8*]* %47, i64 0, i64 1
%49 = load i8*, i8** %48
%50 = call i32 @strlen(i8* %49)
%51 = add nsw i32 %44, %50
%52 = add nsw i32 %51, 2
%53 = call i8* @malloc(i32 %52)
store i8* %53, i8** %8
%54 = load i8*, i8** %8
%55 = load i32, i32* %5
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [4 x [2 x i8*]], [4 x [2 x i8*]]* %4, i64 0, i64 %56
%58 = getelementptr inbounds [2 x i8*], [2 x i8*]* %57, i64 0, i64 1
%59 = load i8*, i8** %58
%60 = call i32 @strcpy(i8* %54, i8* %59)
%61 = load i8*, i8** %8
%62 = call i32 @strcat(i8* %61, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%63 = load i8*, i8** %8
%64 = load i8*, i8** %3
%65 = call i32 @strcat(i8* %63, i8* %64)
%66 = load i8*, i8** %8
%67 = call i32* @popen(i8* %66, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
store i32* %67, i32** %9
%68 = load i8*, i8** %8
%69 = call i32 @free(i8* %68)
%70 = load i32*, i32** %9
store i32* %70, i32** %2
br label %78
71: ; preds = %27, %17
br label %72
72: ; preds = %71
%73 = load i32, i32* %5
%74 = add nsw i32 %73, 1
store i32 %74, i32* %5
br label %13
75: ; preds = %13
%76 = load i8*, i8** %3
%77 = call i32* @fopen(i8* %76, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
store i32* %77, i32** %2
br label %78
78: ; preds = %75, %43
%79 = load i32*, i32** %2
ret i32* %79
}

LLVM IR (-O2):
@.str = [4 x i8] c".gz\00"
@.str.1 = [5 x i8] c"zcat\00"
@.str.2 = [3 x i8] c".Z\00"
@.str.3 = [5 x i8] c".bz2\00"
@.str.4 = [6 x i8] c"bzcat\00"
@.str.5 = [4 x i8] c".xz\00"
@.str.6 = [6 x i8] c"xzcat\00"
@__const.open_input.tab = [4 x [2 x i8*]] [[2 x i8*] [i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i32 0, i32 0)], [2 x i8*] [i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i32 0, i32 0)], [2 x i8*] [i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i32 0, i32 0)], [2 x i8*] [i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i32 0, i32 0)]]
@.str.7 = [2 x i8] c" \00"
@.str.8 = [2 x i8] c"r\00"
define noalias i32* @open_input(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = sext i32 %2 to i64
%4 = getelementptr inbounds i8, i8* %0, i64 %3
%5 = tail call i32 @strlen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%6 = icmp sgt i32 %2, %5
br i1 %6, label %7, label %26
7: ; preds = %1
%8 = sext i32 %5 to i64
%9 = sub nsw i64 0, %8
%10 = getelementptr inbounds i8, i8* %4, i64 %9
%11 = tail call i32 @strcmp(i8* dereferenceable(1) %10, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %26
13: ; preds = %47, %38, %29, %7
%14 = phi i64 [ 0, %7 ], [ 1, %29 ], [ 2, %38 ], [ 3, %47 ]
%15 = getelementptr inbounds [4 x [2 x i8*]], [4 x [2 x i8*]]* @__const.open_input.tab, i64 0, i64 %14, i64 1
%16 = load i8*, i8** %15
%17 = tail call i32 @strlen(i8* %16)
%18 = add i32 %2, 2
%19 = add i32 %18, %17
%20 = tail call i8* @malloc(i32 %19)
%21 = tail call i32 @strcpy(i8* %20, i8* %16)
%22 = tail call i32 @strcat(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%23 = tail call i32 @strcat(i8* %20, i8* %0)
%24 = tail call i32* @popen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%25 = tail call i32 @free(i8* %20)
br label %55
26: ; preds = %7, %1
%27 = tail call i32 @strlen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%28 = icmp sgt i32 %2, %27
br i1 %28, label %29, label %35
29: ; preds = %26
%30 = sext i32 %27 to i64
%31 = sub nsw i64 0, %30
%32 = getelementptr inbounds i8, i8* %4, i64 %31
%33 = tail call i32 @strcmp(i8* dereferenceable(1) %32, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%34 = icmp eq i32 %33, 0
br i1 %34, label %13, label %35
35: ; preds = %29, %26
%36 = tail call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%37 = icmp sgt i32 %2, %36
br i1 %37, label %38, label %44
38: ; preds = %35
%39 = sext i32 %36 to i64
%40 = sub nsw i64 0, %39
%41 = getelementptr inbounds i8, i8* %4, i64 %40
%42 = tail call i32 @strcmp(i8* dereferenceable(1) %41, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%43 = icmp eq i32 %42, 0
br i1 %43, label %13, label %44
44: ; preds = %38, %35
%45 = tail call i32 @strlen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%46 = icmp sgt i32 %2, %45
br i1 %46, label %47, label %53
47: ; preds = %44
%48 = sext i32 %45 to i64
%49 = sub nsw i64 0, %48
%50 = getelementptr inbounds i8, i8* %4, i64 %49
%51 = tail call i32 @strcmp(i8* dereferenceable(1) %50, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%52 = icmp eq i32 %51, 0
br i1 %52, label %13, label %53
53: ; preds = %47, %44
%54 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
br label %55
55: ; preds = %13, %53
%56 = phi i32* [ %24, %13 ], [ %54, %53 ]
ret i32* %56
}