#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 */
struct stat {
  int /*<<< orphan*/ st_mode;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ S_ISFIFO(int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ lstat(char *, struct stat *);
FILE *openStream(char *argv[], int open_counter, FILE *file_pes[]) {
  FILE *result = NULL;
  struct stat file_stat;
  if (lstat(argv[6 + open_counter], &file_stat) == 0) {
    if (!S_ISFIFO(file_stat.st_mode)) {
      result = fopen(argv[6 + open_counter], "rb");
      file_pes[open_counter] = result;
    } else {
      result = file_pes[open_counter];
    }
  }
  return result;
}


x86 assembly (clang, -O0):
<openStream>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
add    $0x6,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
lea    -0x28(%rbp),%rsi
call   1040 <lstat@plt>
cmp    $0x0,%rax
jne    11cb <openStream+0x9b>
mov    -0x28(%rbp),%edi
call   1030 <S_ISFIFO@plt>
cmp    $0x0,%eax
jne    11b6 <openStream+0x86>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
add    $0x6,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe68(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdx
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
jmp    11c6 <openStream+0x96>
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x20(%rbp)
jmp    11cb <openStream+0x9b>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<openStream>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %rdi,%rbx
movslq %esi,%r15
mov    0x30(%rdi,%r15,8),%rdi
lea    0x8(%rsp),%rsi
call   1040 <lstat@plt>
test   %rax,%rax
je     115a <openStream+0x2a>
xor    %eax,%eax
jmp    1185 <openStream+0x55>
mov    0x8(%rsp),%edi
call   1030 <S_ISFIFO@plt>
test   %eax,%eax
je     116d <openStream+0x3d>
mov    (%r14,%r15,8),%rax
jmp    1185 <openStream+0x55>
lea    0x6(%r15),%rax
mov    (%rbx,%rax,8),%rdi
lea    0xe84(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,(%r14,%r15,8)
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [3 x i8] c"rb\00"
define i32* @openStream(i8** %0, i32 %1, i32** %2) {
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32**
%7 = alloca i32*
%8 = alloca %struct.stat
store i8** %0, i8*** %4
store i32 %1, i32* %5
store i32** %2, i32*** %6
store i32* null, i32** %7
%9 = load i8**, i8*** %4
%10 = load i32, i32* %5
%11 = add nsw i32 6, %10
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8*, i8** %9, i64 %12
%14 = load i8*, i8** %13
%15 = call i64 @lstat(i8* %14, %struct.stat* %8)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %42
17: ; preds = %3
%18 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%19 = load i32, i32* %18
%20 = call i32 @S_ISFIFO(i32 %19)
%21 = icmp ne i32 %20, 0
br i1 %21, label %35, label %22
22: ; preds = %17
%23 = load i8**, i8*** %4
%24 = load i32, i32* %5
%25 = add nsw i32 6, %24
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8*, i8** %23, i64 %26
%28 = load i8*, i8** %27
%29 = call i32* @fopen(i8* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %29, i32** %7
%30 = load i32*, i32** %7
%31 = load i32**, i32*** %6
%32 = load i32, i32* %5
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i32*, i32** %31, i64 %33
store i32* %30, i32** %34
br label %41
35: ; preds = %17
%36 = load i32**, i32*** %6
%37 = load i32, i32* %5
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i32*, i32** %36, i64 %38
%40 = load i32*, i32** %39
store i32* %40, i32** %7
br label %41
41: ; preds = %35, %22
br label %42
42: ; preds = %41, %3
%43 = load i32*, i32** %7
ret i32* %43
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [3 x i8] c"rb\00"
define i32* @openStream(i8** nocapture %0, i32 %1, i32** nocapture %2) {
%4 = alloca %struct.stat
%5 = bitcast %struct.stat* %4 to i8*
%6 = add nsw i32 %1, 6
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i8*, i8** %0, i64 %7
%9 = load i8*, i8** %8
%10 = call i64 @lstat(i8* %9, %struct.stat* %4)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %26
12: ; preds = %3
%13 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%14 = load i32, i32* %13
%15 = tail call i32 @S_ISFIFO(i32 %14)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %12
%18 = load i8*, i8** %8
%19 = tail call i32* @fopen(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%20 = sext i32 %1 to i64
%21 = getelementptr inbounds i32*, i32** %2, i64 %20
store i32* %19, i32** %21
br label %26
22: ; preds = %12
%23 = sext i32 %1 to i64
%24 = getelementptr inbounds i32*, i32** %2, i64 %23
%25 = load i32*, i32** %24
br label %26
26: ; preds = %17, %22, %3
%27 = phi i32* [ %25, %22 ], [ %19, %17 ], [ null, %3 ]
ret i32* %27
}