#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct sockaddr {
  int dummy;
};
struct TYPE_2__ {
  int fd;
};
struct epoll_event {
  int events;
  TYPE_1__ data;
};
typedef int socklen_t;

/* Variables and functions */
scalar_t__ EAGAIN;
int EPOLLET;
int EPOLLIN;
int /*<<< orphan*/ EPOLL_CTL_ADD;
scalar_t__ EWOULDBLOCK;
int NI_MAXHOST;
int NI_MAXSERV;
int NI_NUMERICHOST;
int NI_NUMERICSERV;
int /*<<< orphan*/ abort();
int accept(int, struct sockaddr *, int *);
int epoll_ctl(int, int /*<<< orphan*/, int, struct epoll_event *);
scalar_t__ errno;
int getnameinfo(struct sockaddr *, int, char *, int, char *, int, int);
int make_socket_non_blocking(int);
int /*<<< orphan*/ perror(char *);
void accept_connection(int sfd, int efd, int num) {
  int s;
  struct epoll_event event;
  while (1) {
    struct sockaddr in_addr;
    socklen_t in_len;
    int infd;
    char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV];
    in_len = sizeof in_addr;
    infd = accept(sfd, &in_addr, &in_len);
    if (infd == -1) {
      if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) {
        break;
      } else {
        perror("accept");
        break;
      }
    }
    s = getnameinfo(&in_addr, in_len, hbuf, sizeof hbuf, sbuf, sizeof sbuf,
                    NI_NUMERICHOST | NI_NUMERICSERV);
    if (s == 0) {
    }
    s = make_socket_non_blocking(infd);
    if (s == -1)
      abort();
    event.data.fd = infd;
    event.events = EPOLLIN | EPOLLET;
    s = epoll_ctl(efd, EPOLL_CTL_ADD, infd, &event);
    if (s == -1) {
      perror("epoll_ctl");
      abort();
    }
  }
}


