#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 TYPE_2__ {
  int fd;
};
struct sockaddr_in {
  TYPE_1__ data;
  int /*<<< orphan*/ events;
};
struct sockaddr {
  int dummy;
};
struct epoll_event {
  TYPE_1__ data;
  int /*<<< orphan*/ events;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ e;
typedef int /*<<< orphan*/ cli_addr;

/* Variables and functions */
int /*<<< orphan*/ EPOLLIN;
int /*<<< orphan*/ EPOLL_CTL_ADD;
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ close(int);
scalar_t__ epoll_ctl(int, int /*<<< orphan*/, int, struct sockaddr_in *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
int server_service(int srv_fd, int epoll_fd) {
  int cli_fd = -1;
  struct sockaddr_in cli_addr;
  socklen_t cli_addr_len = sizeof(struct sockaddr_in);
  struct epoll_event e;
  memset(&cli_addr, 0, sizeof(cli_addr));
  memset(&e, 0, sizeof(e));
  cli_fd = accept(srv_fd, (struct sockaddr *)&cli_addr, &cli_addr_len);
  if (cli_fd < 0) {
    printf("Cannot accept client\n");
    close(epoll_fd);
    close(srv_fd);
    return 1;
  }
  e.events = EPOLLIN;
  e.data.fd = cli_fd;
  if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, cli_fd, &e) < 0) {
    printf("Cannot accept client\n");
    close(epoll_fd);
    close(srv_fd);
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<server_service>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0xffffffff,-0x10(%rbp)
movl   $0x8,-0x1c(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
call   1070 <accept@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    11d1 <server_service+0x81>
lea    0xe50(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    1234 <server_service+0xe4>
mov    0x2e10(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0xc(%rbp),%edi
mov    0x2df3(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%edx
lea    -0x28(%rbp),%rcx
call   1060 <epoll_ctl@plt>
cmp    $0x0,%rax
jge    122d <server_service+0xdd>
lea    0xdf4(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    1234 <server_service+0xe4>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<server_service>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %esi,%r14d
mov    %edi,%r15d
movl   $0x8,0xc(%rsp)
lea    0x10(%rsp),%rbx
xor    %ebp,%ebp
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
lea    0xc(%rsp),%rdx
mov    %r15d,%edi
mov    %rbx,%rsi
call   1070 <accept@plt>
test   %eax,%eax
js     11cc <server_service+0x7c>
mov    0x2e40(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,0x4(%rsp)
mov    %eax,(%rsp)
mov    0x2e28(%rip),%rcx
mov    (%rcx),%esi
mov    %rsp,%rcx
mov    %r14d,%edi
mov    %eax,%edx
call   1060 <epoll_ctl@plt>
test   %rax,%rax
jns    11ed <server_service+0x9d>
lea    0xe2d(%rip),%rdi
call   1030 <puts@plt>
mov    %r14d,%edi
call   1050 <close@plt>
mov    %r15d,%edi
call   1050 <close@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.epoll_event = type { %struct.TYPE_2__, i32 }
%struct.sockaddr = type { i32 }
@.str = [22 x i8] c"Cannot accept client\0A\00"
@EPOLLIN = global i32 0
@EPOLL_CTL_ADD = global i32 0
define i32 @server_service(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.sockaddr_in
%8 = alloca i32
%9 = alloca %struct.epoll_event
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 -1, i32* %6
store i32 8, i32* %8
%10 = call i32 @memset(%struct.sockaddr_in* %7, i32 0, i32 8)
%11 = bitcast %struct.epoll_event* %9 to %struct.sockaddr_in*
%12 = call i32 @memset(%struct.sockaddr_in* %11, i32 0, i32 8)
%13 = load i32, i32* %4
%14 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%15 = call i32 @accept(i32 %13, %struct.sockaddr* %14, i32* %8)
store i32 %15, i32* %6
%16 = load i32, i32* %6
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %24
18: ; preds = %2
%19 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%20 = load i32, i32* %5
%21 = call i32 @close(i32 %20)
%22 = load i32, i32* %4
%23 = call i32 @close(i32 %22)
store i32 1, i32* %3
br label %43
24: ; preds = %2
%25 = load i32, i32* @EPOLLIN
%26 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %9, i32 0, i32 1
store i32 %25, i32* %26
%27 = load i32, i32* %6
%28 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %9, i32 0, i32 0
%29 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %28, i32 0, i32 0
store i32 %27, i32* %29
%30 = load i32, i32* %5
%31 = load i32, i32* @EPOLL_CTL_ADD
%32 = load i32, i32* %6
%33 = bitcast %struct.epoll_event* %9 to %struct.sockaddr_in*
%34 = call i64 @epoll_ctl(i32 %30, i32 %31, i32 %32, %struct.sockaddr_in* %33)
%35 = icmp slt i64 %34, 0
br i1 %35, label %36, label %42
36: ; preds = %24
%37 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%38 = load i32, i32* %5
%39 = call i32 @close(i32 %38)
%40 = load i32, i32* %4
%41 = call i32 @close(i32 %40)
store i32 1, i32* %3
br label %43
42: ; preds = %24
store i32 0, i32* %3
br label %43
43: ; preds = %42, %36, %18
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.epoll_event = type { %struct.TYPE_2__, i32 }
%struct.sockaddr = type { i32 }
@EPOLLIN = global i32 0
@EPOLL_CTL_ADD = global i32 0
@str.1 = [21 x i8] c"Cannot accept client\00"
define i32 @server_service(i32 %0, i32 %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca %struct.epoll_event
%6 = bitcast %struct.sockaddr_in* %3 to i8*
%7 = bitcast i32* %4 to i8*
store i32 8, i32* %4
%8 = bitcast %struct.epoll_event* %5 to i8*
%9 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 8)
%10 = bitcast %struct.epoll_event* %5 to %struct.sockaddr_in*
%11 = call i32 @memset(%struct.sockaddr_in* %10, i32 0, i32 8)
%12 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%13 = call i32 @accept(i32 %0, %struct.sockaddr* %12, i32* %4)
%14 = icmp slt i32 %13, 0
br i1 %14, label %22, label %15
15: ; preds = %2
%16 = load i32, i32* @EPOLLIN
%17 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %5, i64 0, i32 1
store i32 %16, i32* %17
%18 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %5, i64 0, i32 0, i32 0
store i32 %13, i32* %18
%19 = load i32, i32* @EPOLL_CTL_ADD
%20 = call i64 @epoll_ctl(i32 %1, i32 %19, i32 %13, %struct.sockaddr_in* %10)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %27
22: ; preds = %15, %2
%23 = phi i8* [ getelementptr inbounds ([21 x i8], [21 x i8]* @str.1, i64 0, i64 0), %2 ], [ getelementptr inbounds ([21 x i8], [21 x i8]* @str.1, i64 0, i64 0), %15 ]
%24 = call i32 @puts(i8* dereferenceable(1) %23)
%25 = call i32 @close(i32 %1)
%26 = call i32 @close(i32 %0)
br label %27
27: ; preds = %22, %15
%28 = phi i32 [ 0, %15 ], [ 1, %22 ]
ret i32 %28
}