#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 close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
int pipes_fils_end_close(int num_fils, int **pipes) {
  int indice;
  for (indice = 5; indice < 9; indice++) {
    if (num_fils == (indice - 4)) {
      if (indice == 5) {
        if (close(pipes[8][0]) == -1) {
          fprintf(stderr, "Erreur lors de fermeture de pipes[8][0] \n");
        }
      } else {
        if (close(pipes[(indice - 1)][0]) == -1) {
          fprintf(stderr, "Erreur lors de fermeture de pipes[%d][0] \n",
                  indice);
        }
      }
      if (close(pipes[indice][1]) == -1) {
        fprintf(stderr, "Erreur lors de fermeture de pipes[%d][1] \n", indice);
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<pipes_fils_end_close>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x5,-0x14(%rbp)
cmpl   $0x9,-0x14(%rbp)
jge    121e <pipes_fils_end_close+0xfe>
mov    -0x4(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x4,%ecx
cmp    %ecx,%eax
jne    120b <pipes_fils_end_close+0xeb>
cmpl   $0x5,-0x14(%rbp)
jne    118f <pipes_fils_end_close+0x6f>
mov    -0x10(%rbp),%rax
mov    0x40(%rax),%rax
mov    (%rax),%edi
call   1030 <close@plt>
cmp    $0xffffffff,%eax
jne    118a <pipes_fils_end_close+0x6a>
mov    0x2e66(%rip),%rax
mov    (%rax),%edi
lea    0xe7d(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    11cf <pipes_fils_end_close+0xaf>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    (%rax),%edi
call   1030 <close@plt>
cmp    $0xffffffff,%eax
jne    11ca <pipes_fils_end_close+0xaa>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xe67(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    11cf <pipes_fils_end_close+0xaf>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    0x4(%rax),%edi
call   1030 <close@plt>
cmp    $0xffffffff,%eax
jne    1206 <pipes_fils_end_close+0xe6>
mov    0x2ded(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xe56(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    120b <pipes_fils_end_close+0xeb>
jmp    1210 <pipes_fils_end_close+0xf0>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1136 <pipes_fils_end_close+0x16>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pipes_fils_end_close>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
lea    -0x1(%rbx),%eax
cmp    $0x3,%eax
ja     12d8 <pipes_fils_end_close+0x1b8>
mov    %rsi,%r14
lea    0xec4(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x40(%r14),%rax
mov    (%rax),%edi
call   1030 <close@plt>
cmp    $0xffffffff,%eax
jne    116c <pipes_fils_end_close+0x4c>
mov    0x2e84(%rip),%rax
mov    (%rax),%edi
lea    0xeab(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x28(%r14),%rax
mov    0x4(%rax),%edi
call   1030 <close@plt>
cmp    $0xffffffff,%eax
jne    1199 <pipes_fils_end_close+0x79>
mov    0x2e5c(%rip),%rax
mov    (%rax),%edi
lea    0xed8(%rip),%rsi
mov    $0x5,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
cmp    $0x4,%ebx
je     127f <pipes_fils_end_close+0x15f>
cmp    $0x3,%ebx
je     1221 <pipes_fils_end_close+0x101>
cmp    $0x2,%ebx
jne    12d8 <pipes_fils_end_close+0x1b8>
mov    0x28(%r14),%rax
mov    (%rax),%edi
call   1030 <close@plt>
cmp    $0xffffffff,%eax
jne    11dc <pipes_fils_end_close+0xbc>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
lea    0xe6a(%rip),%rsi
mov    $0x6,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x30(%r14),%rax
mov    0x4(%rax),%edi
call   1030 <close@plt>
cmp    $0xffffffff,%eax
je     11f7 <pipes_fils_end_close+0xd7>
cmp    $0x4,%ebx
jne    1218 <pipes_fils_end_close+0xf8>
jmp    127f <pipes_fils_end_close+0x15f>
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
lea    0xe5e(%rip),%rsi
mov    $0x6,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
cmp    $0x4,%ebx
je     127f <pipes_fils_end_close+0x15f>
cmp    $0x3,%ebx
jne    12d8 <pipes_fils_end_close+0x1b8>
mov    0x30(%r14),%rax
mov    (%rax),%edi
call   1030 <close@plt>
cmp    $0xffffffff,%eax
jne    124d <pipes_fils_end_close+0x12d>
mov    0x2da8(%rip),%rax
mov    (%rax),%edi
lea    0xdf9(%rip),%rsi
mov    $0x7,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x38(%r14),%rax
mov    0x4(%rax),%edi
call   1030 <close@plt>
cmp    $0xffffffff,%eax
jne    127a <pipes_fils_end_close+0x15a>
mov    0x2d7b(%rip),%rax
mov    (%rax),%edi
lea    0xdf7(%rip),%rsi
mov    $0x7,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
cmp    $0x4,%ebx
jne    12d8 <pipes_fils_end_close+0x1b8>
mov    0x38(%r14),%rax
mov    (%rax),%edi
call   1030 <close@plt>
cmp    $0xffffffff,%eax
jne    12ab <pipes_fils_end_close+0x18b>
mov    0x2d4a(%rip),%rax
mov    (%rax),%edi
lea    0xd9b(%rip),%rsi
mov    $0x8,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x40(%r14),%rax
mov    0x4(%rax),%edi
call   1030 <close@plt>
cmp    $0xffffffff,%eax
jne    12d8 <pipes_fils_end_close+0x1b8>
mov    0x2d1d(%rip),%rax
mov    (%rax),%edi
lea    0xd99(%rip),%rsi
mov    $0x8,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [42 x i8] c"Erreur lors de fermeture de pipes[8][0] \0A\00"
@.str.1 = [43 x i8] c"Erreur lors de fermeture de pipes[%d][0] \0A\00"
@.str.2 = [43 x i8] c"Erreur lors de fermeture de pipes[%d][1] \0A\00"
define i32 @pipes_fils_end_close(i32 %0, i32** %1) {
%3 = alloca i32
%4 = alloca i32**
%5 = alloca i32
store i32 %0, i32* %3
store i32** %1, i32*** %4
store i32 5, i32* %5
br label %6
6: ; preds = %61, %2
%7 = load i32, i32* %5
%8 = icmp slt i32 %7, 9
br i1 %8, label %9, label %64
9: ; preds = %6
%10 = load i32, i32* %3
%11 = load i32, i32* %5
%12 = sub nsw i32 %11, 4
%13 = icmp eq i32 %10, %12
br i1 %13, label %14, label %60
14: ; preds = %9
%15 = load i32, i32* %5
%16 = icmp eq i32 %15, 5
br i1 %16, label %17, label %29
17: ; preds = %14
%18 = load i32**, i32*** %4
%19 = getelementptr inbounds i32*, i32** %18, i64 8
%20 = load i32*, i32** %19
%21 = getelementptr inbounds i32, i32* %20, i64 0
%22 = load i32, i32* %21
%23 = call i32 @close(i32 %22)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %28
25: ; preds = %17
%26 = load i32, i32* @stderr
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
br label %28
28: ; preds = %25, %17
br label %45
29: ; preds = %14
%30 = load i32**, i32*** %4
%31 = load i32, i32* %5
%32 = sub nsw i32 %31, 1
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i32*, i32** %30, i64 %33
%35 = load i32*, i32** %34
%36 = getelementptr inbounds i32, i32* %35, i64 0
%37 = load i32, i32* %36
%38 = call i32 @close(i32 %37)
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %44
40: ; preds = %29
%41 = load i32, i32* @stderr
%42 = load i32, i32* %5
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i32 %42)
br label %44
44: ; preds = %40, %29
br label %45
45: ; preds = %44, %28
%46 = load i32**, i32*** %4
%47 = load i32, i32* %5
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i32*, i32** %46, i64 %48
%50 = load i32*, i32** %49
%51 = getelementptr inbounds i32, i32* %50, i64 1
%52 = load i32, i32* %51
%53 = call i32 @close(i32 %52)
%54 = icmp eq i32 %53, -1
br i1 %54, label %55, label %59
55: ; preds = %45
%56 = load i32, i32* @stderr
%57 = load i32, i32* %5
%58 = call i32 (i32, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i32 %57)
br label %59
59: ; preds = %55, %45
br label %60
60: ; preds = %59, %9
br label %61
61: ; preds = %60
%62 = load i32, i32* %5
%63 = add nsw i32 %62, 1
store i32 %63, i32* %5
br label %6
64: ; preds = %6
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [42 x i8] c"Erreur lors de fermeture de pipes[8][0] \0A\00"
@.str.1 = [43 x i8] c"Erreur lors de fermeture de pipes[%d][0] \0A\00"
@.str.2 = [43 x i8] c"Erreur lors de fermeture de pipes[%d][1] \0A\00"
define i32 @pipes_fils_end_close(i32 %0, i32** nocapture %1) {
switch i32 %0, label %83 [
i32 1, label %3
i32 2, label %23
i32 3, label %43
i32 4, label %64
]
3: ; preds = %2
%4 = getelementptr inbounds i32*, i32** %1, i64 8
%5 = load i32*, i32** %4
%6 = load i32, i32* %5
%7 = tail call i32 @close(i32 %6)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %12
9: ; preds = %3
%10 = load i32, i32* @stderr
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %9, %3
%13 = getelementptr inbounds i32*, i32** %1, i64 5
%14 = load i32*, i32** %13
%15 = getelementptr inbounds i32, i32* %14, i64 1
%16 = load i32, i32* %15
%17 = tail call i32 @close(i32 %16)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %22
19: ; preds = %12
%20 = load i32, i32* @stderr
%21 = tail call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i32 5)
br label %22
22: ; preds = %19, %12
switch i32 %0, label %83 [
i32 2, label %23
i32 3, label %43
i32 4, label %64
]
23: ; preds = %2, %22
%24 = getelementptr inbounds i32*, i32** %1, i64 5
%25 = load i32*, i32** %24
%26 = load i32, i32* %25
%27 = tail call i32 @close(i32 %26)
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %32
29: ; preds = %23
%30 = load i32, i32* @stderr
%31 = tail call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i32 6)
br label %32
32: ; preds = %23, %29
%33 = getelementptr inbounds i32*, i32** %1, i64 6
%34 = load i32*, i32** %33
%35 = getelementptr inbounds i32, i32* %34, i64 1
%36 = load i32, i32* %35
%37 = tail call i32 @close(i32 %36)
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %42
39: ; preds = %32
%40 = load i32, i32* @stderr
%41 = tail call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i32 6)
br label %42
42: ; preds = %39, %32
switch i32 %0, label %83 [
i32 3, label %43
i32 4, label %64
]
43: ; preds = %2, %22, %42
%44 = getelementptr inbounds i32*, i32** %1, i64 6
%45 = load i32*, i32** %44
%46 = load i32, i32* %45
%47 = tail call i32 @close(i32 %46)
%48 = icmp eq i32 %47, -1
br i1 %48, label %49, label %52
49: ; preds = %43
%50 = load i32, i32* @stderr
%51 = tail call i32 (i32, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i32 7)
br label %52
52: ; preds = %49, %43
%53 = getelementptr inbounds i32*, i32** %1, i64 7
%54 = load i32*, i32** %53
%55 = getelementptr inbounds i32, i32* %54, i64 1
%56 = load i32, i32* %55
%57 = tail call i32 @close(i32 %56)
%58 = icmp eq i32 %57, -1
br i1 %58, label %59, label %62
59: ; preds = %52
%60 = load i32, i32* @stderr
%61 = tail call i32 (i32, i8*, ...) @fprintf(i32 %60, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i32 7)
br label %62
62: ; preds = %59, %52
%63 = icmp eq i32 %0, 4
br i1 %63, label %64, label %83
64: ; preds = %2, %22, %42, %62
%65 = getelementptr inbounds i32*, i32** %1, i64 7
%66 = load i32*, i32** %65
%67 = load i32, i32* %66
%68 = tail call i32 @close(i32 %67)
%69 = icmp eq i32 %68, -1
br i1 %69, label %70, label %73
70: ; preds = %64
%71 = load i32, i32* @stderr
%72 = tail call i32 (i32, i8*, ...) @fprintf(i32 %71, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i32 8)
br label %73
73: ; preds = %70, %64
%74 = getelementptr inbounds i32*, i32** %1, i64 8
%75 = load i32*, i32** %74
%76 = getelementptr inbounds i32, i32* %75, i64 1
%77 = load i32, i32* %76
%78 = tail call i32 @close(i32 %77)
%79 = icmp eq i32 %78, -1
br i1 %79, label %80, label %83
80: ; preds = %73
%81 = load i32, i32* @stderr
%82 = tail call i32 (i32, i8*, ...) @fprintf(i32 %81, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i32 8)
br label %83
83: ; preds = %2, %22, %42, %80, %73, %62
ret i32 0
}