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

/* Variables and functions */
int /*<<< orphan*/ EPOLLIN;
int /*<<< orphan*/ EPOLL_CTL_ADD;
int /*<<< orphan*/ attach_bpf(int);
int /*<<< orphan*/ build_rcv_group(int *, int, int, int);
int /*<<< orphan*/ close(int);
int epoll_create(int);
scalar_t__ epoll_ctl(int, int /*<<< orphan*/, int, struct epoll_event *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ error(int, int /*<<< orphan*/, char *);
int /*<<< orphan*/ receive_on_node(int *, int, int, int, int);
int /*<<< orphan*/ send_from_node(int, int, int);
void test(int *rcv_fd, int len, int family, int proto) {
  struct epoll_event ev;
  int epfd, node;
  build_rcv_group(rcv_fd, len, family, proto);
  attach_bpf(rcv_fd[0]);
  epfd = epoll_create(1);
  if (epfd < 0)
    error(1, errno, "failed to create epoll");
  for (node = 0; node < len; ++node) {
    ev.events = EPOLLIN;
    ev.data.fd = rcv_fd[node];
    if (epoll_ctl(epfd, EPOLL_CTL_ADD, rcv_fd[node], &ev))
      error(1, errno, "failed to register sock epoll");
  }
  for (node = 0; node < len; ++node) {
    send_from_node(node, family, proto);
    receive_on_node(rcv_fd, len, epfd, node, proto);
  }
  for (node = len - 1; node >= 0; --node) {
    send_from_node(node, family, proto);
    receive_on_node(rcv_fd, len, epfd, node, proto);
  }
  close(epfd);
  for (node = 0; node < len; ++node)
    close(rcv_fd[node]);
}


x86 assembly (clang, -O0):
<test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
call   1040 <build_rcv_group@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1030 <attach_bpf@plt>
mov    $0x1,%edi
call   1090 <epoll_create@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    11e3 <test+0x63>
mov    0x2e00(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edi
lea    0xe22(%rip),%rdx
call   1080 <error@plt>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1267 <test+0xe7>
mov    0x2deb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%edi
mov    0x2dc6(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    -0x20(%rbp),%rcx
call   1060 <epoll_ctl@plt>
cmp    $0x0,%rax
je     1254 <test+0xd4>
mov    0x2d8f(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edi
lea    0xdc8(%rip),%rdx
call   1080 <error@plt>
jmp    1259 <test+0xd9>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11ea <test+0x6a>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    12ac <test+0x12c>
mov    -0x28(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
call   10a0 <send_from_node@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x24(%rbp),%edx
mov    -0x28(%rbp),%ecx
mov    -0x14(%rbp),%r8d
call   1070 <receive_on_node@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    126e <test+0xee>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jl     12f1 <test+0x171>
mov    -0x28(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
call   10a0 <send_from_node@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x24(%rbp),%edx
mov    -0x28(%rbp),%ecx
mov    -0x14(%rbp),%r8d
call   1070 <receive_on_node@plt>
mov    -0x28(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x28(%rbp)
jmp    12b5 <test+0x135>
mov    -0x24(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    132a <test+0x1aa>
mov    -0x8(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
call   1050 <close@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1300 <test+0x180>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%r15d
mov    %edx,%ebx
mov    %esi,%r14d
mov    %rdi,%r12
call   1040 <build_rcv_group@plt>
mov    (%r12),%edi
call   1030 <attach_bpf@plt>
mov    $0x1,%edi
call   1090 <epoll_create@plt>
mov    %eax,%r13d
test   %eax,%eax
js     11c2 <test+0x42>
test   %r14d,%r14d
jg     11e5 <test+0x65>
jmp    12f4 <test+0x174>
mov    0x2e07(%rip),%rax
mov    (%rax),%esi
lea    0xe2e(%rip),%rdx
mov    $0x1,%edi
call   1080 <error@plt>
test   %r14d,%r14d
jle    12f4 <test+0x174>
mov    %ebx,0x4(%rsp)
mov    %r14d,%eax
mov    %rax,0x8(%rsp)
xor    %ebp,%ebp
lea    0x10(%rsp),%rbx
jmp    120b <test+0x8b>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rbp
cmp    %rbp,0x8(%rsp)
je     1255 <test+0xd5>
mov    0x2dd6(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
mov    (%r12,%rbp,4),%edx
mov    %edx,0x10(%rsp)
mov    0x2db9(%rip),%rax
mov    (%rax),%esi
mov    %r13d,%edi
mov    %rbx,%rcx
call   1060 <epoll_ctl@plt>
test   %rax,%rax
je     1200 <test+0x80>
mov    0x2d90(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edi
lea    0xdc9(%rip),%rdx
call   1080 <error@plt>
jmp    1200 <test+0x80>
test   %r14d,%r14d
mov    0x4(%rsp),%ebx
jle    12f4 <test+0x174>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebp,%edi
mov    %ebx,%esi
mov    %r15d,%edx
call   10a0 <send_from_node@plt>
mov    %r12,%rdi
mov    %r14d,%esi
mov    %r13d,%edx
mov    %ebp,%ecx
mov    %r15d,%r8d
call   1070 <receive_on_node@plt>
add    $0x1,%ebp
cmp    %ebp,%r14d
jne    1270 <test+0xf0>
test   %r14d,%r14d
jle    12f4 <test+0x174>
lea    0x1(%r14),%ebx
lea    -0x2(%rbx),%ebp
mov    %ebp,%edi
mov    0x4(%rsp),%esi
mov    %r15d,%edx
call   10a0 <send_from_node@plt>
mov    %r12,%rdi
mov    %r14d,%esi
mov    %r13d,%edx
mov    %ebp,%ecx
mov    %r15d,%r8d
call   1070 <receive_on_node@plt>
add    $0xffffffff,%ebx
cmp    $0x1,%ebx
ja     12a0 <test+0x120>
mov    %r13d,%edi
call   1050 <close@plt>
test   %r14d,%r14d
mov    0x8(%rsp),%rbp
jle    12fc <test+0x17c>
xor    %ebx,%ebx
mov    (%r12,%rbx,4),%edi
call   1050 <close@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    12e0 <test+0x160>
jmp    12fc <test+0x17c>
mov    %r13d,%edi
call   1050 <close@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.epoll_event = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
@errno = global i32 0
@.str = [23 x i8] c"failed to create epoll\00"
@EPOLLIN = global i32 0
@EPOLL_CTL_ADD = global i32 0
@.str.1 = [30 x i8] c"failed to register sock epoll\00"
define void @test(i32* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.epoll_event
%10 = alloca i32
%11 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%12 = load i32*, i32** %5
%13 = load i32, i32* %6
%14 = load i32, i32* %7
%15 = load i32, i32* %8
%16 = call i32 @build_rcv_group(i32* %12, i32 %13, i32 %14, i32 %15)
%17 = load i32*, i32** %5
%18 = getelementptr inbounds i32, i32* %17, i64 0
%19 = load i32, i32* %18
%20 = call i32 @attach_bpf(i32 %19)
%21 = call i32 @epoll_create(i32 1)
store i32 %21, i32* %10
%22 = load i32, i32* %10
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %4
%25 = load i32, i32* @errno
%26 = call i32 @error(i32 1, i32 %25, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %27
27: ; preds = %24, %4
store i32 0, i32* %11
br label %28
28: ; preds = %55, %27
%29 = load i32, i32* %11
%30 = load i32, i32* %6
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %58
32: ; preds = %28
%33 = load i32, i32* @EPOLLIN
%34 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %9, i32 0, i32 1
store i32 %33, i32* %34
%35 = load i32*, i32** %5
%36 = load i32, i32* %11
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i32, i32* %35, i64 %37
%39 = load i32, i32* %38
%40 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %9, i32 0, i32 0
%41 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %40, i32 0, i32 0
store i32 %39, i32* %41
%42 = load i32, i32* %10
%43 = load i32, i32* @EPOLL_CTL_ADD
%44 = load i32*, i32** %5
%45 = load i32, i32* %11
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i32, i32* %44, i64 %46
%48 = load i32, i32* %47
%49 = call i64 @epoll_ctl(i32 %42, i32 %43, i32 %48, %struct.epoll_event* %9)
%50 = icmp ne i64 %49, 0
br i1 %50, label %51, label %54
51: ; preds = %32
%52 = load i32, i32* @errno
%53 = call i32 @error(i32 1, i32 %52, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
br label %54
54: ; preds = %51, %32
br label %55
55: ; preds = %54
%56 = load i32, i32* %11
%57 = add nsw i32 %56, 1
store i32 %57, i32* %11
br label %28
58: ; preds = %28
store i32 0, i32* %11
br label %59
59: ; preds = %74, %58
%60 = load i32, i32* %11
%61 = load i32, i32* %6
%62 = icmp slt i32 %60, %61
br i1 %62, label %63, label %77
63: ; preds = %59
%64 = load i32, i32* %11
%65 = load i32, i32* %7
%66 = load i32, i32* %8
%67 = call i32 @send_from_node(i32 %64, i32 %65, i32 %66)
%68 = load i32*, i32** %5
%69 = load i32, i32* %6
%70 = load i32, i32* %10
%71 = load i32, i32* %11
%72 = load i32, i32* %8
%73 = call i32 @receive_on_node(i32* %68, i32 %69, i32 %70, i32 %71, i32 %72)
br label %74
74: ; preds = %63
%75 = load i32, i32* %11
%76 = add nsw i32 %75, 1
store i32 %76, i32* %11
br label %59
77: ; preds = %59
%78 = load i32, i32* %6
%79 = sub nsw i32 %78, 1
store i32 %79, i32* %11
br label %80
80: ; preds = %94, %77
%81 = load i32, i32* %11
%82 = icmp sge i32 %81, 0
br i1 %82, label %83, label %97
83: ; preds = %80
%84 = load i32, i32* %11
%85 = load i32, i32* %7
%86 = load i32, i32* %8
%87 = call i32 @send_from_node(i32 %84, i32 %85, i32 %86)
%88 = load i32*, i32** %5
%89 = load i32, i32* %6
%90 = load i32, i32* %10
%91 = load i32, i32* %11
%92 = load i32, i32* %8
%93 = call i32 @receive_on_node(i32* %88, i32 %89, i32 %90, i32 %91, i32 %92)
br label %94
94: ; preds = %83
%95 = load i32, i32* %11
%96 = add nsw i32 %95, -1
store i32 %96, i32* %11
br label %80
97: ; preds = %80
%98 = load i32, i32* %10
%99 = call i32 @close(i32 %98)
store i32 0, i32* %11
br label %100
100: ; preds = %111, %97
%101 = load i32, i32* %11
%102 = load i32, i32* %6
%103 = icmp slt i32 %101, %102
br i1 %103, label %104, label %114
104: ; preds = %100
%105 = load i32*, i32** %5
%106 = load i32, i32* %11
%107 = sext i32 %106 to i64
%108 = getelementptr inbounds i32, i32* %105, i64 %107
%109 = load i32, i32* %108
%110 = call i32 @close(i32 %109)
br label %111
111: ; preds = %104
%112 = load i32, i32* %11
%113 = add nsw i32 %112, 1
store i32 %113, i32* %11
br label %100
114: ; preds = %100
ret void
}

LLVM IR (-O2):
%struct.epoll_event = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
@errno = global i32 0
@.str = [23 x i8] c"failed to create epoll\00"
@EPOLLIN = global i32 0
@EPOLL_CTL_ADD = global i32 0
@.str.1 = [30 x i8] c"failed to register sock epoll\00"
define void @test(i32* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca %struct.epoll_event
%6 = bitcast %struct.epoll_event* %5 to i8*
%7 = tail call i32 @build_rcv_group(i32* %0, i32 %1, i32 %2, i32 %3)
%8 = load i32, i32* %0
%9 = tail call i32 @attach_bpf(i32 %8)
%10 = tail call i32 @epoll_create(i32 1)
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %4
%13 = load i32, i32* @errno
%14 = tail call i32 @error(i32 1, i32 %13, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %12, %4
%16 = icmp sgt i32 %1, 0
br i1 %16, label %17, label %49
17: ; preds = %15
%18 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %5, i64 0, i32 1
%19 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %5, i64 0, i32 0, i32 0
%20 = zext i32 %1 to i64
br label %22
21: ; preds = %33
br i1 %16, label %37, label %49
22: ; preds = %17, %33
%23 = phi i64 [ 0, %17 ], [ %34, %33 ]
%24 = load i32, i32* @EPOLLIN
store i32 %24, i32* %18
%25 = getelementptr inbounds i32, i32* %0, i64 %23
%26 = load i32, i32* %25
store i32 %26, i32* %19
%27 = load i32, i32* @EPOLL_CTL_ADD
%28 = call i64 @epoll_ctl(i32 %10, i32 %27, i32 %26, %struct.epoll_event* %5)
%29 = icmp eq i64 %28, 0
br i1 %29, label %33, label %30
30: ; preds = %22
%31 = load i32, i32* @errno
%32 = call i32 @error(i32 1, i32 %31, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
br label %33
33: ; preds = %22, %30
%34 = add nuw nsw i64 %23, 1
%35 = icmp eq i64 %34, %20
br i1 %35, label %21, label %22
36: ; preds = %37
br i1 %16, label %43, label %49
37: ; preds = %21, %37
%38 = phi i32 [ %41, %37 ], [ 0, %21 ]
%39 = call i32 @send_from_node(i32 %38, i32 %2, i32 %3)
%40 = call i32 @receive_on_node(i32* %0, i32 %1, i32 %10, i32 %38, i32 %3)
%41 = add nuw nsw i32 %38, 1
%42 = icmp eq i32 %41, %1
br i1 %42, label %36, label %37
43: ; preds = %36, %43
%44 = phi i32 [ %45, %43 ], [ %1, %36 ]
%45 = add nsw i32 %44, -1
%46 = call i32 @send_from_node(i32 %45, i32 %2, i32 %3)
%47 = call i32 @receive_on_node(i32* %0, i32 %1, i32 %10, i32 %45, i32 %3)
%48 = icmp ugt i32 %44, 1
br i1 %48, label %43, label %51
49: ; preds = %36, %21, %15
%50 = call i32 @close(i32 %10)
br label %62
51: ; preds = %43
%52 = call i32 @close(i32 %10)
br i1 %16, label %53, label %62
53: ; preds = %51
%54 = zext i32 %1 to i64
br label %55
55: ; preds = %53, %55
%56 = phi i64 [ 0, %53 ], [ %60, %55 ]
%57 = getelementptr inbounds i32, i32* %0, i64 %56
%58 = load i32, i32* %57
%59 = call i32 @close(i32 %58)
%60 = add nuw nsw i64 %56, 1
%61 = icmp eq i64 %60, %54
br i1 %61, label %62, label %55
62: ; preds = %55, %49, %51
ret void
}