#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*/ socklen_t;

/* Variables and functions */
scalar_t__ EAGAIN;
scalar_t__ EHOSTDOWN;
scalar_t__ EHOSTUNREACH;
scalar_t__ ENETDOWN;
scalar_t__ ENETUNREACH;
scalar_t__ ENONET;
scalar_t__ ENOPROTOOPT;
scalar_t__ EOPNOTSUPP;
scalar_t__ EPROTO;
scalar_t__ EWOULDBLOCK;
int accept(int, struct sockaddr *, int /*<<< orphan*/ *);
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ stderr;
int sock_accept(int listen_sock) {
  int sock;
  struct sockaddr_in cin;
  int cin_len = sizeof(struct sockaddr_in);
  memset(&cin, 0, sizeof(struct sockaddr_in));
  sock = accept(listen_sock, (struct sockaddr *)&cin, (socklen_t *)&cin_len);
  if (sock < 0) {
    if ((errno == EAGAIN) || (errno == EWOULDBLOCK) || (errno == ENETDOWN) ||
        (errno == EPROTO) || (errno == ENOPROTOOPT) || (errno == EHOSTDOWN) ||
        (errno == ENONET) || (errno == EHOSTUNREACH) || (errno == EOPNOTSUPP) ||
        (errno == ENETUNREACH)) {
      return 0;
    } else
      do {
        fprintf(stderr, "accept failed\n");
        exit(0);
      } while (0);
  }
  return sock;
}


