#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;
};

/* Variables and functions */
scalar_t__ EINTR;
int accept(int, struct sockaddr *, int *);
scalar_t__ errno;
int accept_con(int sd) {
  int nd = -1;
  int len;
  struct sockaddr raddr;
  do {
    nd = accept(sd, &raddr, &len);
  } while ((nd < 1) && (errno == EINTR));
  if (nd < 0) {
    return (-1);
  }
  return (nd);
}


x86 assembly (clang, -O0):
<accept_con>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
movl   $0xffffffff,-0xc(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
lea    -0x10(%rbp),%rdx
call   1030 <accept@plt>
mov    %eax,-0xc(%rbp)
xor    %eax,%eax
cmpl   $0x1,-0xc(%rbp)
mov    %al,-0x19(%rbp)
jge    115e <accept_con+0x4e>
mov    0x2e95(%rip),%rax
mov    (%rax),%rax
mov    0x2e83(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1122 <accept_con+0x12>
cmpl   $0x0,-0xc(%rbp)
jge    117f <accept_con+0x6f>
movl   $0xffffffff,-0x4(%rbp)
jmp    1185 <accept_con+0x75>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<accept_con>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
lea    0x8(%rsp),%r14
lea    0xc(%rsp),%r15
mov    0x2eb0(%rip),%r12
mov    0x2ea1(%rip),%r13
nopw   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   1030 <accept@plt>
test   %eax,%eax
jg     115b <accept_con+0x4b>
mov    0x0(%r13),%rcx
cmp    %rcx,(%r12)
je     1140 <accept_con+0x30>
test   %eax,%eax
mov    $0xffffffff,%ecx
cmovns %eax,%ecx
mov    %ecx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
@errno = global i64 0
@EINTR = global i64 0
define i32 @accept_con(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.sockaddr
store i32 %0, i32* %3
store i32 -1, i32* %4
br label %7
7: ; preds = %17, %1
%8 = load i32, i32* %3
%9 = call i32 @accept(i32 %8, %struct.sockaddr* %6, i32* %5)
store i32 %9, i32* %4
br label %10
10: ; preds = %7
%11 = load i32, i32* %4
%12 = icmp slt 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 %7, label %19
19: ; preds = %17
%20 = load i32, i32* %4
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %19
store i32 -1, i32* %2
br label %25
23: ; preds = %19
%24 = load i32, i32* %4
store i32 %24, i32* %2
br label %25
25: ; preds = %23, %22
%26 = load i32, i32* %2
ret i32 %26
}

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