#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 */
typedef int /*<<< orphan*/ uint8_t;

/* Variables and functions */
scalar_t__ EAGAIN;
scalar_t__ EWOULDBLOCK;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ O_NONBLOCK;
int /*<<< orphan*/ alarm(int);
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int pipe2(int *, int /*<<< orphan*/);
int /*<<< orphan*/ read(int, int /*<<< orphan*/ *, int);
int main() {
  int fds[2];
  int status;
  uint8_t buffer;
  status = pipe2(fds, O_NONBLOCK);
  if (status < 0) {
    perror("pipe2");
    exit(EXIT_FAILURE);
  }
  (void)alarm(5);
  (void)read(fds[0], &buffer, 1);
  if (errno != EAGAIN && errno != EWOULDBLOCK) {
    perror("read");
    exit(EXIT_FAILURE);
  }
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0xc(%rbp),%rdi
mov    0x2e7e(%rip),%rax
mov    (%rax),%esi
call   1060 <pipe2@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    1198 <main+0x48>
lea    0xe7b(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    $0x5,%edi
call   1030 <alarm@plt>
mov    -0xc(%rbp),%edi
lea    -0x14(%rbp),%rsi
mov    $0x1,%edx
call   1040 <read@plt>
mov    0x2e1e(%rip),%rax
mov    (%rax),%rax
mov    0x2dec(%rip),%rcx
cmp    (%rcx),%rax
je     1201 <main+0xb1>
mov    0x2e04(%rip),%rax
mov    (%rax),%rax
mov    0x2df2(%rip),%rcx
cmp    (%rcx),%rax
je     1201 <main+0xb1>
lea    0xe18(%rip),%rdi
call   1050 <perror@plt>
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    0x2db8(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
mov    0x2e8d(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rdi
call   1060 <pipe2@plt>
test   %eax,%eax
jns    1174 <main+0x24>
lea    0xe8e(%rip),%rdi
jmp    11ba <main+0x6a>
mov    $0x5,%edi
call   1030 <alarm@plt>
mov    0x10(%rsp),%edi
lea    0xc(%rsp),%rsi
mov    $0x1,%edx
call   1040 <read@plt>
mov    0x2e40(%rip),%rax
mov    (%rax),%rax
mov    0x2e0e(%rip),%rcx
cmp    (%rcx),%rax
je     11cd <main+0x7d>
mov    0x2e22(%rip),%rcx
cmp    (%rcx),%rax
je     11cd <main+0x7d>
lea    0xe4c(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    0x2dec(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@O_NONBLOCK = global i32 0
@.str = [6 x i8] c"pipe2\00"
@EXIT_FAILURE = global i32 0
@errno = global i64 0
@EAGAIN = global i64 0
@EWOULDBLOCK = global i64 0
@.str.1 = [5 x i8] c"read\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i32]
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%6 = load i32, i32* @O_NONBLOCK
%7 = call i32 @pipe2(i32* %5, i32 %6)
store i32 %7, i32* %3
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %0
%11 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* @EXIT_FAILURE
%13 = call i32 @exit(i32 %12)
unreachable
14: ; preds = %0
%15 = call i32 @alarm(i32 5)
%16 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%17 = load i32, i32* %16
%18 = call i32 @read(i32 %17, i32* %4, i32 1)
%19 = load i64, i64* @errno
%20 = load i64, i64* @EAGAIN
%21 = icmp ne i64 %19, %20
br i1 %21, label %22, label %30
22: ; preds = %14
%23 = load i64, i64* @errno
%24 = load i64, i64* @EWOULDBLOCK
%25 = icmp ne i64 %23, %24
br i1 %25, label %26, label %30
26: ; preds = %22
%27 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%28 = load i32, i32* @EXIT_FAILURE
%29 = call i32 @exit(i32 %28)
unreachable
30: ; preds = %22, %14
%31 = load i32, i32* @EXIT_SUCCESS
%32 = call i32 @exit(i32 %31)
unreachable
}

LLVM IR (-O2):
@O_NONBLOCK = global i32 0
@.str = [6 x i8] c"pipe2\00"
@EXIT_FAILURE = global i32 0
@errno = global i64 0
@EAGAIN = global i64 0
@EWOULDBLOCK = global i64 0
@.str.1 = [5 x i8] c"read\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca [2 x i32]
%2 = alloca i32
%3 = bitcast [2 x i32]* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%6 = load i32, i32* @O_NONBLOCK
%7 = call i32 @pipe2(i32* %5, i32 %6)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %0
%10 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* @EXIT_FAILURE
%12 = call i32 @exit(i32 %11)
unreachable
13: ; preds = %0
%14 = call i32 @alarm(i32 5)
%15 = load i32, i32* %5
%16 = call i32 @read(i32 %15, i32* %2, i32 1)
%17 = load i64, i64* @errno
%18 = load i64, i64* @EAGAIN
%19 = icmp eq i64 %17, %18
%20 = load i64, i64* @EWOULDBLOCK
%21 = icmp eq i64 %17, %20
%22 = select i1 %19, i1 true, i1 %21
br i1 %22, label %27, label %23
23: ; preds = %13
%24 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%25 = load i32, i32* @EXIT_FAILURE
%26 = call i32 @exit(i32 %25)
unreachable
27: ; preds = %13
%28 = load i32, i32* @EXIT_SUCCESS
%29 = call i32 @exit(i32 %28)
unreachable
}