#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_in {
  int /*<<< orphan*/ sin_addr;
};
struct sockaddr {
  int dummy;
};

/* Variables and functions */
scalar_t__ EINTR;
int accept(int, struct sockaddr *, int *);
scalar_t__ errno;
int /*<<< orphan*/ inet_ntoa(int /*<<< orphan*/);
int /*<<< orphan*/ strncpy(char *, int /*<<< orphan*/, int);
int u_accept(int fd, char *hostn, int hostnsize) {
  int len = sizeof(struct sockaddr);
  struct sockaddr_in netclient;
  int retval;
  while (((retval = accept(fd, (struct sockaddr *)(&netclient), &len)) == -1) &&
         (errno == EINTR))
    ;
  if ((retval == -1) || (hostn == NULL) || (hostnsize <= 0))
    return retval;
  strncpy(hostn, inet_ntoa(netclient.sin_addr), hostnsize);
  return retval;
}


x86 assembly (clang, -O0):
<u_accept>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x4,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   1050 <accept@plt>
mov    %eax,%ecx
mov    %ecx,-0x24(%rbp)
xor    %eax,%eax
cmp    $0xffffffff,%ecx
mov    %al,-0x25(%rbp)
jne    1186 <u_accept+0x56>
mov    0x2e6d(%rip),%rax
mov    (%rax),%rax
mov    0x2e5b(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    1196 <u_accept+0x66>
jmp    119b <u_accept+0x6b>
jmp    1149 <u_accept+0x19>
cmpl   $0xffffffff,-0x24(%rbp)
je     11ba <u_accept+0x8a>
cmpq   $0x0,-0x10(%rbp)
je     11ba <u_accept+0x8a>
cmpl   $0x0,-0x14(%rbp)
jg     11c5 <u_accept+0x95>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11e9 <u_accept+0xb9>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%edi
call   1040 <inet_ntoa@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%esi
mov    -0x14(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<u_accept>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,0x8(%rsp)
mov    %rsi,0x10(%rsp)
mov    %edi,%ebx
movl   $0x4,0xc(%rsp)
mov    %rsp,%r12
lea    0xc(%rsp),%r13
mov    0x2e80(%rip),%r14
mov    0x2e71(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r12,%rsi
mov    %r13,%rdx
call   1050 <accept@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    118c <u_accept+0x5c>
mov    (%r15),%rax
cmp    %rax,(%r14)
je     1170 <u_accept+0x40>
mov    0x8(%rsp),%ebx
test   %ebx,%ebx
mov    0x10(%rsp),%r14
jle    11b7 <u_accept+0x87>
test   %r14,%r14
je     11b7 <u_accept+0x87>
cmp    $0xffffffff,%ebp
je     11b7 <u_accept+0x87>
mov    (%rsp),%edi
call   1040 <inet_ntoa@plt>
mov    %r14,%rdi
mov    %eax,%esi
mov    %ebx,%edx
call   1030 <strncpy@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_in = type { i32 }
%struct.sockaddr = type { i32 }
@errno = global i64 0
@EINTR = global i64 0
define i32 @u_accept(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.sockaddr_in
%10 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 4, i32* %8
br label %11
11: ; preds = %22, %3
%12 = load i32, i32* %5
%13 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%14 = call i32 @accept(i32 %12, %struct.sockaddr* %13, i32* %8)
store i32 %14, i32* %10
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %20
16: ; preds = %11
%17 = load i64, i64* @errno
%18 = load i64, i64* @EINTR
%19 = icmp eq i64 %17, %18
br label %20
20: ; preds = %16, %11
%21 = phi i1 [ false, %11 ], [ %19, %16 ]
br i1 %21, label %22, label %23
22: ; preds = %20
br label %11
23: ; preds = %20
%24 = load i32, i32* %10
%25 = icmp eq i32 %24, -1
br i1 %25, label %32, label %26
26: ; preds = %23
%27 = load i8*, i8** %6
%28 = icmp eq i8* %27, null
br i1 %28, label %32, label %29
29: ; preds = %26
%30 = load i32, i32* %7
%31 = icmp sle i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %29, %26, %23
%33 = load i32, i32* %10
store i32 %33, i32* %4
br label %42
34: ; preds = %29
%35 = load i8*, i8** %6
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
%37 = load i32, i32* %36
%38 = call i32 @inet_ntoa(i32 %37)
%39 = load i32, i32* %7
%40 = call i32 @strncpy(i8* %35, i32 %38, i32 %39)
%41 = load i32, i32* %10
store i32 %41, i32* %4
br label %42
42: ; preds = %34, %32
%43 = load i32, i32* %4
ret i32 %43
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@errno = global i64 0
@EINTR = global i64 0
define i32 @u_accept(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.sockaddr_in
%6 = bitcast i32* %4 to i8*
store i32 4, i32* %4
%7 = bitcast %struct.sockaddr_in* %5 to i8*
%8 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
br label %9
9: ; preds = %9, %3
%10 = call i32 @accept(i32 %0, %struct.sockaddr* %8, i32* %4)
%11 = icmp eq i32 %10, -1
%12 = load i64, i64* @errno
%13 = load i64, i64* @EINTR
%14 = icmp eq i64 %12, %13
%15 = select i1 %11, i1 %14, i1 false
br i1 %15, label %9, label %16
16: ; preds = %9
%17 = icmp eq i8* %1, null
%18 = or i1 %17, %11
%19 = icmp slt i32 %2, 1
%20 = or i1 %19, %18
br i1 %20, label %26, label %21
21: ; preds = %16
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0
%23 = load i32, i32* %22
%24 = call i32 @inet_ntoa(i32 %23)
%25 = call i32 @strncpy(i8* %1, i32 %24, i32 %2)
br label %26
26: ; preds = %16, %21
ret i32 %10
}