#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*/ LOG_ERR;
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *);
int /*<<< orphan*/ verifyFile(char const *, char const *, char const *);
int waitForChild(int, int);
int monitorFile(const char *path, const char *file, const char *contents,
                int timeout) {
  int pid;
  int file_ok;
  pid = fork();
  if (pid == 0) {
    verifyFile(path, file, contents);
    exit(1);
  } else if (pid > 0) {
    file_ok = waitForChild(pid, timeout);
    return file_ok;
  } else {
    syslog(LOG_ERR, "Error encountered when child process was forked.");
    exit(1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<monitorFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jne    1196 <monitorFile+0x46>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1060 <verifyFile@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
cmpl   $0x0,-0x20(%rbp)
jle    11b7 <monitorFile+0x67>
mov    -0x20(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1040 <waitForChild@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
lea    0xe39(%rip),%rsi
call   1030 <syslog@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

x86 assembly (clang, -O2):
<monitorFile>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %ecx,%ebx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
je     1184 <monitorFile+0x34>
jle    119c <monitorFile+0x4c>
mov    %eax,%edi
mov    %ebx,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <waitForChild@plt>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1060 <verifyFile@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
lea    0xe54(%rip),%rsi
call   1030 <syslog@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@LOG_ERR = global i32 0
@.str = [49 x i8] c"Error encountered when child process was forked.\00"
define i32 @monitorFile(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%11 = call i32 (...) @fork()
store i32 %11, i32* %9
%12 = load i32, i32* %9
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %20
14: ; preds = %4
%15 = load i8*, i8** %5
%16 = load i8*, i8** %6
%17 = load i8*, i8** %7
%18 = call i32 @verifyFile(i8* %15, i8* %16, i8* %17)
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %4
%21 = load i32, i32* %9
%22 = icmp sgt i32 %21, 0
br i1 %22, label %23, label %28
23: ; preds = %20
%24 = load i32, i32* %9
%25 = load i32, i32* %8
%26 = call i32 @waitForChild(i32 %24, i32 %25)
store i32 %26, i32* %10
%27 = load i32, i32* %10
ret i32 %27
28: ; preds = %20
%29 = load i32, i32* @LOG_ERR
%30 = call i32 @syslog(i32 %29, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
%31 = call i32 @exit(i32 1)
unreachable
}

LLVM IR (-O2):
@LOG_ERR = global i32 0
@.str = [49 x i8] c"Error encountered when child process was forked.\00"
define i32 @monitorFile(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = tail call i32 (...) @fork()
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %4
%8 = tail call i32 @verifyFile(i8* %0, i8* %1, i8* %2)
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %4
%11 = icmp sgt i32 %5, 0
br i1 %11, label %12, label %14
12: ; preds = %10
%13 = tail call i32 @waitForChild(i32 %5, i32 %3)
ret i32 %13
14: ; preds = %10
%15 = load i32, i32* @LOG_ERR
%16 = tail call i32 @syslog(i32 %15, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
%17 = tail call i32 @exit(i32 1)
unreachable
}