x86 assembly (clang, -O0):
<sock_accept>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x4,-0x14(%rbp)
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rdx
call   1050 <accept@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    12b0 <sock_accept+0x170>
mov    0x2e1a(%rip),%rax
mov    (%rax),%rax
mov    0x2df0(%rip),%rcx
cmp    (%rcx),%rax
je     1283 <sock_accept+0x143>
mov    0x2e00(%rip),%rax
mov    (%rax),%rax
mov    0x2dee(%rip),%rcx
cmp    (%rcx),%rax
je     1283 <sock_accept+0x143>
mov    0x2de6(%rip),%rax
mov    (%rax),%rax
mov    0x2e14(%rip),%rcx
cmp    (%rcx),%rax
je     1283 <sock_accept+0x143>
mov    0x2dcc(%rip),%rax
mov    (%rax),%rax
mov    0x2dda(%rip),%rcx
cmp    (%rcx),%rax
je     1283 <sock_accept+0x143>
mov    0x2db2(%rip),%rax
mov    (%rax),%rax
mov    0x2df0(%rip),%rcx
cmp    (%rcx),%rax
je     1283 <sock_accept+0x143>
mov    0x2d98(%rip),%rax
mov    (%rax),%rax
mov    0x2d7e(%rip),%rcx
cmp    (%rcx),%rax
je     1283 <sock_accept+0x143>
mov    0x2d7e(%rip),%rax
mov    (%rax),%rax
mov    0x2da4(%rip),%rcx
cmp    (%rcx),%rax
je     1283 <sock_accept+0x143>
mov    0x2d64(%rip),%rax
mov    (%rax),%rax
mov    0x2d82(%rip),%rcx
cmp    (%rcx),%rax
je     1283 <sock_accept+0x143>
mov    0x2d4a(%rip),%rax
mov    (%rax),%rax
mov    0x2d48(%rip),%rcx
cmp    (%rcx),%rax
je     1283 <sock_accept+0x143>
mov    0x2d30(%rip),%rax
mov    (%rax),%rax
mov    0x2d66(%rip),%rcx
cmp    (%rcx),%rax
jne    128f <sock_accept+0x14f>
movl   $0x0,-0x4(%rbp)
jmp    12b6 <sock_accept+0x176>
jmp    1294 <sock_accept+0x154>
mov    0x2d15(%rip),%rax
mov    (%rax),%edi
lea    0xd5c(%rip),%rsi
call   1040 <fprintf@plt>
xor    %edi,%edi
call   1060 <exit@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sock_accept>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebx
movl   $0x4,0xc(%rsp)
lea    0x10(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
lea    0xc(%rsp),%rdx
mov    %ebx,%edi
mov    %r14,%rsi
call   1050 <accept@plt>
test   %eax,%eax
jns    1229 <sock_accept+0xe9>
mov    0x2e1d(%rip),%rax
mov    (%rax),%rcx
mov    0x2df3(%rip),%rax
cmp    (%rax),%rcx
je     1227 <sock_accept+0xe7>
mov    0x2dfb(%rip),%rax
cmp    (%rax),%rcx
je     1227 <sock_accept+0xe7>
mov    0x2e2b(%rip),%rax
cmp    (%rax),%rcx
je     1227 <sock_accept+0xe7>
mov    0x2dff(%rip),%rax
cmp    (%rax),%rcx
je     1227 <sock_accept+0xe7>
mov    0x2e23(%rip),%rax
cmp    (%rax),%rcx
je     1227 <sock_accept+0xe7>
mov    0x2dbf(%rip),%rax
cmp    (%rax),%rcx
je     1227 <sock_accept+0xe7>
mov    0x2df3(%rip),%rax
cmp    (%rax),%rcx
je     1227 <sock_accept+0xe7>
mov    0x2ddf(%rip),%rax
cmp    (%rax),%rcx
je     1227 <sock_accept+0xe7>
mov    0x2db3(%rip),%rax
cmp    (%rax),%rcx
je     1227 <sock_accept+0xe7>
mov    0x2ddf(%rip),%rdx
mov    $0x0,%eax
cmp    (%rdx),%rcx
je     1229 <sock_accept+0xe9>
mov    0x2d9e(%rip),%rax
mov    (%rax),%edi
lea    0xde5(%rip),%rsi
call   1040 <fprintf@plt>
xor    %edi,%edi
call   1060 <exit@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@errno = global i64 0
@EAGAIN = global i64 0
@EWOULDBLOCK = global i64 0
@ENETDOWN = global i64 0
@EPROTO = global i64 0
@ENOPROTOOPT = global i64 0
@EHOSTDOWN = global i64 0
@ENONET = global i64 0
@EHOSTUNREACH = global i64 0
@EOPNOTSUPP = global i64 0
@ENETUNREACH = global i64 0
@stderr = global i32 0
@.str = [15 x i8] c"accept failed\0A\00"
define i32 @sock_accept(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.sockaddr_in
%6 = alloca i32
store i32 %0, i32* %3
store i32 4, i32* %6
%7 = call i32 @memset(%struct.sockaddr_in* %5, i32 0, i32 4)
%8 = load i32, i32* %3
%9 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%10 = call i32 @accept(i32 %8, %struct.sockaddr* %9, i32* %6)
store i32 %10, i32* %4
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %61
13: ; preds = %1
%14 = load i64, i64* @errno
%15 = load i64, i64* @EAGAIN
%16 = icmp eq i64 %14, %15
br i1 %16, label %53, label %17
17: ; preds = %13
%18 = load i64, i64* @errno
%19 = load i64, i64* @EWOULDBLOCK
%20 = icmp eq i64 %18, %19
br i1 %20, label %53, label %21
21: ; preds = %17
%22 = load i64, i64* @errno
%23 = load i64, i64* @ENETDOWN
%24 = icmp eq i64 %22, %23
br i1 %24, label %53, label %25
25: ; preds = %21
%26 = load i64, i64* @errno
%27 = load i64, i64* @EPROTO
%28 = icmp eq i64 %26, %27
br i1 %28, label %53, label %29
29: ; preds = %25
%30 = load i64, i64* @errno
%31 = load i64, i64* @ENOPROTOOPT
%32 = icmp eq i64 %30, %31
br i1 %32, label %53, label %33
33: ; preds = %29
%34 = load i64, i64* @errno
%35 = load i64, i64* @EHOSTDOWN
%36 = icmp eq i64 %34, %35
br i1 %36, label %53, label %37
37: ; preds = %33
%38 = load i64, i64* @errno
%39 = load i64, i64* @ENONET
%40 = icmp eq i64 %38, %39
br i1 %40, label %53, label %41
41: ; preds = %37
%42 = load i64, i64* @errno
%43 = load i64, i64* @EHOSTUNREACH
%44 = icmp eq i64 %42, %43
br i1 %44, label %53, label %45
45: ; preds = %41
%46 = load i64, i64* @errno
%47 = load i64, i64* @EOPNOTSUPP
%48 = icmp eq i64 %46, %47
br i1 %48, label %53, label %49
49: ; preds = %45
%50 = load i64, i64* @errno
%51 = load i64, i64* @ENETUNREACH
%52 = icmp eq i64 %50, %51
br i1 %52, label %53, label %54
53: ; preds = %49, %45, %41, %37, %33, %29, %25, %21, %17, %13
store i32 0, i32* %2
br label %63
54: ; preds = %49
br label %55
55: ; preds = %54
%56 = load i32, i32* @stderr
%57 = call i32 @fprintf(i32 %56, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%58 = call i32 @exit(i32 0)
unreachable
59: ; No predecessors!
br label %60
60: ; preds = %59
br label %61
61: ; preds = %60, %1
%62 = load i32, i32* %4
store i32 %62, i32* %2
br label %63
63: ; preds = %61, %53
%64 = load i32, i32* %2
ret i32 %64
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@errno = global i64 0
@EAGAIN = global i64 0
@EWOULDBLOCK = global i64 0
@ENETDOWN = global i64 0
@EPROTO = global i64 0
@ENOPROTOOPT = global i64 0
@EHOSTDOWN = global i64 0
@ENONET = global i64 0
@EHOSTUNREACH = global i64 0
@EOPNOTSUPP = global i64 0
@ENETUNREACH = global i64 0
@stderr = global i32 0
@.str = [15 x i8] c"accept failed\0A\00"
define i32 @sock_accept(i32 %0) {
%2 = alloca %struct.sockaddr_in
%3 = alloca i32
%4 = bitcast %struct.sockaddr_in* %2 to i8*
%5 = bitcast i32* %3 to i8*
store i32 4, i32* %3
%6 = call i32 @memset(%struct.sockaddr_in* %2, i32 0, i32 4)
%7 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%8 = call i32 @accept(i32 %0, %struct.sockaddr* %7, i32* %3)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %45
10: ; preds = %1
%11 = load i64, i64* @errno
%12 = load i64, i64* @EAGAIN
%13 = icmp eq i64 %11, %12
%14 = load i64, i64* @EWOULDBLOCK
%15 = icmp eq i64 %11, %14
%16 = select i1 %13, i1 true, i1 %15
%17 = load i64, i64* @ENETDOWN
%18 = icmp eq i64 %11, %17
%19 = select i1 %16, i1 true, i1 %18
%20 = load i64, i64* @EPROTO
%21 = icmp eq i64 %11, %20
%22 = select i1 %19, i1 true, i1 %21
%23 = load i64, i64* @ENOPROTOOPT
%24 = icmp eq i64 %11, %23
%25 = select i1 %22, i1 true, i1 %24
%26 = load i64, i64* @EHOSTDOWN
%27 = icmp eq i64 %11, %26
%28 = select i1 %25, i1 true, i1 %27
%29 = load i64, i64* @ENONET
%30 = icmp eq i64 %11, %29
%31 = select i1 %28, i1 true, i1 %30
%32 = load i64, i64* @EHOSTUNREACH
%33 = icmp eq i64 %11, %32
%34 = select i1 %31, i1 true, i1 %33
%35 = load i64, i64* @EOPNOTSUPP
%36 = icmp eq i64 %11, %35
%37 = select i1 %34, i1 true, i1 %36
%38 = load i64, i64* @ENETUNREACH
%39 = icmp eq i64 %11, %38
%40 = select i1 %37, i1 true, i1 %39
br i1 %40, label %45, label %41
41: ; preds = %10
%42 = load i32, i32* @stderr
%43 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%44 = call i32 @exit(i32 0)
unreachable
45: ; preds = %1, %10
%46 = phi i32 [ 0, %10 ], [ %8, %1 ]
ret i32 %46
}