#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_address;

/* 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*/ memset(char *, char, int);
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];
  for (int i = 0; i < number; ++i) {
    int sockfd = events[i].data.fd;
    if (sockfd == listenfd) {
      int sockfd = events[i].data.fd;
      if (sockfd == listenfd) {
        struct sockaddr_in client_address;
        socklen_t client_addrlength = sizeof(client_address);
        int connfd = accept(listenfd, (struct sockaddr *)&client_address,
                            &client_addrlength);
        addfd(epollfd, connfd, 1);
      }
    } else if (events[i].events & EPOLLIN) {
      printf("et event trigger once\n");
      while (1) {
        memset(buf, '\0', 10);
        int ret = recv(sockfd, buf, 10 - 1, 0);
        if (ret < 0) {
          if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) {
            printf("read later\n");
            break;
          }
          close(sockfd);
          break;
        } else if (ret == 0) {
          close(sockfd);
        } else {
          printf("get %d bytes of content:%s\n", ret, buf);
        }
      }
    } else {
      printf("something else happend\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    12fd <et+0x19d>
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    11ed <et+0x8d>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    0x4(%rax,%rcx,8),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    11e8 <et+0x88>
movl   $0x4,-0x34(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x30(%rbp),%rsi
lea    -0x34(%rbp),%rdx
call   1080 <accept@plt>
mov    %eax,-0x38(%rbp)
mov    -0x10(%rbp),%edi
mov    -0x38(%rbp),%esi
mov    $0x1,%edx
call   1040 <addfd@plt>
jmp    12ea <et+0x18a>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%eax
mov    0x2de9(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     12d7 <et+0x177>
lea    0xdef(%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    $0x9,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jge    129c <et+0x13c>
mov    0x2d89(%rip),%rax
mov    (%rax),%rax
mov    0x2d67(%rip),%rcx
cmp    (%rcx),%rax
je     127c <et+0x11c>
mov    0x2d6f(%rip),%rax
mov    (%rax),%rax
mov    0x2d5d(%rip),%rcx
cmp    (%rcx),%rax
jne    128f <et+0x12f>
lea    0xd94(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12d2 <et+0x172>
mov    -0x28(%rbp),%edi
call   1070 <close@plt>
jmp    12d2 <et+0x172>
cmpl   $0x0,-0x3c(%rbp)
jne    12b3 <et+0x153>
mov    -0x28(%rbp),%edi
call   1070 <close@plt>
jmp    12c8 <et+0x168>
mov    -0x3c(%rbp),%esi
lea    -0x1e(%rbp),%rdx
lea    0xd62(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12cd <et+0x16d>
jmp    1218 <et+0xb8>
jmp    12e5 <et+0x185>
lea    0xd61(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12ea <et+0x18a>
jmp    12ef <et+0x18f>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    117c <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    12b9 <et+0x149>
mov    %ecx,%ebx
mov    %rdi,%rbp
mov    %esi,%eax
mov    %rax,0x10(%rsp)
lea    0x1e(%rsp),%r13
lea    0xe5e(%rip),%r15
xor    %r14d,%r14d
jmp    11e8 <et+0x78>
nopw   0x0(%rax,%rax,1)
movl   $0x4,0xc(%rsp)
mov    %ebx,%edi
lea    0x18(%rsp),%rsi
lea    0xc(%rsp),%rdx
call   1090 <accept@plt>
mov    0x8(%rsp),%edi
mov    %eax,%esi
mov    $0x1,%edx
call   1040 <addfd@plt>
add    $0x1,%r14
cmp    0x10(%rsp),%r14
je     12b9 <et+0x149>
mov    0x4(%rbp,%r14,8),%r12d
cmp    %ebx,%r12d
je     11b0 <et+0x40>
mov    0x2def(%rip),%rax
mov    (%rax),%eax
test   %eax,0x0(%rbp,%r14,8)
je     129f <et+0x12f>
lea    0xe26(%rip),%rdi
call   1050 <puts@plt>
jmp    122f <et+0xbf>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15,%rdi
mov    %eax,%esi
mov    %r13,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r13,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1070 <memset@plt>
mov    %r12d,%edi
mov    %r13,%rsi
mov    $0x9,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
js     1270 <et+0x100>
test   %eax,%eax
jne    1220 <et+0xb0>
mov    %r12d,%edi
call   1080 <close@plt>
jmp    122f <et+0xbf>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x2d61(%rip),%rax
mov    (%rax),%rax
mov    0x2d3f(%rip),%rcx
cmp    (%rcx),%rax
je     12a8 <et+0x138>
mov    0x2d43(%rip),%rcx
cmp    (%rcx),%rax
je     12a8 <et+0x138>
mov    %r12d,%edi
call   1080 <close@plt>
jmp    11d9 <et+0x69>
lea    0xd76(%rip),%rdi
jmp    12af <et+0x13f>
lea    0xd9a(%rip),%rdi
call   1050 <puts@plt>
jmp    11d9 <et+0x69>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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