#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;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ client_addr;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
scalar_t__ EAGAIN;
int EPOLLIN;
scalar_t__ EWOULDBLOCK;
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ addfd(int, int, int);
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int recv(int, char *, int, int /*<<< orphan*/);
void et(struct epoll_event *events, int number, int epollfd, int listenfd) {
  char buf[10];
  int i;
  for (i = 0; i < number; i++) {
    int sockfd = events[i].data.fd;
    if (sockfd == listenfd) {
      struct sockaddr_in client_addr;
      socklen_t client_addrlen = sizeof(client_addr);
      int connfd =
          accept(listenfd, (struct sockaddr *)&client_addr, &client_addrlen);
      if (connfd < 0) {
        perror("accept failed..");
        exit(-1);
      }
      addfd(epollfd, connfd, 1);
    } else if (events[i].events & EPOLLIN) {
      printf("sockefd %d read event trigger once\n", sockfd);
      while (1) {
        memset(buf, 0, sizeof(buf));
        int ret = recv(sockfd, buf, 10, 0);
        if (ret < 0) {
          if (errno == EAGAIN || errno == EWOULDBLOCK) {
            printf("read later\n");
            break;
          }
          printf("some other error\n");
          close(sockfd);
          break;
        } else if (ret == 0) {
          printf("client closed.\n");
          close(sockfd);
          break;
        } else {
          printf("get %d bytes from client: %s\n", ret, buf);
        }
      }
    } else {
      printf("something else happened\n");
    }
  }
}


