#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__ EINTR;
int accept(int, struct sockaddr *, int /*<<< orphan*/ *);
int /*<<< orphan*/ anetSetError(char *, char *, int /*<<< orphan*/);
scalar_t__ errno;
int /*<<< orphan*/ strerror(scalar_t__);
int anetGenericAccept(char *err, int s, struct sockaddr *sa, socklen_t *len) {
  int fd;
  do {
    fd = accept(s, sa, len);
  } while (fd == -1 && errno == EINTR);
  if (fd == -1) {
    anetSetError(err, "accept: %s", strerror(errno));
    return -1;
  }
  return fd;
}


x86 assembly (clang, -O0):
<anetGenericAccept>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1040 <accept@plt>
mov    %eax,-0x2c(%rbp)
xor    %eax,%eax
cmpl   $0xffffffff,-0x2c(%rbp)
mov    %al,-0x2d(%rbp)
jne    1183 <anetGenericAccept+0x53>
mov    0x2e70(%rip),%rax
mov    (%rax),%rax
mov    0x2e5e(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x2d(%rbp)
mov    -0x2d(%rbp),%al
test   $0x1,%al
jne    1147 <anetGenericAccept+0x17>
cmpl   $0xffffffff,-0x2c(%rbp)
jne    11cd <anetGenericAccept+0x9d>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    0x2e39(%rip),%rax
mov    (%rax),%rdi
call   1050 <strerror@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,%edx
lea    0xe44(%rip),%rsi
call   1030 <anetSetError@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d3 <anetGenericAccept+0xa3>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<anetGenericAccept>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r15
mov    %rdx,%r12
mov    %esi,%ebx
mov    %rdi,(%rsp)
mov    0x2e92(%rip),%r13
mov    0x2e83(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebx,%edi
mov    %r12,%rsi
mov    %r15,%rdx
call   1040 <accept@plt>
mov    %eax,%ebp
mov    0x0(%r13),%rdi
cmp    $0xffffffff,%eax
jne    117d <anetGenericAccept+0x4d>
cmp    (%r14),%rdi
je     1160 <anetGenericAccept+0x30>
cmp    $0xffffffff,%ebp
jne    1199 <anetGenericAccept+0x69>
call   1050 <strerror@plt>
lea    0xe72(%rip),%rsi
mov    (%rsp),%rdi
mov    %eax,%edx
call   1030 <anetSetError@plt>
mov    %ebp,%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
@EINTR = global i64 0
@.str = [11 x i8] c"accept: %s\00"
define i32 @anetGenericAccept(i8* %0, i32 %1, %struct.sockaddr* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca %struct.sockaddr*
%9 = alloca i32*
%10 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store %struct.sockaddr* %2, %struct.sockaddr** %8
store i32* %3, i32** %9
br label %11
11: ; preds = %23, %4
%12 = load i32, i32* %7
%13 = load %struct.sockaddr*, %struct.sockaddr** %8
%14 = load i32*, i32** %9
%15 = call i32 @accept(i32 %12, %struct.sockaddr* %13, i32* %14)
store i32 %15, i32* %10
br label %16
16: ; preds = %11
%17 = load i32, i32* %10
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %23
19: ; preds = %16
%20 = load i64, i64* @errno
%21 = load i64, i64* @EINTR
%22 = icmp eq i64 %20, %21
br label %23
23: ; preds = %19, %16
%24 = phi i1 [ false, %16 ], [ %22, %19 ]
br i1 %24, label %11, label %25
25: ; preds = %23
%26 = load i32, i32* %10
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %33
28: ; preds = %25
%29 = load i8*, i8** %6
%30 = load i64, i64* @errno
%31 = call i32 @strerror(i64 %30)
%32 = call i32 @anetSetError(i8* %29, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %31)
store i32 -1, i32* %5
br label %35
33: ; preds = %25
%34 = load i32, i32* %10
store i32 %34, i32* %5
br label %35
35: ; preds = %33, %28
%36 = load i32, i32* %5
ret i32 %36
}

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