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

/* Variables and functions */
int /*<<< orphan*/ IN_MODIFY;
int /*<<< orphan*/ cg_control(char const *, char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int inotify_add_watch(int, int /*<<< orphan*/, int /*<<< orphan*/);
int inotify_init1(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int cg_prepare_for_wait(const char *cgroup) {
  int fd, ret = -1;
  fd = inotify_init1(0);
  if (fd == -1) {
    fprintf(stderr, "Error: inotify_init1() failed\n");
    return fd;
  }
  ret = inotify_add_watch(fd, cg_control(cgroup, "cgroup.events"), IN_MODIFY);
  if (ret == -1) {
    fprintf(stderr, "Error: inotify_add_watch() failed\n");
    close(fd);
  }
  return fd;
}


x86 assembly (clang, -O0):
<cg_prepare_for_wait>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0xffffffff,-0x18(%rbp)
xor    %edi,%edi
call   1060 <inotify_init1@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1197 <cg_prepare_for_wait+0x47>
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
lea    0xe79(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11f0 <cg_prepare_for_wait+0xa0>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe77(%rip),%rsi
call   1070 <cg_control@plt>
mov    -0x1c(%rbp),%edi
mov    %eax,%esi
mov    0x2e37(%rip),%rax
mov    (%rax),%edx
call   1050 <inotify_add_watch@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    11ea <cg_prepare_for_wait+0x9a>
mov    0x2e04(%rip),%rax
mov    (%rax),%edi
lea    0xe50(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x14(%rbp),%edi
call   1030 <close@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cg_prepare_for_wait>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %edi,%edi
call   1060 <inotify_init1@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
je     11a9 <cg_prepare_for_wait+0x59>
lea    0xeb3(%rip),%rsi
mov    %r14,%rdi
call   1070 <cg_control@plt>
mov    0x2e75(%rip),%rcx
mov    (%rcx),%edx
mov    %ebx,%edi
mov    %eax,%esi
call   1050 <inotify_add_watch@plt>
cmp    $0xffffffff,%eax
jne    11be <cg_prepare_for_wait+0x6e>
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
lea    0xe92(%rip),%rsi
call   1040 <fprintf@plt>
mov    %ebx,%edi
call   1030 <close@plt>
jmp    11be <cg_prepare_for_wait+0x6e>
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
lea    0xe47(%rip),%rsi
call   1040 <fprintf@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [31 x i8] c"Error: inotify_init1() failed\0A\00"
@.str.1 = [14 x i8] c"cgroup.events\00"
@IN_MODIFY = global i32 0
@.str.2 = [35 x i8] c"Error: inotify_add_watch() failed\0A\00"
define i32 @cg_prepare_for_wait(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 -1, i32* %5
%6 = call i32 @inotify_init1(i32 0)
store i32 %6, i32* %4
%7 = load i32, i32* %4
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %13
9: ; preds = %1
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* %4
store i32 %12, i32* %2
br label %28
13: ; preds = %1
%14 = load i32, i32* %4
%15 = load i8*, i8** %3
%16 = call i32 @cg_control(i8* %15, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%17 = load i32, i32* @IN_MODIFY
%18 = call i32 @inotify_add_watch(i32 %14, i32 %16, i32 %17)
store i32 %18, i32* %5
%19 = load i32, i32* %5
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %26
21: ; preds = %13
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
%24 = load i32, i32* %4
%25 = call i32 @close(i32 %24)
br label %26
26: ; preds = %21, %13
%27 = load i32, i32* %4
store i32 %27, i32* %2
br label %28
28: ; preds = %26, %9
%29 = load i32, i32* %2
ret i32 %29
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [31 x i8] c"Error: inotify_init1() failed\0A\00"
@.str.1 = [14 x i8] c"cgroup.events\00"
@IN_MODIFY = global i32 0
@.str.2 = [35 x i8] c"Error: inotify_add_watch() failed\0A\00"
define i32 @cg_prepare_for_wait(i8* %0) {
%2 = tail call i32 @inotify_init1(i32 0)
%3 = icmp eq i32 %2, -1
br i1 %3, label %4, label %7
4: ; preds = %1
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
br label %16
7: ; preds = %1
%8 = tail call i32 @cg_control(i8* %0, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%9 = load i32, i32* @IN_MODIFY
%10 = tail call i32 @inotify_add_watch(i32 %2, i32 %8, i32 %9)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %16
12: ; preds = %7
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
%15 = tail call i32 @close(i32 %2)
br label %16
16: ; preds = %7, %12, %4
ret i32 %2
}