#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 inotify_event {
  int dummy;
};

/* Variables and functions */
int EXIT_FAILURE;
int /*<<< orphan*/ IN_CLOSE_NOWRITE;
int inotify_add_watch(int, char *, int /*<<< orphan*/);
int inotify_init();
int /*<<< orphan*/ perror(char *);
scalar_t__ read(int, struct inotify_event *, int);
int /*<<< orphan*/ stop_servo(char *);
int /*<<< orphan*/ usleep(int);
int main() {
  struct inotify_event iev;
  int inotify_fd;
  inotify_fd = inotify_init();
  if (inotify_fd == -1) {
    perror("inotify_init");
    return EXIT_FAILURE;
  }
  if (inotify_add_watch(inotify_fd, "/watch", IN_CLOSE_NOWRITE) == -1) {
    perror("inotify_add_watch");
    return EXIT_FAILURE;
  }
  do {
    if (read(inotify_fd, &iev, sizeof(struct inotify_event)) <= 0) {
      perror("read");
      break;
    }
    usleep(500000);
    stop_servo("/tmp/v4/left/run");
    stop_servo("/tmp/v4/right/run");
  } while (1);
  return EXIT_FAILURE;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1050 <inotify_init@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    11a0 <main+0x40>
lea    0xe76(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e42(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    124c <main+0xec>
mov    -0xc(%rbp),%edi
mov    0x2e3e(%rip),%rax
mov    (%rax),%edx
lea    0xe5a(%rip),%rsi
call   1060 <inotify_add_watch@plt>
cmp    $0xffffffff,%eax
jne    11de <main+0x7e>
lea    0xe4c(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e04(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    124c <main+0xec>
jmp    11e3 <main+0x83>
mov    -0xc(%rbp),%edi
lea    -0x8(%rbp),%rsi
mov    $0x4,%edx
call   1030 <read@plt>
cmp    $0x0,%rax
jg     120f <main+0xaf>
lea    0xe21(%rip),%rdi
call   1070 <perror@plt>
jmp    1240 <main+0xe0>
mov    $0x7a120,%edi
call   1080 <usleep@plt>
lea    0xe0b(%rip),%rdi
call   1040 <stop_servo@plt>
lea    0xe10(%rip),%rdi
call   1040 <stop_servo@plt>
mov    $0x1,%al
test   $0x1,%al
jne    11e3 <main+0x83>
jmp    1240 <main+0xe0>
mov    0x2d91(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1050 <inotify_init@plt>
cmp    $0xffffffff,%eax
jne    1185 <main+0x25>
lea    0xe80(%rip),%r14
jmp    120e <main+0xae>
mov    %eax,%ebx
mov    0x2e5a(%rip),%rax
mov    (%rax),%edx
lea    0xe76(%rip),%rsi
mov    %ebx,%edi
call   1060 <inotify_add_watch@plt>
cmp    $0xffffffff,%eax
jne    11ac <main+0x4c>
lea    0xe6a(%rip),%r14
jmp    120e <main+0xae>
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1030 <read@plt>
lea    0xe62(%rip),%r14
test   %rax,%rax
jle    120e <main+0xae>
lea    0xe5b(%rip),%r15
lea    0xe65(%rip),%r12
lea    0x8(%rsp),%r13
nopl   0x0(%rax)
mov    $0x7a120,%edi
call   1080 <usleep@plt>
mov    %r15,%rdi
call   1040 <stop_servo@plt>
mov    %r12,%rdi
call   1040 <stop_servo@plt>
mov    %ebx,%edi
mov    %r13,%rsi
mov    $0x4,%edx
call   1030 <read@plt>
test   %rax,%rax
jg     11e0 <main+0x80>
mov    %r14,%rdi
call   1070 <perror@plt>
mov    0x2dbb(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.inotify_event = type { i32 }
@.str = [13 x i8] c"inotify_init\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [7 x i8] c"/watch\00"
@IN_CLOSE_NOWRITE = global i32 0
@.str.2 = [18 x i8] c"inotify_add_watch\00"
@.str.3 = [5 x i8] c"read\00"
@.str.4 = [17 x i8] c"/tmp/v4/left/run\00"
@.str.5 = [18 x i8] c"/tmp/v4/right/run\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.inotify_event
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 (...) @inotify_init()
store i32 %4, i32* %3
%5 = load i32, i32* %3
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
store i32 %9, i32* %1
br label %32
10: ; preds = %0
%11 = load i32, i32* %3
%12 = load i32, i32* @IN_CLOSE_NOWRITE
%13 = call i32 @inotify_add_watch(i32 %11, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %18
15: ; preds = %10
%16 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
store i32 %17, i32* %1
br label %32
18: ; preds = %10
br label %19
19: ; preds = %29, %18
%20 = load i32, i32* %3
%21 = call i64 @read(i32 %20, %struct.inotify_event* %2, i32 4)
%22 = icmp sle i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %19
%24 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %30
25: ; preds = %19
%26 = call i32 @usleep(i32 500000)
%27 = call i32 @stop_servo(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%28 = call i32 @stop_servo(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
br label %29
29: ; preds = %25
br i1 true, label %19, label %30
30: ; preds = %29, %23
%31 = load i32, i32* @EXIT_FAILURE
store i32 %31, i32* %1
br label %32
32: ; preds = %30, %15, %7
%33 = load i32, i32* %1
ret i32 %33
}

LLVM IR (-O2):
%struct.inotify_event = type { i32 }
@.str = [13 x i8] c"inotify_init\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [7 x i8] c"/watch\00"
@IN_CLOSE_NOWRITE = global i32 0
@.str.2 = [18 x i8] c"inotify_add_watch\00"
@.str.3 = [5 x i8] c"read\00"
@.str.4 = [17 x i8] c"/tmp/v4/left/run\00"
@.str.5 = [18 x i8] c"/tmp/v4/right/run\00"
define i32 @main() {
%1 = alloca %struct.inotify_event
%2 = bitcast %struct.inotify_event* %1 to i8*
%3 = tail call i32 (...) @inotify_init()
%4 = icmp eq i32 %3, -1
br i1 %4, label %18, label %5
5: ; preds = %0
%6 = load i32, i32* @IN_CLOSE_NOWRITE
%7 = tail call i32 @inotify_add_watch(i32 %3, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %6)
%8 = icmp eq i32 %7, -1
br i1 %8, label %18, label %9
9: ; preds = %5
%10 = call i64 @read(i32 %3, %struct.inotify_event* %1, i32 4)
%11 = icmp slt i64 %10, 1
br i1 %11, label %18, label %12
12: ; preds = %9, %12
%13 = tail call i32 @usleep(i32 500000)
%14 = tail call i32 @stop_servo(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%15 = tail call i32 @stop_servo(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
%16 = call i64 @read(i32 %3, %struct.inotify_event* %1, i32 4)
%17 = icmp slt i64 %16, 1
br i1 %17, label %18, label %12
18: ; preds = %12, %9, %5, %0
%19 = phi i8* [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), %0 ], [ getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), %5 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), %9 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), %12 ]
%20 = tail call i32 @perror(i8* %19)
%21 = load i32, i32* @EXIT_FAILURE
ret i32 %21
}