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

/* Variables and functions */
scalar_t__ EINTR;
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ assert(int);
scalar_t__ errno;
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int AcceptSock(int *pSock, int nSock) {
  struct sockaddr_in addrin;
  int lSize;
  assert(pSock != NULL && nSock > 0);
  while (1) {
    lSize = sizeof(addrin);
    memset(&addrin, 0, sizeof(addrin));
    if ((*pSock = accept(nSock, (struct sockaddr *)&addrin, &lSize)) > 0)
      return 0;
    else if (errno == EINTR)
      continue;
  }
}


x86 assembly (clang, -O0):
<AcceptSock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x8(%rbp)
mov    %al,-0x15(%rbp)
je     1159 <AcceptSock+0x29>
cmpl   $0x0,-0xc(%rbp)
setg   %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
movl   $0x4,-0x14(%rbp)
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
mov    -0xc(%rbp),%edi
lea    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rdx
call   1050 <accept@plt>
mov    -0x8(%rbp),%rcx
mov    %eax,(%rcx)
cmp    $0x0,%eax
jle    11a4 <AcceptSock+0x74>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret
mov    0x2e35(%rip),%rax
mov    (%rax),%rax
mov    0x2e23(%rip),%rcx
cmp    (%rcx),%rax
jne    11c3 <AcceptSock+0x93>
jmp    1166 <AcceptSock+0x36>
jmp    11c8 <AcceptSock+0x98>
jmp    1166 <AcceptSock+0x36>

x86 assembly (clang, -O2):
<AcceptSock>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %esi,%r14d
mov    %rdi,%rbx
test   %rdi,%rdi
setne  %al
test   %esi,%esi
setg   %cl
and    %al,%cl
movzbl %cl,%edi
call   1040 <assert@plt>
lea    0x10(%rsp),%rbp
lea    0xc(%rsp),%r15
nop
movl   $0x4,0xc(%rsp)
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    %r15,%rdx
call   1050 <accept@plt>
mov    %eax,(%rbx)
test   %eax,%eax
jle    1160 <AcceptSock+0x30>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
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 @AcceptSock(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca %struct.sockaddr_in
%6 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%7 = load i32*, i32** %3
%8 = icmp ne i32* %7, null
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = load i32, i32* %4
%11 = icmp sgt i32 %10, 0
br label %12
12: ; preds = %9, %2
%13 = phi i1 [ false, %2 ], [ %11, %9 ]
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
br label %16
16: ; preds = %12, %28, %30
store i32 4, i32* %6
%17 = call i32 @memset(%struct.sockaddr_in* %5, i32 0, i32 4)
%18 = load i32, i32* %4
%19 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%20 = call i32 @accept(i32 %18, %struct.sockaddr* %19, i32* %6)
%21 = load i32*, i32** %3
store i32 %20, i32* %21
%22 = icmp sgt i32 %20, 0
br i1 %22, label %23, label %24
23: ; preds = %16
ret i32 0
24: ; preds = %16
%25 = load i64, i64* @errno
%26 = load i64, i64* @EINTR
%27 = icmp eq i64 %25, %26
br i1 %27, label %28, label %29
28: ; preds = %24
br label %16
29: ; preds = %24
br label %30
30: ; preds = %29
br label %16
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@errno = global i64 0
@EINTR = global i64 0
define i32 @AcceptSock(i32* writeonly %0, i32 %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = bitcast %struct.sockaddr_in* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = icmp ne i32* %0, null
%8 = icmp sgt i32 %1, 0
%9 = and i1 %7, %8
%10 = zext i1 %9 to i32
%11 = tail call i32 @assert(i32 %10)
%12 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
br label %13
13: ; preds = %13, %2
store i32 4, i32* %4
%14 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 4)
%15 = call i32 @accept(i32 %1, %struct.sockaddr* %12, i32* %4)
store i32 %15, i32* %0
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %13
17: ; preds = %13
ret i32 0
}