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

/* Variables and functions */
scalar_t__ EAGAIN;
scalar_t__ ECONNABORTED;
scalar_t__ EINTR;
scalar_t__ EMFILE;
scalar_t__ EWOULDBLOCK;
int accept(int, struct sockaddr *, int *);
scalar_t__ errno;
int ipc_accept(int afd) {
  struct sockaddr_un addr = {};
  socklen_t addrlen = sizeof(addr);
  int fd = accept(afd, (struct sockaddr *)&addr, &addrlen);
  if (fd < 0 && (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR ||
                 errno == ECONNABORTED || errno == EMFILE)) {
    errno = EAGAIN;
    return -1;
  }
  return fd;
}


x86 assembly (clang, -O0):
<ipc_accept>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
movl   $0x4,-0x14(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rdx
call   1040 <accept@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1201 <ipc_accept+0xe1>
mov    0x2e7a(%rip),%rax
mov    (%rax),%rax
mov    0x2e40(%rip),%rcx
cmp    (%rcx),%rax
je     11e1 <ipc_accept+0xc1>
mov    0x2e60(%rip),%rax
mov    (%rax),%rax
mov    0x2e4e(%rip),%rcx
cmp    (%rcx),%rax
je     11e1 <ipc_accept+0xc1>
mov    0x2e46(%rip),%rax
mov    (%rax),%rax
mov    0x2e2c(%rip),%rcx
cmp    (%rcx),%rax
je     11e1 <ipc_accept+0xc1>
mov    0x2e2c(%rip),%rax
mov    (%rax),%rax
mov    0x2e0a(%rip),%rcx
cmp    (%rcx),%rax
je     11e1 <ipc_accept+0xc1>
mov    0x2e12(%rip),%rax
mov    (%rax),%rax
mov    0x2de0(%rip),%rcx
cmp    (%rcx),%rax
jne    1201 <ipc_accept+0xe1>
mov    0x2dc8(%rip),%rax
mov    (%rax),%rcx
mov    0x2dee(%rip),%rax
mov    %rcx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    1207 <ipc_accept+0xe7>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ipc_accept>:
push   %rax
movl   $0x0,(%rsp)
movl   $0x4,0x4(%rsp)
mov    %rsp,%rsi
lea    0x4(%rsp),%rdx
call   1030 <accept@plt>
test   %eax,%eax
js     1133 <ipc_accept+0x23>
pop    %rcx
ret
mov    0x2ea6(%rip),%rcx
mov    (%rcx),%rsi
mov    0x2e6c(%rip),%rdx
mov    (%rdx),%rdx
cmp    %rdx,%rsi
je     117c <ipc_accept+0x6c>
mov    0x2e85(%rip),%rdi
cmp    (%rdi),%rsi
je     117c <ipc_accept+0x6c>
mov    0x2e71(%rip),%rdi
cmp    (%rdi),%rsi
je     117c <ipc_accept+0x6c>
mov    0x2e5d(%rip),%rdi
cmp    (%rdi),%rsi
je     117c <ipc_accept+0x6c>
mov    0x2e41(%rip),%rdi
cmp    (%rdi),%rsi
jne    1131 <ipc_accept+0x21>
mov    %rdx,(%rcx)
mov    $0xffffffff,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.sockaddr_un = type { i32 }
%struct.sockaddr = type { i32 }
@errno = global i64 0
@EAGAIN = global i64 0
@EWOULDBLOCK = global i64 0
@EINTR = global i64 0
@ECONNABORTED = global i64 0
@EMFILE = global i64 0
define i32 @ipc_accept(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.sockaddr_un
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
%7 = bitcast %struct.sockaddr_un* %4 to i8*
store i32 4, i32* %5
%8 = load i32, i32* %3
%9 = bitcast %struct.sockaddr_un* %4 to %struct.sockaddr*
%10 = call i32 @accept(i32 %8, %struct.sockaddr* %9, i32* %5)
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %35
13: ; preds = %1
%14 = load i64, i64* @errno
%15 = load i64, i64* @EAGAIN
%16 = icmp eq i64 %14, %15
br i1 %16, label %33, label %17
17: ; preds = %13
%18 = load i64, i64* @errno
%19 = load i64, i64* @EWOULDBLOCK
%20 = icmp eq i64 %18, %19
br i1 %20, label %33, label %21
21: ; preds = %17
%22 = load i64, i64* @errno
%23 = load i64, i64* @EINTR
%24 = icmp eq i64 %22, %23
br i1 %24, label %33, label %25
25: ; preds = %21
%26 = load i64, i64* @errno
%27 = load i64, i64* @ECONNABORTED
%28 = icmp eq i64 %26, %27
br i1 %28, label %33, label %29
29: ; preds = %25
%30 = load i64, i64* @errno
%31 = load i64, i64* @EMFILE
%32 = icmp eq i64 %30, %31
br i1 %32, label %33, label %35
33: ; preds = %29, %25, %21, %17, %13
%34 = load i64, i64* @EAGAIN
store i64 %34, i64* @errno
store i32 -1, i32* %2
br label %37
35: ; preds = %29, %1
%36 = load i32, i32* %6
store i32 %36, i32* %2
br label %37
37: ; preds = %35, %33
%38 = load i32, i32* %2
ret i32 %38
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32 }
%struct.sockaddr = type { i32 }
@errno = global i64 0
@EAGAIN = global i64 0
@EWOULDBLOCK = global i64 0
@EINTR = global i64 0
@ECONNABORTED = global i64 0
@EMFILE = global i64 0
define i32 @ipc_accept(i32 %0) {
%2 = alloca %struct.sockaddr_un
%3 = alloca i32
%4 = bitcast %struct.sockaddr_un* %2 to i8*
%5 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %2, i64 0, i32 0
store i32 0, i32* %5
%6 = bitcast i32* %3 to i8*
store i32 4, i32* %3
%7 = bitcast %struct.sockaddr_un* %2 to %struct.sockaddr*
%8 = call i32 @accept(i32 %0, %struct.sockaddr* %7, i32* %3)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %27
10: ; preds = %1
%11 = load i64, i64* @errno
%12 = load i64, i64* @EAGAIN
%13 = icmp eq i64 %11, %12
%14 = load i64, i64* @EWOULDBLOCK
%15 = icmp eq i64 %11, %14
%16 = select i1 %13, i1 true, i1 %15
%17 = load i64, i64* @EINTR
%18 = icmp eq i64 %11, %17
%19 = select i1 %16, i1 true, i1 %18
%20 = load i64, i64* @ECONNABORTED
%21 = icmp eq i64 %11, %20
%22 = select i1 %19, i1 true, i1 %21
%23 = load i64, i64* @EMFILE
%24 = icmp eq i64 %11, %23
%25 = select i1 %22, i1 true, i1 %24
br i1 %25, label %26, label %27
26: ; preds = %10
store i64 %12, i64* @errno
br label %27
27: ; preds = %1, %10, %26
%28 = phi i32 [ -1, %26 ], [ %8, %10 ], [ %8, %1 ]
ret i32 %28
}