#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 */
typedef int /*<<< orphan*/ uint64_t;
typedef int /*<<< orphan*/ triggered;

/* Variables and functions */
int EPOLLERR;
int EPOLLHUP;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ err(int /*<<< orphan*/, char *);
int read(int, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ users_reacquire_ports();
int timer_read(int fd, int event, void *data) {
  uint64_t triggered;
  int rc;
  if ((event & EPOLLERR) == EPOLLERR || (event & EPOLLHUP) == EPOLLHUP)
    return -1;
  rc = read(fd, &triggered, sizeof(triggered));
  if (rc != sizeof(triggered))
    err(EXIT_FAILURE, "Error reading from timerfd");
  users_reacquire_ports();
  return 0;
}


x86 assembly (clang, -O0):
<timer_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    0x2e94(%rip),%rcx
and    (%rcx),%eax
mov    0x2e8b(%rip),%rcx
cmp    (%rcx),%eax
je     1178 <timer_read+0x48>
mov    -0xc(%rbp),%eax
mov    0x2e69(%rip),%rcx
and    (%rcx),%eax
mov    0x2e60(%rip),%rcx
cmp    (%rcx),%eax
jne    1184 <timer_read+0x54>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c9 <timer_read+0x99>
mov    -0x8(%rbp),%edi
lea    -0x1c(%rbp),%rsi
mov    $0x4,%edx
call   1040 <read@plt>
mov    %eax,-0x20(%rbp)
movslq -0x20(%rbp),%rax
cmp    $0x4,%rax
je     11bb <timer_read+0x8b>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
lea    0xe4a(%rip),%rsi
call   1050 <err@plt>
mov    $0x0,%al
call   1030 <users_reacquire_ports@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timer_read>:
push   %rbx
sub    $0x10,%rsp
mov    0x2ea4(%rip),%rax
not    %esi
mov    $0xffffffff,%ebx
test   %esi,(%rax)
je     1184 <timer_read+0x54>
mov    0x2e82(%rip),%rax
test   %esi,(%rax)
je     1184 <timer_read+0x54>
lea    0xc(%rsp),%rsi
mov    $0x4,%edx
call   1040 <read@plt>
cmp    $0x4,%eax
je     117b <timer_read+0x4b>
mov    0x2e6b(%rip),%rax
mov    (%rax),%edi
lea    0xe8a(%rip),%rsi
call   1050 <err@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <users_reacquire_ports@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@EPOLLERR = global i32 0
@EPOLLHUP = global i32 0
@EXIT_FAILURE = global i32 0
@.str = [27 x i8] c"Error reading from timerfd\00"
define i32 @timer_read(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8* %2, i8** %7
%10 = load i32, i32* %6
%11 = load i32, i32* @EPOLLERR
%12 = and i32 %10, %11
%13 = load i32, i32* @EPOLLERR
%14 = icmp eq i32 %12, %13
br i1 %14, label %21, label %15
15: ; preds = %3
%16 = load i32, i32* %6
%17 = load i32, i32* @EPOLLHUP
%18 = and i32 %16, %17
%19 = load i32, i32* @EPOLLHUP
%20 = icmp eq i32 %18, %19
br i1 %20, label %21, label %22
21: ; preds = %15, %3
store i32 -1, i32* %4
br label %33
22: ; preds = %15
%23 = load i32, i32* %5
%24 = call i32 @read(i32 %23, i32* %8, i32 4)
store i32 %24, i32* %9
%25 = load i32, i32* %9
%26 = sext i32 %25 to i64
%27 = icmp ne i64 %26, 4
br i1 %27, label %28, label %31
28: ; preds = %22
%29 = load i32, i32* @EXIT_FAILURE
%30 = call i32 @err(i32 %29, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %31
31: ; preds = %28, %22
%32 = call i32 (...) @users_reacquire_ports()
store i32 0, i32* %4
br label %33
33: ; preds = %31, %21
%34 = load i32, i32* %4
ret i32 %34
}

LLVM IR (-O2):
@EPOLLERR = global i32 0
@EPOLLHUP = global i32 0
@EXIT_FAILURE = global i32 0
@.str = [27 x i8] c"Error reading from timerfd\00"
define i32 @timer_read(i32 %0, i32 %1, i8* nocapture readnone %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = load i32, i32* @EPOLLERR
%7 = and i32 %6, %1
%8 = icmp eq i32 %7, %6
br i1 %8, label %21, label %9
9: ; preds = %3
%10 = load i32, i32* @EPOLLHUP
%11 = and i32 %10, %1
%12 = icmp eq i32 %11, %10
br i1 %12, label %21, label %13
13: ; preds = %9
%14 = call i32 @read(i32 %0, i32* %4, i32 4)
%15 = icmp eq i32 %14, 4
br i1 %15, label %19, label %16
16: ; preds = %13
%17 = load i32, i32* @EXIT_FAILURE
%18 = tail call i32 @err(i32 %17, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %16, %13
%20 = tail call i32 (...) @users_reacquire_ports()
br label %21
21: ; preds = %3, %9, %19
%22 = phi i32 [ 0, %19 ], [ -1, %9 ], [ -1, %3 ]
ret i32 %22
}