#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 sockaddr {
  int dummy;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ blah;

/* Variables and functions */
scalar_t__ ENOTSOCK;
int O_NONBLOCK;
int O_RDONLY;
int /*<<< orphan*/ SOCK_NONBLOCK;
scalar_t__ accept4(int, struct sockaddr *, int *, int /*<<< orphan*/);
scalar_t__ errno;
int open(char *, int);
int main(void) {
  struct sockaddr blah;
  socklen_t blahlen = sizeof(blah);
  int fd = open("/dev/null", O_RDONLY | O_NONBLOCK);
  if (fd < 0)
    return 111;
  if ((accept4(fd, &blah, &blahlen, SOCK_NONBLOCK) < 0) && (errno != ENOTSOCK))
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x4,-0xc(%rbp)
mov    0x2ea3(%rip),%rax
mov    (%rax),%esi
mov    0x2ea2(%rip),%rax
or     (%rax),%esi
lea    0xeb1(%rip),%rdi
call   1040 <open@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    116d <main+0x4d>
movl   $0x6f,-0x4(%rbp)
jmp    11bd <main+0x9d>
mov    -0x10(%rbp),%edi
mov    0x2e59(%rip),%rax
mov    (%rax),%ecx
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
call   1030 <accept4@plt>
cmp    $0x0,%rax
jge    11b6 <main+0x96>
mov    0x2e29(%rip),%rax
mov    (%rax),%rax
mov    0x2e27(%rip),%rcx
cmp    (%rcx),%rax
je     11b6 <main+0x96>
movl   $0x1,-0x4(%rbp)
jmp    11bd <main+0x9d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
movl   $0x4,0xc(%rsp)
mov    0x2ead(%rip),%rax
mov    0x2eae(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xebb(%rip),%rdi
call   1040 <open@plt>
test   %eax,%eax
js     118f <main+0x6f>
mov    0x2e7b(%rip),%rcx
mov    (%rcx),%ecx
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %eax,%edi
call   1030 <accept4@plt>
test   %rax,%rax
jns    1188 <main+0x68>
mov    0x2e4c(%rip),%rax
mov    (%rax),%rcx
mov    0x2e4a(%rip),%rdx
mov    $0x1,%eax
cmp    (%rdx),%rcx
jne    118a <main+0x6a>
xor    %eax,%eax
add    $0x18,%rsp
ret
mov    $0x6f,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
@.str = [10 x i8] c"/dev/null\00"
@O_RDONLY = global i32 0
@O_NONBLOCK = global i32 0
@SOCK_NONBLOCK = global i32 0
@errno = global i64 0
@ENOTSOCK = global i64 0
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.sockaddr
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 4, i32* %3
%5 = load i32, i32* @O_RDONLY
%6 = load i32, i32* @O_NONBLOCK
%7 = or i32 %5, %6
%8 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %7)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %0
store i32 111, i32* %1
br label %23
12: ; preds = %0
%13 = load i32, i32* %4
%14 = load i32, i32* @SOCK_NONBLOCK
%15 = call i64 @accept4(i32 %13, %struct.sockaddr* %2, i32* %3, i32 %14)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %12
%18 = load i64, i64* @errno
%19 = load i64, i64* @ENOTSOCK
%20 = icmp ne i64 %18, %19
br i1 %20, label %21, label %22
21: ; preds = %17
store i32 1, i32* %1
br label %23
22: ; preds = %17, %12
store i32 0, i32* %1
br label %23
23: ; preds = %22, %21, %11
%24 = load i32, i32* %1
ret i32 %24
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@.str = [10 x i8] c"/dev/null\00"
@O_RDONLY = global i32 0
@O_NONBLOCK = global i32 0
@SOCK_NONBLOCK = global i32 0
@errno = global i64 0
@ENOTSOCK = global i64 0
define i32 @main() {
%1 = alloca %struct.sockaddr
%2 = alloca i32
%3 = bitcast %struct.sockaddr* %1 to i8*
%4 = bitcast i32* %2 to i8*
store i32 4, i32* %2
%5 = load i32, i32* @O_RDONLY
%6 = load i32, i32* @O_NONBLOCK
%7 = or i32 %6, %5
%8 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = icmp slt i32 %8, 0
br i1 %9, label %19, label %10
10: ; preds = %0
%11 = load i32, i32* @SOCK_NONBLOCK
%12 = call i64 @accept4(i32 %8, %struct.sockaddr* %1, i32* %2, i32 %11)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %10
%15 = load i64, i64* @errno
%16 = load i64, i64* @ENOTSOCK
%17 = icmp eq i64 %15, %16
br i1 %17, label %18, label %19
18: ; preds = %14, %10
br label %19
19: ; preds = %14, %0, %18
%20 = phi i32 [ 0, %18 ], [ 111, %0 ], [ 1, %14 ]
ret i32 %20
}