#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 uint32_t;
struct inotify_event {
  int len;
  char *name;
};
typedef int /*<<< orphan*/ evdev;

/* Variables and functions */
scalar_t__ ENOENT;
int EPOLLERR;
int EPOLLHUP;
int /*<<< orphan*/ FIONREAD;
int /*<<< orphan*/ LOG_ERR;
int /*<<< orphan*/ LOG_WARNING;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int /*<<< orphan*/ evdev_try_add(int);
int evloop_remove(int);
int /*<<< orphan*/ free(struct inotify_event *);
int ioctl(int, int /*<<< orphan*/, int *);
int /*<<< orphan*/ logdebug(char *, ...);
int /*<<< orphan*/ logmsg(int /*<<< orphan*/, char *, ...);
scalar_t__ malloc(int);
int open(char *, int /*<<< orphan*/);
int read(int, struct inotify_event *, int);
int snprintf(char *, int, char *, char *, char *);
int /*<<< orphan*/ strerror(scalar_t__);
scalar_t__ strncmp(char *, char *, int);
void evdev_inotify_process(int fd, uint32_t events) {
  int ret;
  int efd;
  int qsize;
  struct inotify_event *all_ie;
  struct inotify_event *ie;
  char evdev[32];
  if (events & (EPOLLERR | EPOLLHUP)) {
    logmsg(LOG_WARNING, "inotify fd lost; this should not happen");
    ret = evloop_remove(fd);
    if (ret < 0)
      logmsg(LOG_ERR, "Could not remove inotify from event loop");
    close(fd);
    return;
  }
  ret = ioctl(fd, FIONREAD, &qsize);
  if (ret < 0) {
    logmsg(LOG_ERR, "Could not determine inotify queue size: %s",
           strerror(errno));
    return;
  }
  all_ie = (struct inotify_event *)malloc(qsize);
  if (all_ie == NULL) {
    logmsg(LOG_ERR, "Could not allocate %d bytes for inotify events", qsize);
    return;
  }
  ret = read(fd, all_ie, qsize);
  if (ret < 0) {
    logmsg(LOG_WARNING, "inotify read failed: %s", strerror(errno));
    free(all_ie);
    return;
  }
  qsize /= sizeof(struct inotify_event);
  for (ie = all_ie; (ie - all_ie) < qsize;
       ie += (1 + (ie->len / sizeof(struct inotify_event)))) {
    if ((ie->len == 0) || (ie->name == NULL)) {
      logdebug("inotify event with no name\n");
      continue;
    }
    logdebug("Found new event device %s/%s\n", "/dev/input", ie->name);
    if (strncmp("event", ie->name, 5)) {
      logdebug("Discarding %s/%s\n", "/dev/input", ie->name);
      continue;
    }
    ret = snprintf(evdev, sizeof(evdev), "%s/%s", "/dev/input", ie->name);
    if ((ret <= 0) || (ret >= sizeof(evdev)))
      continue;
    efd = open(evdev, O_RDWR);
    if (efd < 0) {
      if (errno != ENOENT)
        logmsg(LOG_WARNING, "Could not open %s: %s", evdev, strerror(errno));
      continue;
    }
    evdev_try_add(efd);
  }
  free(all_ie);
}


