#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 */

/* Type definitions */
struct epoll_event {
  int dummy;
};
typedef int /*<<< orphan*/ off_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ do_event(struct epoll_event *, int, int, int,
                            int /*<<< orphan*/);
int epoll_wait(int, struct epoll_event *, int, int);
int errno;
int /*<<< orphan*/ error(int /*<<< orphan*/, int, char *, int);
void main_loop(int efd, int sockfd, int datafd, off_t datasz) {
  int i;
  int num_ready;
  struct epoll_event events[100];
  while (1) {
    num_ready = epoll_wait(efd, events, 100, -1);
    if (num_ready == -1) {
      error(EXIT_FAILURE, errno, "Error %d on epoll_wait", errno);
    }
    for (i = 0; i < num_ready; i++) {
      do_event(&events[i], sockfd, efd, datafd, datasz);
    }
  }
}


x86 assembly (clang, -O0):
<main_loop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1b0,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x1b0(%rbp),%rsi
mov    $0x64,%edx
mov    $0xffffffff,%ecx
call   1040 <epoll_wait@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    1194 <main_loop+0x64>
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
mov    0x2e63(%rip),%rax
mov    (%rax),%esi
mov    0x2e5a(%rip),%rax
mov    (%rax),%ecx
lea    0xe71(%rip),%rdx
call   1050 <error@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11d9 <main_loop+0xa9>
movslq -0x14(%rbp),%rax
lea    -0x1b0(%rbp),%rdi
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%esi
mov    -0x4(%rbp),%edx
mov    -0xc(%rbp),%ecx
mov    -0x10(%rbp),%r8d
call   1030 <do_event@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    119b <main_loop+0x6b>
jmp    1147 <main_loop+0x17>

x86 assembly (clang, -O2):
<main_loop>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x198,%rsp
mov    %ecx,%r14d
mov    %edx,%r15d
mov    %esi,%ebx
mov    %edi,%ebp
jmp    1170 <main_loop+0x40>
nopl   (%rax)
mov    0x2e81(%rip),%rax
mov    (%rax),%edi
mov    0x2e80(%rip),%rax
mov    (%rax),%ecx
mov    %ecx,%esi
lea    0xe95(%rip),%rdx
call   1050 <error@plt>
mov    %ebp,%edi
mov    %rsp,%rsi
mov    $0x64,%edx
mov    $0xffffffff,%ecx
call   1040 <epoll_wait@plt>
cmp    $0xffffffff,%eax
je     1150 <main_loop+0x20>
test   %eax,%eax
jle    1170 <main_loop+0x40>
mov    %eax,%r13d
mov    %rsp,%r12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r12,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
mov    %r15d,%ecx
mov    %r14d,%r8d
call   1030 <do_event@plt>
add    $0x4,%r12
add    $0xffffffffffffffff,%r13
jne    11a0 <main_loop+0x70>
jmp    1170 <main_loop+0x40>

LLVM IR (-O0):
%struct.epoll_event = type { i32 }
@EXIT_FAILURE = global i32 0
@errno = global i32 0
@.str = [23 x i8] c"Error %d on epoll_wait\00"
define void @main_loop(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca [100 x %struct.epoll_event]
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
br label %12
12: ; preds = %4, %40
%13 = load i32, i32* %5
%14 = getelementptr inbounds [100 x %struct.epoll_event], [100 x %struct.epoll_event]* %11, i64 0, i64 0
%15 = call i32 @epoll_wait(i32 %13, %struct.epoll_event* %14, i32 100, i32 -1)
store i32 %15, i32* %10
%16 = load i32, i32* %10
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %23
18: ; preds = %12
%19 = load i32, i32* @EXIT_FAILURE
%20 = load i32, i32* @errno
%21 = load i32, i32* @errno
%22 = call i32 @error(i32 %19, i32 %20, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %21)
br label %23
23: ; preds = %18, %12
store i32 0, i32* %9
br label %24
24: ; preds = %37, %23
%25 = load i32, i32* %9
%26 = load i32, i32* %10
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %40
28: ; preds = %24
%29 = load i32, i32* %9
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [100 x %struct.epoll_event], [100 x %struct.epoll_event]* %11, i64 0, i64 %30
%32 = load i32, i32* %6
%33 = load i32, i32* %5
%34 = load i32, i32* %7
%35 = load i32, i32* %8
%36 = call i32 @do_event(%struct.epoll_event* %31, i32 %32, i32 %33, i32 %34, i32 %35)
br label %37
37: ; preds = %28
%38 = load i32, i32* %9
%39 = add nsw i32 %38, 1
store i32 %39, i32* %9
br label %24
40: ; preds = %24
br label %12
}

LLVM IR (-O2):
%struct.epoll_event = type { i32 }
@EXIT_FAILURE = global i32 0
@errno = global i32 0
@.str = [23 x i8] c"Error %d on epoll_wait\00"
define void @main_loop(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca [100 x %struct.epoll_event]
%6 = bitcast [100 x %struct.epoll_event]* %5 to i8*
%7 = getelementptr inbounds [100 x %struct.epoll_event], [100 x %struct.epoll_event]* %5, i64 0, i64 0
br label %8
8: ; preds = %15, %4
%9 = call i32 @epoll_wait(i32 %0, %struct.epoll_event* %7, i32 100, i32 -1)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %16
11: ; preds = %8
%12 = load i32, i32* @EXIT_FAILURE
%13 = load i32, i32* @errno
%14 = call i32 @error(i32 %12, i32 %13, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %13)
br label %15
15: ; preds = %20, %11, %16
br label %8
16: ; preds = %8
%17 = icmp sgt i32 %9, 0
br i1 %17, label %18, label %15
18: ; preds = %16
%19 = zext i32 %9 to i64
br label %20
20: ; preds = %18, %20
%21 = phi i64 [ 0, %18 ], [ %24, %20 ]
%22 = getelementptr inbounds [100 x %struct.epoll_event], [100 x %struct.epoll_event]* %5, i64 0, i64 %21
%23 = call i32 @do_event(%struct.epoll_event* %22, i32 %1, i32 %0, i32 %2, i32 %3)
%24 = add nuw nsw i64 %21, 1
%25 = icmp eq i64 %24, %19
br i1 %25, label %15, label %20
}