x86 assembly (clang, -O0):
<et>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1341 <et+0x1c1>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    0x4(%rax,%rcx,8),%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    1212 <et+0x92>
movl   $0x4,-0x34(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x30(%rbp),%rsi
lea    -0x34(%rbp),%rdx
call   1090 <accept@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
jge    11fd <et+0x7d>
lea    0xe12(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%edi
mov    -0x38(%rbp),%esi
mov    $0x1,%edx
call   1040 <addfd@plt>
jmp    132e <et+0x1ae>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%eax
mov    0x2dc4(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     131b <et+0x19b>
mov    -0x28(%rbp),%esi
lea    0xdd7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x1e(%rbp),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1060 <memset@plt>
mov    -0x28(%rbp),%edi
lea    -0x1e(%rbp),%rsi
mov    $0xa,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jge    12d2 <et+0x152>
mov    0x2d61(%rip),%rax
mov    (%rax),%rax
mov    0x2d3f(%rip),%rcx
cmp    (%rcx),%rax
je     12a4 <et+0x124>
mov    0x2d47(%rip),%rax
mov    (%rax),%rax
mov    0x2d35(%rip),%rcx
cmp    (%rcx),%rax
jne    12b7 <et+0x137>
lea    0xd89(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1316 <et+0x196>
lea    0xd82(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%edi
call   1070 <close@plt>
jmp    1316 <et+0x196>
cmpl   $0x0,-0x3c(%rbp)
jne    12f7 <et+0x177>
lea    0xd6f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%edi
call   1070 <close@plt>
jmp    1316 <et+0x196>
mov    -0x3c(%rbp),%esi
lea    -0x1e(%rbp),%rdx
lea    0xd5d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1311 <et+0x191>
jmp    1240 <et+0xc0>
jmp    1329 <et+0x1a9>
lea    0xd5e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    132e <et+0x1ae>
jmp    1333 <et+0x1b3>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    119c <et+0x1c>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<et>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %edx,0x8(%rsp)
test   %esi,%esi
jle    12e0 <et+0x150>
mov    %ecx,%ebx
mov    %rdi,%rbp
mov    %esi,%eax
mov    %rax,0x10(%rsp)
lea    0x1e(%rsp),%r13
lea    0xe72(%rip),%r15
xor    %r14d,%r14d
jmp    11e2 <et+0x52>
lea    0xe84(%rip),%rdi
call   1050 <puts@plt>
add    $0x1,%r14
cmp    0x10(%rsp),%r14
je     12e0 <et+0x150>
mov    0x4(%rbp,%r14,8),%r12d
cmp    %ebx,%r12d
jne    1220 <et+0x90>
movl   $0x4,0xc(%rsp)
mov    %ebx,%edi
lea    0x18(%rsp),%rsi
lea    0xc(%rsp),%rdx
call   10a0 <accept@plt>
test   %eax,%eax
js     12ef <et+0x15f>
mov    0x8(%rsp),%edi
mov    %eax,%esi
mov    $0x1,%edx
call   1040 <addfd@plt>
jmp    11d3 <et+0x43>
nop
mov    0x2dc1(%rip),%rax
mov    (%rax),%eax
test   %eax,0x0(%rbp,%r14,8)
je     11c7 <et+0x37>
lea    0xdd9(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1070 <memset@plt>
mov    %r12d,%edi
mov    %r13,%rsi
mov    $0xa,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
js     1290 <et+0x100>
test   %eax,%eax
je     12c7 <et+0x137>
mov    %r15,%rdi
mov    %eax,%esi
mov    %r13,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1250 <et+0xc0>
nopw   0x0(%rax,%rax,1)
mov    0x2d41(%rip),%rax
mov    (%rax),%rax
mov    0x2d1f(%rip),%rcx
cmp    (%rcx),%rax
je     12bb <et+0x12b>
mov    0x2d23(%rip),%rcx
cmp    (%rcx),%rax
je     12bb <et+0x12b>
lea    0xdc0(%rip),%rdi
jmp    12ce <et+0x13e>
lea    0xdc8(%rip),%rdi
jmp    11ce <et+0x3e>
lea    0xd9c(%rip),%rdi
call   1050 <puts@plt>
mov    %r12d,%edi
call   1080 <close@plt>
jmp    11d3 <et+0x43>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd0a(%rip),%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.epoll_event = type { i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [16 x i8] c"accept failed..\00"
@EPOLLIN = global i32 0
@.str.1 = [36 x i8] c"sockefd %d read event trigger once\0A\00"
@errno = global i64 0
@EAGAIN = global i64 0
@EWOULDBLOCK = global i64 0
@.str.2 = [12 x i8] c"read later\0A\00"
@.str.3 = [18 x i8] c"some other error\0A\00"
@.str.4 = [16 x i8] c"client closed.\0A\00"
@.str.5 = [30 x i8] c"get %d bytes from client: %s\0A\00"
@.str.6 = [25 x i8] c"something else happened\0A\00"
define void @et(%struct.epoll_event* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca %struct.epoll_event*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [10 x i8]
%10 = alloca i32
%11 = alloca i32
%12 = alloca %struct.sockaddr_in
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store %struct.epoll_event* %0, %struct.epoll_event** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
store i32 0, i32* %10
br label %16
16: ; preds = %97, %4
%17 = load i32, i32* %10
%18 = load i32, i32* %6
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %100
20: ; preds = %16
%21 = load %struct.epoll_event*, %struct.epoll_event** %5
%22 = load i32, i32* %10
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %21, i64 %23
%25 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %24, i32 0, i32 1
%26 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %25, i32 0, i32 0
%27 = load i32, i32* %26
store i32 %27, i32* %11
%28 = load i32, i32* %11
%29 = load i32, i32* %8
%30 = icmp eq i32 %28, %29
br i1 %30, label %31, label %44
31: ; preds = %20
store i32 4, i32* %13
%32 = load i32, i32* %8
%33 = bitcast %struct.sockaddr_in* %12 to %struct.sockaddr*
%34 = call i32 @accept(i32 %32, %struct.sockaddr* %33, i32* %13)
store i32 %34, i32* %14
%35 = load i32, i32* %14
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %31
%38 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%39 = call i32 @exit(i32 -1)
unreachable
40: ; preds = %31
%41 = load i32, i32* %7
%42 = load i32, i32* %14
%43 = call i32 @addfd(i32 %41, i32 %42, i32 1)
br label %96
44: ; preds = %20
%45 = load %struct.epoll_event*, %struct.epoll_event** %5
%46 = load i32, i32* %10
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %45, i64 %47
%49 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %48, i32 0, i32 0
%50 = load i32, i32* %49
%51 = load i32, i32* @EPOLLIN
%52 = and i32 %50, %51
%53 = icmp ne i32 %52, 0
br i1 %53, label %54, label %93
54: ; preds = %44
%55 = load i32, i32* %11
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i32 %55)
br label %57
57: ; preds = %54, %91
%58 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 0
%59 = call i32 @memset(i8* %58, i32 0, i32 10)
%60 = load i32, i32* %11
%61 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 0
%62 = call i32 @recv(i32 %60, i8* %61, i32 10, i32 0)
store i32 %62, i32* %15
%63 = load i32, i32* %15
%64 = icmp slt i32 %63, 0
br i1 %64, label %65, label %79
65: ; preds = %57
%66 = load i64, i64* @errno
%67 = load i64, i64* @EAGAIN
%68 = icmp eq i64 %66, %67
br i1 %68, label %73, label %69
69: ; preds = %65
%70 = load i64, i64* @errno
%71 = load i64, i64* @EWOULDBLOCK
%72 = icmp eq i64 %70, %71
br i1 %72, label %73, label %75
73: ; preds = %69, %65
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %92
75: ; preds = %69
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%77 = load i32, i32* %11
%78 = call i32 @close(i32 %77)
br label %92
79: ; preds = %57
%80 = load i32, i32* %15
%81 = icmp eq i32 %80, 0
br i1 %81, label %82, label %86
82: ; preds = %79
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%84 = load i32, i32* %11
%85 = call i32 @close(i32 %84)
br label %92
86: ; preds = %79
%87 = load i32, i32* %15
%88 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 0
%89 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), i32 %87, i8* %88)
br label %90
90: ; preds = %86
br label %91
91: ; preds = %90
br label %57
92: ; preds = %82, %75, %73
br label %95
93: ; preds = %44
%94 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0))
br label %95
95: ; preds = %93, %92
br label %96
96: ; preds = %95, %40
br label %97
97: ; preds = %96
%98 = load i32, i32* %10
%99 = add nsw i32 %98, 1
store i32 %99, i32* %10
br label %16
100: ; preds = %16
ret void
}

LLVM IR (-O2):
%struct.epoll_event = type { i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [16 x i8] c"accept failed..\00"
@EPOLLIN = global i32 0
@.str.1 = [36 x i8] c"sockefd %d read event trigger once\0A\00"
@errno = global i64 0
@EAGAIN = global i64 0
@EWOULDBLOCK = global i64 0
@.str.5 = [30 x i8] c"get %d bytes from client: %s\0A\00"
@str = [24 x i8] c"something else happened\00"
@str.7 = [15 x i8] c"client closed.\00"
@str.8 = [17 x i8] c"some other error\00"
@str.9 = [11 x i8] c"read later\00"
define void @et(%struct.epoll_event* nocapture %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca [10 x i8]
%6 = alloca %struct.sockaddr_in
%7 = alloca i32
%8 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%9 = icmp sgt i32 %1, 0
br i1 %9, label %10, label %67
10: ; preds = %4
%11 = bitcast %struct.sockaddr_in* %6 to i8*
%12 = bitcast i32* %7 to i8*
%13 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%14 = zext i32 %1 to i64
br label %15
15: ; preds = %10, %64
%16 = phi i64 [ 0, %10 ], [ %65, %64 ]
%17 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %0, i64 %16, i32 1, i32 0
%18 = load i32, i32* %17
%19 = icmp eq i32 %18, %3
br i1 %19, label %20, label %28
20: ; preds = %15
store i32 4, i32* %7
%21 = call i32 @accept(i32 %3, %struct.sockaddr* %13, i32* %7)
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%25 = call i32 @exit(i32 -1)
unreachable
26: ; preds = %20
%27 = call i32 @addfd(i32 %2, i32 %21, i32 1)
br label %64
28: ; preds = %15
%29 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %0, i64 %16, i32 0
%30 = load i32, i32* %29
%31 = load i32, i32* @EPOLLIN
%32 = and i32 %31, %30
%33 = icmp eq i32 %32, 0
br i1 %33, label %62, label %34
34: ; preds = %28
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%36 = call i32 @memset(i8* %8, i32 0, i32 10)
%37 = call i32 @recv(i32 %18, i8* %8, i32 10, i32 0)
%38 = icmp slt i32 %37, 0
br i1 %38, label %39, label %51
39: ; preds = %57, %34
%40 = load i64, i64* @errno
%41 = load i64, i64* @EAGAIN
%42 = icmp eq i64 %40, %41
%43 = load i64, i64* @EWOULDBLOCK
%44 = icmp eq i64 %40, %43
%45 = select i1 %42, i1 true, i1 %44
br i1 %45, label %46, label %48
46: ; preds = %39
%47 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.9, i64 0, i64 0))
br label %64
48: ; preds = %39
%49 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.8, i64 0, i64 0))
%50 = call i32 @close(i32 %18)
br label %64
51: ; preds = %34, %57
%52 = phi i32 [ %60, %57 ], [ %37, %34 ]
%53 = icmp eq i32 %52, 0
br i1 %53, label %54, label %57
54: ; preds = %51
%55 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.7, i64 0, i64 0))
%56 = call i32 @close(i32 %18)
br label %64
57: ; preds = %51
%58 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), i32 %52, i8* %8)
%59 = call i32 @memset(i8* %8, i32 0, i32 10)
%60 = call i32 @recv(i32 %18, i8* %8, i32 10, i32 0)
%61 = icmp slt i32 %60, 0
br i1 %61, label %39, label %51
62: ; preds = %28
%63 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
br label %64
64: ; preds = %54, %48, %46, %62, %26
%65 = add nuw nsw i64 %16, 1
%66 = icmp eq i64 %65, %14
br i1 %66, label %67, label %15
67: ; preds = %64, %4
ret void
}