#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__ EINTR;
int accept(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
scalar_t__ errno;
int /*<<< orphan*/ socket_set_nonblock(int);
int socket_accept_any(int server_fd) {
  int fd;
  do {
    errno = 0;
    do {
      fd = (accept(server_fd, NULL, 0));
    } while (fd < 0 && errno == EINTR);
  } while (0);
  ;
  if (fd < 0) {
    ((void)0);
    return -1;
  }
  socket_set_nonblock(fd);
  return fd;
}


x86 assembly (clang, -O0):
<socket_accept_any>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    0x2eae(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1040 <accept@plt>
mov    %eax,-0xc(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0xc(%rbp)
mov    %al,-0xd(%rbp)
jge    1173 <socket_accept_any+0x53>
mov    0x2e80(%rip),%rax
mov    (%rax),%rax
mov    0x2e6e(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
test   $0x1,%al
jne    1139 <socket_accept_any+0x19>
jmp    1183 <socket_accept_any+0x63>
cmpl   $0x0,-0xc(%rbp)
jge    1199 <socket_accept_any+0x79>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a7 <socket_accept_any+0x87>
mov    -0xc(%rbp),%edi
call   1030 <socket_set_nonblock@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<socket_accept_any>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebp
mov    0x2eb0(%rip),%r14
movq   $0x0,(%r14)
mov    0x2e9a(%rip),%r15
xchg   %ax,%ax
mov    %ebp,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1040 <accept@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    1159 <socket_accept_any+0x39>
mov    (%r15),%rax
cmp    %rax,(%r14)
je     1140 <socket_accept_any+0x20>
test   %ebx,%ebx
js     1166 <socket_accept_any+0x46>
mov    %ebx,%edi
call   1030 <socket_set_nonblock@plt>
jmp    116b <socket_accept_any+0x4b>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
@EINTR = global i64 0
define i32 @socket_accept_any(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
br label %5
5: ; preds = %1
store i64 0, i64* @errno
br label %6
6: ; preds = %16, %5
%7 = load i32, i32* %3
%8 = call i32 @accept(i32 %7, i32* null, i32 0)
store i32 %8, i32* %4
br label %9
9: ; preds = %6
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %9
%13 = load i64, i64* @errno
%14 = load i64, i64* @EINTR
%15 = icmp eq i64 %13, %14
br label %16
16: ; preds = %12, %9
%17 = phi i1 [ false, %9 ], [ %15, %12 ]
br i1 %17, label %6, label %18
18: ; preds = %16
br label %19
19: ; preds = %18
%20 = load i32, i32* %4
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %19
store i32 -1, i32* %2
br label %27
23: ; preds = %19
%24 = load i32, i32* %4
%25 = call i32 @socket_set_nonblock(i32 %24)
%26 = load i32, i32* %4
store i32 %26, i32* %2
br label %27
27: ; preds = %23, %22
%28 = load i32, i32* %2
ret i32 %28
}

LLVM IR (-O2):
@errno = global i64 0
@EINTR = global i64 0
define i32 @socket_accept_any(i32 %0) {
store i64 0, i64* @errno
br label %2
2: ; preds = %2, %1
%3 = tail call i32 @accept(i32 %0, i32* null, i32 0)
%4 = icmp slt i32 %3, 0
%5 = load i64, i64* @errno
%6 = load i64, i64* @EINTR
%7 = icmp eq i64 %5, %6
%8 = select i1 %4, i1 %7, i1 false
br i1 %8, label %2, label %9
9: ; preds = %2
br i1 %4, label %12, label %10
10: ; preds = %9
%11 = tail call i32 @socket_set_nonblock(i32 %3)
br label %12
12: ; preds = %9, %10
%13 = phi i32 [ %3, %10 ], [ -1, %9 ]
ret i32 %13
}