#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 scalar_t__ pid_t;

/* Variables and functions */
int /*<<< orphan*/ LINUX_REBOOT_CMD_RESTART;
int WEXITSTATUS(int);
scalar_t__ WIFEXITED(int);
scalar_t__ execve(char *, char **, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
scalar_t__ fork();
scalar_t__ mount(char *, char *, char *, int /*<<< orphan*/,
                 int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ reboot(int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ usleep(int);
int /*<<< orphan*/ waitpid(scalar_t__, int *, int /*<<< orphan*/);
int main(void) {
  int ReturnVal;
  pid_t RioplayPID;
  int status;
  char *ntpargs[] = {"-b", "130.126.24.24", NULL};
  if (mount("none", "/proc", "proc", 0, NULL) != 0) {
    perror("mount");
  }
  if (fork() == 0) {
    if (execve("/bin/ntpdate", ntpargs, NULL) < 0) {
      perror("ntpdate");
      exit(0);
    }
  }
  while (1) {
    ReturnVal = 0;
    RioplayPID = fork();
    if (RioplayPID == 0) {
      execve("/bin/rioplay", NULL, NULL);
    } else {
      printf("init: rioplay started with PID %d\n", RioplayPID);
      waitpid(RioplayPID, &status, 0);
      if (WIFEXITED(status)) {
        ReturnVal = WEXITSTATUS(status);
      }
      printf("\ninit: rioplay exited with status %d\n", ReturnVal);
      if (ReturnVal < 0) {
        printf("init: error returned from waitpid()\n");
        exit(1);
      } else if (ReturnVal == 1) {
        printf("init: rebooting...\n\n");
        fflush(stdout);
        usleep(100000);
        reboot(LINUX_REBOOT_CMD_RESTART);
      }
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2c1a(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0x2c17(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0x2c14(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xe1a(%rip),%rdi
lea    0xe18(%rip),%rsi
lea    0xe12(%rip),%rdx
xor    %ecx,%ecx
xor    %eax,%eax
mov    %eax,%r8d
call   1030 <mount@plt>
cmp    $0x0,%rax
je     1227 <main+0x67>
lea    0xdfa(%rip),%rdi
call   1090 <perror@plt>
mov    $0x0,%al
call   10d0 <fork@plt>
cmp    $0x0,%rax
jne    126e <main+0xae>
lea    -0x30(%rbp),%rsi
lea    0xddf(%rip),%rdi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <execve@plt>
cmp    $0x0,%rax
jge    1269 <main+0xa9>
lea    0xdca(%rip),%rdi
call   1090 <perror@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
jmp    126e <main+0xae>
jmp    1273 <main+0xb3>
movl   $0x0,-0x8(%rbp)
mov    $0x0,%al
call   10d0 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    12a8 <main+0xe8>
lea    0xd98(%rip),%rdi
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   1050 <execve@plt>
jmp    1361 <main+0x1a1>
mov    -0x10(%rbp),%rsi
lea    0xd89(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x14(%rbp),%rsi
xor    %edx,%edx
call   1080 <waitpid@plt>
mov    -0x14(%rbp),%edi
call   10a0 <WIFEXITED@plt>
cmp    $0x0,%rax
je     12e6 <main+0x126>
mov    -0x14(%rbp),%edi
call   1070 <WEXITSTATUS@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xd6f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x0,-0x8(%rbp)
jge    1319 <main+0x159>
lea    0xd7d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
cmpl   $0x1,-0x8(%rbp)
jne    1357 <main+0x197>
lea    0xd80(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2c98(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
mov    $0x186a0,%edi
call   10e0 <usleep@plt>
mov    0x2c90(%rip),%rax
mov    (%rax),%edi
call   10c0 <reboot@plt>
jmp    135c <main+0x19c>
jmp    1361 <main+0x1a1>
jmp    1273 <main+0xb3>

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x30,%rsp
mov    0x2c24(%rip),%rax
mov    %rax,0x20(%rsp)
movaps 0x2c08(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
lea    0xe1d(%rip),%rdi
lea    0xe1b(%rip),%rsi
lea    0xe15(%rip),%rdx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1040 <mount@plt>
test   %rax,%rax
je     121d <main+0x4d>
lea    0xe04(%rip),%rdi
call   10a0 <perror@plt>
xor    %eax,%eax
call   10e0 <fork@plt>
test   %rax,%rax
jne    1270 <main+0xa0>
lea    0xdf2(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %edx,%edx
call   1060 <execve@plt>
test   %rax,%rax
jns    1270 <main+0xa0>
lea    0xddf(%rip),%rdi
call   10a0 <perror@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0xdc8(%rip),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <execve@plt>
xor    %eax,%eax
call   10e0 <fork@plt>
test   %rax,%rax
je     1260 <main+0x90>
mov    %rax,%rbx
lea    0xdb6(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
xor    %edx,%edx
call   1090 <waitpid@plt>
mov    0xc(%rsp),%edi
call   10b0 <WIFEXITED@plt>
test   %rax,%rax
je     1310 <main+0x140>
mov    0xc(%rsp),%edi
call   1080 <WEXITSTATUS@plt>
mov    %eax,%ebx
lea    0xda0(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
test   %ebx,%ebx
js     1325 <main+0x155>
cmp    $0x1,%ebx
jne    1270 <main+0xa0>
lea    0xdad(%rip),%rdi
call   1030 <puts@plt>
mov    0x2cec(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
mov    $0x186a0,%edi
call   10f0 <usleep@plt>
mov    0x2ce4(%rip),%rax
mov    (%rax),%edi
call   10d0 <reboot@plt>
jmp    1270 <main+0xa0>
nopl   0x0(%rax,%rax,1)
lea    0xd48(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1270 <main+0xa0>
lea    0xd6d(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"-b\00"
@.str.1 = [14 x i8] c"130.126.24.24\00"
@__const.main.ntpargs = [3 x i8*] [i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i32 0, i32 0), i8* null]
@.str.2 = [5 x i8] c"none\00"
@.str.3 = [6 x i8] c"/proc\00"
@.str.4 = [5 x i8] c"proc\00"
@.str.5 = [6 x i8] c"mount\00"
@.str.6 = [13 x i8] c"/bin/ntpdate\00"
@.str.7 = [8 x i8] c"ntpdate\00"
@.str.8 = [13 x i8] c"/bin/rioplay\00"
@.str.9 = [35 x i8] c"init: rioplay started with PID %d\0A\00"
@.str.10 = [38 x i8] c"\0Ainit: rioplay exited with status %d\0A\00"
@.str.11 = [37 x i8] c"init: error returned from waitpid()\0A\00"
@.str.12 = [21 x i8] c"init: rebooting...\0A\0A\00"
@stdout = global i32 0
@LINUX_REBOOT_CMD_RESTART = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i64
%4 = alloca i32
%5 = alloca [3 x i8*]
store i32 0, i32* %1
%6 = bitcast [3 x i8*]* %5 to i8*
%7 = call i64 @mount(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 0, i32* null)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
br label %11
11: ; preds = %9, %0
%12 = call i64 (...) @fork()
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %22
14: ; preds = %11
%15 = getelementptr inbounds [3 x i8*], [3 x i8*]* %5, i64 0, i64 0
%16 = call i64 @execve(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i8** %15, i32* null)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
%20 = call i32 @exit(i32 0)
unreachable
21: ; preds = %14
br label %22
22: ; preds = %21, %11
br label %23
23: ; preds = %22, %60
store i32 0, i32* %2
%24 = call i64 (...) @fork()
store i64 %24, i64* %3
%25 = load i64, i64* %3
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = call i64 @execve(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0), i8** null, i32* null)
br label %60
29: ; preds = %23
%30 = load i64, i64* %3
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.9, i64 0, i64 0), i64 %30)
%32 = load i64, i64* %3
%33 = call i32 @waitpid(i64 %32, i32* %4, i32 0)
%34 = load i32, i32* %4
%35 = call i64 @WIFEXITED(i32 %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %29
%38 = load i32, i32* %4
%39 = call i32 @WEXITSTATUS(i32 %38)
store i32 %39, i32* %2
br label %40
40: ; preds = %37, %29
%41 = load i32, i32* %2
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.10, i64 0, i64 0), i32 %41)
%43 = load i32, i32* %2
%44 = icmp slt i32 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %40
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.11, i64 0, i64 0))
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %40
%49 = load i32, i32* %2
%50 = icmp eq i32 %49, 1
br i1 %50, label %51, label %58
51: ; preds = %48
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.12, i64 0, i64 0))
%53 = load i32, i32* @stdout
%54 = call i32 @fflush(i32 %53)
%55 = call i32 @usleep(i32 100000)
%56 = load i32, i32* @LINUX_REBOOT_CMD_RESTART
%57 = call i32 @reboot(i32 %56)
br label %58
58: ; preds = %51, %48
br label %59
59: ; preds = %58
br label %60
60: ; preds = %59, %27
br label %23
}

LLVM IR (-O2):
@.str = [3 x i8] c"-b\00"
@.str.1 = [14 x i8] c"130.126.24.24\00"
@__const.main.ntpargs = [3 x i8*] [i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i32 0, i32 0), i8* null]
@.str.2 = [5 x i8] c"none\00"
@.str.3 = [6 x i8] c"/proc\00"
@.str.4 = [5 x i8] c"proc\00"
@.str.5 = [6 x i8] c"mount\00"
@.str.6 = [13 x i8] c"/bin/ntpdate\00"
@.str.7 = [8 x i8] c"ntpdate\00"
@.str.8 = [13 x i8] c"/bin/rioplay\00"
@.str.9 = [35 x i8] c"init: rioplay started with PID %d\0A\00"
@.str.10 = [38 x i8] c"\0Ainit: rioplay exited with status %d\0A\00"
@stdout = global i32 0
@LINUX_REBOOT_CMD_RESTART = global i32 0
@str = [20 x i8] c"init: rebooting...\0A\00"
@str.13 = [36 x i8] c"init: error returned from waitpid()\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [3 x i8*]
%3 = bitcast i32* %1 to i8*
%4 = bitcast [3 x i8*]* %2 to i8*
%5 = tail call i64 @mount(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 0, i32* null)
%6 = icmp eq i64 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %0
%8 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
br label %9
9: ; preds = %7, %0
%10 = tail call i64 (...) @fork()
%11 = icmp eq i64 %10, 0
br i1 %11, label %13, label %12
12: ; preds = %13, %9
br label %20
13: ; preds = %9
%14 = getelementptr inbounds [3 x i8*], [3 x i8*]* %2, i64 0, i64 0
%15 = call i64 @execve(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i8** %14, i32* null)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %12
17: ; preds = %13
%18 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
%19 = call i32 @exit(i32 0)
unreachable
20: ; preds = %33, %12
%21 = call i64 (...) @fork()
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = call i64 @execve(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0), i8** null, i32* null)
br label %33
25: ; preds = %20
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.9, i64 0, i64 0), i64 %21)
%27 = call i32 @waitpid(i64 %21, i32* %1, i32 0)
%28 = load i32, i32* %1
%29 = call i64 @WIFEXITED(i32 %28)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %25
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.10, i64 0, i64 0), i32 0)
br label %33
33: ; preds = %31, %44, %42, %23
br label %20
34: ; preds = %25
%35 = load i32, i32* %1
%36 = call i32 @WEXITSTATUS(i32 %35)
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.10, i64 0, i64 0), i32 %36)
%38 = icmp slt i32 %36, 0
br i1 %38, label %39, label %42
39: ; preds = %34
%40 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.13, i64 0, i64 0))
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %34
%43 = icmp eq i32 %36, 1
br i1 %43, label %44, label %33
44: ; preds = %42
%45 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%46 = load i32, i32* @stdout
%47 = call i32 @fflush(i32 %46)
%48 = call i32 @usleep(i32 100000)
%49 = load i32, i32* @LINUX_REBOOT_CMD_RESTART
%50 = call i32 @reboot(i32 %49)
br label %33
}