#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_in {
  int dummy;
};
struct sockaddr {
  int dummy;
};
struct TYPE_2__ {
  int fd;
};
struct epoll_event {
  int events;
  TYPE_1__ data;
};

/* Variables and functions */
int EPOLLET;
int EPOLLIN;
int /*<<< orphan*/ EPOLL_CTL_ADD;
int accept(int, struct sockaddr *, int);
int /*<<< orphan*/ epoll_ctl(int, int /*<<< orphan*/, int,
                             struct epoll_event *);
void accept_socket(int serverfd, int epollfd) {
  struct sockaddr_in address;
  int clientfd =
      accept(serverfd, (struct sockaddr *)&address, sizeof(struct sockaddr_in));
  if (clientfd < 0) {
    return;
  }
  struct epoll_event event;
  event.data.fd = clientfd;
  event.events = EPOLLIN | EPOLLET;
  epoll_ctl(epollfd, EPOLL_CTL_ADD, clientfd, &event);
}


x86 assembly (clang, -O0):
<accept_socket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   1040 <accept@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1151 <accept_socket+0x31>
jmp    1184 <accept_socket+0x64>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e8a(%rip),%rax
mov    (%rax),%eax
mov    0x2e69(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e6a(%rip),%rax
mov    (%rax),%esi
mov    -0x14(%rbp),%edx
lea    -0x20(%rbp),%rcx
call   1030 <epoll_ctl@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<accept_socket>:
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebx
lea    0x8(%rsp),%rsi
mov    $0x4,%edx
call   1040 <accept@plt>
test   %eax,%eax
js     1168 <accept_socket+0x48>
mov    0x2ea7(%rip),%rcx
mov    0x2e88(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
mov    %eax,0x4(%rsp)
mov    %edx,(%rsp)
mov    0x2e86(%rip),%rcx
mov    (%rcx),%esi
mov    %rsp,%rcx
mov    %ebx,%edi
mov    %eax,%edx
call   1030 <epoll_ctl@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.epoll_event = type { i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@EPOLLIN = global i32 0
@EPOLLET = global i32 0
@EPOLL_CTL_ADD = global i32 0
define void @accept_socket(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.sockaddr_in
%6 = alloca i32
%7 = alloca %struct.epoll_event
store i32 %0, i32* %3
store i32 %1, 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 4)
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %2
br label %26
14: ; preds = %2
%15 = load i32, i32* %6
%16 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %7, i32 0, i32 1
%17 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %16, i32 0, i32 0
store i32 %15, i32* %17
%18 = load i32, i32* @EPOLLIN
%19 = load i32, i32* @EPOLLET
%20 = or i32 %18, %19
%21 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %7, i32 0, i32 0
store i32 %20, i32* %21
%22 = load i32, i32* %4
%23 = load i32, i32* @EPOLL_CTL_ADD
%24 = load i32, i32* %6
%25 = call i32 @epoll_ctl(i32 %22, i32 %23, i32 %24, %struct.epoll_event* %7)
br label %26
26: ; preds = %14, %13
ret void
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.epoll_event = type { i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@EPOLLIN = global i32 0
@EPOLLET = global i32 0
@EPOLL_CTL_ADD = global i32 0
define void @accept_socket(i32 %0, i32 %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.epoll_event
%5 = bitcast %struct.sockaddr_in* %3 to i8*
%6 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%7 = call i32 @accept(i32 %0, %struct.sockaddr* %6, i32 4)
%8 = icmp slt i32 %7, 0
br i1 %8, label %18, label %9
9: ; preds = %2
%10 = bitcast %struct.epoll_event* %4 to i8*
%11 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %4, i64 0, i32 1, i32 0
store i32 %7, i32* %11
%12 = load i32, i32* @EPOLLIN
%13 = load i32, i32* @EPOLLET
%14 = or i32 %13, %12
%15 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %4, i64 0, i32 0
store i32 %14, i32* %15
%16 = load i32, i32* @EPOLL_CTL_ADD
%17 = call i32 @epoll_ctl(i32 %1, i32 %16, i32 %7, %struct.epoll_event* %4)
br label %18
18: ; preds = %2, %9
ret void
}