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

/* Variables and functions */
scalar_t__ EINTR;
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ bzero(void *, int);
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sock_optimize(int, int);
int tcp_accept(int sock, int rdwr) {
  struct sockaddr_in s;
  int newsock;
  socklen_t namelen;
  namelen = sizeof(s);
  bzero((void *)&s, namelen);
retry:
  if ((newsock = accept(sock, (struct sockaddr *)&s, &namelen)) < 0) {
    if (errno == EINTR)
      goto retry;
    perror("accept");
    exit(6);
  }
  sock_optimize(newsock, rdwr);
  return (newsock);
}


x86 assembly (clang, -O0):
<tcp_accept>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x4,-0x18(%rbp)
lea    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1040 <bzero@plt>
mov    -0x4(%rbp),%edi
lea    -0x10(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   1050 <accept@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11c2 <tcp_accept+0x72>
mov    0x2e4c(%rip),%rax
mov    (%rax),%rax
mov    0x2e3a(%rip),%rcx
cmp    (%rcx),%rax
jne    11ac <tcp_accept+0x5c>
jmp    1171 <tcp_accept+0x21>
lea    0xe4d(%rip),%rdi
call   1030 <perror@plt>
mov    $0x6,%edi
call   1070 <exit@plt>
mov    -0x14(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1060 <sock_optimize@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tcp_accept>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,0x8(%rsp)
mov    %edi,%ebp
movl   $0x4,0xc(%rsp)
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    $0x4,%esi
call   1040 <bzero@plt>
lea    0xc(%rsp),%r12
mov    0x2e56(%rip),%r13
mov    0x2e47(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %r15,%rsi
mov    %r12,%rdx
call   1050 <accept@plt>
test   %eax,%eax
jns    11d0 <tcp_accept+0x80>
mov    0x0(%r13),%rax
cmp    (%r14),%rax
je     11a0 <tcp_accept+0x50>
lea    0xe3f(%rip),%rdi
call   1030 <perror@plt>
mov    $0x6,%edi
call   1070 <exit@plt>
mov    %eax,%ebx
mov    %eax,%edi
mov    0x8(%rsp),%esi
call   1060 <sock_optimize@plt>
mov    %ebx,%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
@.str = [7 x i8] c"accept\00"
define i32 @tcp_accept(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.sockaddr_in
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 4, i32* %7
%8 = bitcast %struct.sockaddr_in* %5 to i8*
%9 = load i32, i32* %7
%10 = call i32 @bzero(i8* %8, i32 %9)
br label %11
11: ; preds = %20, %2
%12 = load i32, i32* %3
%13 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%14 = call i32 @accept(i32 %12, %struct.sockaddr* %13, i32* %7)
store i32 %14, i32* %6
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %24
16: ; preds = %11
%17 = load i64, i64* @errno
%18 = load i64, i64* @EINTR
%19 = icmp eq i64 %17, %18
br i1 %19, label %20, label %21
20: ; preds = %16
br label %11
21: ; preds = %16
%22 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%23 = call i32 @exit(i32 6)
unreachable
24: ; preds = %11
%25 = load i32, i32* %6
%26 = load i32, i32* %4
%27 = call i32 @sock_optimize(i32 %25, i32 %26)
%28 = load i32, i32* %6
ret i32 %28
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@errno = global i64 0
@EINTR = global i64 0
@.str = [7 x i8] c"accept\00"
define i32 @tcp_accept(i32 %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*
store i32 4, i32* %4
%7 = call i32 @bzero(i8* %5, i32 4)
%8 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
br label %9
9: ; preds = %12, %2
%10 = call i32 @accept(i32 %0, %struct.sockaddr* %8, i32* %4)
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %19
12: ; preds = %9
%13 = load i64, i64* @errno
%14 = load i64, i64* @EINTR
%15 = icmp eq i64 %13, %14
br i1 %15, label %9, label %16
16: ; preds = %12
%17 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @exit(i32 6)
unreachable
19: ; preds = %9
%20 = call i32 @sock_optimize(i32 %10, i32 %1)
ret i32 %10
}