#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*/ *);
scalar_t__ errno;
int /*<<< orphan*/ kr_net_set_error(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ strerror(scalar_t__);
int anetGenericAccept(char *err, int s, struct sockaddr *sa, socklen_t *len) {
  int fd;
  while (1) {
    fd = accept(s, sa, len);
    if (fd == -1) {
      if (errno == EINTR)
        continue;
      else {
        kr_net_set_error(err, "accept: %s", strerror(errno));
        return -1;
      }
    }
    break;
  }
  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)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    11b8 <anetGenericAccept+0x88>
mov    0x2e75(%rip),%rax
mov    (%rax),%rax
mov    0x2e63(%rip),%rcx
cmp    (%rcx),%rax
jne    1183 <anetGenericAccept+0x53>
jmp    1147 <anetGenericAccept+0x17>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    0x2e4e(%rip),%rax
mov    (%rax),%rdi
call   1050 <strerror@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,%edx
lea    0xe59(%rip),%rsi
call   1030 <kr_net_set_error@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c3 <anetGenericAccept+0x93>
jmp    11bd <anetGenericAccept+0x8d>
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
cmp    $0xffffffff,%eax
jne    1194 <anetGenericAccept+0x64>
mov    0x0(%r13),%rdi
cmp    (%r14),%rdi
je     1160 <anetGenericAccept+0x30>
call   1050 <strerror@plt>
lea    0xe77(%rip),%rsi
mov    (%rsp),%rdi
mov    %eax,%edx
call   1030 <kr_net_set_error@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 = %4, %22
%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
%16 = load i32, i32* %10
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %28
18: ; preds = %11
%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
br label %11
23: ; preds = %18
%24 = load i8*, i8** %6
%25 = load i64, i64* @errno
%26 = call i32 @strerror(i64 %25)
%27 = call i32 @kr_net_set_error(i8* %24, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %26)
store i32 -1, i32* %5
br label %31
28: ; preds = %11
br label %29
29: ; preds = %28
%30 = load i32, i32* %10
store i32 %30, i32* %5
br label %31
31: ; preds = %29, %23
%32 = load i32, i32* %5
ret i32 %32
}

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 = %8, %4
%6 = tail call i32 @accept(i32 %1, %struct.sockaddr* %2, i32* %3)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %15
8: ; preds = %5
%9 = load i64, i64* @errno
%10 = load i64, i64* @EINTR
%11 = icmp eq i64 %9, %10
br i1 %11, label %5, label %12
12: ; preds = %8
%13 = tail call i32 @strerror(i64 %9)
%14 = tail call i32 @kr_net_set_error(i8* %0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %13)
br label %15
15: ; preds = %5, %12
ret i32 %6
}