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

/* Variables and functions */
scalar_t__ EINTR;
scalar_t__ ENOENT;
int LINE_MAX;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ O_WRONLY;
int PATH_MAX;
int /*<<< orphan*/ W_OK;
int access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ close(int);
char *dirname(char *);
scalar_t__ errno;
int eventfd(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ puts(char *);
int read(int, int /*<<< orphan*/ *, int);
int snprintf(char *, int, char *, ...);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
scalar_t__ strlen(char *);
int write(int, char *, scalar_t__);
int main(int argc, char **argv) {
  int efd = -1;
  int cfd = -1;
  int oomfd = -1;
  int event_control = -1;
  char event_control_path[PATH_MAX];
  char oom_control_path[PATH_MAX];
  char line[LINE_MAX];
  int ret;
  if (argc != 2) {
    fputs("Usage: cgroup_event_listener <path-to-control-file>\n", stderr);
    return 1;
  }
  cfd = open(argv[1], O_RDONLY);
  if (cfd == -1) {
    fprintf(stderr, "Cannot open %s: %s\n", argv[1], strerror(errno));
    goto out;
  }
  ret = snprintf(event_control_path, PATH_MAX, "%s/cgroup.event_control",
                 dirname(argv[1]));
  if (ret >= PATH_MAX) {
    fputs("Path to cgroup.event_control is too long\n", stderr);
    goto out;
  }
  event_control = open(event_control_path, O_WRONLY);
  if (event_control == -1) {
    fprintf(stderr, "Cannot open %s: %s\n", event_control_path,
            strerror(errno));
    goto out;
  }
  efd = eventfd(0, 0);
  if (efd == -1) {
    perror("eventfd() failed");
    goto out;
  }
  ret = snprintf(oom_control_path, PATH_MAX, "%s/memory.oom_control", argv[1]);
  if (ret >= PATH_MAX) {
    fputs("Path to memory.oom_control is too long\n", stderr);
    goto out;
  }
  oomfd = open(oom_control_path, O_RDONLY);
  if (oomfd == -1) {
    fprintf(stderr, "Cannot open %s: %s\n", oom_control_path, strerror(errno));
    goto out;
  }
  ret = snprintf(line, LINE_MAX, "%d %d", efd, oomfd);
  if (ret >= LINE_MAX) {
    fputs("Arguments string is too long\n", stderr);
    goto out;
  }
  ret = write(event_control, line, strlen(line) + 1);
  if (ret == -1) {
    perror("Cannot write to cgroup.event_control");
    goto out;
  }
  do {
    uint64_t result;
    ret = read(efd, &result, sizeof(result));
    if (ret == -1) {
      if (errno == EINTR)
        continue;
      perror("Cannot read from eventfd");
      break;
    }
    assert(ret == sizeof(result));
    ret = access(event_control_path, W_OK);
    if ((ret == -1) && (errno == ENOENT)) {
      puts("The cgroup seems to have removed.");
      ret = 0;
      break;
    }
    if (ret == -1) {
      perror("cgroup.event_control "
             "is not accessible any more");
      break;
    }
    printf("%s: crossed\n", argv[1]);
  } while (0);
out:
  if (efd >= 0)
    close(efd);
  if (event_control >= 0)
    close(event_control);
  if (cfd >= 0)
    close(cfd);
  return (ret != 0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
movl   $0xffffffff,-0x18(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
movl   $0xffffffff,-0x20(%rbp)
mov    0x2db4(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rdx
mov    %rdx,-0x28(%rbp)
mov    %rcx,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x68(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x30(%rbp)
mov    (%rax),%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x60(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
mov    0x2d52(%rip),%rax
mov    (%rax),%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x40(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     12d6 <main+0xd6>
mov    0x2d0b(%rip),%rax
mov    (%rax),%esi
lea    0xd42(%rip),%rdi
call   1090 <fputs@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x48(%rbp)
jmp    1693 <main+0x493>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2cfb(%rip),%rax
mov    (%rax),%esi
call   10e0 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    133b <main+0x13b>
mov    0x2cc0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x74(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x70(%rbp)
mov    0x2ca0(%rip),%rax
mov    (%rax),%rdi
call   1120 <strerror@plt>
mov    -0x74(%rbp),%edi
mov    -0x70(%rbp),%rdx
mov    %rax,%rcx
lea    0xd04(%rip),%rsi
call   10d0 <fprintf@plt>
jmp    1647 <main+0x447>
mov    0x2cae(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x78(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <dirname@plt>
mov    -0x68(%rbp),%rdi
mov    -0x78(%rbp),%esi
mov    %rax,%rcx
lea    0xce4(%rip),%rdx
mov    $0x0,%al
call   1070 <snprintf@plt>
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%eax
mov    0x2c77(%rip),%rcx
cmp    (%rcx),%eax
jl     139b <main+0x19b>
mov    0x2c38(%rip),%rax
mov    (%rax),%esi
lea    0xcd0(%rip),%rdi
call   1090 <fputs@plt>
jmp    1647 <main+0x447>
mov    -0x68(%rbp),%rdi
mov    0x2bf2(%rip),%rax
mov    (%rax),%esi
call   10e0 <open@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    13f0 <main+0x1f0>
mov    0x2bff(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x7c(%rbp)
mov    0x2beb(%rip),%rax
mov    (%rax),%rdi
call   1120 <strerror@plt>
mov    -0x7c(%rbp),%edi
mov    -0x68(%rbp),%rdx
mov    %rax,%rcx
lea    0xc4f(%rip),%rsi
call   10d0 <fprintf@plt>
jmp    1647 <main+0x447>
xor    %esi,%esi
mov    %esi,%edi
call   1110 <eventfd@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1417 <main+0x217>
lea    0xc7e(%rip),%rdi
call   1100 <perror@plt>
jmp    1647 <main+0x447>
mov    -0x60(%rbp),%rdi
mov    0x2bce(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
lea    0xc69(%rip),%rdx
mov    $0x0,%al
call   1070 <snprintf@plt>
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%eax
mov    0x2ba9(%rip),%rcx
cmp    (%rcx),%eax
jl     1469 <main+0x269>
mov    0x2b6a(%rip),%rax
mov    (%rax),%esi
lea    0xc53(%rip),%rdi
call   1090 <fputs@plt>
jmp    1647 <main+0x447>
mov    -0x60(%rbp),%rdi
mov    0x2b6c(%rip),%rax
mov    (%rax),%esi
call   10e0 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    14be <main+0x2be>
mov    0x2b31(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x80(%rbp)
mov    0x2b1d(%rip),%rax
mov    (%rax),%rdi
call   1120 <strerror@plt>
mov    -0x80(%rbp),%edi
mov    -0x60(%rbp),%rdx
mov    %rax,%rcx
lea    0xb81(%rip),%rsi
call   10d0 <fprintf@plt>
jmp    1647 <main+0x447>
mov    -0x58(%rbp),%rdi
mov    0x2b0f(%rip),%rax
mov    (%rax),%esi
mov    -0x14(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
lea    0xc01(%rip),%rdx
mov    $0x0,%al
call   1070 <snprintf@plt>
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%eax
mov    0x2aeb(%rip),%rcx
cmp    (%rcx),%eax
jl     150f <main+0x30f>
mov    0x2ac4(%rip),%rax
mov    (%rax),%esi
lea    0xbdb(%rip),%rdi
call   1090 <fputs@plt>
jmp    1647 <main+0x447>
mov    -0x58(%rbp),%rdi
mov    -0x20(%rbp),%eax
mov    %eax,-0x84(%rbp)
call   1050 <strlen@plt>
mov    -0x84(%rbp),%edi
mov    -0x58(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1040 <write@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0xffffffff,-0x44(%rbp)
jne    1555 <main+0x355>
lea    0xbb3(%rip),%rdi
call   1100 <perror@plt>
jmp    1647 <main+0x447>
jmp    155a <main+0x35a>
mov    -0x14(%rbp),%edi
lea    -0x4c(%rbp),%rsi
mov    $0x4,%edx
call   10b0 <read@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0xffffffff,-0x44(%rbp)
jne    15a8 <main+0x3a8>
mov    0x2a39(%rip),%rax
mov    (%rax),%rax
mov    0x2a27(%rip),%rcx
cmp    (%rcx),%rax
jne    1597 <main+0x397>
jmp    163d <main+0x43d>
lea    0xb85(%rip),%rdi
call   1100 <perror@plt>
jmp    1642 <main+0x442>
movslq -0x44(%rbp),%rax
cmp    $0x4,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10c0 <assert@plt>
mov    -0x68(%rbp),%rdi
mov    0x2a08(%rip),%rax
mov    (%rax),%esi
call   10f0 <access@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0xffffffff,-0x44(%rbp)
jne    160e <main+0x40e>
mov    0x29d5(%rip),%rax
mov    (%rax),%rax
mov    0x29b3(%rip),%rcx
cmp    (%rcx),%rax
jne    160e <main+0x40e>
lea    0xb3f(%rip),%rdi
call   1030 <puts@plt>
movl   $0x0,-0x44(%rbp)
jmp    1642 <main+0x442>
cmpl   $0xffffffff,-0x44(%rbp)
jne    1629 <main+0x429>
lea    0xb3f(%rip),%rdi
call   1100 <perror@plt>
jmp    1642 <main+0x442>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xb56(%rip),%rdi
call   1060 <printf@plt>
jmp    1642 <main+0x442>
jmp    1647 <main+0x447>
cmpl   $0x0,-0x14(%rbp)
jl     1659 <main+0x459>
mov    -0x14(%rbp),%edi
call   10a0 <close@plt>
cmpl   $0x0,-0x20(%rbp)
jl     166b <main+0x46b>
mov    -0x20(%rbp),%edi
call   10a0 <close@plt>
cmpl   $0x0,-0x18(%rbp)
jl     167d <main+0x47d>
mov    -0x18(%rbp),%edi
call   10a0 <close@plt>
cmpl   $0x0,-0x44(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x48(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    0x2dd8(%rip),%rbx
mov    (%rbx),%eax
mov    %rsp,%r15
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
mov    %rsp,%r12
sub    %rax,%r12
mov    %r12,%rsp
mov    0x2d9d(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r14
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
cmp    $0x2,%edi
jne    13d3 <main+0x1d3>
mov    0x8(%rsi),%rdi
mov    0x2d7e(%rip),%rax
mov    %rsi,%r13
mov    (%rax),%esi
call   10e0 <open@plt>
cmp    $0xffffffff,%eax
je     13f2 <main+0x1f2>
mov    %eax,-0x34(%rbp)
mov    (%rbx),%ebx
mov    %r13,-0x40(%rbp)
mov    0x8(%r13),%rdi
call   1080 <dirname@plt>
lea    0xdbb(%rip),%rdx
mov    %r15,%rdi
mov    %ebx,%esi
mov    %rax,%rcx
xor    %eax,%eax
call   1070 <snprintf@plt>
mov    %eax,%ebx
mov    0x2d4a(%rip),%rax
cmp    (%rax),%ebx
jge    1427 <main+0x227>
mov    %rax,%r13
mov    0x2ce0(%rip),%rax
mov    (%rax),%esi
mov    %r15,%rdi
call   10e0 <open@plt>
cmp    $0xffffffff,%eax
je     1441 <main+0x241>
mov    %eax,-0x30(%rbp)
xor    %edi,%edi
xor    %esi,%esi
call   1110 <eventfd@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0xffffffff,%eax
je     14e2 <main+0x2e2>
mov    0x0(%r13),%esi
mov    -0x40(%rbp),%rax
mov    0x8(%rax),%rcx
lea    0xda6(%rip),%rdx
mov    %r12,%rdi
xor    %eax,%eax
call   1070 <snprintf@plt>
mov    %eax,%ebx
cmp    0x0(%r13),%eax
jge    1474 <main+0x274>
mov    0x2ccd(%rip),%rax
mov    (%rax),%esi
mov    %r12,%rdi
call   10e0 <open@plt>
cmp    $0xffffffff,%eax
je     1492 <main+0x292>
mov    0x2cab(%rip),%r13
mov    0x0(%r13),%esi
lea    0xda2(%rip),%rdx
mov    %r14,%rdi
mov    -0x2c(%rbp),%r12d
mov    %r12d,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   1070 <snprintf@plt>
cmp    0x0(%r13),%eax
jge    14c9 <main+0x2c9>
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rdx
mov    -0x30(%rbp),%edi
mov    %r14,%rsi
call   1040 <write@plt>
cmp    $0xffffffff,%eax
je     153f <main+0x33f>
lea    -0x44(%rbp),%rsi
mov    %r12d,%edi
mov    $0x4,%edx
call   10b0 <read@plt>
cmp    $0xffffffff,%eax
je     14f0 <main+0x2f0>
xor    %edi,%edi
cmp    $0x4,%eax
sete   %dil
call   10c0 <assert@plt>
mov    0x2c2b(%rip),%rax
mov    (%rax),%esi
mov    %r15,%rdi
call   10f0 <access@plt>
cmp    $0xffffffff,%eax
je     1519 <main+0x319>
mov    %eax,%ebx
mov    -0x40(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xdc5(%rip),%rdi
call   1060 <printf@plt>
jmp    1550 <main+0x350>
mov    0x2be6(%rip),%rax
mov    (%rax),%esi
lea    0xc1d(%rip),%rdi
call   1090 <fputs@plt>
mov    $0x1,%eax
jmp    157c <main+0x37c>
mov    0x2bc7(%rip),%rax
mov    (%rax),%ebx
mov    0x8(%r13),%r14
mov    0x2bb2(%rip),%rax
mov    (%rax),%rdi
call   1120 <strerror@plt>
lea    0xc20(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %rax,%rcx
call   10d0 <fprintf@plt>
jmp    1575 <main+0x375>
mov    0x2b92(%rip),%rax
mov    (%rax),%esi
lea    0xc2a(%rip),%rdi
call   1090 <fputs@plt>
jmp    1569 <main+0x369>
mov    0x2b78(%rip),%rax
mov    (%rax),%r14d
mov    0x2b66(%rip),%rax
mov    (%rax),%rdi
call   1120 <strerror@plt>
lea    0xbd4(%rip),%rsi
mov    %r14d,%edi
mov    %r15,%rdx
mov    %rax,%rcx
call   10d0 <fprintf@plt>
jmp    1569 <main+0x369>
mov    0x2b45(%rip),%rax
mov    (%rax),%esi
lea    0xc2e(%rip),%rdi
call   1090 <fputs@plt>
mov    -0x2c(%rbp),%r12d
jmp    1550 <main+0x350>
mov    0x2b27(%rip),%rax
mov    (%rax),%r14d
mov    0x2b15(%rip),%rax
mov    (%rax),%rdi
call   1120 <strerror@plt>
lea    0xb83(%rip),%rsi
mov    %r14d,%edi
mov    %r12,%rdx
mov    %rax,%rcx
call   10d0 <fprintf@plt>
mov    -0x2c(%rbp),%r12d
jmp    1550 <main+0x350>
mov    %eax,%ebx
mov    0x2aee(%rip),%rax
mov    (%rax),%esi
lea    0xc05(%rip),%rdi
call   1090 <fputs@plt>
jmp    1550 <main+0x350>
lea    0xba2(%rip),%rdi
call   1100 <perror@plt>
jmp    155d <main+0x35d>
mov    0x2ac1(%rip),%rax
mov    (%rax),%rax
mov    0x2aaf(%rip),%rcx
mov    $0xffffffff,%ebx
cmp    (%rcx),%rax
je     1550 <main+0x350>
lea    0xc11(%rip),%rdi
call   1100 <perror@plt>
jmp    1550 <main+0x350>
mov    0x2a98(%rip),%rax
mov    (%rax),%rax
mov    0x2a76(%rip),%rcx
cmp    (%rcx),%rax
jne    158b <main+0x38b>
lea    0xc06(%rip),%rdi
call   1030 <puts@plt>
xor    %ebx,%ebx
jmp    1550 <main+0x350>
lea    0xbb8(%rip),%rdi
call   1100 <perror@plt>
mov    $0xffffffff,%ebx
test   %r12d,%r12d
js     155d <main+0x35d>
mov    %r12d,%edi
call   10a0 <close@plt>
mov    -0x30(%rbp),%edi
test   %edi,%edi
js     1569 <main+0x369>
call   10a0 <close@plt>
mov    -0x34(%rbp),%edi
test   %edi,%edi
js     1575 <main+0x375>
call   10a0 <close@plt>
xor    %eax,%eax
test   %ebx,%ebx
setne  %al
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xbcc(%rip),%rdi
jmp    1546 <main+0x346>

LLVM IR (-O0):
@PATH_MAX = global i32 0
@LINE_MAX = global i32 0
@.str = [53 x i8] c"Usage: cgroup_event_listener <path-to-control-file>\0A\00"
@stderr = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [20 x i8] c"Cannot open %s: %s\0A\00"
@errno = global i64 0
@.str.2 = [24 x i8] c"%s/cgroup.event_control\00"
@.str.3 = [42 x i8] c"Path to cgroup.event_control is too long\0A\00"
@O_WRONLY = global i32 0
@.str.4 = [17 x i8] c"eventfd() failed\00"
@.str.5 = [22 x i8] c"%s/memory.oom_control\00"
@.str.6 = [40 x i8] c"Path to memory.oom_control is too long\0A\00"
@.str.7 = [6 x i8] c"%d %d\00"
@.str.8 = [30 x i8] c"Arguments string is too long\0A\00"
@.str.9 = [37 x i8] c"Cannot write to cgroup.event_control\00"
@EINTR = global i64 0
@.str.10 = [25 x i8] c"Cannot read from eventfd\00"
@W_OK = global i32 0
@ENOENT = global i64 0
@.str.11 = [34 x i8] c"The cgroup seems to have removed.\00"
@.str.12 = [48 x i8] c"cgroup.event_control is not accessible any more\00"
@.str.13 = [13 x i8] c"%s: crossed\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i64
%13 = alloca i64
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -1, i32* %6
store i32 -1, i32* %7
store i32 -1, i32* %8
store i32 -1, i32* %9
%17 = load i32, i32* @PATH_MAX
%18 = zext i32 %17 to i64
%19 = call i8* @llvm.stacksave()
store i8* %19, i8** %10
%20 = alloca i8, i64 %18
store i64 %18, i64* %11
%21 = load i32, i32* @PATH_MAX
%22 = zext i32 %21 to i64
%23 = alloca i8, i64 %22
store i64 %22, i64* %12
%24 = load i32, i32* @LINE_MAX
%25 = zext i32 %24 to i64
%26 = alloca i8, i64 %25
store i64 %25, i64* %13
%27 = load i32, i32* %4
%28 = icmp ne i32 %27, 2
br i1 %28, label %29, label %32
29: ; preds = %2
%30 = load i32, i32* @stderr
%31 = call i32 @fputs(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i32 %30)
store i32 1, i32* %3
store i32 1, i32* %15
br label %182
32: ; preds = %2
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = load i32, i32* @O_RDONLY
%37 = call i32 @open(i8* %35, i32 %36)
store i32 %37, i32* %7
%38 = load i32, i32* %7
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %48
40: ; preds = %32
%41 = load i32, i32* @stderr
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 1
%44 = load i8*, i8** %43
%45 = load i64, i64* @errno
%46 = call i8* @strerror(i64 %45)
%47 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %44, i8* %46)
br label %160
48: ; preds = %32
%49 = load i32, i32* @PATH_MAX
%50 = load i8**, i8*** %5
%51 = getelementptr inbounds i8*, i8** %50, i64 1
%52 = load i8*, i8** %51
%53 = call i8* @dirname(i8* %52)
%54 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %20, i32 %49, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %53)
store i32 %54, i32* %14
%55 = load i32, i32* %14
%56 = load i32, i32* @PATH_MAX
%57 = icmp sge i32 %55, %56
br i1 %57, label %58, label %61
58: ; preds = %48
%59 = load i32, i32* @stderr
%60 = call i32 @fputs(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i32 %59)
br label %160
61: ; preds = %48
%62 = load i32, i32* @O_WRONLY
%63 = call i32 @open(i8* %20, i32 %62)
store i32 %63, i32* %9
%64 = load i32, i32* %9
%65 = icmp eq i32 %64, -1
br i1 %65, label %66, label %71
66: ; preds = %61
%67 = load i32, i32* @stderr
%68 = load i64, i64* @errno
%69 = call i8* @strerror(i64 %68)
%70 = call i32 @fprintf(i32 %67, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %20, i8* %69)
br label %160
71: ; preds = %61
%72 = call i32 @eventfd(i32 0, i32 0)
store i32 %72, i32* %6
%73 = load i32, i32* %6
%74 = icmp eq i32 %73, -1
br i1 %74, label %75, label %77
75: ; preds = %71
%76 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
br label %160
77: ; preds = %71
%78 = load i32, i32* @PATH_MAX
%79 = load i8**, i8*** %5
%80 = getelementptr inbounds i8*, i8** %79, i64 1
%81 = load i8*, i8** %80
%82 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %23, i32 %78, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i8* %81)
store i32 %82, i32* %14
%83 = load i32, i32* %14
%84 = load i32, i32* @PATH_MAX
%85 = icmp sge i32 %83, %84
br i1 %85, label %86, label %89
86: ; preds = %77
%87 = load i32, i32* @stderr
%88 = call i32 @fputs(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.6, i64 0, i64 0), i32 %87)
br label %160
89: ; preds = %77
%90 = load i32, i32* @O_RDONLY
%91 = call i32 @open(i8* %23, i32 %90)
store i32 %91, i32* %8
%92 = load i32, i32* %8
%93 = icmp eq i32 %92, -1
br i1 %93, label %94, label %99
94: ; preds = %89
%95 = load i32, i32* @stderr
%96 = load i64, i64* @errno
%97 = call i8* @strerror(i64 %96)
%98 = call i32 @fprintf(i32 %95, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %23, i8* %97)
br label %160
99: ; preds = %89
%100 = load i32, i32* @LINE_MAX
%101 = load i32, i32* %6
%102 = load i32, i32* %8
%103 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %26, i32 %100, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i32 %101, i32 %102)
store i32 %103, i32* %14
%104 = load i32, i32* %14
%105 = load i32, i32* @LINE_MAX
%106 = icmp sge i32 %104, %105
br i1 %106, label %107, label %110
107: ; preds = %99
%108 = load i32, i32* @stderr
%109 = call i32 @fputs(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.8, i64 0, i64 0), i32 %108)
br label %160
110: ; preds = %99
%111 = load i32, i32* %9
%112 = call i64 @strlen(i8* %26)
%113 = add nsw i64 %112, 1
%114 = call i32 @write(i32 %111, i8* %26, i64 %113)
store i32 %114, i32* %14
%115 = load i32, i32* %14
%116 = icmp eq i32 %115, -1
br i1 %116, label %117, label %119
117: ; preds = %110
%118 = call i32 @perror(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.9, i64 0, i64 0))
br label %160
119: ; preds = %110
br label %120
120: ; preds = %119
%121 = load i32, i32* %6
%122 = call i32 @read(i32 %121, i32* %16, i32 4)
store i32 %122, i32* %14
%123 = load i32, i32* %14
%124 = icmp eq i32 %123, -1
br i1 %124, label %125, label %132
125: ; preds = %120
%126 = load i64, i64* @errno
%127 = load i64, i64* @EINTR
%128 = icmp eq i64 %126, %127
br i1 %128, label %129, label %130
129: ; preds = %125
br label %158
130: ; preds = %125
%131 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.10, i64 0, i64 0))
br label %159
132: ; preds = %120
%133 = load i32, i32* %14
%134 = sext i32 %133 to i64
%135 = icmp eq i64 %134, 4
%136 = zext i1 %135 to i32
%137 = call i32 @assert(i32 %136)
%138 = load i32, i32* @W_OK
%139 = call i32 @access(i8* %20, i32 %138)
store i32 %139, i32* %14
%140 = load i32, i32* %14
%141 = icmp eq i32 %140, -1
br i1 %141, label %142, label %148
142: ; preds = %132
%143 = load i64, i64* @errno
%144 = load i64, i64* @ENOENT
%145 = icmp eq i64 %143, %144
br i1 %145, label %146, label %148
146: ; preds = %142
%147 = call i32 @puts(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.11, i64 0, i64 0))
store i32 0, i32* %14
br label %159
148: ; preds = %142, %132
%149 = load i32, i32* %14
%150 = icmp eq i32 %149, -1
br i1 %150, label %151, label %153
151: ; preds = %148
%152 = call i32 @perror(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.12, i64 0, i64 0))
br label %159
153: ; preds = %148
%154 = load i8**, i8*** %5
%155 = getelementptr inbounds i8*, i8** %154, i64 1
%156 = load i8*, i8** %155
%157 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.13, i64 0, i64 0), i8* %156)
br label %158
158: ; preds = %153, %129
br label %159
159: ; preds = %158, %151, %146, %130
br label %160
160: ; preds = %159, %117, %107, %94, %86, %75, %66, %58, %40
%161 = load i32, i32* %6
%162 = icmp sge i32 %161, 0
br i1 %162, label %163, label %166
163: ; preds = %160
%164 = load i32, i32* %6
%165 = call i32 @close(i32 %164)
br label %166
166: ; preds = %163, %160
%167 = load i32, i32* %9
%168 = icmp sge i32 %167, 0
br i1 %168, label %169, label %172
169: ; preds = %166
%170 = load i32, i32* %9
%171 = call i32 @close(i32 %170)
br label %172
172: ; preds = %169, %166
%173 = load i32, i32* %7
%174 = icmp sge i32 %173, 0
br i1 %174, label %175, label %178
175: ; preds = %172
%176 = load i32, i32* %7
%177 = call i32 @close(i32 %176)
br label %178
178: ; preds = %175, %172
%179 = load i32, i32* %14
%180 = icmp ne i32 %179, 0
%181 = zext i1 %180 to i32
store i32 %181, i32* %3
store i32 1, i32* %15
br label %182
182: ; preds = %178, %29
%183 = load i8*, i8** %10
%184 = load i32, i32* %3
ret i32 %184
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@LINE_MAX = global i32 0
@.str = [53 x i8] c"Usage: cgroup_event_listener <path-to-control-file>\0A\00"
@stderr = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [20 x i8] c"Cannot open %s: %s\0A\00"
@errno = global i64 0
@.str.2 = [24 x i8] c"%s/cgroup.event_control\00"
@.str.3 = [42 x i8] c"Path to cgroup.event_control is too long\0A\00"
@O_WRONLY = global i32 0
@.str.4 = [17 x i8] c"eventfd() failed\00"
@.str.5 = [22 x i8] c"%s/memory.oom_control\00"
@.str.6 = [40 x i8] c"Path to memory.oom_control is too long\0A\00"
@.str.7 = [6 x i8] c"%d %d\00"
@.str.8 = [30 x i8] c"Arguments string is too long\0A\00"
@.str.9 = [37 x i8] c"Cannot write to cgroup.event_control\00"
@EINTR = global i64 0
@.str.10 = [25 x i8] c"Cannot read from eventfd\00"
@W_OK = global i32 0
@ENOENT = global i64 0
@.str.11 = [34 x i8] c"The cgroup seems to have removed.\00"
@.str.12 = [48 x i8] c"cgroup.event_control is not accessible any more\00"
@.str.13 = [13 x i8] c"%s: crossed\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = load i32, i32* @PATH_MAX
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = alloca i8, i64 %5
%8 = load i32, i32* @LINE_MAX
%9 = zext i32 %8 to i64
%10 = alloca i8, i64 %9
%11 = icmp eq i32 %0, 2
br i1 %11, label %15, label %12
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = tail call i32 @fputs(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i32 %13)
br label %133
15: ; preds = %2
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = load i32, i32* @O_RDONLY
%19 = tail call i32 @open(i8* %17, i32 %18)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %27
21: ; preds = %15
%22 = load i32, i32* @stderr
%23 = load i8*, i8** %16
%24 = load i64, i64* @errno
%25 = tail call i8* @strerror(i64 %24)
%26 = tail call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %23, i8* %25)
br label %129
27: ; preds = %15
%28 = load i32, i32* @PATH_MAX
%29 = load i8*, i8** %16
%30 = tail call i8* @dirname(i8* %29)
%31 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %6, i32 %28, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %30)
%32 = load i32, i32* @PATH_MAX
%33 = icmp slt i32 %31, %32
br i1 %33, label %37, label %34
34: ; preds = %27
%35 = load i32, i32* @stderr
%36 = call i32 @fputs(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i32 %35)
br label %124
37: ; preds = %27
%38 = load i32, i32* @O_WRONLY
%39 = call i32 @open(i8* %6, i32 %38)
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %46
41: ; preds = %37
%42 = load i32, i32* @stderr
%43 = load i64, i64* @errno
%44 = call i8* @strerror(i64 %43)
%45 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %6, i8* %44)
br label %124
46: ; preds = %37
%47 = call i32 @eventfd(i32 0, i32 0)
%48 = icmp eq i32 %47, -1
br i1 %48, label %49, label %51
49: ; preds = %46
%50 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
br label %119
51: ; preds = %46
%52 = load i32, i32* @PATH_MAX
%53 = load i8*, i8** %16
%54 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %7, i32 %52, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i8* %53)
%55 = load i32, i32* @PATH_MAX
%56 = icmp slt i32 %54, %55
br i1 %56, label %60, label %57
57: ; preds = %51
%58 = load i32, i32* @stderr
%59 = call i32 @fputs(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.6, i64 0, i64 0), i32 %58)
br label %114
60: ; preds = %51
%61 = load i32, i32* @O_RDONLY
%62 = call i32 @open(i8* %7, i32 %61)
%63 = icmp eq i32 %62, -1
br i1 %63, label %64, label %69
64: ; preds = %60
%65 = load i32, i32* @stderr
%66 = load i64, i64* @errno
%67 = call i8* @strerror(i64 %66)
%68 = call i32 @fprintf(i32 %65, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %7, i8* %67)
br label %114
69: ; preds = %60
%70 = load i32, i32* @LINE_MAX
%71 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %10, i32 %70, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i32 %47, i32 %62)
%72 = load i32, i32* @LINE_MAX
%73 = icmp slt i32 %71, %72
br i1 %73, label %77, label %74
74: ; preds = %69
%75 = load i32, i32* @stderr
%76 = call i32 @fputs(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.8, i64 0, i64 0), i32 %75)
br label %114
77: ; preds = %69
%78 = call i64 @strlen(i8* %10)
%79 = add nsw i64 %78, 1
%80 = call i32 @write(i32 %39, i8* %10, i64 %79)
%81 = icmp eq i32 %80, -1
br i1 %81, label %82, label %84
82: ; preds = %77
%83 = call i32 @perror(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.9, i64 0, i64 0))
br label %114
84: ; preds = %77
%85 = bitcast i32* %3 to i8*
%86 = call i32 @read(i32 %47, i32* %3, i32 4)
%87 = icmp eq i32 %86, -1
br i1 %87, label %88, label %94
88: ; preds = %84
%89 = load i64, i64* @errno
%90 = load i64, i64* @EINTR
%91 = icmp eq i64 %89, %90
br i1 %91, label %112, label %92
92: ; preds = %88
%93 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.10, i64 0, i64 0))
br label %112
94: ; preds = %84
%95 = icmp eq i32 %86, 4
%96 = zext i1 %95 to i32
%97 = call i32 @assert(i32 %96)
%98 = load i32, i32* @W_OK
%99 = call i32 @access(i8* %6, i32 %98)
%100 = icmp eq i32 %99, -1
br i1 %100, label %101, label %109
101: ; preds = %94
%102 = load i64, i64* @errno
%103 = load i64, i64* @ENOENT
%104 = icmp eq i64 %102, %103
br i1 %104, label %105, label %107
105: ; preds = %101
%106 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.11, i64 0, i64 0))
br label %112
107: ; preds = %101
%108 = call i32 @perror(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.12, i64 0, i64 0))
br label %112
109: ; preds = %94
%110 = load i8*, i8** %16
%111 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.13, i64 0, i64 0), i8* %110)
br label %112
112: ; preds = %88, %109, %107, %105, %92
%113 = phi i32 [ -1, %92 ], [ 0, %105 ], [ -1, %107 ], [ %99, %109 ], [ -1, %88 ]
br label %114
114: ; preds = %112, %82, %74, %64, %57
%115 = phi i32 [ %54, %57 ], [ %54, %64 ], [ %71, %74 ], [ -1, %82 ], [ %113, %112 ]
%116 = icmp sgt i32 %47, -1
br i1 %116, label %117, label %119
117: ; preds = %114
%118 = call i32 @close(i32 %47)
br label %119
119: ; preds = %49, %117, %114
%120 = phi i32 [ %115, %117 ], [ %115, %114 ], [ %31, %49 ]
%121 = icmp sgt i32 %39, -1
br i1 %121, label %122, label %124
122: ; preds = %119
%123 = call i32 @close(i32 %39)
br label %124
124: ; preds = %34, %41, %122, %119
%125 = phi i32 [ %120, %122 ], [ %120, %119 ], [ %31, %34 ], [ %31, %41 ]
%126 = icmp sgt i32 %19, -1
br i1 %126, label %127, label %129
127: ; preds = %124
%128 = call i32 @close(i32 %19)
br label %129
129: ; preds = %21, %127, %124
%130 = phi i32 [ undef, %21 ], [ %125, %127 ], [ %125, %124 ]
%131 = icmp ne i32 %130, 0
%132 = zext i1 %131 to i32
br label %133
133: ; preds = %129, %12
%134 = phi i32 [ 1, %12 ], [ %132, %129 ]
ret i32 %134
}