#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 /*<<< orphan*/ LOG_DEBUG;
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int /*<<< orphan*/ getpid();
int /*<<< orphan*/ strerror(scalar_t__);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, int /*<<< orphan*/, ...);
int iTermFileDescriptorServerAccept(int socketFd) {
  struct sockaddr_un remote;
  socklen_t sizeOfRemote = sizeof(remote);
  int connectionFd = -1;
  do {
    syslog(LOG_DEBUG,
           "Client(%d) "
           "accept()",
           getpid());
    connectionFd = accept(socketFd, (struct sockaddr *)&remote, &sizeOfRemote);
    syslog(LOG_DEBUG,
           "Client(%d) "
           "accept() returned %d error=%s",
           getpid(), connectionFd, strerror(errno));
  } while (connectionFd == -1 && errno == EINTR);
  if (connectionFd != -1) {
    close(socketFd);
  }
  return connectionFd;
}


x86 assembly (clang, -O0):
<iTermFileDescriptorServerAccept>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x4,-0xc(%rbp)
movl   $0xffffffff,-0x10(%rbp)
mov    0x2e60(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x20(%rbp),%edi
mov    %eax,%edx
lea    0xe78(%rip),%rsi
mov    $0x0,%al
call   1050 <syslog@plt>
mov    -0x4(%rbp),%edi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
call   1060 <accept@plt>
mov    %eax,-0x10(%rbp)
mov    0x2e27(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    0x2e1b(%rip),%rax
mov    (%rax),%rdi
call   1070 <strerror@plt>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%edx
mov    -0x14(%rbp),%ecx
mov    %eax,%r8d
lea    0xe34(%rip),%rsi
mov    $0x0,%al
call   1050 <syslog@plt>
xor    %eax,%eax
cmpl   $0xffffffff,-0x10(%rbp)
mov    %al,-0x21(%rbp)
jne    1210 <iTermFileDescriptorServerAccept+0xc0>
mov    0x2de3(%rip),%rax
mov    (%rax),%rax
mov    0x2dd1(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1169 <iTermFileDescriptorServerAccept+0x19>
cmpl   $0xffffffff,-0x10(%rbp)
je     122d <iTermFileDescriptorServerAccept+0xdd>
mov    -0x4(%rbp),%edi
call   1040 <close@plt>
mov    -0x10(%rbp),%eax
add    $0x30,%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)
mov    0x2e61(%rip),%r12
mov    0x2e6a(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
mov    (%r12),%ebp
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %ebp,%edi
lea    0xe6c(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <syslog@plt>
mov    %ebx,%edi
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rdx
call   1060 <accept@plt>
mov    %eax,%ebp
mov    (%r12),%r14d
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%r15d
mov    0x0(%r13),%rdi
call   1070 <strerror@plt>
mov    %r14d,%edi
lea    0xe43(%rip),%rsi
mov    %r15d,%edx
mov    %ebp,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   1050 <syslog@plt>
cmp    $0xffffffff,%ebp
jne    11f5 <iTermFileDescriptorServerAccept+0xa5>
mov    0x2dec(%rip),%rax
mov    (%rax),%rax
cmp    %rax,0x0(%r13)
je     1180 <iTermFileDescriptorServerAccept+0x30>
cmp    $0xffffffff,%ebp
je     1201 <iTermFileDescriptorServerAccept+0xb1>
mov    %ebx,%edi
call   1040 <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 }
@LOG_DEBUG = global i32 0
@.str = [20 x i8] c"Client(%d) accept()\00"
@.str.1 = [41 x i8] c"Client(%d) accept() returned %d error=%s\00"
@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 = %26, %1
%7 = load i32, i32* @LOG_DEBUG
%8 = call i32 (...) @getpid()
%9 = call i32 (i32, i8*, i32, ...) @syslog(i32 %7, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = load i32, i32* %2
%11 = bitcast %struct.sockaddr_un* %3 to %struct.sockaddr*
%12 = call i32 @accept(i32 %10, %struct.sockaddr* %11, i32* %4)
store i32 %12, i32* %5
%13 = load i32, i32* @LOG_DEBUG
%14 = call i32 (...) @getpid()
%15 = load i32, i32* %5
%16 = load i64, i64* @errno
%17 = call i32 @strerror(i64 %16)
%18 = call i32 (i32, i8*, i32, ...) @syslog(i32 %13, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %14, i32 %15, i32 %17)
br label %19
19: ; preds = %6
%20 = load i32, i32* %5
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %26
22: ; preds = %19
%23 = load i64, i64* @errno
%24 = load i64, i64* @EINTR
%25 = icmp eq i64 %23, %24
br label %26
26: ; preds = %22, %19
%27 = phi i1 [ false, %19 ], [ %25, %22 ]
br i1 %27, label %6, label %28
28: ; preds = %26
%29 = load i32, i32* %5
%30 = icmp ne i32 %29, -1
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = load i32, i32* %2
%33 = call i32 @close(i32 %32)
br label %34
34: ; preds = %31, %28
%35 = load i32, i32* %5
ret i32 %35
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32 }
%struct.sockaddr = type { i32 }
@LOG_DEBUG = global i32 0
@.str = [20 x i8] c"Client(%d) accept()\00"
@.str.1 = [41 x i8] c"Client(%d) accept() returned %d error=%s\00"
@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 = load i32, i32* @LOG_DEBUG
%9 = call i32 (...) @getpid()
%10 = call i32 (i32, i8*, i32, ...) @syslog(i32 %8, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = call i32 @accept(i32 %0, %struct.sockaddr* %6, i32* %3)
%12 = load i32, i32* @LOG_DEBUG
%13 = call i32 (...) @getpid()
%14 = load i64, i64* @errno
%15 = call i32 @strerror(i64 %14)
%16 = call i32 (i32, i8*, i32, ...) @syslog(i32 %12, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %13, i32 %11, i32 %15)
%17 = icmp eq i32 %11, -1
%18 = load i64, i64* @errno
%19 = load i64, i64* @EINTR
%20 = icmp eq i64 %18, %19
%21 = select i1 %17, i1 %20, i1 false
br i1 %21, label %7, label %22
22: ; preds = %7
br i1 %17, label %25, label %23
23: ; preds = %22
%24 = call i32 @close(i32 %0)
br label %25
25: ; preds = %23, %22
ret i32 %11
}