#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 */
typedef int uint32_t;
struct TYPE_2__ {
  int fd;
};
struct epoll_event {
  int events;
  TYPE_1__ data;
};
typedef int /*<<< orphan*/ off_t;

/* Variables and functions */
int EPOLLHUP;
int EPOLLIN;
int EPOLLOUT;
int /*<<< orphan*/ acceptnew(int, int, struct epoll_event *);
int /*<<< orphan*/ sclose(int);
int /*<<< orphan*/ shut(int, int);
int swrite_sendfile(int, int, int /*<<< orphan*/);
void do_event(struct epoll_event *evp, int sockfd, int efd, int datafd,
              off_t datasz) {
  int connfd = -1;
  int done = 0;
  uint32_t events = evp->events;
  if (events & EPOLLIN) {
    acceptnew(sockfd, efd, evp);
  } else if (events & EPOLLOUT) {
    connfd = evp->data.fd;
    done = swrite_sendfile(connfd, datafd, datasz);
    if (done == 1) {
      shut(connfd, efd);
    }
  } else if (events & EPOLLHUP) {
    connfd = evp->data.fd;
    sclose(connfd);
  }
}


x86 assembly (clang, -O0):
<do_event>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    0x2e6e(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1199 <do_event+0x59>
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    -0x8(%rbp),%rdx
call   1050 <acceptnew@plt>
jmp    1214 <do_event+0xd4>
mov    -0x24(%rbp),%eax
mov    0x2e35(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     11e3 <do_event+0xa3>
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1060 <swrite_sendfile@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x1,-0x20(%rbp)
jne    11de <do_event+0x9e>
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1040 <shut@plt>
jmp    120f <do_event+0xcf>
mov    -0x24(%rbp),%eax
mov    0x2de3(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     120a <do_event+0xca>
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1030 <sclose@plt>
jmp    120f <do_event+0xcf>
jmp    1214 <do_event+0xd4>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_event>:
push   %rbp
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %rdi,%rdx
mov    (%rdi),%eax
mov    0x2e97(%rip),%rdi
test   %eax,(%rdi)
je     1164 <do_event+0x24>
mov    %esi,%edi
mov    %ebx,%esi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <acceptnew@plt>
mov    0x2e6d(%rip),%rsi
test   %eax,(%rsi)
je     1192 <do_event+0x52>
mov    0x4(%rdx),%ebp
mov    %ebp,%edi
mov    %ecx,%esi
mov    %r8d,%edx
call   1060 <swrite_sendfile@plt>
cmp    $0x1,%eax
jne    11ab <do_event+0x6b>
mov    %ebp,%edi
mov    %ebx,%esi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <shut@plt>
mov    0x2e37(%rip),%rcx
test   %eax,(%rcx)
je     11ab <do_event+0x6b>
mov    0x4(%rdx),%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <sclose@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.epoll_event = type { i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@EPOLLIN = global i32 0
@EPOLLOUT = global i32 0
@EPOLLHUP = global i32 0
define void @do_event(%struct.epoll_event* %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca %struct.epoll_event*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store %struct.epoll_event* %0, %struct.epoll_event** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
store i32 -1, i32* %11
store i32 0, i32* %12
%14 = load %struct.epoll_event*, %struct.epoll_event** %6
%15 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %14, i32 0, i32 0
%16 = load i32, i32* %15
store i32 %16, i32* %13
%17 = load i32, i32* %13
%18 = load i32, i32* @EPOLLIN
%19 = and i32 %17, %18
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %5
%22 = load i32, i32* %7
%23 = load i32, i32* %8
%24 = load %struct.epoll_event*, %struct.epoll_event** %6
%25 = call i32 @acceptnew(i32 %22, i32 %23, %struct.epoll_event* %24)
br label %61
26: ; preds = %5
%27 = load i32, i32* %13
%28 = load i32, i32* @EPOLLOUT
%29 = and i32 %27, %28
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %47
31: ; preds = %26
%32 = load %struct.epoll_event*, %struct.epoll_event** %6
%33 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %32, i32 0, i32 1
%34 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %33, i32 0, i32 0
%35 = load i32, i32* %34
store i32 %35, i32* %11
%36 = load i32, i32* %11
%37 = load i32, i32* %9
%38 = load i32, i32* %10
%39 = call i32 @swrite_sendfile(i32 %36, i32 %37, i32 %38)
store i32 %39, i32* %12
%40 = load i32, i32* %12
%41 = icmp eq i32 %40, 1
br i1 %41, label %42, label %46
42: ; preds = %31
%43 = load i32, i32* %11
%44 = load i32, i32* %8
%45 = call i32 @shut(i32 %43, i32 %44)
br label %46
46: ; preds = %42, %31
br label %60
47: ; preds = %26
%48 = load i32, i32* %13
%49 = load i32, i32* @EPOLLHUP
%50 = and i32 %48, %49
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %59
52: ; preds = %47
%53 = load %struct.epoll_event*, %struct.epoll_event** %6
%54 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %53, i32 0, i32 1
%55 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %54, i32 0, i32 0
%56 = load i32, i32* %55
store i32 %56, i32* %11
%57 = load i32, i32* %11
%58 = call i32 @sclose(i32 %57)
br label %59
59: ; preds = %52, %47
br label %60
60: ; preds = %59, %46
br label %61
61: ; preds = %60, %21
ret void
}

LLVM IR (-O2):
%struct.epoll_event = type { i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@EPOLLIN = global i32 0
@EPOLLOUT = global i32 0
@EPOLLHUP = global i32 0
define void @do_event(%struct.epoll_event* %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %0, i64 0, i32 0
%7 = load i32, i32* %6
%8 = load i32, i32* @EPOLLIN
%9 = and i32 %8, %7
%10 = icmp eq i32 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %5
%12 = tail call i32 @acceptnew(i32 %1, i32 %2, %struct.epoll_event* %0)
br label %32
13: ; preds = %5
%14 = load i32, i32* @EPOLLOUT
%15 = and i32 %14, %7
%16 = icmp eq i32 %15, 0
br i1 %16, label %24, label %17
17: ; preds = %13
%18 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %0, i64 0, i32 1, i32 0
%19 = load i32, i32* %18
%20 = tail call i32 @swrite_sendfile(i32 %19, i32 %3, i32 %4)
%21 = icmp eq i32 %20, 1
br i1 %21, label %22, label %32
22: ; preds = %17
%23 = tail call i32 @shut(i32 %19, i32 %2)
br label %32
24: ; preds = %13
%25 = load i32, i32* @EPOLLHUP
%26 = and i32 %25, %7
%27 = icmp eq i32 %26, 0
br i1 %27, label %32, label %28
28: ; preds = %24
%29 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %0, i64 0, i32 1, i32 0
%30 = load i32, i32* %29
%31 = tail call i32 @sclose(i32 %30)
br label %32
32: ; preds = %22, %17, %28, %24, %11
ret void
}