#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 /*<<< orphan*/ socklen_t;

/* Variables and functions */
scalar_t__ ECONNABORTED;
scalar_t__ EINTR;
int accept(int, struct sockaddr *, int /*<<< orphan*/ *);
scalar_t__ errno;
int /*<<< orphan*/ perr_exit(char *);
int Accept(int fd, struct sockaddr *sa, socklen_t *salenptr) {
  int n;
again:
  if ((n = accept(fd, sa, salenptr)) < 0) {
    if ((errno == ECONNABORTED) || (errno == EINTR))
      goto again;
    else
      perr_exit("accept error");
  }
  return n;
}


x86 assembly (clang, -O0):
<Accept>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <accept@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    1199 <Accept+0x79>
mov    0x2e8a(%rip),%rax
mov    (%rax),%rax
mov    0x2e70(%rip),%rcx
cmp    (%rcx),%rax
je     1183 <Accept+0x63>
mov    0x2e70(%rip),%rax
mov    (%rax),%rax
mov    0x2e5e(%rip),%rcx
cmp    (%rcx),%rax
jne    1188 <Accept+0x68>
jmp    1133 <Accept+0x13>
lea    0xe71(%rip),%rdi
call   1040 <perr_exit@plt>
jmp    1199 <Accept+0x79>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Accept>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %edi,%ebp
mov    0x2ea6(%rip),%r12
mov    0x2e8f(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %r15,%rsi
mov    %r14,%rdx
call   1030 <accept@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    1185 <Accept+0x65>
mov    (%r12),%rax
cmp    0x0(%r13),%rax
je     1150 <Accept+0x30>
mov    0x2e64(%rip),%rcx
cmp    (%rcx),%rax
je     1150 <Accept+0x30>
lea    0xe80(%rip),%rdi
call   1040 <perr_exit@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
@errno = global i64 0
@ECONNABORTED = global i64 0
@EINTR = global i64 0
@.str = [13 x i8] c"accept error\00"
define i32 @Accept(i32 %0, %struct.sockaddr* %1, i32* %2) {
%4 = alloca i32
%5 = alloca %struct.sockaddr*
%6 = alloca i32*
%7 = alloca i32
store i32 %0, i32* %4
store %struct.sockaddr* %1, %struct.sockaddr** %5
store i32* %2, i32** %6
br label %8
8: ; preds = %22, %3
%9 = load i32, i32* %4
%10 = load %struct.sockaddr*, %struct.sockaddr** %5
%11 = load i32*, i32** %6
%12 = call i32 @accept(i32 %9, %struct.sockaddr* %10, i32* %11)
store i32 %12, i32* %7
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %26
14: ; preds = %8
%15 = load i64, i64* @errno
%16 = load i64, i64* @ECONNABORTED
%17 = icmp eq i64 %15, %16
br i1 %17, label %22, label %18
18: ; preds = %14
%19 = load i64, i64* @errno
%20 = load i64, i64* @EINTR
%21 = icmp eq i64 %19, %20
br i1 %21, label %22, label %23
22: ; preds = %18, %14
br label %8
23: ; preds = %18
%24 = call i32 @perr_exit(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %25
25: ; preds = %23
br label %26
26: ; preds = %25, %8
%27 = load i32, i32* %7
ret i32 %27
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@errno = global i64 0
@ECONNABORTED = global i64 0
@EINTR = global i64 0
@.str = [13 x i8] c"accept error\00"
define i32 @Accept(i32 %0, %struct.sockaddr* %1, i32* %2) {
br label %4
4: ; preds = %7, %3
%5 = tail call i32 @accept(i32 %0, %struct.sockaddr* %1, i32* %2)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %16
7: ; preds = %4
%8 = load i64, i64* @errno
%9 = load i64, i64* @ECONNABORTED
%10 = icmp eq i64 %8, %9
%11 = load i64, i64* @EINTR
%12 = icmp eq i64 %8, %11
%13 = select i1 %10, i1 true, i1 %12
br i1 %13, label %4, label %14
14: ; preds = %7
%15 = tail call i32 @perr_exit(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %4, %14
ret i32 %5
}