#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;
};
typedef int /*<<< orphan*/ socklen_t;

/* Variables and functions */
scalar_t__ EINTR;
int accept(int, struct sockaddr *, int /*<<< orphan*/ *);
scalar_t__ errno;
int /*<<< orphan*/ printf(char *, scalar_t__, int);
int accept_cr(int fd, struct sockaddr *addr, socklen_t *len) {
  int ret;
repeat_accept:
  ret = accept(fd, addr, len);
  if (ret < 0) {
    if (errno == EINTR) {
      goto repeat_accept;
    }
    printf("accept error errno=%d fd=%d\n", errno, fd);
  }
  return ret;
}


x86 assembly (clang, -O0):
<accept_cr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <accept@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1188 <accept_cr+0x68>
mov    0x2e89(%rip),%rax
mov    (%rax),%rax
mov    0x2e77(%rip),%rcx
cmp    (%rcx),%rax
jne    116f <accept_cr+0x4f>
jmp    1133 <accept_cr+0x13>
mov    0x2e6a(%rip),%rax
mov    (%rax),%rsi
mov    -0x4(%rbp),%edx
lea    0xe7d(%rip),%rdi
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<accept_cr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%rbp
mov    %edi,%r14d
mov    0x2ea5(%rip),%r12
mov    0x2e96(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14d,%edi
mov    %rbp,%rsi
mov    %r15,%rdx
call   1040 <accept@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    117d <accept_cr+0x5d>
mov    (%r12),%rsi
cmp    0x0(%r13),%rsi
je     1150 <accept_cr+0x30>
lea    0xe8b(%rip),%rdi
mov    %r14d,%edx
call   1030 <printf@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
@errno = global i64 0
@EINTR = global i64 0
@.str = [29 x i8] c"accept error errno=%d fd=%d\0A\00"
define i32 @accept_cr(i32 %0, %struct.sockaddr* %1, i32* %2) {
%4 = alloca i32
%5 = alloca %struct.sockaddr*
%6 = alloca i32*
%7 = alloca i32
store i32 %0, i32* %4
store %struct.sockaddr* %1, %struct.sockaddr** %5
store i32* %2, i32** %6
br label %8
8: ; preds = %19, %3
%9 = load i32, i32* %4
%10 = load %struct.sockaddr*, %struct.sockaddr** %5
%11 = load i32*, i32** %6
%12 = call i32 @accept(i32 %9, %struct.sockaddr* %10, i32* %11)
store i32 %12, i32* %7
%13 = load i32, i32* %7
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %24
15: ; preds = %8
%16 = load i64, i64* @errno
%17 = load i64, i64* @EINTR
%18 = icmp eq i64 %16, %17
br i1 %18, label %19, label %20
19: ; preds = %15
br label %8
20: ; preds = %15
%21 = load i64, i64* @errno
%22 = load i32, i32* %4
%23 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i64 %21, i32 %22)
br label %24
24: ; preds = %20, %8
%25 = load i32, i32* %7
ret i32 %25
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@errno = global i64 0
@EINTR = global i64 0
@.str = [29 x i8] c"accept error errno=%d fd=%d\0A\00"
define i32 @accept_cr(i32 %0, %struct.sockaddr* %1, i32* %2) {
br label %4
4: ; preds = %7, %3
%5 = tail call i32 @accept(i32 %0, %struct.sockaddr* %1, i32* %2)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %13
7: ; preds = %4
%8 = load i64, i64* @errno
%9 = load i64, i64* @EINTR
%10 = icmp eq i64 %8, %9
br i1 %10, label %4, label %11
11: ; preds = %7
%12 = tail call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i64 %8, i32 %0)
br label %13
13: ; preds = %4, %11
ret i32 %5
}