#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*/ error(char *, char const *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ getFileExt(char const *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char const *);
scalar_t__ strcmp(int /*<<< orphan*/, char *);
FILE *openFile(const char *fname) {
  FILE *fp;
  char cmd[128];
  if (strcmp(getFileExt(fname), "gz") == 0) {
    sprintf(cmd, "gunzip -c %s", fname);
    fp = popen(cmd, "r");
  } else {
    fp = fopen(fname, "r");
  }
  if (fp == NULL) {
    error("The file %s does not exist!", fname);
  }
  return fp;
}


x86 assembly (clang, -O0):
<openFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <getFileExt@plt>
mov    %eax,%edi
lea    0xe7f(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    11c3 <openFile+0x63>
lea    -0x90(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe61(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0x90(%rbp),%rdi
lea    0xe5b(%rip),%rsi
call   1060 <popen@plt>
mov    %rax,-0x10(%rbp)
jmp    11d7 <openFile+0x77>
mov    -0x8(%rbp),%rdi
lea    0xe42(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11f2 <openFile+0x92>
mov    -0x8(%rbp),%rsi
lea    0xe25(%rip),%rdi
call   1050 <error@plt>
mov    -0x10(%rbp),%rax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<openFile>:
push   %r14
push   %rbx
sub    $0x88,%rsp
mov    %rdi,%r14
call   1040 <getFileExt@plt>
lea    0xe87(%rip),%rsi
mov    %eax,%edi
call   1030 <strcmp@plt>
test   %rax,%rax
je     1196 <openFile+0x36>
lea    0xe84(%rip),%rsi
mov    %r14,%rdi
call   1070 <fopen@plt>
jmp    11ba <openFile+0x5a>
lea    0xe66(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %r14,%rdx
call   1080 <sprintf@plt>
lea    0xe5e(%rip),%rsi
mov    %rbx,%rdi
call   1060 <popen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11d1 <openFile+0x71>
lea    0xe49(%rip),%rdi
mov    %r14,%rsi
call   1050 <error@plt>
mov    %rbx,%rax
add    $0x88,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c"gz\00"
@.str.1 = [13 x i8] c"gunzip -c %s\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [28 x i8] c"The file %s does not exist!\00"
define i32* @openFile(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca [128 x i8]
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @getFileExt(i8* %5)
%7 = call i64 @strcmp(i32 %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %15
9: ; preds = %1
%10 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%11 = load i8*, i8** %2
%12 = call i32 @sprintf(i8* %10, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%13 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%14 = call i32* @popen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %14, i32** %3
br label %18
15: ; preds = %1
%16 = load i8*, i8** %2
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %17, i32** %3
br label %18
18: ; preds = %15, %9
%19 = load i32*, i32** %3
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = load i8*, i8** %2
%23 = call i32 @error(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %22)
br label %24
24: ; preds = %21, %18
%25 = load i32*, i32** %3
ret i32* %25
}

LLVM IR (-O2):
@.str = [3 x i8] c"gz\00"
@.str.1 = [13 x i8] c"gunzip -c %s\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [28 x i8] c"The file %s does not exist!\00"
define i32* @openFile(i8* %0) {
%2 = alloca [128 x i8]
%3 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%4 = tail call i32 @getFileExt(i8* %0)
%5 = tail call i64 @strcmp(i32 %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%9 = call i32* @popen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %12
10: ; preds = %1
%11 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %12
12: ; preds = %10, %7
%13 = phi i32* [ %9, %7 ], [ %11, %10 ]
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = tail call i32 @error(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br label %17
17: ; preds = %15, %12
ret i32* %13
}