#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 *, 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 event_control = -1;
  char event_control_path[PATH_MAX];
  char line[LINE_MAX];
  int ret;
  if (argc != 3) {
    fputs("Usage: cgroup_event_listener <path-to-control-file> <args>\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(line, LINE_MAX, "%d %d %s", efd, cfd, argv[2]);
  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;
  }
  while (1) {
    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 accessable any more");
      break;
    }
    printf("%s %s: crossed\n", argv[1], argv[2]);
  }
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    $0x70,%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)
mov    0x2dbe(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
mov    0x2d7a(%rip),%rax
mov    (%rax),%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     12ae <main+0xae>
mov    0x2d33(%rip),%rax
mov    (%rax),%esi
lea    0xd6a(%rip),%rdi
call   1090 <fputs@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x40(%rbp)
jmp    15d3 <main+0x3d3>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2d23(%rip),%rax
mov    (%rax),%esi
call   10e0 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    1313 <main+0x113>
mov    0x2ce8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x64(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x60(%rbp)
mov    0x2cc8(%rip),%rax
mov    (%rax),%rdi
call   1120 <strerror@plt>
mov    -0x64(%rbp),%edi
mov    -0x60(%rbp),%rdx
mov    %rax,%rcx
lea    0xd33(%rip),%rsi
call   10d0 <fprintf@plt>
jmp    1587 <main+0x387>
mov    0x2cd6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x68(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <dirname@plt>
mov    -0x58(%rbp),%rdi
mov    -0x68(%rbp),%esi
mov    %rax,%rcx
lea    0xd13(%rip),%rdx
mov    $0x0,%al
call   1070 <snprintf@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    0x2c9f(%rip),%rcx
cmp    (%rcx),%eax
jl     1373 <main+0x173>
mov    0x2c60(%rip),%rax
mov    (%rax),%esi
lea    0xcff(%rip),%rdi
call   1090 <fputs@plt>
jmp    1587 <main+0x387>
mov    -0x58(%rbp),%rdi
mov    0x2c1a(%rip),%rax
mov    (%rax),%esi
call   10e0 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    13c8 <main+0x1c8>
mov    0x2c27(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x6c(%rbp)
mov    0x2c13(%rip),%rax
mov    (%rax),%rdi
call   1120 <strerror@plt>
mov    -0x6c(%rbp),%edi
mov    -0x58(%rbp),%rdx
mov    %rax,%rcx
lea    0xc7e(%rip),%rsi
call   10d0 <fprintf@plt>
jmp    1587 <main+0x387>
xor    %esi,%esi
mov    %esi,%edi
call   1110 <eventfd@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    13ef <main+0x1ef>
lea    0xcad(%rip),%rdi
call   1100 <perror@plt>
jmp    1587 <main+0x387>
mov    -0x50(%rbp),%rdi
mov    0x2bde(%rip),%rax
mov    (%rax),%esi
mov    -0x14(%rbp),%ecx
mov    -0x18(%rbp),%r8d
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%r9
lea    0xc91(%rip),%rdx
mov    $0x0,%al
call   1070 <snprintf@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    0x2bb2(%rip),%rcx
cmp    (%rcx),%eax
jl     1448 <main+0x248>
mov    0x2b8b(%rip),%rax
mov    (%rax),%esi
lea    0xc6e(%rip),%rdi
call   1090 <fputs@plt>
jmp    1587 <main+0x387>
mov    -0x50(%rbp),%rdi
mov    -0x1c(%rbp),%eax
mov    %eax,-0x70(%rbp)
call   1050 <strlen@plt>
mov    -0x70(%rbp),%edi
mov    -0x50(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1040 <write@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0xffffffff,-0x3c(%rbp)
jne    1488 <main+0x288>
lea    0xc4c(%rip),%rdi
call   1100 <perror@plt>
jmp    1587 <main+0x387>
jmp    148d <main+0x28d>
jmp    1492 <main+0x292>
mov    -0x14(%rbp),%edi
lea    -0x44(%rbp),%rsi
mov    $0x4,%edx
call   10b0 <read@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0xffffffff,-0x3c(%rbp)
jne    14e0 <main+0x2e0>
mov    0x2b01(%rip),%rax
mov    (%rax),%rax
mov    0x2aef(%rip),%rcx
cmp    (%rcx),%rax
jne    14cf <main+0x2cf>
jmp    148d <main+0x28d>
lea    0xc19(%rip),%rdi
call   1100 <perror@plt>
jmp    1582 <main+0x382>
movslq -0x3c(%rbp),%rax
cmp    $0x4,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10c0 <assert@plt>
mov    -0x58(%rbp),%rdi
mov    0x2ad0(%rip),%rax
mov    (%rax),%esi
call   10f0 <access@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0xffffffff,-0x3c(%rbp)
jne    1546 <main+0x346>
mov    0x2a9d(%rip),%rax
mov    (%rax),%rax
mov    0x2a7b(%rip),%rcx
cmp    (%rcx),%rax
jne    1546 <main+0x346>
lea    0xbd3(%rip),%rdi
call   1030 <puts@plt>
movl   $0x0,-0x3c(%rbp)
jmp    1582 <main+0x382>
cmpl   $0xffffffff,-0x3c(%rbp)
jne    1561 <main+0x361>
lea    0xbd3(%rip),%rdi
call   1100 <perror@plt>
jmp    1582 <main+0x382>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xbe2(%rip),%rdi
call   1060 <printf@plt>
jmp    148d <main+0x28d>
jmp    1587 <main+0x387>
cmpl   $0x0,-0x14(%rbp)
jl     1599 <main+0x399>
mov    -0x14(%rbp),%edi
call   10a0 <close@plt>
cmpl   $0x0,-0x1c(%rbp)
jl     15ab <main+0x3ab>
mov    -0x1c(%rbp),%edi
call   10a0 <close@plt>
cmpl   $0x0,-0x18(%rbp)
jl     15bd <main+0x3bd>
mov    -0x18(%rbp),%edi
call   10a0 <close@plt>
cmpl   $0x0,-0x3c(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x40(%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    $0x18,%rsp
mov    0x2dd8(%rip),%r13
mov    0x0(%r13),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    0x2da4(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r15
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
cmp    $0x3,%edi
jne    13a9 <main+0x1a9>
mov    %rsi,%r12
mov    0x8(%rsi),%rdi
mov    0x2d82(%rip),%rax
mov    (%rax),%esi
call   10e0 <open@plt>
cmp    $0xffffffff,%eax
je     13c8 <main+0x1c8>
mov    %eax,-0x2c(%rbp)
mov    0x0(%r13),%r14d
mov    0x8(%r12),%rdi
call   1080 <dirname@plt>
lea    0xdca(%rip),%rdx
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %rax,%rcx
xor    %eax,%eax
call   1070 <snprintf@plt>
mov    %eax,%r14d
cmp    0x0(%r13),%eax
jge    13fe <main+0x1fe>
mov    0x2cee(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   10e0 <open@plt>
cmp    $0xffffffff,%eax
je     1418 <main+0x218>
mov    %eax,-0x30(%rbp)
xor    %edi,%edi
xor    %esi,%esi
call   1110 <eventfd@plt>
cmp    $0xffffffff,%eax
je     14c5 <main+0x2c5>
mov    %eax,%r13d
mov    0x2cfc(%rip),%rax
mov    (%rax),%esi
mov    0x10(%r12),%r9
lea    0xdb9(%rip),%rdx
mov    %r15,%rdi
mov    %r13d,%ecx
mov    -0x2c(%rbp),%r8d
xor    %eax,%eax
call   1070 <snprintf@plt>
mov    %eax,%r14d
mov    0x2cd3(%rip),%rax
cmp    (%rax),%r14d
jge    1448 <main+0x248>
mov    %r15,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rdx
mov    -0x30(%rbp),%edi
mov    %r15,%rsi
call   1040 <write@plt>
cmp    $0xffffffff,%eax
je     14d3 <main+0x2d3>
lea    -0x34(%rbp),%r14
mov    0x2c97(%rip),%r15
jmp    135a <main+0x15a>
nopl   0x0(%rax,%rax,1)
mov    0x2c71(%rip),%rax
mov    (%rax),%rax
mov    0x2c5f(%rip),%rcx
cmp    (%rcx),%rax
jne    14e5 <main+0x2e5>
mov    %r13d,%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   10b0 <read@plt>
cmp    $0xffffffff,%eax
je     1340 <main+0x140>
xor    %edi,%edi
cmp    $0x4,%eax
sete   %dil
call   10c0 <assert@plt>
mov    (%r15),%esi
mov    %rbx,%rdi
call   10f0 <access@plt>
cmp    $0xffffffff,%eax
je     1464 <main+0x264>
mov    0x8(%r12),%rsi
mov    0x10(%r12),%rdx
lea    0xdb8(%rip),%rdi
call   1060 <printf@plt>
jmp    135a <main+0x15a>
mov    0x2c10(%rip),%rax
mov    (%rax),%esi
lea    0xc47(%rip),%rdi
call   1090 <fputs@plt>
mov    $0x1,%eax
jmp    14b6 <main+0x2b6>
mov    0x2bf1(%rip),%rax
mov    (%rax),%ebx
mov    0x8(%r12),%r14
mov    0x2bdb(%rip),%rax
mov    (%rax),%rdi
call   1120 <strerror@plt>
lea    0xc50(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %rax,%rcx
call   10d0 <fprintf@plt>
jmp    14ae <main+0x2ae>
mov    0x2bbb(%rip),%rax
mov    (%rax),%esi
lea    0xc5a(%rip),%rdi
call   1090 <fputs@plt>
jmp    14a2 <main+0x2a2>
mov    0x2ba1(%rip),%rax
mov    (%rax),%r15d
mov    0x2b8f(%rip),%rax
mov    (%rax),%rdi
call   1120 <strerror@plt>
lea    0xc04(%rip),%rsi
mov    %r15d,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
call   10d0 <fprintf@plt>
jmp    14a2 <main+0x2a2>
mov    0x2b71(%rip),%rax
mov    (%rax),%esi
lea    0xc54(%rip),%rdi
call   1090 <fputs@plt>
test   %r13d,%r13d
jns    148e <main+0x28e>
jmp    1496 <main+0x296>
mov    0x2b4d(%rip),%rax
mov    (%rax),%rax
mov    0x2b2b(%rip),%rcx
cmp    (%rcx),%rax
jne    14dc <main+0x2dc>
lea    0xc87(%rip),%rdi
call   1030 <puts@plt>
xor    %r14d,%r14d
test   %r13d,%r13d
js     1496 <main+0x296>
mov    %r13d,%edi
call   10a0 <close@plt>
mov    -0x30(%rbp),%edi
test   %edi,%edi
js     14a2 <main+0x2a2>
call   10a0 <close@plt>
mov    -0x2c(%rbp),%edi
test   %edi,%edi
js     14ae <main+0x2ae>
call   10a0 <close@plt>
xor    %eax,%eax
test   %r14d,%r14d
setne  %al
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xbc6(%rip),%rdi
call   1100 <perror@plt>
jmp    1496 <main+0x296>
lea    0xbf0(%rip),%rdi
jmp    14ec <main+0x2ec>
lea    0xc47(%rip),%rdi
jmp    14ec <main+0x2ec>
lea    0xc03(%rip),%rdi
call   1100 <perror@plt>
mov    $0xffffffff,%r14d
test   %r13d,%r13d
jns    148e <main+0x28e>
jmp    1496 <main+0x296>

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

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