x86 assembly (clang, -O0):
<evdev_inotify_process>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    0x2de0(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2dc7(%rip),%rdx
or     (%rdx),%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     124e <evdev_inotify_process+0x7e>
mov    0x2dd3(%rip),%rax
mov    (%rax),%edi
lea    0xdf2(%rip),%rsi
mov    $0x0,%al
call   10c0 <logmsg@plt>
mov    -0x4(%rbp),%edi
call   1050 <evloop_remove@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1241 <evdev_inotify_process+0x71>
mov    0x2d6f(%rip),%rax
mov    (%rax),%edi
lea    0xdee(%rip),%rsi
mov    $0x0,%al
call   10c0 <logmsg@plt>
mov    -0x4(%rbp),%edi
call   1080 <close@plt>
jmp    14de <evdev_inotify_process+0x30e>
mov    -0x4(%rbp),%edi
mov    0x2d88(%rip),%rax
mov    (%rax),%esi
lea    -0x14(%rbp),%rdx
call   1070 <ioctl@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    12a3 <evdev_inotify_process+0xd3>
mov    0x2d29(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
mov    0x2d3d(%rip),%rax
mov    (%rax),%rdi
call   10e0 <strerror@plt>
mov    -0x54(%rbp),%edi
mov    %eax,%edx
lea    0xdba(%rip),%rsi
mov    $0x0,%al
call   10c0 <logmsg@plt>
jmp    14de <evdev_inotify_process+0x30e>
mov    -0x14(%rbp),%edi
call   10a0 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    12d9 <evdev_inotify_process+0x109>
mov    0x2cdf(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xdaf(%rip),%rsi
mov    $0x0,%al
call   10c0 <logmsg@plt>
jmp    14de <evdev_inotify_process+0x30e>
mov    -0x4(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1090 <read@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1331 <evdev_inotify_process+0x161>
mov    0x2cdc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x58(%rbp)
mov    0x2cb8(%rip),%rax
mov    (%rax),%rdi
call   10e0 <strerror@plt>
mov    -0x58(%rbp),%edi
mov    %eax,%edx
lea    0xd8f(%rip),%rsi
mov    $0x0,%al
call   10c0 <logmsg@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
jmp    14de <evdev_inotify_process+0x30e>
movslq -0x14(%rbp),%rax
shr    $0x4,%rax
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
sar    $0x4,%rax
movslq -0x14(%rbp),%rcx
cmp    %rcx,%rax
jge    14d5 <evdev_inotify_process+0x305>
mov    -0x28(%rbp),%rax
cmpl   $0x0,(%rax)
je     137c <evdev_inotify_process+0x1ac>
mov    -0x28(%rbp),%rax
cmpq   $0x0,0x8(%rax)
jne    138f <evdev_inotify_process+0x1bf>
lea    0xd40(%rip),%rdi
mov    $0x0,%al
call   10b0 <logdebug@plt>
jmp    14b5 <evdev_inotify_process+0x2e5>
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xd41(%rip),%rdi
lea    0xd58(%rip),%rsi
mov    $0x0,%al
call   10b0 <logdebug@plt>
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xd4d(%rip),%rdi
mov    $0x5,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
je     13f1 <evdev_inotify_process+0x221>
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xd30(%rip),%rdi
lea    0xd18(%rip),%rsi
mov    $0x0,%al
call   10b0 <logdebug@plt>
jmp    14b5 <evdev_inotify_process+0x2e5>
lea    -0x50(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%r8
mov    $0x20,%esi
lea    0xd17(%rip),%rdx
lea    0xced(%rip),%rcx
call   1060 <snprintf@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jle    1430 <evdev_inotify_process+0x260>
movslq -0xc(%rbp),%rax
cmp    $0x20,%rax
jb     1435 <evdev_inotify_process+0x265>
jmp    14b5 <evdev_inotify_process+0x2e5>
lea    -0x50(%rbp),%rdi
mov    0x2ba8(%rip),%rax
mov    (%rax),%esi
call   10d0 <open@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    14ad <evdev_inotify_process+0x2dd>
mov    0x2b65(%rip),%rax
mov    (%rax),%rax
mov    0x2b43(%rip),%rcx
cmp    (%rcx),%rax
je     14a8 <evdev_inotify_process+0x2d8>
mov    0x2b63(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x64(%rbp)
lea    -0x50(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    0x2b37(%rip),%rax
mov    (%rax),%rdi
call   10e0 <strerror@plt>
mov    -0x64(%rbp),%edi
mov    -0x60(%rbp),%rdx
mov    %eax,%ecx
lea    0xc85(%rip),%rsi
mov    $0x0,%al
call   10c0 <logmsg@plt>
jmp    14b5 <evdev_inotify_process+0x2e5>
mov    -0x10(%rbp),%edi
call   10f0 <evdev_try_add@plt>
mov    -0x28(%rbp),%rax
movslq (%rax),%rax
shr    $0x4,%rax
add    $0x1,%rax
shl    $0x4,%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    1344 <evdev_inotify_process+0x174>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<evdev_inotify_process>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %edi,%ebp
mov    0x2de1(%rip),%rax
mov    0x2dca(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
test   %esi,%ecx
je     1244 <evdev_inotify_process+0x74>
mov    0x2ddb(%rip),%rax
mov    (%rax),%edi
lea    0xdfa(%rip),%rsi
xor    %eax,%eax
call   10c0 <logmsg@plt>
mov    %ebp,%edi
call   1050 <evloop_remove@plt>
test   %eax,%eax
jns    122f <evdev_inotify_process+0x5f>
mov    0x2d81(%rip),%rax
mov    (%rax),%edi
lea    0xe00(%rip),%rsi
xor    %eax,%eax
call   10c0 <logmsg@plt>
mov    %ebp,%edi
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <close@plt>
mov    0x2d95(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %ebp,%edi
call   1070 <ioctl@plt>
test   %eax,%eax
js     13dd <evdev_inotify_process+0x20d>
mov    0x8(%rsp),%edi
call   10a0 <malloc@plt>
test   %rax,%rax
je     1402 <evdev_inotify_process+0x232>
mov    %rax,%r15
mov    0x8(%rsp),%edx
mov    %ebp,%edi
mov    %rax,%rsi
call   1090 <read@plt>
test   %eax,%eax
js     141f <evdev_inotify_process+0x24f>
mov    0x8(%rsp),%eax
mov    %eax,%ecx
sar    $0x4,%ecx
mov    %ecx,0x8(%rsp)
cmp    $0x10,%eax
jl     1449 <evdev_inotify_process+0x279>
lea    0xe1a(%rip),%r14
lea    0xe2f(%rip),%rbp
lea    0xe46(%rip),%r12
lea    0xe4a(%rip),%r13
mov    %r15,%rbx
jmp    1300 <evdev_inotify_process+0x130>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
xor    %eax,%eax
call   10b0 <logdebug@plt>
movslq (%rbx),%rax
and    $0xfffffffffffffff0,%rax
add    %rax,%rbx
add    $0x10,%rbx
mov    %rbx,%rax
sub    %r15,%rax
sar    $0x4,%rax
movslq 0x8(%rsp),%rcx
cmp    %rcx,%rax
jge    1449 <evdev_inotify_process+0x279>
cmpl   $0x0,(%rbx)
je     12d0 <evdev_inotify_process+0x100>
mov    0x8(%rbx),%rdx
test   %rdx,%rdx
je     12d0 <evdev_inotify_process+0x100>
mov    %rbp,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   10b0 <logdebug@plt>
mov    0x8(%rbx),%rsi
mov    %r13,%rdi
mov    $0x5,%edx
call   1040 <strncmp@plt>
mov    0x8(%rbx),%r8
test   %rax,%rax
je     134b <evdev_inotify_process+0x17b>
lea    0xdd2(%rip),%rdi
mov    %r12,%rsi
mov    %r8,%rdx
xor    %eax,%eax
call   10b0 <logdebug@plt>
jmp    12da <evdev_inotify_process+0x10a>
lea    0x10(%rsp),%rdi
mov    $0x20,%esi
lea    0xdc4(%rip),%rdx
mov    %r12,%rcx
call   1060 <snprintf@plt>
add    $0xffffffe0,%eax
cmp    $0xffffffe1,%eax
jb     12da <evdev_inotify_process+0x10a>
mov    0x2c71(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rdi
call   10d0 <open@plt>
test   %eax,%eax
js     1393 <evdev_inotify_process+0x1c3>
mov    %eax,%edi
call   10f0 <evdev_try_add@plt>
jmp    12da <evdev_inotify_process+0x10a>
mov    0x2c26(%rip),%rax
mov    (%rax),%rdi
mov    0x2c04(%rip),%rax
cmp    (%rax),%rdi
je     12da <evdev_inotify_process+0x10a>
mov    0x2c24(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
call   10e0 <strerror@plt>
mov    0xc(%rsp),%edi
lea    0xd5c(%rip),%rsi
lea    0x10(%rsp),%rdx
mov    %eax,%ecx
xor    %eax,%eax
call   10c0 <logmsg@plt>
jmp    12da <evdev_inotify_process+0x10a>
mov    0x2bbc(%rip),%rax
mov    (%rax),%ebx
mov    0x2bd3(%rip),%rax
mov    (%rax),%rdi
call   10e0 <strerror@plt>
lea    0xc55(%rip),%rsi
mov    %ebx,%edi
mov    %eax,%edx
jmp    1416 <evdev_inotify_process+0x246>
mov    0x2b97(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rsp),%edx
lea    0xc66(%rip),%rsi
xor    %eax,%eax
call   10c0 <logmsg@plt>
jmp    1451 <evdev_inotify_process+0x281>
mov    0x2bb2(%rip),%rax
mov    (%rax),%ebp
mov    0x2b91(%rip),%rax
mov    (%rax),%rdi
call   10e0 <strerror@plt>
lea    0xc6d(%rip),%rsi
mov    %ebp,%edi
mov    %eax,%edx
xor    %eax,%eax
call   10c0 <logmsg@plt>
mov    %r15,%rdi
call   1030 <free@plt>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.inotify_event = type { i32, i8* }
@EPOLLERR = global i32 0
@EPOLLHUP = global i32 0
@LOG_WARNING = global i32 0
@.str = [40 x i8] c"inotify fd lost; this should not happen\00"
@LOG_ERR = global i32 0
@.str.1 = [41 x i8] c"Could not remove inotify from event loop\00"
@FIONREAD = global i32 0
@.str.2 = [43 x i8] c"Could not determine inotify queue size: %s\00"
@errno = global i64 0
@.str.3 = [47 x i8] c"Could not allocate %d bytes for inotify events\00"
@.str.4 = [24 x i8] c"inotify read failed: %s\00"
@.str.5 = [28 x i8] c"inotify event with no name\0A\00"
@.str.6 = [30 x i8] c"Found new event device %s/%s\0A\00"
@.str.7 = [11 x i8] c"/dev/input\00"
@.str.8 = [6 x i8] c"event\00"
@.str.9 = [18 x i8] c"Discarding %s/%s\0A\00"
@.str.10 = [6 x i8] c"%s/%s\00"
@O_RDWR = global i32 0
@ENOENT = global i64 0
@.str.11 = [22 x i8] c"Could not open %s: %s\00"
define void @evdev_inotify_process(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.inotify_event*
%9 = alloca %struct.inotify_event*
%10 = alloca [32 x i8]
store i32 %0, i32* %3
store i32 %1, i32* %4
%11 = load i32, i32* %4
%12 = load i32, i32* @EPOLLERR
%13 = load i32, i32* @EPOLLHUP
%14 = or i32 %12, %13
%15 = and i32 %11, %14
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %30
17: ; preds = %2
%18 = load i32, i32* @LOG_WARNING
%19 = call i32 (i32, i8*, ...) @logmsg(i32 %18, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%20 = load i32, i32* %3
%21 = call i32 @evloop_remove(i32 %20)
store i32 %21, i32* %5
%22 = load i32, i32* %5
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %17
%25 = load i32, i32* @LOG_ERR
%26 = call i32 (i32, i8*, ...) @logmsg(i32 %25, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0))
br label %27
27: ; preds = %24, %17
%28 = load i32, i32* %3
%29 = call i32 @close(i32 %28)
br label %153
30: ; preds = %2
%31 = load i32, i32* %3
%32 = load i32, i32* @FIONREAD
%33 = call i32 @ioctl(i32 %31, i32 %32, i32* %7)
store i32 %33, i32* %5
%34 = load i32, i32* %5
%35 = icmp slt i32 %34, 0
br i1 %35, label %36, label %41
36: ; preds = %30
%37 = load i32, i32* @LOG_ERR
%38 = load i64, i64* @errno
%39 = call i32 @strerror(i64 %38)
%40 = call i32 (i32, i8*, ...) @logmsg(i32 %37, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i32 %39)
br label %153
41: ; preds = %30
%42 = load i32, i32* %7
%43 = call i64 @malloc(i32 %42)
%44 = inttoptr i64 %43 to %struct.inotify_event*
store %struct.inotify_event* %44, %struct.inotify_event** %8
%45 = load %struct.inotify_event*, %struct.inotify_event** %8
%46 = icmp eq %struct.inotify_event* %45, null
br i1 %46, label %47, label %51
47: ; preds = %41
%48 = load i32, i32* @LOG_ERR
%49 = load i32, i32* %7
%50 = call i32 (i32, i8*, ...) @logmsg(i32 %48, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0), i32 %49)
br label %153
51: ; preds = %41
%52 = load i32, i32* %3
%53 = load %struct.inotify_event*, %struct.inotify_event** %8
%54 = load i32, i32* %7
%55 = call i32 @read(i32 %52, %struct.inotify_event* %53, i32 %54)
store i32 %55, i32* %5
%56 = load i32, i32* %5
%57 = icmp slt i32 %56, 0
br i1 %57, label %58, label %65
58: ; preds = %51
%59 = load i32, i32* @LOG_WARNING
%60 = load i64, i64* @errno
%61 = call i32 @strerror(i64 %60)
%62 = call i32 (i32, i8*, ...) @logmsg(i32 %59, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i32 %61)
%63 = load %struct.inotify_event*, %struct.inotify_event** %8
%64 = call i32 @free(%struct.inotify_event* %63)
br label %153
65: ; preds = %51
%66 = load i32, i32* %7
%67 = sext i32 %66 to i64
%68 = udiv i64 %67, 16
%69 = trunc i64 %68 to i32
store i32 %69, i32* %7
%70 = load %struct.inotify_event*, %struct.inotify_event** %8
store %struct.inotify_event* %70, %struct.inotify_event** %9
br label %71
71: ; preds = %141, %65
%72 = load %struct.inotify_event*, %struct.inotify_event** %9
%73 = load %struct.inotify_event*, %struct.inotify_event** %8
%74 = ptrtoint %struct.inotify_event* %72 to i64
%75 = ptrtoint %struct.inotify_event* %73 to i64
%76 = sub i64 %74, %75
%77 = sdiv exact i64 %76, 16
%78 = load i32, i32* %7
%79 = sext i32 %78 to i64
%80 = icmp slt i64 %77, %79
br i1 %80, label %81, label %150
81: ; preds = %71
%82 = load %struct.inotify_event*, %struct.inotify_event** %9
%83 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %82, i32 0, i32 0
%84 = load i32, i32* %83
%85 = icmp eq i32 %84, 0
br i1 %85, label %91, label %86
86: ; preds = %81
%87 = load %struct.inotify_event*, %struct.inotify_event** %9
%88 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %87, i32 0, i32 1
%89 = load i8*, i8** %88
%90 = icmp eq i8* %89, null
br i1 %90, label %91, label %93
91: ; preds = %86, %81
%92 = call i32 (i8*, ...) @logdebug(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
br label %141
93: ; preds = %86
%94 = load %struct.inotify_event*, %struct.inotify_event** %9
%95 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %94, i32 0, i32 1
%96 = load i8*, i8** %95
%97 = call i32 (i8*, ...) @logdebug(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), i8* %96)
%98 = load %struct.inotify_event*, %struct.inotify_event** %9
%99 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %98, i32 0, i32 1
%100 = load i8*, i8** %99
%101 = call i64 @strncmp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0), i8* %100, i32 5)
%102 = icmp ne i64 %101, 0
br i1 %102, label %103, label %108
103: ; preds = %93
%104 = load %struct.inotify_event*, %struct.inotify_event** %9
%105 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %104, i32 0, i32 1
%106 = load i8*, i8** %105
%107 = call i32 (i8*, ...) @logdebug(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), i8* %106)
br label %141
108: ; preds = %93
%109 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%110 = load %struct.inotify_event*, %struct.inotify_event** %9
%111 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %110, i32 0, i32 1
%112 = load i8*, i8** %111
%113 = call i32 @snprintf(i8* %109, i32 32, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), i8* %112)
store i32 %113, i32* %5
%114 = load i32, i32* %5
%115 = icmp sle i32 %114, 0
br i1 %115, label %120, label %116
116: ; preds = %108
%117 = load i32, i32* %5
%118 = sext i32 %117 to i64
%119 = icmp uge i64 %118, 32
br i1 %119, label %120, label %121
120: ; preds = %116, %108
br label %141
121: ; preds = %116
%122 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%123 = load i32, i32* @O_RDWR
%124 = call i32 @open(i8* %122, i32 %123)
store i32 %124, i32* %6
%125 = load i32, i32* %6
%126 = icmp slt i32 %125, 0
br i1 %126, label %127, label %138
127: ; preds = %121
%128 = load i64, i64* @errno
%129 = load i64, i64* @ENOENT
%130 = icmp ne i64 %128, %129
br i1 %130, label %131, label %137
131: ; preds = %127
%132 = load i32, i32* @LOG_WARNING
%133 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%134 = load i64, i64* @errno
%135 = call i32 @strerror(i64 %134)
%136 = call i32 (i32, i8*, ...) @logmsg(i32 %132, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.11, i64 0, i64 0), i8* %133, i32 %135)
br label %137
137: ; preds = %131, %127
br label %141
138: ; preds = %121
%139 = load i32, i32* %6
%140 = call i32 @evdev_try_add(i32 %139)
br label %141
141: ; preds = %138, %137, %120, %103, %91
%142 = load %struct.inotify_event*, %struct.inotify_event** %9
%143 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %142, i32 0, i32 0
%144 = load i32, i32* %143
%145 = sext i32 %144 to i64
%146 = udiv i64 %145, 16
%147 = add i64 1, %146
%148 = load %struct.inotify_event*, %struct.inotify_event** %9
%149 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %148, i64 %147
store %struct.inotify_event* %149, %struct.inotify_event** %9
br label %71
150: ; preds = %71
%151 = load %struct.inotify_event*, %struct.inotify_event** %8
%152 = call i32 @free(%struct.inotify_event* %151)
br label %153
153: ; preds = %150, %58, %47, %36, %27
ret void
}

LLVM IR (-O2):
%struct.inotify_event = type { i32, i8* }
@EPOLLERR = global i32 0
@EPOLLHUP = global i32 0
@LOG_WARNING = global i32 0
@.str = [40 x i8] c"inotify fd lost; this should not happen\00"
@LOG_ERR = global i32 0
@.str.1 = [41 x i8] c"Could not remove inotify from event loop\00"
@FIONREAD = global i32 0
@.str.2 = [43 x i8] c"Could not determine inotify queue size: %s\00"
@errno = global i64 0
@.str.3 = [47 x i8] c"Could not allocate %d bytes for inotify events\00"
@.str.4 = [24 x i8] c"inotify read failed: %s\00"
@.str.5 = [28 x i8] c"inotify event with no name\0A\00"
@.str.6 = [30 x i8] c"Found new event device %s/%s\0A\00"
@.str.7 = [11 x i8] c"/dev/input\00"
@.str.8 = [6 x i8] c"event\00"
@.str.9 = [18 x i8] c"Discarding %s/%s\0A\00"
@.str.10 = [6 x i8] c"%s/%s\00"
@O_RDWR = global i32 0
@ENOENT = global i64 0
@.str.11 = [22 x i8] c"Could not open %s: %s\00"
define void @evdev_inotify_process(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca [32 x i8]
%5 = bitcast i32* %3 to i8*
%6 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%7 = load i32, i32* @EPOLLERR
%8 = load i32, i32* @EPOLLHUP
%9 = or i32 %8, %7
%10 = and i32 %9, %1
%11 = icmp eq i32 %10, 0
br i1 %11, label %22, label %12
12: ; preds = %2
%13 = load i32, i32* @LOG_WARNING
%14 = tail call i32 (i32, i8*, ...) @logmsg(i32 %13, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%15 = tail call i32 @evloop_remove(i32 %0)
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %12
%18 = load i32, i32* @LOG_ERR
%19 = tail call i32 (i32, i8*, ...) @logmsg(i32 %18, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %17, %12
%21 = tail call i32 @close(i32 %0)
br label %105
22: ; preds = %2
%23 = load i32, i32* @FIONREAD
%24 = call i32 @ioctl(i32 %0, i32 %23, i32* %3)
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %22
%27 = load i32, i32* @LOG_ERR
%28 = load i64, i64* @errno
%29 = call i32 @strerror(i64 %28)
%30 = call i32 (i32, i8*, ...) @logmsg(i32 %27, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i32 %29)
br label %105
31: ; preds = %22
%32 = load i32, i32* %3
%33 = call i64 @malloc(i32 %32)
%34 = inttoptr i64 %33 to %struct.inotify_event*
%35 = icmp eq i64 %33, 0
br i1 %35, label %36, label %40
36: ; preds = %31
%37 = load i32, i32* @LOG_ERR
%38 = load i32, i32* %3
%39 = call i32 (i32, i8*, ...) @logmsg(i32 %37, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0), i32 %38)
br label %105
40: ; preds = %31
%41 = load i32, i32* %3
%42 = call i32 @read(i32 %0, %struct.inotify_event* %34, i32 %41)
%43 = icmp slt i32 %42, 0
br i1 %43, label %44, label %50
44: ; preds = %40
%45 = load i32, i32* @LOG_WARNING
%46 = load i64, i64* @errno
%47 = call i32 @strerror(i64 %46)
%48 = call i32 (i32, i8*, ...) @logmsg(i32 %45, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i32 %47)
%49 = call i32 @free(%struct.inotify_event* %34)
br label %105
50: ; preds = %40
%51 = load i32, i32* %3
%52 = ashr i32 %51, 4
store i32 %52, i32* %3
%53 = icmp sgt i32 %51, 15
br i1 %53, label %54, label %103
54: ; preds = %50, %91
%55 = phi %struct.inotify_event* [ %96, %91 ], [ %34, %50 ]
%56 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %55, i64 0, i32 0
%57 = load i32, i32* %56
%58 = icmp eq i32 %57, 0
br i1 %58, label %63, label %59
59: ; preds = %54
%60 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %55, i64 0, i32 1
%61 = load i8*, i8** %60
%62 = icmp eq i8* %61, null
br i1 %62, label %63, label %65
63: ; preds = %59, %54
%64 = call i32 (i8*, ...) @logdebug(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
br label %91
65: ; preds = %59
%66 = call i32 (i8*, ...) @logdebug(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), i8* %61)
%67 = load i8*, i8** %60
%68 = call i64 @strncmp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0), i8* %67, i32 5)
%69 = icmp eq i64 %68, 0
%70 = load i8*, i8** %60
br i1 %69, label %73, label %71
71: ; preds = %65
%72 = call i32 (i8*, ...) @logdebug(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), i8* %70)
br label %91
73: ; preds = %65
%74 = call i32 @snprintf(i8* %6, i32 32, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), i8* %70)
%75 = add i32 %74, -32
%76 = icmp ult i32 %75, -31
br i1 %76, label %91, label %77
77: ; preds = %73
%78 = load i32, i32* @O_RDWR
%79 = call i32 @open(i8* %6, i32 %78)
%80 = icmp slt i32 %79, 0
br i1 %80, label %81, label %89
81: ; preds = %77
%82 = load i64, i64* @errno
%83 = load i64, i64* @ENOENT
%84 = icmp eq i64 %82, %83
br i1 %84, label %91, label %85
85: ; preds = %81
%86 = load i32, i32* @LOG_WARNING
%87 = call i32 @strerror(i64 %82)
%88 = call i32 (i32, i8*, ...) @logmsg(i32 %86, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.11, i64 0, i64 0), i8* %6, i32 %87)
br label %91
89: ; preds = %77
%90 = call i32 @evdev_try_add(i32 %79)
br label %91
91: ; preds = %81, %85, %73, %89, %71, %63
%92 = load i32, i32* %56
%93 = sext i32 %92 to i64
%94 = lshr i64 %93, 4
%95 = add nuw nsw i64 %94, 1
%96 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %55, i64 %95
%97 = ptrtoint %struct.inotify_event* %96 to i64
%98 = sub i64 %97, %33
%99 = ashr exact i64 %98, 4
%100 = load i32, i32* %3
%101 = sext i32 %100 to i64
%102 = icmp slt i64 %99, %101
br i1 %102, label %54, label %103
103: ; preds = %91, %50
%104 = call i32 @free(%struct.inotify_event* %34)
br label %105
105: ; preds = %103, %44, %36, %26, %20
ret void
}