#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 epoll_event {
  int events;
  TYPE_1__ data;
};
typedef int /*<<< orphan*/ ev;

/* Variables and functions */
int EPOLLHUP;
int EPOLLIN;
int EPOLLRDHUP;
int /*<<< orphan*/ EPOLL_CTL_ADD;
int accept_connection(int);
int /*<<< orphan*/ close(int);
int epoll_create(int);
int epoll_ctl(int, int /*<<< orphan*/, int, struct epoll_event *);
int /*<<< orphan*/ err(int, char *);
int /*<<< orphan*/ file_transfer_loop(int, char *, int);
int /*<<< orphan*/ memset(struct epoll_event *, int /*<<< orphan*/, int);
int open_server(char *);
int /*<<< orphan*/ puts(char *);
void receive(char **args) {
  int sock;
  sock = open_server(args[0]);
  int epfd;
  epfd = epoll_create(1);
  if (epfd == -1)
    err(1, "epoll_create");
  for (;;) {
    int client;
    client = accept_connection(sock);
    if (client == -1)
      continue;
    else
      puts("transmitter connected");
    struct epoll_event ev;
    memset(&ev, 0, sizeof(ev));
    ev.events = EPOLLIN | EPOLLHUP | EPOLLRDHUP;
    ev.data.fd = client;
    int ret;
    ret = epoll_ctl(epfd, EPOLL_CTL_ADD, client, &ev);
    if (ret == -1)
      err(1, "epoll_ctl: server sock");
    file_transfer_loop(client, args[1], epfd);
    close(client);
  }
  close(sock);
}


