#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*/ EBADF;
int /*<<< orphan*/ assert(int);
int close(int);
int /*<<< orphan*/ closefrom(int);
int /*<<< orphan*/ errno;
int pipe(int *);
int main(void) {
  int fd[2];
  int val;
  val = pipe(fd);
  assert(val == 0);
  assert(fd[0] >= 3);
  closefrom(3);
  val = close(3);
  assert((val == -1) && (errno = EBADF));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0xc(%rbp),%rdi
call   1050 <pipe@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
cmpl   $0x3,-0xc(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    $0x3,%edi
call   1030 <closefrom@plt>
mov    $0x3,%edi
call   1040 <close@plt>
mov    %eax,-0x10(%rbp)
xor    %eax,%eax
cmpl   $0xffffffff,-0x10(%rbp)
mov    %al,-0x11(%rbp)
jne    11be <main+0x7e>
mov    0x2e2e(%rip),%rax
mov    (%rax),%eax
mov    0x2e2d(%rip),%rcx
mov    %eax,(%rcx)
cmp    $0x0,%eax
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    %rsp,%rdi
call   1050 <pipe@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1060 <assert@plt>
xor    %edi,%edi
cmpl   $0x3,(%rsp)
setge  %dil
call   1060 <assert@plt>
mov    $0x3,%edi
call   1030 <closefrom@plt>
mov    $0x3,%edi
call   1040 <close@plt>
xor    %edi,%edi
cmp    $0xffffffff,%eax
jne    119a <main+0x5a>
mov    0x2e51(%rip),%rax
mov    (%rax),%eax
mov    0x2e50(%rip),%rcx
mov    %eax,(%rcx)
xor    %edi,%edi
test   %eax,%eax
setne  %dil
call   1060 <assert@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@EBADF = global i32 0
@errno = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i32]
%3 = alloca i32
store i32 0, i32* %1
%4 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%5 = call i32 @pipe(i32* %4)
store i32 %5, i32* %3
%6 = load i32, i32* %3
%7 = icmp eq i32 %6, 0
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%11 = load i32, i32* %10
%12 = icmp sge i32 %11, 3
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = call i32 @closefrom(i32 3)
%16 = call i32 @close(i32 3)
store i32 %16, i32* %3
%17 = load i32, i32* %3
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %22
19: ; preds = %0
%20 = load i32, i32* @EBADF
store i32 %20, i32* @errno
%21 = icmp ne i32 %20, 0
br label %22
22: ; preds = %19, %0
%23 = phi i1 [ false, %0 ], [ %21, %19 ]
%24 = zext i1 %23 to i32
%25 = call i32 @assert(i32 %24)
ret i32 0
}

LLVM IR (-O2):
@EBADF = global i32 0
@errno = global i32 0
define i32 @main() {
%1 = alloca [2 x i32]
%2 = bitcast [2 x i32]* %1 to i8*
%3 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%4 = call i32 @pipe(i32* %3)
%5 = icmp eq i32 %4, 0
%6 = zext i1 %5 to i32
%7 = call i32 @assert(i32 %6)
%8 = load i32, i32* %3
%9 = icmp sgt i32 %8, 2
%10 = zext i1 %9 to i32
%11 = call i32 @assert(i32 %10)
%12 = call i32 @closefrom(i32 3)
%13 = call i32 @close(i32 3)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %19
15: ; preds = %0
%16 = load i32, i32* @EBADF
store i32 %16, i32* @errno
%17 = icmp ne i32 %16, 0
%18 = zext i1 %17 to i32
br label %19
19: ; preds = %15, %0
%20 = phi i32 [ 0, %0 ], [ %18, %15 ]
%21 = call i32 @assert(i32 %20)
ret i32 0
}