#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
double mtime(char const *);
int /*<<< orphan*/ printf(char *, char const *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ sys(char *, char **);
int /*<<< orphan*/ usleep(int);
int main(int argc, char **argv) {
  const char *argv0 = *argv++;
  const char *path = 0;
  char **command = 0;
  while (*argv) {
    if (!path) {
      path = *argv++;
      continue;
    }
    if (!command) {
      command = argv;
      break;
    }
  }
  if (!path) {
    fprintf(stderr, "Usage: %s path [ command [ args .. ] ]\n", argv0);
    exit(1);
  }
  double recent_mtime = mtime(path);
  fprintf(stderr, "mtime: %.3f\n", recent_mtime);
  while (1) {
    usleep(50 * 1000);
    double old_mtime = recent_mtime;
    recent_mtime = mtime(path);
    fprintf(stderr, "mtime: %.3f\n", recent_mtime);
    if (recent_mtime == old_mtime)
      continue;
    if (command)
      sys(*command, command);
    else
      printf("%s\n", path);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     11ed <main+0x8d>
cmpq   $0x0,-0x20(%rbp)
jne    11d0 <main+0x70>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    119c <main+0x3c>
cmpq   $0x0,-0x28(%rbp)
jne    11e8 <main+0x88>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    11ed <main+0x8d>
jmp    119c <main+0x3c>
cmpq   $0x0,-0x20(%rbp)
jne    121d <main+0xbd>
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xdf4(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x20(%rbp),%rdi
call   1030 <mtime@plt>
movsd  %xmm0,-0x30(%rbp)
mov    0x2dae(%rip),%rax
mov    (%rax),%edi
movsd  -0x30(%rbp),%xmm0
lea    0xde8(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
mov    $0xc350,%edi
call   1080 <usleep@plt>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <mtime@plt>
movsd  %xmm0,-0x30(%rbp)
mov    0x2d70(%rip),%rax
mov    (%rax),%edi
movsd  -0x30(%rbp),%xmm0
lea    0xdaa(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
movsd  -0x30(%rbp),%xmm0
ucomisd -0x38(%rbp),%xmm0
jne    12a0 <main+0x140>
jp     12a0 <main+0x140>
jmp    1247 <main+0xe7>
cmpq   $0x0,-0x28(%rbp)
je     12c0 <main+0x160>
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
mov    -0x28(%rbp),%rsi
call   1070 <sys@plt>
jmp    12d0 <main+0x170>
mov    -0x20(%rbp),%rsi
lea    0xd6a(%rip),%rdi
call   1040 <printf@plt>
jmp    1247 <main+0xe7>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    (%rsi),%rdx
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rax,%rbx
mov    0x8(%r14),%rax
test   %rax,%rax
je     1197 <main+0x37>
add    $0x8,%r14
test   %rbx,%rbx
je     1180 <main+0x20>
jmp    11a3 <main+0x43>
test   %rbx,%rbx
je     1241 <main+0xe1>
xor    %r14d,%r14d
mov    %rbx,%rdi
call   1030 <mtime@plt>
movsd  %xmm0,(%rsp)
mov    0x2e29(%rip),%r13
mov    0x0(%r13),%edi
lea    0xe66(%rip),%r15
mov    %r15,%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
movsd  (%rsp),%xmm0
lea    0xe5d(%rip),%r12
jmp    11f0 <main+0x90>
nopw   0x0(%rax,%rax,1)
mov    (%r14),%rdi
mov    %r14,%rsi
call   1070 <sys@plt>
movsd  (%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    $0xc350,%edi
call   1080 <usleep@plt>
mov    %rbx,%rdi
call   1030 <mtime@plt>
movsd  %xmm0,(%rsp)
mov    0x0(%r13),%edi
mov    %r15,%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
movsd  (%rsp),%xmm0
ucomisd 0x8(%rsp),%xmm0
jne    122a <main+0xca>
jnp    11f0 <main+0x90>
test   %r14,%r14
jne    11e0 <main+0x80>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
movsd  (%rsp),%xmm0
jmp    11f0 <main+0x90>
mov    0x2d98(%rip),%rax
mov    (%rax),%edi
lea    0xdaf(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [40 x i8] c"Usage: %s path [ command [ args .. ] ]\0A\00"
@.str.1 = [13 x i8] c"mtime: %.3f\0A\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8**
%9 = alloca double
%10 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i32 1
store i8** %12, i8*** %5
%13 = load i8*, i8** %11
store i8* %13, i8** %6
store i8* null, i8** %7
store i8** null, i8*** %8
br label %14
14: ; preds = %30, %21, %2
%15 = load i8**, i8*** %5
%16 = load i8*, i8** %15
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %31
18: ; preds = %14
%19 = load i8*, i8** %7
%20 = icmp ne i8* %19, null
br i1 %20, label %25, label %21
21: ; preds = %18
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i32 1
store i8** %23, i8*** %5
%24 = load i8*, i8** %22
store i8* %24, i8** %7
br label %14
25: ; preds = %18
%26 = load i8**, i8*** %8
%27 = icmp ne i8** %26, null
br i1 %27, label %30, label %28
28: ; preds = %25
%29 = load i8**, i8*** %5
store i8** %29, i8*** %8
br label %31
30: ; preds = %25
br label %14
31: ; preds = %28, %14
%32 = load i8*, i8** %7
%33 = icmp ne i8* %32, null
br i1 %33, label %39, label %34
34: ; preds = %31
%35 = load i32, i32* @stderr
%36 = load i8*, i8** %6
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* %36)
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %31
%40 = load i8*, i8** %7
%41 = call double @mtime(i8* %40)
store double %41, double* %9
%42 = load i32, i32* @stderr
%43 = load double, double* %9
%44 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), double %43)
br label %45
45: ; preds = %39, %56, %68
%46 = call i32 @usleep(i32 50000)
%47 = load double, double* %9
store double %47, double* %10
%48 = load i8*, i8** %7
%49 = call double @mtime(i8* %48)
store double %49, double* %9
%50 = load i32, i32* @stderr
%51 = load double, double* %9
%52 = call i32 (i32, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), double %51)
%53 = load double, double* %9
%54 = load double, double* %10
%55 = fcmp oeq double %53, %54
br i1 %55, label %56, label %57
56: ; preds = %45
br label %45
57: ; preds = %45
%58 = load i8**, i8*** %8
%59 = icmp ne i8** %58, null
br i1 %59, label %60, label %65
60: ; preds = %57
%61 = load i8**, i8*** %8
%62 = load i8*, i8** %61
%63 = load i8**, i8*** %8
%64 = call i32 @sys(i8* %62, i8** %63)
br label %68
65: ; preds = %57
%66 = load i8*, i8** %7
%67 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %66)
br label %68
68: ; preds = %65, %60
br label %45
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [40 x i8] c"Usage: %s path [ command [ args .. ] ]\0A\00"
@.str.1 = [13 x i8] c"mtime: %.3f\0A\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = load i8*, i8** %1
br label %4
4: ; preds = %11, %2
%5 = phi i8* [ null, %2 ], [ %8, %11 ]
%6 = phi i8** [ %1, %2 ], [ %7, %11 ]
%7 = getelementptr inbounds i8*, i8** %6, i64 1
%8 = load i8*, i8** %7
%9 = icmp eq i8* %8, null
%10 = icmp eq i8* %5, null
br i1 %9, label %12, label %11
11: ; preds = %4
br i1 %10, label %4, label %17
12: ; preds = %4
br i1 %10, label %13, label %17
13: ; preds = %12
%14 = load i32, i32* @stderr
%15 = tail call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* %3)
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %11, %12
%18 = phi i8** [ null, %12 ], [ %7, %11 ]
%19 = tail call double @mtime(i8* %5)
%20 = load i32, i32* @stderr
%21 = tail call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), double %19)
%22 = icmp eq i8** %18, null
br label %23
23: ; preds = %34, %17
%24 = phi double [ %19, %17 ], [ %26, %34 ]
%25 = tail call i32 @usleep(i32 50000)
%26 = tail call double @mtime(i8* %5)
%27 = load i32, i32* @stderr
%28 = tail call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), double %26)
%29 = fcmp oeq double %26, %24
br i1 %29, label %34, label %30
30: ; preds = %23
br i1 %22, label %35, label %31
31: ; preds = %30
%32 = load i8*, i8** %18
%33 = tail call i32 @sys(i8* %32, i8** %18)
br label %34
34: ; preds = %31, %35, %23
br label %23
35: ; preds = %30
%36 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %5)
br label %34
}