#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_un {
  int dummy;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ remote;

/* Variables and functions */
scalar_t__ EINTR;
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int iTermFileDescriptorServerAccept(int socketFd) {
  struct sockaddr_un remote;
  socklen_t sizeOfRemote = sizeof(remote);
  int connectionFd = -1;
  do {
    connectionFd = accept(socketFd, (struct sockaddr *)&remote, &sizeOfRemote);
  } while (connectionFd == -1 && errno == EINTR);
  if (connectionFd != -1) {
    close(socketFd);
  }
  return connectionFd;
}


x86 assembly (clang, -O0):
<iTermFileDescriptorServerAccept>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x4,-0xc(%rbp)
movl   $0xffffffff,-0x10(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
call   1040 <accept@plt>
mov    %eax,-0x10(%rbp)
xor    %eax,%eax
cmpl   $0xffffffff,-0x10(%rbp)
mov    %al,-0x11(%rbp)
jne    1175 <iTermFileDescriptorServerAccept+0x55>
mov    0x2e7e(%rip),%rax
mov    (%rax),%rax
mov    0x2e6c(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1139 <iTermFileDescriptorServerAccept+0x19>
cmpl   $0xffffffff,-0x10(%rbp)
je     1192 <iTermFileDescriptorServerAccept+0x72>
mov    -0x4(%rbp),%edi
call   1030 <close@plt>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iTermFileDescriptorServerAccept>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebx
movl   $0x4,0xc(%rsp)
lea    0x10(%rsp),%r14
lea    0xc(%rsp),%r15
mov    0x2e97(%rip),%r12
mov    0x2e88(%rip),%r13
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   1040 <accept@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    116e <iTermFileDescriptorServerAccept+0x4e>
mov    0x0(%r13),%rax
cmp    %rax,(%r12)
je     1150 <iTermFileDescriptorServerAccept+0x30>
cmp    $0xffffffff,%ebp
je     117a <iTermFileDescriptorServerAccept+0x5a>
mov    %ebx,%edi
call   1030 <close@plt>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_un = type { i32 }
%struct.sockaddr = type { i32 }
@errno = global i64 0
@EINTR = global i64 0
define i32 @iTermFileDescriptorServerAccept(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.sockaddr_un
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
store i32 4, i32* %4
store i32 -1, i32* %5
br label %6
6: ; preds = %17, %1
%7 = load i32, i32* %2
%8 = bitcast %struct.sockaddr_un* %3 to %struct.sockaddr*
%9 = call i32 @accept(i32 %7, %struct.sockaddr* %8, i32* %4)
store i32 %9, i32* %5
br label %10
10: ; preds = %6
%11 = load i32, i32* %5
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %17
13: ; preds = %10
%14 = load i64, i64* @errno
%15 = load i64, i64* @EINTR
%16 = icmp eq i64 %14, %15
br label %17
17: ; preds = %13, %10
%18 = phi i1 [ false, %10 ], [ %16, %13 ]
br i1 %18, label %6, label %19
19: ; preds = %17
%20 = load i32, i32* %5
%21 = icmp ne i32 %20, -1
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = load i32, i32* %2
%24 = call i32 @close(i32 %23)
br label %25
25: ; preds = %22, %19
%26 = load i32, i32* %5
ret i32 %26
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32 }
%struct.sockaddr = type { i32 }
@errno = global i64 0
@EINTR = global i64 0
define i32 @iTermFileDescriptorServerAccept(i32 %0) {
%2 = alloca %struct.sockaddr_un
%3 = alloca i32
%4 = bitcast %struct.sockaddr_un* %2 to i8*
%5 = bitcast i32* %3 to i8*
store i32 4, i32* %3
%6 = bitcast %struct.sockaddr_un* %2 to %struct.sockaddr*
br label %7
7: ; preds = %7, %1
%8 = call i32 @accept(i32 %0, %struct.sockaddr* %6, i32* %3)
%9 = icmp eq i32 %8, -1
%10 = load i64, i64* @errno
%11 = load i64, i64* @EINTR
%12 = icmp eq i64 %10, %11
%13 = select i1 %9, i1 %12, i1 false
br i1 %13, label %7, label %14
14: ; preds = %7
br i1 %9, label %17, label %15
15: ; preds = %14
%16 = call i32 @close(i32 %0)
br label %17
17: ; preds = %15, %14
ret i32 %8
}