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

/* Variables and functions */
int O_NONBLOCK;
int O_RDONLY;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int open(char *, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int open_fifos(int num, char **fifos, int *fifo_fds) {
  int i;
  for (i = 0; i < num; i++) {
    fifo_fds[i] = open(fifos[i], O_RDONLY | O_NONBLOCK);
    if (fifo_fds[i] < 0) {
      fprintf(stderr, "Couldn't open named pipe %s : %s\n", fifos[i],
              strerror(errno));
      return -1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<open_fifos>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11f7 <open_fifos+0xc7>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    0x2e77(%rip),%rax
mov    (%rax),%esi
mov    0x2e76(%rip),%rax
or     (%rax),%esi
call   1040 <open@plt>
mov    %eax,%edx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jge    11e4 <open_fifos+0xb4>
mov    0x2e31(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rdx
mov    %rax,%rcx
lea    0xe2d(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fe <open_fifos+0xce>
jmp    11e9 <open_fifos+0xb9>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    114a <open_fifos+0x1a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_fifos>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edi,%edi
jle    1182 <open_fifos+0x52>
mov    %rdx,%r15
mov    %rsi,%r14
mov    %edi,%ebp
xor    %ebx,%ebx
mov    0x2e90(%rip),%r12
mov    0x2e91(%rip),%r13
nopw   0x0(%rax,%rax,1)
mov    (%r14,%rbx,8),%rdi
mov    0x0(%r13),%esi
or     (%r12),%esi
call   1040 <open@plt>
mov    %eax,(%r15,%rbx,4)
test   %eax,%eax
js     1186 <open_fifos+0x56>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1160 <open_fifos+0x30>
xor    %eax,%eax
jmp    11ba <open_fifos+0x8a>
mov    0x2e43(%rip),%rax
mov    (%rax),%ebp
mov    (%r14,%rbx,8),%r14
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe58(%rip),%rsi
mov    %ebp,%edi
mov    %r14,%rdx
mov    %rax,%rcx
call   1030 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
@O_NONBLOCK = global i32 0
@stderr = global i32 0
@.str = [34 x i8] c"Couldn't open named pipe %s : %s\0A\00"
@errno = global i32 0
define i32 @open_fifos(i32 %0, i8** %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i32*
%8 = alloca i32
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i32* %2, i32** %7
store i32 0, i32* %8
br label %9
9: ; preds = %44, %3
%10 = load i32, i32* %8
%11 = load i32, i32* %5
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %47
13: ; preds = %9
%14 = load i8**, i8*** %6
%15 = load i32, i32* %8
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8*, i8** %14, i64 %16
%18 = load i8*, i8** %17
%19 = load i32, i32* @O_RDONLY
%20 = load i32, i32* @O_NONBLOCK
%21 = or i32 %19, %20
%22 = call i32 @open(i8* %18, i32 %21)
%23 = load i32*, i32** %7
%24 = load i32, i32* %8
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32, i32* %23, i64 %25
store i32 %22, i32* %26
%27 = load i32*, i32** %7
%28 = load i32, i32* %8
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i32, i32* %27, i64 %29
%31 = load i32, i32* %30
%32 = icmp slt i32 %31, 0
br i1 %32, label %33, label %43
33: ; preds = %13
%34 = load i32, i32* @stderr
%35 = load i8**, i8*** %6
%36 = load i32, i32* %8
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8*, i8** %35, i64 %37
%39 = load i8*, i8** %38
%40 = load i32, i32* @errno
%41 = call i8* @strerror(i32 %40)
%42 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %39, i8* %41)
store i32 -1, i32* %4
br label %48
43: ; preds = %13
br label %44
44: ; preds = %43
%45 = load i32, i32* %8
%46 = add nsw i32 %45, 1
store i32 %46, i32* %8
br label %9
47: ; preds = %9
store i32 0, i32* %4
br label %48
48: ; preds = %47, %33
%49 = load i32, i32* %4
ret i32 %49
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@O_NONBLOCK = global i32 0
@stderr = global i32 0
@.str = [34 x i8] c"Couldn't open named pipe %s : %s\0A\00"
@errno = global i32 0
define i32 @open_fifos(i32 %0, i8** nocapture %1, i32* nocapture writeonly %2) {
%4 = icmp sgt i32 %0, 0
br i1 %4, label %5, label %28
5: ; preds = %3
%6 = zext i32 %0 to i64
br label %7
7: ; preds = %5, %25
%8 = phi i64 [ 0, %5 ], [ %26, %25 ]
%9 = getelementptr inbounds i8*, i8** %1, i64 %8
%10 = load i8*, i8** %9
%11 = load i32, i32* @O_RDONLY
%12 = load i32, i32* @O_NONBLOCK
%13 = or i32 %12, %11
%14 = tail call i32 @open(i8* %10, i32 %13)
%15 = getelementptr inbounds i32, i32* %2, i64 %8
store i32 %14, i32* %15
%16 = icmp slt i32 %14, 0
br i1 %16, label %17, label %25
17: ; preds = %7
%18 = and i64 %8, 4294967295
%19 = getelementptr inbounds i8*, i8** %1, i64 %18
%20 = load i32, i32* @stderr
%21 = load i8*, i8** %19
%22 = load i32, i32* @errno
%23 = tail call i8* @strerror(i32 %22)
%24 = tail call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %21, i8* %23)
br label %28
25: ; preds = %7
%26 = add nuw nsw i64 %8, 1
%27 = icmp eq i64 %26, %6
br i1 %27, label %28, label %7
28: ; preds = %25, %3, %17
%29 = phi i32 [ -1, %17 ], [ 0, %3 ], [ 0, %25 ]
ret i32 %29
}