#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 signalfd_siginfo {
  int ssi_signo;
};
typedef int /*<<< orphan*/ info;

/* Variables and functions */
int EPOLLERR;
int EPOLLHUP;
int /*<<< orphan*/ LOG_WARNING;
#define SIGHUP 130
#define SIGINT 129
#define SIGTERM 128
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int read(int, struct signalfd_siginfo *, int);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *);
int /*<<< orphan*/ users_sync();
int signal_read(int fd, int event, void *data) {
  int rc;
  struct signalfd_siginfo info;
  if ((event & EPOLLERR) == EPOLLERR || (event & EPOLLHUP) == EPOLLHUP)
    return -1;
  rc = read(fd, &info, sizeof(info));
  if (rc != sizeof(info))
    return -1;
  switch (info.ssi_signo) {
  case SIGHUP:
    syslog(LOG_WARNING, "Got HUP, re-reading passwd file");
    users_sync();
    break;
  case SIGTERM:
  case SIGINT:
    exit(0);
    break;
  }
  return 0;
}


x86 assembly (clang, -O0):
<signal_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    0x2e7c(%rip),%rcx
and    (%rcx),%eax
mov    0x2e73(%rip),%rcx
cmp    (%rcx),%eax
je     1188 <signal_read+0x48>
mov    -0xc(%rbp),%eax
mov    0x2e59(%rip),%rcx
and    (%rcx),%eax
mov    0x2e50(%rip),%rcx
cmp    (%rcx),%eax
jne    1194 <signal_read+0x54>
movl   $0xffffffff,-0x4(%rbp)
jmp    121b <signal_read+0xdb>
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x4,%edx
call   1030 <read@plt>
mov    %eax,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
cmp    $0x4,%rax
je     11c2 <signal_read+0x82>
movl   $0xffffffff,-0x4(%rbp)
jmp    121b <signal_read+0xdb>
mov    -0x20(%rbp),%eax
mov    %eax,-0x24(%rbp)
add    $0xffffff80,%eax
sub    $0x2,%eax
jb     120d <signal_read+0xcd>
jmp    11d9 <signal_read+0x99>
mov    -0x24(%rbp),%eax
sub    $0x82,%eax
jne    1214 <signal_read+0xd4>
jmp    11ec <signal_read+0xac>
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
lea    0xe04(%rip),%rsi
call   1040 <syslog@plt>
mov    $0x0,%al
call   1060 <users_sync@plt>
jmp    1214 <signal_read+0xd4>
xor    %edi,%edi
call   1050 <exit@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<signal_read>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e8c(%rip),%rax
not    %esi
mov    $0xffffffff,%ebx
test   %esi,(%rax)
je     11b0 <signal_read+0x70>
mov    0x2e72(%rip),%rax
test   %esi,(%rax)
je     11b0 <signal_read+0x70>
lea    0x8(%rsp),%rsi
mov    $0x4,%edx
call   1030 <read@plt>
cmp    $0x4,%eax
jne    11b0 <signal_read+0x70>
mov    0x8(%rsp),%eax
cmp    $0x82,%eax
je     1192 <signal_read+0x52>
xor    %ebx,%ebx
add    $0xffffff80,%eax
cmp    $0x2,%eax
jae    11b0 <signal_read+0x70>
xor    %edi,%edi
call   1050 <exit@plt>
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
lea    0xe5e(%rip),%rsi
call   1040 <syslog@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <users_sync@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.signalfd_siginfo = type { i32 }
@EPOLLERR = global i32 0
@EPOLLHUP = global i32 0
@LOG_WARNING = global i32 0
@.str = [32 x i8] c"Got HUP, re-reading passwd file\00"
define i32 @signal_read(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca %struct.signalfd_siginfo
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 %39
22: ; preds = %15
%23 = load i32, i32* %5
%24 = call i32 @read(i32 %23, %struct.signalfd_siginfo* %9, i32 4)
store i32 %24, i32* %8
%25 = load i32, i32* %8
%26 = sext i32 %25 to i64
%27 = icmp ne i64 %26, 4
br i1 %27, label %28, label %29
28: ; preds = %22
store i32 -1, i32* %4
br label %39
29: ; preds = %22
%30 = getelementptr inbounds %struct.signalfd_siginfo, %struct.signalfd_siginfo* %9, i32 0, i32 0
%31 = load i32, i32* %30
switch i32 %31, label %38 [
i32 130, label %32
i32 128, label %36
i32 129, label %36
]
32: ; preds = %29
%33 = load i32, i32* @LOG_WARNING
%34 = call i32 @syslog(i32 %33, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%35 = call i32 (...) @users_sync()
br label %38
36: ; preds = %29, %29
%37 = call i32 @exit(i32 0)
unreachable
38: ; preds = %29, %32
store i32 0, i32* %4
br label %39
39: ; preds = %38, %28, %21
%40 = load i32, i32* %4
ret i32 %40
}

LLVM IR (-O2):
%struct.signalfd_siginfo = type { i32 }
@EPOLLERR = global i32 0
@EPOLLHUP = global i32 0
@LOG_WARNING = global i32 0
@.str = [32 x i8] c"Got HUP, re-reading passwd file\00"
define i32 @signal_read(i32 %0, i32 %1, i8* nocapture readnone %2) {
%4 = alloca %struct.signalfd_siginfo
%5 = bitcast %struct.signalfd_siginfo* %4 to i8*
%6 = load i32, i32* @EPOLLERR
%7 = and i32 %6, %1
%8 = icmp eq i32 %7, %6
br i1 %8, label %25, 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 %25, label %13
13: ; preds = %9
%14 = call i32 @read(i32 %0, %struct.signalfd_siginfo* %4, i32 4)
%15 = icmp eq i32 %14, 4
br i1 %15, label %16, label %25
16: ; preds = %13
%17 = getelementptr inbounds %struct.signalfd_siginfo, %struct.signalfd_siginfo* %4, i64 0, i32 0
%18 = load i32, i32* %17
switch i32 %18, label %25 [
i32 130, label %19
i32 128, label %23
i32 129, label %23
]
19: ; preds = %16
%20 = load i32, i32* @LOG_WARNING
%21 = tail call i32 @syslog(i32 %20, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%22 = tail call i32 (...) @users_sync()
br label %25
23: ; preds = %16, %16
%24 = tail call i32 @exit(i32 0)
unreachable
25: ; preds = %19, %16, %13, %3, %9
%26 = phi i32 [ -1, %9 ], [ -1, %3 ], [ -1, %13 ], [ 0, %16 ], [ 0, %19 ]
ret i32 %26
}