#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 */
int EPOLLIN;
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ addfd(int, int, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ memset(char *, int, 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];
  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, 0);
    } else if (events[i].events & EPOLLIN) {
      printf("event trigger once \n");
      memset(buf, 0x00, sizeof(buf));
      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 happened \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    0xdd0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    125f <lt+0xff>
lea    0xdd9(%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    0xe46(%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 = [21 x i8] c"event trigger once \0A\00"
@.str.1 = [28 x i8] c"get %d bytes of content:%s\0A\00"
@.str.2 = [26 x i8] c"something else happened \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 ([21 x i8], [21 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, i32 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 ([26 x i8], [26 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 = [25 x i8] c"something else happened \00"
@str.3 = [20 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 %43
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, %40
%16 = phi i64 [ 0, %10 ], [ %41, %40 ]
%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 0)
br label %40
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 %38, label %29
29: ; preds = %23
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.3, 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, 1
br i1 %33, label %34, label %36
34: ; preds = %29
%35 = call i32 @close(i32 %18)
br label %40
36: ; preds = %29
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %32, i8* %8)
br label %40
38: ; preds = %23
%39 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
br label %40
40: ; preds = %34, %36, %20, %38
%41 = add nuw nsw i64 %16, 1
%42 = icmp eq i64 %41, %14
br i1 %42, label %43, label %15
43: ; preds = %40, %4
ret void
}