#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 /*<<< orphan*/ _SC_OPEN_MAX;
int /*<<< orphan*/ abort();
scalar_t__ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
scalar_t__ pipe(int *);
int /*<<< orphan*/ printf(char *);
int sysconf(int /*<<< orphan*/);
int main(void) {
  int i;
  int filemax;
  filemax = sysconf(_SC_OPEN_MAX);
  if (filemax < 10)
    abort();
  for (i = 0; i < filemax * 10; i++) {
    int pip[2];
    if (pipe(pip) != 0) {
      perror("pipe");
      abort();
    }
    if (close(pip[0]) != 0 || close(pip[1]) != 0) {
      perror("close");
      abort();
    }
  }
  printf("pass\n");
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
call   1080 <sysconf@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xa,-0xc(%rbp)
jge    11a1 <main+0x31>
mov    $0x0,%al
call   1030 <abort@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
imul   $0xa,-0xc(%rbp),%ecx
cmp    %ecx,%eax
jge    1227 <main+0xb7>
lea    -0x14(%rbp),%rdi
call   1060 <pipe@plt>
cmp    $0x0,%rax
je     11dd <main+0x6d>
lea    0xe2f(%rip),%rdi
call   1070 <perror@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
cmp    $0x0,%rax
jne    1201 <main+0x91>
mov    -0x10(%rbp),%edi
call   1050 <close@plt>
cmp    $0x0,%rax
je     1214 <main+0xa4>
lea    0xdfd(%rip),%rdi
call   1070 <perror@plt>
mov    $0x0,%al
call   1030 <abort@plt>
jmp    1219 <main+0xa9>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11a8 <main+0x38>
lea    0xddd(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    0x2e66(%rip),%rax
mov    (%rax),%edi
call   1080 <sysconf@plt>
cmp    $0xa,%eax
jge    118d <main+0x1d>
xor    %eax,%eax
call   1030 <abort@plt>
add    %eax,%eax
lea    (%rax,%rax,4),%eax
cmp    $0x2,%eax
mov    $0x1,%ebp
cmovge %eax,%ebp
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1060 <pipe@plt>
test   %rax,%rax
jne    11e9 <main+0x79>
mov    (%rsp),%edi
call   1050 <close@plt>
test   %rax,%rax
jne    11e0 <main+0x70>
mov    0x4(%rsp),%edi
call   1050 <close@plt>
test   %rax,%rax
jne    11e0 <main+0x70>
add    $0xffffffff,%ebp
jne    11a0 <main+0x30>
lea    0xe37(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   1090 <exit@plt>
lea    0xe1e(%rip),%rdi
jmp    11f0 <main+0x80>
lea    0xe10(%rip),%rdi
call   1070 <perror@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@_SC_OPEN_MAX = global i32 0
@.str = [5 x i8] c"pipe\00"
@.str.1 = [6 x i8] c"close\00"
@.str.2 = [6 x i8] c"pass\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [2 x i32]
store i32 0, i32* %1
%5 = load i32, i32* @_SC_OPEN_MAX
%6 = call i32 @sysconf(i32 %5)
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 10
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 (...) @abort()
unreachable
11: ; preds = %0
store i32 0, i32* %2
br label %12
12: ; preds = %38, %11
%13 = load i32, i32* %2
%14 = load i32, i32* %3
%15 = mul nsw i32 %14, 10
%16 = icmp slt i32 %13, %15
br i1 %16, label %17, label %41
17: ; preds = %12
%18 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%19 = call i64 @pipe(i32* %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%23 = call i32 (...) @abort()
unreachable
24: ; preds = %17
%25 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%26 = load i32, i32* %25
%27 = call i64 @close(i32 %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %34, label %29
29: ; preds = %24
%30 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%31 = load i32, i32* %30
%32 = call i64 @close(i32 %31)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %29, %24
%35 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%36 = call i32 (...) @abort()
unreachable
37: ; preds = %29
br label %38
38: ; preds = %37
%39 = load i32, i32* %2
%40 = add nsw i32 %39, 1
store i32 %40, i32* %2
br label %12
41: ; preds = %12
%42 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%43 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@_SC_OPEN_MAX = global i32 0
@.str = [5 x i8] c"pipe\00"
@.str.1 = [6 x i8] c"close\00"
@str = [5 x i8] c"pass\00"
define i32 @main() {
%1 = alloca [2 x i32]
%2 = load i32, i32* @_SC_OPEN_MAX
%3 = tail call i32 @sysconf(i32 %2)
%4 = icmp slt i32 %3, 10
br i1 %4, label %11, label %5
5: ; preds = %0
%6 = mul i32 %3, 10
%7 = bitcast [2 x i32]* %1 to i8*
%8 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%9 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%10 = call i32 @llvm.smax.i32(i32 %6, i32 1)
br label %13
11: ; preds = %0
%12 = tail call i32 (...) @abort()
unreachable
13: ; preds = %5, %31
%14 = phi i32 [ 0, %5 ], [ %32, %31 ]
%15 = call i64 @pipe(i32* %8)
%16 = icmp eq i64 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %13
%18 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%19 = call i32 (...) @abort()
unreachable
20: ; preds = %13
%21 = load i32, i32* %8
%22 = call i64 @close(i32 %21)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %20
%25 = load i32, i32* %9
%26 = call i64 @close(i32 %25)
%27 = icmp eq i64 %26, 0
br i1 %27, label %31, label %28
28: ; preds = %24, %20
%29 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%30 = call i32 (...) @abort()
unreachable
31: ; preds = %24
%32 = add nuw nsw i32 %14, 1
%33 = icmp eq i32 %32, %10
br i1 %33, label %34, label %13
34: ; preds = %31
%35 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
%36 = call i32 @exit(i32 0)
unreachable
}