#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 */
int EPOLLIN;
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ addfd(int, int, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ printf(char *, ...);
int recv(int, char *, int, int /*<<< orphan*/);
void lt(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) {
      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, 0);
    } else if (events[i].events & EPOLLIN) {
      printf("event trigger once\n");
      memset(buf, '\0', 10);
      int ret = recv(sockfd, buf, 10 - 1, 0);
      if (ret <= 0) {
        close(sockfd);
        continue;
      }
      printf("get %d bytes of content:%s\n", ret, buf);
    } else {
      printf("something else happend\n");
    }
  }
}


x86 assembly (clang, -O0):
<lt>:
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    1277 <lt+0x117>
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    11cf <lt+0x6f>
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
xor    %edx,%edx
call   1040 <addfd@plt>
jmp    1264 <lt+0x104>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%eax
mov    0x2e07(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1251 <lt+0xf1>
lea    0xe0d(%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)
jg     1237 <lt+0xd7>
mov    -0x28(%rbp),%edi
call   1070 <close@plt>
jmp    1269 <lt+0x109>
mov    -0x3c(%rbp),%esi
lea    -0x1e(%rbp),%rdx
lea    0xdcf(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    125f <lt+0xff>
lea    0xdd8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1264 <lt+0x104>
jmp    1269 <lt+0x109>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    117c <lt+0x1c>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,(%rsp)
test   %esi,%esi
jle    1249 <lt+0xd9>
mov    %ecx,%ebx
mov    %rdi,%rbp
mov    %esi,%r12d
lea    0xe(%rsp),%r14
xor    %r13d,%r13d
jmp    11ce <lt+0x5e>
nopl   0x0(%rax,%rax,1)
movl   $0x4,0x4(%rsp)
mov    %ebx,%edi
lea    0x8(%rsp),%rsi
lea    0x4(%rsp),%rdx
call   1090 <accept@plt>
mov    (%rsp),%edi
mov    %eax,%esi
xor    %edx,%edx
call   1040 <addfd@plt>
add    $0x1,%r13
cmp    %r13,%r12
je     1249 <lt+0xd9>
mov    0x4(%rbp,%r13,8),%r15d
cmp    %ebx,%r15d
je     11a0 <lt+0x30>
mov    0x2e09(%rip),%rax
mov    (%rax),%eax
test   %eax,0x0(%rbp,%r13,8)
je     122e <lt+0xbe>
lea    0xe44(%rip),%rdi
call   1050 <puts@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1070 <memset@plt>
mov    %r15d,%edi
mov    %r14,%rsi
mov    $0x9,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jle    123c <lt+0xcc>
lea    0xde0(%rip),%rdi
mov    %eax,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
jmp    11c5 <lt+0x55>
lea    0xde7(%rip),%rdi
call   1050 <puts@plt>
jmp    11c5 <lt+0x55>
mov    %r15d,%edi
call   1080 <close@plt>
jmp    11c5 <lt+0x55>
add    $0x18,%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 = [20 x i8] c"event trigger once\0A\00"
@.str.1 = [28 x i8] c"get %d bytes of content:%s\0A\00"
@.str.2 = [24 x i8] c"something else happend\0A\00"
define void @lt(%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 = %68, %4
%17 = load i32, i32* %10
%18 = load i32, i32* %6
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %71
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 0)
br label %67
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 %64
48: ; preds = %38
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%50 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 0
%51 = call i32 @memset(i8* %50, i8 signext 0, i32 10)
%52 = load i32, i32* %11
%53 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 0
%54 = call i32 @recv(i32 %52, i8* %53, i32 9, i32 0)
store i32 %54, i32* %15
%55 = load i32, i32* %15
%56 = icmp sle i32 %55, 0
br i1 %56, label %57, label %60
57: ; preds = %48
%58 = load i32, i32* %11
%59 = call i32 @close(i32 %58)
br label %68
60: ; preds = %48
%61 = load i32, i32* %15
%62 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 0
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %61, i8* %62)
br label %66
64: ; preds = %38
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
br label %66
66: ; preds = %64, %60
br label %67
67: ; preds = %66, %31
br label %68
68: ; preds = %67, %57
%69 = load i32, i32* %10
%70 = add nsw i32 %69, 1
store i32 %70, i32* %10
br label %16
71: ; 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
@.str.1 = [28 x i8] c"get %d bytes of content:%s\0A\00"
@str = [23 x i8] c"something else happend\00"
@str.3 = [19 x i8] c"event trigger once\00"
define void @lt(%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 = %41, %4
ret void
16: ; preds = %10, %41
%17 = phi i64 [ 0, %10 ], [ %42, %41 ]
%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 0)
br label %41
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 %39, label %30
30: ; preds = %24
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.3, 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, 1
br i1 %34, label %35, label %37
35: ; preds = %30
%36 = call i32 @close(i32 %19)
br label %41
37: ; preds = %30
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %33, i8* %8)
br label %41
39: ; preds = %24
%40 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
br label %41
41: ; preds = %35, %37, %21, %39
%42 = add nuw nsw i64 %17, 1
%43 = icmp eq i64 %42, %14
br i1 %43, label %15, label %16
}