x86 assembly (clang, -O0):
<receive>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1060 <open_server@plt>
mov    %eax,-0xc(%rbp)
mov    $0x1,%edi
call   10b0 <epoll_create@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    11d3 <receive+0x43>
mov    $0x1,%edi
lea    0xe32(%rip),%rsi
call   1090 <err@plt>
jmp    11d8 <receive+0x48>
mov    -0xc(%rbp),%edi
call   1080 <accept_connection@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11f2 <receive+0x62>
jmp    11d8 <receive+0x48>
lea    0xe14(%rip),%rdi
call   1030 <puts@plt>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    0x2dd3(%rip),%rax
mov    (%rax),%eax
mov    0x2daa(%rip),%rcx
or     (%rcx),%eax
mov    0x2da9(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%edi
mov    0x2da4(%rip),%rax
mov    (%rax),%esi
mov    -0x14(%rbp),%edx
lea    -0x20(%rbp),%rcx
call   1070 <epoll_ctl@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    1268 <receive+0xd8>
mov    $0x1,%edi
lea    0xdc0(%rip),%rsi
call   1090 <err@plt>
mov    -0x14(%rbp),%edi
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x10(%rbp),%edx
call   10a0 <file_transfer_loop@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
jmp    11d8 <receive+0x48>

x86 assembly (clang, -O2):
<receive>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    (%rdi),%rdi
call   1060 <open_server@plt>
mov    %eax,%ebp
mov    $0x1,%edi
call   10b0 <epoll_create@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    11ca <receive+0x3a>
lea    0xe40(%rip),%rsi
mov    $0x1,%edi
call   1090 <err@plt>
mov    %rsp,%r12
mov    0x2e0c(%rip),%r15
jmp    11f6 <receive+0x66>
cs nopw 0x0(%rax,%rax,1)
mov    0x8(%r14),%rsi
mov    %r13d,%edi
mov    %ebx,%edx
call   10a0 <file_transfer_loop@plt>
mov    %r13d,%edi
call   1050 <close@plt>
mov    %ebp,%edi
call   1080 <accept_connection@plt>
cmp    $0xffffffff,%eax
je     11f6 <receive+0x66>
mov    %eax,%r13d
lea    0xe01(%rip),%rdi
call   1030 <puts@plt>
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    0x2da1(%rip),%rax
mov    (%rax),%eax
mov    0x2db8(%rip),%rcx
or     (%rcx),%eax
mov    0x2d97(%rip),%rcx
or     (%rcx),%eax
mov    %eax,(%rsp)
mov    %r13d,0x4(%rsp)
mov    (%r15),%esi
mov    %ebx,%edi
mov    %r13d,%edx
mov    %r12,%rcx
call   1070 <epoll_ctl@plt>
cmp    $0xffffffff,%eax
jne    11e0 <receive+0x50>
mov    $0x1,%edi
lea    0xdbf(%rip),%rsi
call   1090 <err@plt>
jmp    11e0 <receive+0x50>

LLVM IR (-O0):
%struct.epoll_event = type { i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@.str = [13 x i8] c"epoll_create\00"
@.str.1 = [22 x i8] c"transmitter connected\00"
@EPOLLIN = global i32 0
@EPOLLHUP = global i32 0
@EPOLLRDHUP = global i32 0
@EPOLL_CTL_ADD = global i32 0
@.str.2 = [23 x i8] c"epoll_ctl: server sock\00"
define void @receive(i8** %0) {
%2 = alloca i8**
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.epoll_event
%7 = alloca i32
store i8** %0, i8*** %2
%8 = load i8**, i8*** %2
%9 = getelementptr inbounds i8*, i8** %8, i64 0
%10 = load i8*, i8** %9
%11 = call i32 @open_server(i8* %10)
store i32 %11, i32* %3
%12 = call i32 @epoll_create(i32 1)
store i32 %12, i32* %4
%13 = load i32, i32* %4
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %1
%16 = call i32 @err(i32 1, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15, %1
br label %18
18: ; preds = %45, %23, %17
%19 = load i32, i32* %3
%20 = call i32 @accept_connection(i32 %19)
store i32 %20, i32* %5
%21 = load i32, i32* %5
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %24
23: ; preds = %18
br label %18
24: ; preds = %18
%25 = call i32 @puts(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %26
26: ; preds = %24
%27 = call i32 @memset(%struct.epoll_event* %6, i32 0, i32 8)
%28 = load i32, i32* @EPOLLIN
%29 = load i32, i32* @EPOLLHUP
%30 = or i32 %28, %29
%31 = load i32, i32* @EPOLLRDHUP
%32 = or i32 %30, %31
%33 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %6, i32 0, i32 0
store i32 %32, i32* %33
%34 = load i32, i32* %5
%35 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %6, i32 0, i32 1
%36 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %35, i32 0, i32 0
store i32 %34, i32* %36
%37 = load i32, i32* %4
%38 = load i32, i32* @EPOLL_CTL_ADD
%39 = load i32, i32* %5
%40 = call i32 @epoll_ctl(i32 %37, i32 %38, i32 %39, %struct.epoll_event* %6)
store i32 %40, i32* %7
%41 = load i32, i32* %7
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %45
43: ; preds = %26
%44 = call i32 @err(i32 1, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
br label %45
45: ; preds = %43, %26
%46 = load i32, i32* %5
%47 = load i8**, i8*** %2
%48 = getelementptr inbounds i8*, i8** %47, i64 1
%49 = load i8*, i8** %48
%50 = load i32, i32* %4
%51 = call i32 @file_transfer_loop(i32 %46, i8* %49, i32 %50)
%52 = load i32, i32* %5
%53 = call i32 @close(i32 %52)
br label %18
}

LLVM IR (-O2):
%struct.epoll_event = type { i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@.str = [13 x i8] c"epoll_create\00"
@.str.1 = [22 x i8] c"transmitter connected\00"
@EPOLLIN = global i32 0
@EPOLLHUP = global i32 0
@EPOLLRDHUP = global i32 0
@EPOLL_CTL_ADD = global i32 0
@.str.2 = [23 x i8] c"epoll_ctl: server sock\00"
define void @receive(i8** nocapture %0) {
%2 = alloca %struct.epoll_event
%3 = load i8*, i8** %0
%4 = tail call i32 @open_server(i8* %3)
%5 = tail call i32 @epoll_create(i32 1)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %1
%10 = bitcast %struct.epoll_event* %2 to i8*
%11 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %2, i64 0, i32 0
%12 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %2, i64 0, i32 1, i32 0
%13 = getelementptr inbounds i8*, i8** %0, i64 1
br label %14
14: ; preds = %17, %9
%15 = call i32 @accept_connection(i32 %4)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %18
17: ; preds = %14, %31
br label %14
18: ; preds = %14
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%20 = call i32 @memset(%struct.epoll_event* %2, i32 0, i32 8)
%21 = load i32, i32* @EPOLLIN
%22 = load i32, i32* @EPOLLHUP
%23 = or i32 %22, %21
%24 = load i32, i32* @EPOLLRDHUP
%25 = or i32 %23, %24
store i32 %25, i32* %11
store i32 %15, i32* %12
%26 = load i32, i32* @EPOLL_CTL_ADD
%27 = call i32 @epoll_ctl(i32 %5, i32 %26, i32 %15, %struct.epoll_event* %2)
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %31
29: ; preds = %18
%30 = call i32 @err(i32 1, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
br label %31
31: ; preds = %29, %18
%32 = load i8*, i8** %13
%33 = call i32 @file_transfer_loop(i32 %15, i8* %32, i32 %5)
%34 = call i32 @close(i32 %15)
br label %17
}