#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 /*<<< orphan*/ _pfatal(int /*<<< orphan*/ *, int /*<<< orphan*/, char *);
int accept(int, struct sockaddr *, int /*<<< orphan*/ *);
scalar_t__ errno;
int fd_accept(int fd, struct sockaddr *addr, socklen_t *addrlen) {
  int ret;
  do {
    ret = accept(fd, addr, addrlen);
  } while (ret == -1 && errno == EINTR);
  if (ret < 0)
    _pfatal(NULL, 0, "fd_accept");
  ;
  return ret;
}


x86 assembly (clang, -O0):
<fd_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   1040 <accept@plt>
mov    %eax,-0x1c(%rbp)
xor    %eax,%eax
cmpl   $0xffffffff,-0x1c(%rbp)
mov    %al,-0x1d(%rbp)
jne    116f <fd_accept+0x4f>
mov    0x2e84(%rip),%rax
mov    (%rax),%rax
mov    0x2e72(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    1133 <fd_accept+0x13>
cmpl   $0x0,-0x1c(%rbp)
jge    1196 <fd_accept+0x76>
xor    %eax,%eax
mov    %eax,%edi
xor    %esi,%esi
lea    0xe6f(%rip),%rdx
call   1030 <_pfatal@plt>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fd_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    0x2e97(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %r15,%rsi
mov    %r14,%rdx
call   1040 <accept@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    116e <fd_accept+0x4e>
mov    0x0(%r13),%rax
cmp    %rax,(%r12)
je     1150 <fd_accept+0x30>
test   %ebx,%ebx
jns    1182 <fd_accept+0x62>
lea    0xe87(%rip),%rdx
xor    %edi,%edi
xor    %esi,%esi
call   1030 <_pfatal@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
@EINTR = global i64 0
@.str = [10 x i8] c"fd_accept\00"
define i32 @fd_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 = %20, %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
br label %13
13: ; preds = %8
%14 = load i32, i32* %7
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %20
16: ; preds = %13
%17 = load i64, i64* @errno
%18 = load i64, i64* @EINTR
%19 = icmp eq i64 %17, %18
br label %20
20: ; preds = %16, %13
%21 = phi i1 [ false, %13 ], [ %19, %16 ]
br i1 %21, label %8, label %22
22: ; preds = %20
%23 = load i32, i32* %7
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = call i32 @_pfatal(i32* null, i32 0, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %27
27: ; preds = %25, %22
%28 = load i32, i32* %7
ret i32 %28
}

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