#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__ EAGAIN;
int /*<<< orphan*/ F_SETFL;
int /*<<< orphan*/ O_NONBLOCK;
int accept(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ assert(int);
scalar_t__ errno;
scalar_t__ fcntl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int vhost_user_accept(int sock) {
  int newsock;
  if ((newsock = accept(sock, NULL, NULL)) == -1) {
    assert(errno == EAGAIN);
  } else {
    assert(fcntl(newsock, F_SETFL, O_NONBLOCK) == 0);
  }
  return newsock;
}


x86 assembly (clang, -O0):
<vhost_user_accept>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   1050 <accept@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    117c <vhost_user_accept+0x4c>
mov    0x2e73(%rip),%rax
mov    (%rax),%rax
mov    0x2e59(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
jmp    11a7 <vhost_user_accept+0x77>
mov    -0x8(%rbp),%edi
mov    0x2e52(%rip),%rax
mov    (%rax),%esi
mov    0x2e59(%rip),%rax
mov    (%rax),%edx
call   1030 <fcntl@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vhost_user_accept>:
push   %rbx
xor    %esi,%esi
xor    %edx,%edx
call   1050 <accept@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
je     115f <vhost_user_accept+0x2f>
mov    0x2e90(%rip),%rax
mov    (%rax),%esi
mov    0x2e97(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
call   1030 <fcntl@plt>
test   %rax,%rax
jmp    1173 <vhost_user_accept+0x43>
mov    0x2e6a(%rip),%rax
mov    (%rax),%rax
mov    0x2e50(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
movzbl %al,%edi
call   1040 <assert@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@errno = global i64 0
@EAGAIN = global i64 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
define i32 @vhost_user_accept(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = call i32 @accept(i32 %4, i32* null, i32* null)
store i32 %5, i32* %3
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %13
7: ; preds = %1
%8 = load i64, i64* @errno
%9 = load i64, i64* @EAGAIN
%10 = icmp eq i64 %8, %9
%11 = zext i1 %10 to i32
%12 = call i32 @assert(i32 %11)
br label %21
13: ; preds = %1
%14 = load i32, i32* %3
%15 = load i32, i32* @F_SETFL
%16 = load i32, i32* @O_NONBLOCK
%17 = call i64 @fcntl(i32 %14, i32 %15, i32 %16)
%18 = icmp eq i64 %17, 0
%19 = zext i1 %18 to i32
%20 = call i32 @assert(i32 %19)
br label %21
21: ; preds = %13, %7
%22 = load i32, i32* %3
ret i32 %22
}

LLVM IR (-O2):
@errno = global i64 0
@EAGAIN = global i64 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
define i32 @vhost_user_accept(i32 %0) {
%2 = tail call i32 @accept(i32 %0, i32* null, i32* null)
%3 = icmp eq i32 %2, -1
br i1 %3, label %4, label %8
4: ; preds = %1
%5 = load i64, i64* @errno
%6 = load i64, i64* @EAGAIN
%7 = icmp eq i64 %5, %6
br label %13
8: ; preds = %1
%9 = load i32, i32* @F_SETFL
%10 = load i32, i32* @O_NONBLOCK
%11 = tail call i64 @fcntl(i32 %2, i32 %9, i32 %10)
%12 = icmp eq i64 %11, 0
br label %13
13: ; preds = %8, %4
%14 = phi i1 [ %12, %8 ], [ %7, %4 ]
%15 = zext i1 %14 to i32
%16 = tail call i32 @assert(i32 %15)
ret i32 %2
}