#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 */
scalar_t__ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int close_fifos(int num, char **fifos, int *fifo_fds) {
  int i;
  int res = 0;
  for (i = 0; i < num; i++) {
    if (fifo_fds[i] < 0)
      continue;
    if (0 != close(fifo_fds[i])) {
      fprintf(stderr, "Error closing named pipe %s : %s\n", fifos[i],
              strerror(errno));
      res = -1;
    }
    fifo_fds[i] = -1;
  }
  return res;
}


x86 assembly (clang, -O0):
<close_fifos>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11f6 <close_fifos+0xc6>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jge    1174 <close_fifos+0x44>
jmp    11e8 <close_fifos+0xb8>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
call   1030 <close@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     11d9 <close_fifos+0xa9>
mov    0x2e47(%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    0x2e23(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rdx
mov    %rax,%rcx
lea    0xe33(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movl   $0xffffffff,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1151 <close_fifos+0x21>
mov    -0x20(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<close_fifos>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edi,%edi
jle    11a9 <close_fifos+0x79>
mov    %rdx,%r12
mov    %rsi,%r14
mov    %edi,%r13d
xor    %r15d,%r15d
xor    %ebp,%ebp
jmp    1161 <close_fifos+0x31>
nop
movl   $0xffffffff,(%r12,%r15,4)
ff
add    $0x1,%r15
cmp    %r15,%r13
je     11ab <close_fifos+0x7b>
mov    (%r12,%r15,4),%edi
test   %edi,%edi
js     1158 <close_fifos+0x28>
call   1030 <close@plt>
test   %rax,%rax
je     1150 <close_fifos+0x20>
mov    0x2e66(%rip),%rax
mov    (%rax),%ebp
mov    (%r14,%r15,8),%rbx
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    %ebp,%edi
lea    0xe69(%rip),%rsi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1040 <fprintf@plt>
mov    $0xffffffff,%ebp
jmp    1150 <close_fifos+0x20>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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