#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;
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*/ memset(char *, int, 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];
  int i;
  for (i = 0; i < number; i++) {
    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("event trigger once \n");
      while (1) {
        memset(buf, 0x00, sizeof(buf));
        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 happended\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    12e2 <et+0x182>
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    11d2 <et+0x72>
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    12cf <et+0x16f>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%eax
mov    0x2e04(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     12bc <et+0x15c>
lea    0xe0a(%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    1281 <et+0x121>
mov    0x2da4(%rip),%rax
mov    (%rax),%rax
mov    0x2d82(%rip),%rcx
cmp    (%rcx),%rax
je     1261 <et+0x101>
mov    0x2d8a(%rip),%rax
mov    (%rax),%rax
mov    0x2d78(%rip),%rcx
cmp    (%rcx),%rax
jne    1274 <et+0x114>
lea    0xdad(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12b7 <et+0x157>
mov    -0x28(%rbp),%edi
call   1070 <close@plt>
jmp    12b7 <et+0x157>
cmpl   $0x0,-0x3c(%rbp)
jne    1298 <et+0x138>
mov    -0x28(%rbp),%edi
call   1070 <close@plt>
jmp    12ad <et+0x14d>
mov    -0x3c(%rbp),%esi
lea    -0x1e(%rbp),%rdx
lea    0xd7b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12b2 <et+0x152>
jmp    11fd <et+0x9d>
jmp    12ca <et+0x16a>
lea    0xd7a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12cf <et+0x16f>
jmp    12d4 <et+0x174>
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    0xe28(%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 = [21 x i8] c"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 = [26 x i8] c"something else happended\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 = %88, %4
%17 = load i32, i32* %10
%18 = load i32, i32* %6
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %91
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 %38
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* %7
%36 = load i32, i32* %14
%37 = call i32 @addfd(i32 %35, i32 %36, i32 1)
br label %87
38: ; preds = %20
%39 = load %struct.epoll_event*, %struct.epoll_event** %5
%40 = load i32, i32* %10
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %39, i64 %41
%43 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %42, i32 0, i32 0
%44 = load i32, i32* %43
%45 = load i32, i32* @EPOLLIN
%46 = and i32 %44, %45
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %84
48: ; preds = %38
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %50
50: ; preds = %48, %82
%51 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 0
%52 = call i32 @memset(i8* %51, i32 0, i32 10)
%53 = load i32, i32* %11
%54 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 0
%55 = call i32 @recv(i32 %53, i8* %54, i32 9, i32 0)
store i32 %55, i32* %15
%56 = load i32, i32* %15
%57 = icmp slt i32 %56, 0
br i1 %57, label %58, label %71
58: ; preds = %50
%59 = load i64, i64* @errno
%60 = load i64, i64* @EAGAIN
%61 = icmp eq i64 %59, %60
br i1 %61, label %66, label %62
62: ; preds = %58
%63 = load i64, i64* @errno
%64 = load i64, i64* @EWOULDBLOCK
%65 = icmp eq i64 %63, %64
br i1 %65, label %66, label %68
66: ; preds = %62, %58
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %83
68: ; preds = %62
%69 = load i32, i32* %11
%70 = call i32 @close(i32 %69)
br label %83
71: ; preds = %50
%72 = load i32, i32* %15
%73 = icmp eq i32 %72, 0
br i1 %73, label %74, label %77
74: ; preds = %71
%75 = load i32, i32* %11
%76 = call i32 @close(i32 %75)
br label %81
77: ; preds = %71
%78 = load i32, i32* %15
%79 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 0
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %78, i8* %79)
br label %81
81: ; preds = %77, %74
br label %82
82: ; preds = %81
br label %50
83: ; preds = %68, %66
br label %86
84: ; preds = %38
%85 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
br label %86
86: ; preds = %84, %83
br label %87
87: ; preds = %86, %31
br label %88
88: ; preds = %87
%89 = load i32, i32* %10
%90 = add nsw i32 %89, 1
store i32 %90, i32* %10
br label %16
91: ; 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 }
@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 = [25 x i8] c"something else happended\00"
@str.4 = [20 x i8] c"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 %61
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, %58
%16 = phi i64 [ 0, %10 ], [ %59, %58 ]
%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 %23
20: ; preds = %15
store i32 4, i32* %7
%21 = call i32 @accept(i32 %3, %struct.sockaddr* %13, i32* %7)
%22 = call i32 @addfd(i32 %2, i32 %21, i32 1)
br label %58
23: ; preds = %15
%24 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %0, i64 %16, i32 0
%25 = load i32, i32* %24
%26 = load i32, i32* @EPOLLIN
%27 = and i32 %26, %25
%28 = icmp eq i32 %27, 0
br i1 %28, label %56, label %29
29: ; preds = %23
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.4, i64 0, i64 0))
%31 = call i32 @memset(i8* %8, i32 0, i32 10)
%32 = call i32 @recv(i32 %18, i8* %8, i32 9, i32 0)
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %45
34: ; preds = %52, %29
%35 = load i64, i64* @errno
%36 = load i64, i64* @EAGAIN
%37 = icmp eq i64 %35, %36
%38 = load i64, i64* @EWOULDBLOCK
%39 = icmp eq i64 %35, %38
%40 = select i1 %37, i1 true, i1 %39
br i1 %40, label %41, label %43
41: ; preds = %34
%42 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.5, i64 0, i64 0))
br label %58
43: ; preds = %34
%44 = call i32 @close(i32 %18)
br label %58
45: ; preds = %29, %52
%46 = phi i32 [ %54, %52 ], [ %32, %29 ]
%47 = icmp eq i32 %46, 0
br i1 %47, label %48, label %50
48: ; preds = %45
%49 = call i32 @close(i32 %18)
br label %52
50: ; preds = %45
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %46, i8* %8)
br label %52
52: ; preds = %50, %48
%53 = call i32 @memset(i8* %8, i32 0, i32 10)
%54 = call i32 @recv(i32 %18, i8* %8, i32 9, i32 0)
%55 = icmp slt i32 %54, 0
br i1 %55, label %34, label %45
56: ; preds = %23
%57 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
br label %58
58: ; preds = %43, %41, %56, %20
%59 = add nuw nsw i64 %16, 1
%60 = icmp eq i64 %59, %14
br i1 %60, label %61, label %15
61: ; preds = %58, %4
ret void
}