#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 genericTcpAccept(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 {
        return -1;
      }
    }
    break;
  }
  return fd;
}


x86 assembly (clang, -O0):
<genericTcpAccept>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%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   1030 <accept@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    116f <genericTcpAccept+0x5f>
mov    0x2e95(%rip),%rax
mov    (%rax),%rax
mov    0x2e83(%rip),%rcx
cmp    (%rcx),%rax
jne    1163 <genericTcpAccept+0x53>
jmp    1127 <genericTcpAccept+0x17>
movl   $0xffffffff,-0x4(%rbp)
jmp    117a <genericTcpAccept+0x6a>
jmp    1174 <genericTcpAccept+0x64>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<genericTcpAccept>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %rdx,%rbx
mov    %esi,%ebp
mov    0x2eb9(%rip),%r15
mov    0x2eaa(%rip),%r12
xchg   %ax,%ax
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1030 <accept@plt>
cmp    $0xffffffff,%eax
jne    114b <genericTcpAccept+0x3b>
mov    (%r15),%rcx
cmp    (%r12),%rcx
je     1130 <genericTcpAccept+0x20>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
@errno = global i64 0
@EINTR = global i64 0
define i32 @genericTcpAccept(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 %24
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
store i32 -1, i32* %5
br label %27
24: ; preds = %11
br label %25
25: ; preds = %24
%26 = load i32, i32* %10
store i32 %26, i32* %5
br label %27
27: ; preds = %25, %23
%28 = load i32, i32* %5
ret i32 %28
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@errno = global i64 0
@EINTR = global i64 0
define i32 @genericTcpAccept(i8* nocapture readnone %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 %12
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 = %5, %8
ret i32 %6
}