#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 */
struct timeval {
  scalar_t__ tv_usec;
  scalar_t__ tv_sec;
};
typedef int /*<<< orphan*/ fd_set;

/* Variables and functions */
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int O_NDELAY;
int O_RDONLY;
int S_IFIFO;
scalar_t__ mknod(char const *, int, int /*<<< orphan*/);
int open(char const *, int);
scalar_t__ select(int, int /*<<< orphan*/ *, int /*<<< orphan*/,
                  int /*<<< orphan*/, struct timeval *);
int /*<<< orphan*/ unlink(char const *);
int main(void) {
  const char filename[] = ".tmp.fifo";
  int hasbug;
  struct timeval tv;
  fd_set rfds;
  int fd;
  if (mknod(filename, S_IFIFO | 0600, 0) != 0)
    return 1;
  fd = open(filename, O_RDONLY | O_NDELAY);
  FD_ZERO(&rfds);
  FD_SET(fd, &rfds);
  tv.tv_sec = tv.tv_usec = 0;
  hasbug = select(fd + 1, &rfds, 0, 0, &tv) > 0;
  unlink(filename);
  return hasbug ? 0 : 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe8a(%rip),%rax
mov    %rax,-0xe(%rbp)
mov    0xe87(%rip),%ax
mov    %ax,-0x6(%rbp)
lea    -0xe(%rbp),%rdi
mov    0x2e40(%rip),%rax
mov    (%rax),%esi
or     $0x180,%esi
xor    %edx,%edx
call   1040 <mknod@plt>
cmp    $0x0,%rax
je     11b5 <main+0x55>
movl   $0x1,-0x4(%rbp)
jmp    123a <main+0xda>
lea    -0xe(%rbp),%rdi
mov    0x2e28(%rip),%rax
mov    (%rax),%esi
mov    0x2e0f(%rip),%rax
or     (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x30(%rbp)
lea    -0x2c(%rbp),%rdi
call   1050 <FD_ZERO@plt>
mov    -0x30(%rbp),%edi
lea    -0x2c(%rbp),%rsi
call   1080 <FD_SET@plt>
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x30(%rbp),%edi
add    $0x1,%edi
lea    -0x2c(%rbp),%rsi
xor    %ecx,%ecx
lea    -0x28(%rbp),%r8
mov    %ecx,%edx
call   1060 <select@plt>
cmp    $0x0,%rax
setg   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x14(%rbp)
lea    -0xe(%rbp),%rdi
call   1030 <unlink@plt>
mov    -0x14(%rbp),%edx
mov    $0x1,%eax
xor    %ecx,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
movabs $0x6669662e706d742e,%rax
66 69 66
mov    %rax,(%rsp)
movw   $0x6f,0x8(%rsp)
mov    0x2e4c(%rip),%rax
mov    $0x180,%esi
or     (%rax),%esi
mov    %rsp,%rdi
xor    %edx,%edx
call   1040 <mknod@plt>
mov    $0x1,%ebp
test   %rax,%rax
jne    1204 <main+0xa4>
mov    0x2e42(%rip),%rax
mov    0x2e2b(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %rsp,%r14
mov    %r14,%rdi
call   1070 <open@plt>
mov    %eax,%ebp
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <FD_ZERO@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1080 <FD_SET@plt>
add    $0x1,%ebp
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
lea    0x10(%rsp),%r8
mov    %ebp,%edi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1060 <select@plt>
xor    %ebp,%ebp
test   %rax,%rax
setle  %bpl
mov    %r14,%rdi
call   1030 <unlink@plt>
mov    %ebp,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
@__const.main.filename = [10 x i8] c".tmp.fifo\00"
@S_IFIFO = global i32 0
@O_RDONLY = global i32 0
@O_NDELAY = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x i8]
%3 = alloca i32
%4 = alloca %struct.timeval
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = bitcast [10 x i8]* %2 to i8*
%8 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%9 = load i32, i32* @S_IFIFO
%10 = or i32 %9, 384
%11 = call i64 @mknod(i8* %8, i32 %10, i32 0)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %0
store i32 1, i32* %1
br label %36
14: ; preds = %0
%15 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%16 = load i32, i32* @O_RDONLY
%17 = load i32, i32* @O_NDELAY
%18 = or i32 %16, %17
%19 = call i32 @open(i8* %15, i32 %18)
store i32 %19, i32* %6
%20 = call i32 @FD_ZERO(i32* %5)
%21 = load i32, i32* %6
%22 = call i32 @FD_SET(i32 %21, i32* %5)
%23 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
store i64 0, i64* %23
%24 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 1
store i64 0, i64* %24
%25 = load i32, i32* %6
%26 = add nsw i32 %25, 1
%27 = call i64 @select(i32 %26, i32* %5, i32 0, i32 0, %struct.timeval* %4)
%28 = icmp sgt i64 %27, 0
%29 = zext i1 %28 to i32
store i32 %29, i32* %3
%30 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%31 = call i32 @unlink(i8* %30)
%32 = load i32, i32* %3
%33 = icmp ne i32 %32, 0
%34 = zext i1 %33 to i64
%35 = select i1 %33, i32 0, i32 1
store i32 %35, i32* %1
br label %36
36: ; preds = %14, %13
%37 = load i32, i32* %1
ret i32 %37
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
@__const.main.filename = [10 x i8] c".tmp.fifo\00"
@S_IFIFO = global i32 0
@O_RDONLY = global i32 0
@O_NDELAY = global i32 0
define i32 @main() {
%1 = alloca [10 x i8]
%2 = alloca %struct.timeval
%3 = alloca i32
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%5 = bitcast %struct.timeval* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = load i32, i32* @S_IFIFO
%8 = or i32 %7, 384
%9 = call i64 @mknod(i8* %4, i32 %8, i32 0)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %24
11: ; preds = %0
%12 = load i32, i32* @O_RDONLY
%13 = load i32, i32* @O_NDELAY
%14 = or i32 %13, %12
%15 = call i32 @open(i8* %4, i32 %14)
%16 = call i32 @FD_ZERO(i32* %3)
%17 = call i32 @FD_SET(i32 %15, i32* %3)
%18 = add nsw i32 %15, 1
%19 = bitcast %struct.timeval* %2 to i8*
%20 = call i64 @select(i32 %18, i32* %3, i32 0, i32 0, %struct.timeval* %2)
%21 = icmp slt i64 %20, 1
%22 = call i32 @unlink(i8* %4)
%23 = zext i1 %21 to i32
br label %24
24: ; preds = %0, %11
%25 = phi i32 [ %23, %11 ], [ 1, %0 ]
ret i32 %25
}