#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 TYPE_2__ {
  int fd;
};
struct epoll_event {
  TYPE_1__ data;
  int /*<<< orphan*/ events;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ EPOLLOUT;
int /*<<< orphan*/ EPOLL_CTL_ADD;
int epoll_create(int);
int /*<<< orphan*/ epoll_ctl(int, int /*<<< orphan*/, int,
                             struct epoll_event *);
int epoll_wait(int, struct epoll_event *, int, int);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int main() {
  struct epoll_event ev;
  struct epoll_event events[(20)];
  int epfd = epoll_create((256));
  if (epfd < 0) {
    perror("epoll create failed: ");
    return 0;
  }
  FILE *fp = fopen("11", "rw");
  if (fp < 0) {
    perror("file open failed:");
    return 0;
  }
  printf("create file success : %d \n", (int)fp);
  ev.events = EPOLLOUT;
  ev.data.fd = (int)fp;
  epoll_ctl(epfd, EPOLL_CTL_ADD, (int)fp, &ev);
  while (1) {
    int nfds = epoll_wait(epfd, events, (20), (500));
    int i = 0;
    for (; i < nfds; i++) {
      printf("receiced data from %d \n", events[i].data.fd);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x100,%edi
call   1080 <epoll_create@plt>
mov    %eax,-0xb4(%rbp)
cmpl   $0x0,-0xb4(%rbp)
jge    11a7 <main+0x47>
lea    0xe6a(%rip),%rdi
call   1070 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    12a4 <main+0x144>
lea    0xe68(%rip),%rdi
lea    0xe64(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0xc0(%rbp)
cmpq   $0x0,-0xc0(%rbp)
jae    11e7 <main+0x87>
lea    0xe46(%rip),%rdi
call   1070 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    12a4 <main+0x144>
mov    -0xc0(%rbp),%rax
mov    %eax,%esi
lea    0xe37(%rip),%rdi
call   1030 <printf@plt>
mov    0x2dd5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc0(%rbp),%rax
mov    %eax,-0x10(%rbp)
mov    -0xb4(%rbp),%edi
mov    0x2dc9(%rip),%rax
mov    (%rax),%esi
mov    -0xc0(%rbp),%rax
mov    %eax,%edx
lea    -0x10(%rbp),%rcx
call   1040 <epoll_ctl@plt>
mov    -0xb4(%rbp),%edi
lea    -0xb0(%rbp),%rsi
mov    $0x14,%edx
mov    $0x1f4,%ecx
call   1050 <epoll_wait@plt>
mov    %eax,-0xc4(%rbp)
movl   $0x0,-0xc8(%rbp)
mov    -0xc8(%rbp),%eax
cmp    -0xc4(%rbp),%eax
jge    129f <main+0x13f>
movslq -0xc8(%rbp),%rax
mov    -0xb0(%rbp,%rax,8),%esi
lea    0xdc3(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc8(%rbp)
jmp    125f <main+0xff>
jmp    1233 <main+0xd3>
mov    -0x4(%rbp),%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xb0,%rsp
mov    $0x100,%edi
call   1080 <epoll_create@plt>
test   %eax,%eax
js     1217 <main+0xb7>
mov    %eax,%r15d
lea    0xe8b(%rip),%rdi
lea    0xe87(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
lea    0xe7b(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
mov    0x2e29(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
mov    %ebx,0x8(%rsp)
mov    0x2e28(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rcx
mov    %r15d,%edi
mov    %ebx,%edx
call   1040 <epoll_ctl@plt>
lea    0x10(%rsp),%r14
lea    0xe5a(%rip),%r12
nopl   (%rax)
mov    %r15d,%edi
mov    %r14,%rsi
mov    $0x14,%edx
mov    $0x1f4,%ecx
call   1050 <epoll_wait@plt>
test   %eax,%eax
jle    11e0 <main+0x80>
mov    %eax,%ebp
xor    %ebx,%ebx
nopl   (%rax)
mov    0x10(%rsp,%rbx,8),%esi
mov    %r12,%rdi
call   1030 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1200 <main+0xa0>
jmp    11e0 <main+0x80>
lea    0xde2(%rip),%rdi
call   1070 <perror@plt>
xor    %eax,%eax
add    $0xb0,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.epoll_event = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
@.str = [22 x i8] c"epoll create failed: \00"
@.str.1 = [3 x i8] c"11\00"
@.str.2 = [3 x i8] c"rw\00"
@.str.3 = [18 x i8] c"file open failed:\00"
@.str.4 = [27 x i8] c"create file success : %d \0A\00"
@EPOLLOUT = global i32 0
@EPOLL_CTL_ADD = global i32 0
@.str.5 = [24 x i8] c"receiced data from %d \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.epoll_event
%3 = alloca [20 x %struct.epoll_event]
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = call i32 @epoll_create(i32 256)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %1
br label %54
13: ; preds = %0
%14 = call i32* @fopen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %14, i32** %5
%15 = load i32*, i32** %5
%16 = icmp ult i32* %15, null
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %1
br label %54
19: ; preds = %13
%20 = load i32*, i32** %5
%21 = ptrtoint i32* %20 to i32
%22 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 %21)
%23 = load i32, i32* @EPOLLOUT
%24 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %2, i32 0, i32 1
store i32 %23, i32* %24
%25 = load i32*, i32** %5
%26 = ptrtoint i32* %25 to i32
%27 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %2, i32 0, i32 0
%28 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %27, i32 0, i32 0
store i32 %26, i32* %28
%29 = load i32, i32* %4
%30 = load i32, i32* @EPOLL_CTL_ADD
%31 = load i32*, i32** %5
%32 = ptrtoint i32* %31 to i32
%33 = call i32 @epoll_ctl(i32 %29, i32 %30, i32 %32, %struct.epoll_event* %2)
br label %34
34: ; preds = %19, %53
%35 = load i32, i32* %4
%36 = getelementptr inbounds [20 x %struct.epoll_event], [20 x %struct.epoll_event]* %3, i64 0, i64 0
%37 = call i32 @epoll_wait(i32 %35, %struct.epoll_event* %36, i32 20, i32 500)
store i32 %37, i32* %6
store i32 0, i32* %7
br label %38
38: ; preds = %50, %34
%39 = load i32, i32* %7
%40 = load i32, i32* %6
%41 = icmp slt i32 %39, %40
br i1 %41, label %42, label %53
42: ; preds = %38
%43 = load i32, i32* %7
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [20 x %struct.epoll_event], [20 x %struct.epoll_event]* %3, i64 0, i64 %44
%46 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %45, i32 0, i32 0
%47 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %46, i32 0, i32 0
%48 = load i32, i32* %47
%49 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i32 %48)
br label %50
50: ; preds = %42
%51 = load i32, i32* %7
%52 = add nsw i32 %51, 1
store i32 %52, i32* %7
br label %38
53: ; preds = %38
br label %34
54: ; preds = %17, %11
%55 = load i32, i32* %1
ret i32 %55
}

LLVM IR (-O2):
%struct.epoll_event = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
@.str = [22 x i8] c"epoll create failed: \00"
@.str.1 = [3 x i8] c"11\00"
@.str.2 = [3 x i8] c"rw\00"
@.str.4 = [27 x i8] c"create file success : %d \0A\00"
@EPOLLOUT = global i32 0
@EPOLL_CTL_ADD = global i32 0
@.str.5 = [24 x i8] c"receiced data from %d \0A\00"
define i32 @main() {
%1 = alloca %struct.epoll_event
%2 = alloca [20 x %struct.epoll_event]
%3 = bitcast %struct.epoll_event* %1 to i8*
%4 = bitcast [20 x %struct.epoll_event]* %2 to i8*
%5 = tail call i32 @epoll_create(i32 256)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = tail call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
ret i32 0
9: ; preds = %0
%10 = tail call i32* @fopen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%11 = ptrtoint i32* %10 to i64
%12 = trunc i64 %11 to i32
%13 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 %12)
%14 = load i32, i32* @EPOLLOUT
%15 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %1, i64 0, i32 1
store i32 %14, i32* %15
%16 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %1, i64 0, i32 0, i32 0
store i32 %12, i32* %16
%17 = load i32, i32* @EPOLL_CTL_ADD
%18 = call i32 @epoll_ctl(i32 %5, i32 %17, i32 %12, %struct.epoll_event* %1)
%19 = getelementptr inbounds [20 x %struct.epoll_event], [20 x %struct.epoll_event]* %2, i64 0, i64 0
br label %20
20: ; preds = %23, %9
%21 = call i32 @epoll_wait(i32 %5, %struct.epoll_event* %19, i32 20, i32 500)
%22 = icmp sgt i32 %21, 0
br i1 %22, label %24, label %23
23: ; preds = %26, %20
br label %20
24: ; preds = %20
%25 = zext i32 %21 to i64
br label %26
26: ; preds = %24, %26
%27 = phi i64 [ 0, %24 ], [ %31, %26 ]
%28 = getelementptr inbounds [20 x %struct.epoll_event], [20 x %struct.epoll_event]* %2, i64 0, i64 %27, i32 0, i32 0
%29 = load i32, i32* %28
%30 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i32 %29)
%31 = add nuw nsw i64 %27, 1
%32 = icmp eq i64 %31, %25
br i1 %32, label %23, label %26
}