x86 assembly (clang, -O0):
<accept_connection>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    0x2e28(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x68(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x60(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
mov    0x2e28(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x58(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x40(%rbp)
movl   $0x4,-0x24(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x20(%rbp),%rsi
lea    -0x24(%rbp),%rdx
call   1080 <accept@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0xffffffff,-0x28(%rbp)
jne    1246 <accept_connection+0xe6>
mov    0x2dc3(%rip),%rax
mov    (%rax),%rax
mov    0x2d91(%rip),%rcx
cmp    (%rcx),%rax
je     1222 <accept_connection+0xc2>
mov    0x2da9(%rip),%rax
mov    (%rax),%rax
mov    0x2d97(%rip),%rcx
cmp    (%rcx),%rax
jne    122e <accept_connection+0xce>
movl   $0x3,-0x44(%rbp)
jmp    130a <accept_connection+0x1aa>
lea    0xdcb(%rip),%rdi
call   1070 <perror@plt>
movl   $0x3,-0x44(%rbp)
jmp    130a <accept_connection+0x1aa>
mov    -0x50(%rbp),%r8
mov    -0x60(%rbp),%rdx
mov    -0x58(%rbp),%rax
mov    -0x68(%rbp),%rcx
mov    -0x24(%rbp),%esi
mov    %eax,%r9d
mov    0x2d5d(%rip),%rax
mov    (%rax),%eax
mov    0x2d7c(%rip),%rdi
or     (%rdi),%eax
lea    -0x20(%rbp),%rdi
sub    $0x10,%rsp
mov    %eax,(%rsp)
call   1050 <getnameinfo@plt>
add    $0x10,%rsp
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    1294 <accept_connection+0x134>
jmp    1294 <accept_connection+0x134>
mov    -0x28(%rbp),%edi
call   1040 <make_socket_non_blocking@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    12b0 <accept_connection+0x150>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x28(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    0x2d23(%rip),%rax
mov    (%rax),%eax
mov    0x2ce2(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2d03(%rip),%rax
mov    (%rax),%esi
mov    -0x28(%rbp),%edx
lea    -0x18(%rbp),%rcx
call   1060 <epoll_ctl@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    1303 <accept_connection+0x1a3>
lea    0xd10(%rip),%rdi
call   1070 <perror@plt>
mov    $0x0,%al
call   1030 <abort@plt>
movl   $0x0,-0x44(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    -0x44(%rbp),%eax
test   %eax,%eax
je     1326 <accept_connection+0x1c6>
jmp    1321 <accept_connection+0x1c1>
jmp    132b <accept_connection+0x1cb>
jmp    1171 <accept_connection+0x11>
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<accept_connection>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %esi,-0x48(%rbp)
mov    %rsp,-0x38(%rbp)
mov    0x2e21(%rip),%rax
mov    (%rax),%r14d
mov    %rsp,%r13
lea    0xf(%r14),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
mov    0x2e36(%rip),%rax
mov    (%rax),%ebx
mov    %rsp,%r12
lea    0xf(%rbx),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
movl   $0x4,-0x2c(%rbp)
lea    -0x40(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
mov    %edi,-0x44(%rbp)
call   1080 <accept@plt>
cmp    $0xffffffff,%eax
je     12c9 <accept_connection+0x169>
mov    %eax,%r15d
lea    -0x40(%rbp),%rdi
mov    %r14,%r8
mov    %rbx,%r14
nopw   0x0(%rax,%rax,1)
mov    -0x2c(%rbp),%esi
mov    0x2dfe(%rip),%rax
mov    (%rax),%eax
mov    0x2dcd(%rip),%rcx
or     (%rcx),%eax
sub    $0x8,%rsp
mov    %rdi,%rbx
mov    %r13,%rdx
mov    %r8d,%ecx
mov    %r12,%r8
mov    %r14d,%r9d
push   %rax
call   1050 <getnameinfo@plt>
add    $0x10,%rsp
mov    %r15d,%edi
call   1040 <make_socket_non_blocking@plt>
cmp    $0xffffffff,%eax
je     130c <accept_connection+0x1ac>
mov    %r15d,-0x4c(%rbp)
mov    0x2d7a(%rip),%rax
mov    (%rax),%eax
mov    0x2da9(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x50(%rbp)
mov    0x2d95(%rip),%rax
mov    (%rax),%esi
mov    -0x48(%rbp),%edi
mov    %r15d,%edx
lea    -0x50(%rbp),%rcx
call   1060 <epoll_ctl@plt>
cmp    $0xffffffff,%eax
je     1313 <accept_connection+0x1b3>
mov    -0x38(%rbp),%rsp
mov    %rsp,-0x38(%rbp)
mov    0x2d34(%rip),%rax
mov    (%rax),%r15d
mov    %rsp,%r13
mov    %r15,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
mov    0x2d46(%rip),%rax
mov    (%rax),%r14d
mov    %rsp,%r12
mov    %r14,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
movl   $0x4,-0x2c(%rbp)
mov    -0x44(%rbp),%edi
mov    %rbx,%rsi
lea    -0x2c(%rbp),%rdx
call   1080 <accept@plt>
mov    %r15,%r8
mov    %rbx,%rdi
mov    %eax,%r15d
cmp    $0xffffffff,%eax
jne    11e0 <accept_connection+0x80>
mov    0x2ce8(%rip),%rax
mov    (%rax),%rax
mov    0x2cb6(%rip),%rcx
cmp    (%rcx),%rax
je     12eb <accept_connection+0x18b>
mov    0x2cca(%rip),%rcx
cmp    (%rcx),%rax
jne    12fe <accept_connection+0x19e>
mov    -0x38(%rbp),%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcfb(%rip),%rdi
call   1070 <perror@plt>
jmp    12eb <accept_connection+0x18b>
xor    %eax,%eax
call   1030 <abort@plt>
lea    0xced(%rip),%rdi
call   1070 <perror@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
%struct.epoll_event = type { i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@NI_MAXHOST = global i32 0
@NI_MAXSERV = global i32 0
@errno = global i64 0
@EAGAIN = global i64 0
@EWOULDBLOCK = global i64 0
@.str = [7 x i8] c"accept\00"
@NI_NUMERICHOST = global i32 0
@NI_NUMERICSERV = global i32 0
@EPOLLIN = global i32 0
@EPOLLET = global i32 0
@EPOLL_CTL_ADD = global i32 0
@.str.1 = [10 x i8] c"epoll_ctl\00"
define void @accept_connection(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.epoll_event
%9 = alloca %struct.sockaddr
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i64
%14 = alloca i64
%15 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
br label %16
16: ; preds = %3, %78
%17 = load i32, i32* @NI_MAXHOST
%18 = zext i32 %17 to i64
%19 = call i8* @llvm.stacksave()
store i8* %19, i8** %12
%20 = alloca i8, i64 %18
store i64 %18, i64* %13
%21 = load i32, i32* @NI_MAXSERV
%22 = zext i32 %21 to i64
%23 = alloca i8, i64 %22
store i64 %22, i64* %14
store i32 4, i32* %10
%24 = load i32, i32* %4
%25 = call i32 @accept(i32 %24, %struct.sockaddr* %9, i32* %10)
store i32 %25, i32* %11
%26 = load i32, i32* %11
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %39
28: ; preds = %16
%29 = load i64, i64* @errno
%30 = load i64, i64* @EAGAIN
%31 = icmp eq i64 %29, %30
br i1 %31, label %36, label %32
32: ; preds = %28
%33 = load i64, i64* @errno
%34 = load i64, i64* @EWOULDBLOCK
%35 = icmp eq i64 %33, %34
br i1 %35, label %36, label %37
36: ; preds = %32, %28
store i32 3, i32* %15
br label %75
37: ; preds = %32
%38 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 3, i32* %15
br label %75
39: ; preds = %16
%40 = load i32, i32* %10
%41 = trunc i64 %18 to i32
%42 = trunc i64 %22 to i32
%43 = load i32, i32* @NI_NUMERICHOST
%44 = load i32, i32* @NI_NUMERICSERV
%45 = or i32 %43, %44
%46 = call i32 @getnameinfo(%struct.sockaddr* %9, i32 %40, i8* %20, i32 %41, i8* %23, i32 %42, i32 %45)
store i32 %46, i32* %7
%47 = load i32, i32* %7
%48 = icmp eq i32 %47, 0
br i1 %48, label %49, label %50
49: ; preds = %39
br label %50
50: ; preds = %49, %39
%51 = load i32, i32* %11
%52 = call i32 @make_socket_non_blocking(i32 %51)
store i32 %52, i32* %7
%53 = load i32, i32* %7
%54 = icmp eq i32 %53, -1
br i1 %54, label %55, label %57
55: ; preds = %50
%56 = call i32 (...) @abort()
unreachable
57: ; preds = %50
%58 = load i32, i32* %11
%59 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %8, i32 0, i32 1
%60 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %59, i32 0, i32 0
store i32 %58, i32* %60
%61 = load i32, i32* @EPOLLIN
%62 = load i32, i32* @EPOLLET
%63 = or i32 %61, %62
%64 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %8, i32 0, i32 0
store i32 %63, i32* %64
%65 = load i32, i32* %5
%66 = load i32, i32* @EPOLL_CTL_ADD
%67 = load i32, i32* %11
%68 = call i32 @epoll_ctl(i32 %65, i32 %66, i32 %67, %struct.epoll_event* %8)
store i32 %68, i32* %7
%69 = load i32, i32* %7
%70 = icmp eq i32 %69, -1
br i1 %70, label %71, label %74
71: ; preds = %57
%72 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%73 = call i32 (...) @abort()
unreachable
74: ; preds = %57
store i32 0, i32* %15
br label %75
75: ; preds = %74, %37, %36
%76 = load i8*, i8** %12
%77 = load i32, i32* %15
switch i32 %77, label %80 [
i32 0, label %78
i32 3, label %79
]
78: ; preds = %75
br label %16
79: ; preds = %75
ret void
80: ; preds = %75
unreachable
}

LLVM IR (-O2):
%struct.epoll_event = type { i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@NI_MAXHOST = global i32 0
@NI_MAXSERV = global i32 0
@errno = global i64 0
@EAGAIN = global i64 0
@EWOULDBLOCK = global i64 0
@.str = [7 x i8] c"accept\00"
@NI_NUMERICHOST = global i32 0
@NI_NUMERICSERV = global i32 0
@EPOLLIN = global i32 0
@EPOLLET = global i32 0
@EPOLL_CTL_ADD = global i32 0
@.str.1 = [10 x i8] c"epoll_ctl\00"
define void @accept_connection(i32 %0, i32 %1, i32 %2) {
%4 = alloca %struct.epoll_event
%5 = alloca %struct.sockaddr
%6 = alloca i32
%7 = bitcast %struct.epoll_event* %4 to i8*
%8 = bitcast %struct.sockaddr* %5 to i8*
%9 = bitcast i32* %6 to i8*
%10 = load i32, i32* @NI_MAXHOST
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
%13 = alloca i8, i64 %11
%14 = load i32, i32* @NI_MAXSERV
%15 = zext i32 %14 to i64
%16 = alloca i8, i64 %15
store i32 4, i32* %6
%17 = call i32 @accept(i32 %0, %struct.sockaddr* %5, i32* %6)
%18 = icmp eq i32 %17, -1
br i1 %18, label %22, label %19
19: ; preds = %3
%20 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %4, i64 0, i32 1, i32 0
%21 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %4, i64 0, i32 0
br label %32
22: ; preds = %58, %3
%23 = phi i8* [ %12, %3 ], [ %61, %58 ]
%24 = load i64, i64* @errno
%25 = load i64, i64* @EAGAIN
%26 = icmp eq i64 %24, %25
%27 = load i64, i64* @EWOULDBLOCK
%28 = icmp eq i64 %24, %27
%29 = select i1 %26, i1 true, i1 %28
br i1 %29, label %68, label %30
30: ; preds = %22
%31 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %68
32: ; preds = %19, %58
%33 = phi i32 [ %17, %19 ], [ %66, %58 ]
%34 = phi i8* [ %16, %19 ], [ %65, %58 ]
%35 = phi i32 [ %14, %19 ], [ %63, %58 ]
%36 = phi i8* [ %13, %19 ], [ %62, %58 ]
%37 = phi i8* [ %12, %19 ], [ %61, %58 ]
%38 = phi i32 [ %10, %19 ], [ %59, %58 ]
%39 = load i32, i32* %6
%40 = load i32, i32* @NI_NUMERICHOST
%41 = load i32, i32* @NI_NUMERICSERV
%42 = or i32 %41, %40
%43 = call i32 @getnameinfo(%struct.sockaddr* %5, i32 %39, i8* %36, i32 %38, i8* %34, i32 %35, i32 %42)
%44 = call i32 @make_socket_non_blocking(i32 %33)
%45 = icmp eq i32 %44, -1
br i1 %45, label %46, label %48
46: ; preds = %32
%47 = call i32 (...) @abort()
unreachable
48: ; preds = %32
store i32 %33, i32* %20
%49 = load i32, i32* @EPOLLIN
%50 = load i32, i32* @EPOLLET
%51 = or i32 %50, %49
store i32 %51, i32* %21
%52 = load i32, i32* @EPOLL_CTL_ADD
%53 = call i32 @epoll_ctl(i32 %1, i32 %52, i32 %33, %struct.epoll_event* %4)
%54 = icmp eq i32 %53, -1
br i1 %54, label %55, label %58
55: ; preds = %48
%56 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%57 = call i32 (...) @abort()
unreachable
58: ; preds = %48
%59 = load i32, i32* @NI_MAXHOST
%60 = zext i32 %59 to i64
%61 = call i8* @llvm.stacksave()
%62 = alloca i8, i64 %60
%63 = load i32, i32* @NI_MAXSERV
%64 = zext i32 %63 to i64
%65 = alloca i8, i64 %64
store i32 4, i32* %6
%66 = call i32 @accept(i32 %0, %struct.sockaddr* %5, i32* %6)
%67 = icmp eq i32 %66, -1
br i1 %67, label %22, label %32
68: ; preds = %30, %22
ret void
}