#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__ EBADF;
scalar_t__ EPIPE;
int /*<<< orphan*/ SIGPIPE;
scalar_t__ SIG_DFL;
int /*<<< orphan*/ SIG_IGN;
int /*<<< orphan*/ _PC_PIPE_BUF;
int /*<<< orphan*/ abort();
scalar_t__ close(int);
int /*<<< orphan*/ err(char *);
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fpathconf(int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
scalar_t__ pipe(int *);
int /*<<< orphan*/ printf(char *);
int read(int, char *, int);
scalar_t__ signal(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int write(int, char *, int);
int main(void) {
  int pip[2];
  char c;
  int pipemax;
  if (pipe(pip) != 0)
    err("pipe");
  pipemax = fpathconf(pip[1], _PC_PIPE_BUF);
  if (pipemax <= 0) {
    fprintf(stderr, "Bad pipemax %d\n", pipemax);
    abort();
  }
  if (write(pip[0], "argh", 1) != -1 || errno != EBADF)
    err("write pipe");
  errno = 0;
  if (read(pip[1], &c, 1) != -1 || errno != EBADF)
    err("write pipe");
  errno = 0;
  if (close(pip[0]) != 0)
    err("close");
  if (signal(SIGPIPE, SIG_IGN) != SIG_DFL)
    err("signal");
  if (write(pip[1], "argh", 1) != -1 || errno != EPIPE)
    err("write closed");
  printf("pass\n");
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0xc(%rbp),%rdi
call   1070 <pipe@plt>
cmp    $0x0,%rax
je     11de <main+0x2e>
lea    0xe42(%rip),%rdi
call   10c0 <err@plt>
mov    -0x8(%rbp),%edi
mov    0x2e00(%rip),%rax
mov    (%rax),%esi
call   10a0 <fpathconf@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jg     121b <main+0x6b>
mov    0x2dcd(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xdf1(%rip),%rsi
call   10b0 <fprintf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0xc(%rbp),%edi
lea    0xdeb(%rip),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
cmp    $0xffffffff,%eax
jne    1252 <main+0xa2>
mov    0x2d79(%rip),%rax
mov    (%rax),%rax
mov    0x2d5f(%rip),%rcx
cmp    (%rcx),%rax
je     125e <main+0xae>
lea    0xdbc(%rip),%rdi
call   10c0 <err@plt>
mov    0x2d53(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%edi
lea    -0xd(%rbp),%rsi
mov    $0x1,%edx
call   1080 <read@plt>
cmp    $0xffffffff,%eax
jne    12a0 <main+0xf0>
mov    0x2d2b(%rip),%rax
mov    (%rax),%rax
mov    0x2d11(%rip),%rcx
cmp    (%rcx),%rax
je     12ac <main+0xfc>
lea    0xd6e(%rip),%rdi
call   10c0 <err@plt>
mov    0x2d05(%rip),%rax
movq   $0x0,(%rax)
mov    -0xc(%rbp),%edi
call   1060 <close@plt>
cmp    $0x0,%rax
je     12d8 <main+0x128>
lea    0xd4d(%rip),%rdi
call   10c0 <err@plt>
mov    0x2ce1(%rip),%rax
mov    (%rax),%edi
mov    0x2cf8(%rip),%rax
mov    (%rax),%esi
call   1090 <signal@plt>
mov    0x2cba(%rip),%rcx
cmp    (%rcx),%rax
je     130b <main+0x15b>
lea    0xd20(%rip),%rdi
call   10c0 <err@plt>
mov    -0x8(%rbp),%edi
lea    0xcfb(%rip),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
cmp    $0xffffffff,%eax
jne    1342 <main+0x192>
mov    0x2c89(%rip),%rax
mov    (%rax),%rax
mov    0x2c8f(%rip),%rcx
cmp    (%rcx),%rax
je     134e <main+0x19e>
lea    0xce4(%rip),%rdi
call   10c0 <err@plt>
lea    0xce5(%rip),%rdi
call   1050 <printf@plt>
xor    %edi,%edi
call   10d0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0x8(%rsp),%rdi
call   1070 <pipe@plt>
test   %rax,%rax
je     11d0 <main+0x20>
lea    0xe50(%rip),%rdi
call   10c0 <err@plt>
mov    0xc(%rsp),%edi
mov    0x2e0d(%rip),%rax
mov    (%rax),%esi
call   10a0 <fpathconf@plt>
test   %eax,%eax
jg     1204 <main+0x54>
mov    0x2de3(%rip),%rcx
mov    (%rcx),%edi
lea    0xe0a(%rip),%rsi
mov    %eax,%edx
call   10b0 <fprintf@plt>
xor    %eax,%eax
call   1030 <abort@plt>
mov    0x8(%rsp),%edi
lea    0xe01(%rip),%rsi
mov    $0x1,%edx
call   1050 <write@plt>
cmp    $0xffffffff,%eax
jne    1234 <main+0x84>
mov    0x2d93(%rip),%rax
mov    (%rax),%rax
mov    0x2d79(%rip),%rcx
cmp    (%rcx),%rax
je     1240 <main+0x90>
lea    0xdda(%rip),%rdi
call   10c0 <err@plt>
mov    0x2d71(%rip),%rbx
movq   $0x0,(%rbx)
mov    0xc(%rsp),%edi
lea    0x7(%rsp),%rsi
mov    $0x1,%edx
call   1080 <read@plt>
cmp    $0xffffffff,%eax
jne    1275 <main+0xc5>
mov    (%rbx),%rax
mov    0x2d38(%rip),%rcx
cmp    (%rcx),%rax
je     1281 <main+0xd1>
lea    0xd99(%rip),%rdi
call   10c0 <err@plt>
movq   $0x0,(%rbx)
mov    0x8(%rsp),%edi
call   1060 <close@plt>
test   %rax,%rax
je     12a2 <main+0xf2>
lea    0xd83(%rip),%rdi
call   10c0 <err@plt>
mov    0x2d17(%rip),%rax
mov    (%rax),%edi
mov    0x2d2e(%rip),%rax
mov    (%rax),%esi
call   1090 <signal@plt>
mov    0x2cf0(%rip),%rcx
cmp    (%rcx),%rax
je     12d1 <main+0x121>
lea    0xd5a(%rip),%rdi
call   10c0 <err@plt>
mov    0xc(%rsp),%edi
lea    0xd34(%rip),%rsi
mov    $0x1,%edx
call   1050 <write@plt>
cmp    $0xffffffff,%eax
jne    12fa <main+0x14a>
mov    (%rbx),%rax
mov    0x2cd3(%rip),%rcx
cmp    (%rcx),%rax
je     1306 <main+0x156>
lea    0xd2c(%rip),%rdi
call   10c0 <err@plt>
lea    0xd2d(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"pipe\00"
@_PC_PIPE_BUF = global i32 0
@stderr = global i32 0
@.str.1 = [16 x i8] c"Bad pipemax %d\0A\00"
@.str.2 = [5 x i8] c"argh\00"
@errno = global i64 0
@EBADF = global i64 0
@.str.3 = [11 x i8] c"write pipe\00"
@.str.4 = [6 x i8] c"close\00"
@SIGPIPE = global i32 0
@SIG_IGN = global i32 0
@SIG_DFL = global i64 0
@.str.5 = [7 x i8] c"signal\00"
@EPIPE = global i64 0
@.str.6 = [13 x i8] c"write closed\00"
@.str.7 = [6 x i8] c"pass\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i32]
%3 = alloca i8
%4 = alloca i32
store i32 0, i32* %1
%5 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%6 = call i64 @pipe(i32* %5)
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 @err(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %0
%11 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%12 = load i32, i32* %11
%13 = load i32, i32* @_PC_PIPE_BUF
%14 = call i32 @fpathconf(i32 %12, i32 %13)
store i32 %14, i32* %4
%15 = load i32, i32* %4
%16 = icmp sle i32 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %10
%18 = load i32, i32* @stderr
%19 = load i32, i32* %4
%20 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %19)
%21 = call i32 (...) @abort()
unreachable
22: ; preds = %10
%23 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%24 = load i32, i32* %23
%25 = call i32 @write(i32 %24, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 1)
%26 = icmp ne i32 %25, -1
br i1 %26, label %31, label %27
27: ; preds = %22
%28 = load i64, i64* @errno
%29 = load i64, i64* @EBADF
%30 = icmp ne i64 %28, %29
br i1 %30, label %31, label %33
31: ; preds = %27, %22
%32 = call i32 @err(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
br label %33
33: ; preds = %31, %27
store i64 0, i64* @errno
%34 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%35 = load i32, i32* %34
%36 = call i32 @read(i32 %35, i8* %3, i32 1)
%37 = icmp ne i32 %36, -1
br i1 %37, label %42, label %38
38: ; preds = %33
%39 = load i64, i64* @errno
%40 = load i64, i64* @EBADF
%41 = icmp ne i64 %39, %40
br i1 %41, label %42, label %44
42: ; preds = %38, %33
%43 = call i32 @err(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
br label %44
44: ; preds = %42, %38
store i64 0, i64* @errno
%45 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%46 = load i32, i32* %45
%47 = call i64 @close(i32 %46)
%48 = icmp ne i64 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %44
%50 = call i32 @err(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
br label %51
51: ; preds = %49, %44
%52 = load i32, i32* @SIGPIPE
%53 = load i32, i32* @SIG_IGN
%54 = call i64 @signal(i32 %52, i32 %53)
%55 = load i64, i64* @SIG_DFL
%56 = icmp ne i64 %54, %55
br i1 %56, label %57, label %59
57: ; preds = %51
%58 = call i32 @err(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
br label %59
59: ; preds = %57, %51
%60 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%61 = load i32, i32* %60
%62 = call i32 @write(i32 %61, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 1)
%63 = icmp ne i32 %62, -1
br i1 %63, label %68, label %64
64: ; preds = %59
%65 = load i64, i64* @errno
%66 = load i64, i64* @EPIPE
%67 = icmp ne i64 %65, %66
br i1 %67, label %68, label %70
68: ; preds = %64, %59
%69 = call i32 @err(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
br label %70
70: ; preds = %68, %64
%71 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
%72 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [5 x i8] c"pipe\00"
@_PC_PIPE_BUF = global i32 0
@stderr = global i32 0
@.str.1 = [16 x i8] c"Bad pipemax %d\0A\00"
@.str.2 = [5 x i8] c"argh\00"
@errno = global i64 0
@EBADF = global i64 0
@.str.3 = [11 x i8] c"write pipe\00"
@.str.4 = [6 x i8] c"close\00"
@SIGPIPE = global i32 0
@SIG_IGN = global i32 0
@SIG_DFL = global i64 0
@.str.5 = [7 x i8] c"signal\00"
@EPIPE = global i64 0
@.str.6 = [13 x i8] c"write closed\00"
@str = [5 x i8] c"pass\00"
define i32 @main() {
%1 = alloca [2 x i32]
%2 = alloca i8
%3 = bitcast [2 x i32]* %1 to i8*
%4 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%5 = call i64 @pipe(i32* %4)
%6 = icmp eq i64 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %0
%8 = call i32 @err(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %0
%10 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%11 = load i32, i32* %10
%12 = load i32, i32* @_PC_PIPE_BUF
%13 = call i32 @fpathconf(i32 %11, i32 %12)
%14 = icmp slt i32 %13, 1
br i1 %14, label %15, label %19
15: ; preds = %9
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%18 = call i32 (...) @abort()
unreachable
19: ; preds = %9
%20 = load i32, i32* %4
%21 = call i32 @write(i32 %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 1)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %27
23: ; preds = %19
%24 = load i64, i64* @errno
%25 = load i64, i64* @EBADF
%26 = icmp eq i64 %24, %25
br i1 %26, label %29, label %27
27: ; preds = %23, %19
%28 = call i32 @err(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
br label %29
29: ; preds = %27, %23
store i64 0, i64* @errno
%30 = load i32, i32* %10
%31 = call i32 @read(i32 %30, i8* %2, i32 1)
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %37
33: ; preds = %29
%34 = load i64, i64* @errno
%35 = load i64, i64* @EBADF
%36 = icmp eq i64 %34, %35
br i1 %36, label %39, label %37
37: ; preds = %33, %29
%38 = call i32 @err(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
br label %39
39: ; preds = %37, %33
store i64 0, i64* @errno
%40 = load i32, i32* %4
%41 = call i64 @close(i32 %40)
%42 = icmp eq i64 %41, 0
br i1 %42, label %45, label %43
43: ; preds = %39
%44 = call i32 @err(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
br label %45
45: ; preds = %43, %39
%46 = load i32, i32* @SIGPIPE
%47 = load i32, i32* @SIG_IGN
%48 = call i64 @signal(i32 %46, i32 %47)
%49 = load i64, i64* @SIG_DFL
%50 = icmp eq i64 %48, %49
br i1 %50, label %53, label %51
51: ; preds = %45
%52 = call i32 @err(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
br label %53
53: ; preds = %51, %45
%54 = load i32, i32* %10
%55 = call i32 @write(i32 %54, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 1)
%56 = icmp eq i32 %55, -1
br i1 %56, label %57, label %61
57: ; preds = %53
%58 = load i64, i64* @errno
%59 = load i64, i64* @EPIPE
%60 = icmp eq i64 %58, %59
br i1 %60, label %63, label %61
61: ; preds = %57, %53
%62 = call i32 @err(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
br label %63
63: ; preds = %61, %57
%64 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
%65 = call i32 @exit(i32 0)
unreachable
}