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

/* Variables and functions */
int ETIMEDOUT;
int epoll_wait(int, struct epoll_event *, int, int);
int errno;
int epoll_wait_read(int epoll, int timeo) {
  struct epoll_event ev;
  int rc = epoll_wait(epoll, &ev, 1, timeo);
  if (rc > 0) {
    return ev.data.fd;
  }
  if (rc == 0)
    return -ETIMEDOUT;
  return -errno;
}


x86 assembly (clang, -O0):
<epoll_wait_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%ecx
lea    -0x10(%rbp),%rsi
mov    $0x1,%edx
call   1030 <epoll_wait@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    114a <epoll_wait_read+0x3a>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1175 <epoll_wait_read+0x65>
cmpl   $0x0,-0x14(%rbp)
jne    1167 <epoll_wait_read+0x57>
xor    %eax,%eax
mov    0x2e7b(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    1175 <epoll_wait_read+0x65>
xor    %eax,%eax
mov    0x2e70(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<epoll_wait_read>:
push   %rax
mov    %esi,%ecx
mov    %rsp,%rsi
mov    $0x1,%edx
call   1030 <epoll_wait@plt>
test   %eax,%eax
jle    1129 <epoll_wait_read+0x19>
mov    (%rsp),%eax
pop    %rcx
ret
je     1134 <epoll_wait_read+0x24>
mov    0x2eae(%rip),%rcx
jmp    113b <epoll_wait_read+0x2b>
mov    0x2e9d(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.epoll_event = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@ETIMEDOUT = global i32 0
@errno = global i32 0
define i32 @epoll_wait_read(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.epoll_event
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%8 = load i32, i32* %4
%9 = load i32, i32* %5
%10 = call i32 @epoll_wait(i32 %8, %struct.epoll_event* %6, i32 1, i32 %9)
store i32 %10, i32* %7
%11 = load i32, i32* %7
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %6, i32 0, i32 0
%15 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %14, i32 0, i32 0
%16 = load i32, i32* %15
store i32 %16, i32* %3
br label %26
17: ; preds = %2
%18 = load i32, i32* %7
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = load i32, i32* @ETIMEDOUT
%22 = sub nsw i32 0, %21
store i32 %22, i32* %3
br label %26
23: ; preds = %17
%24 = load i32, i32* @errno
%25 = sub nsw i32 0, %24
store i32 %25, i32* %3
br label %26
26: ; preds = %23, %20, %13
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
%struct.epoll_event = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@ETIMEDOUT = global i32 0
@errno = global i32 0
define i32 @epoll_wait_read(i32 %0, i32 %1) {
%3 = alloca %struct.epoll_event
%4 = bitcast %struct.epoll_event* %3 to i8*
%5 = call i32 @epoll_wait(i32 %0, %struct.epoll_event* %3, i32 1, i32 %1)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %3, i64 0, i32 0, i32 0
%9 = load i32, i32* %8
br label %18
10: ; preds = %2
%11 = icmp eq i32 %5, 0
br i1 %11, label %12, label %15
12: ; preds = %10
%13 = load i32, i32* @ETIMEDOUT
%14 = sub nsw i32 0, %13
br label %18
15: ; preds = %10
%16 = load i32, i32* @errno
%17 = sub nsw i32 0, %16
br label %18
18: ; preds = %15, %12, %7
%19 = phi i32 [ %9, %7 ], [ %14, %12 ], [ %17, %15 ]
ret i32 %19
}