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

/* Variables and functions */
int /*<<< orphan*/ LOG_ERR;
scalar_t__ WEXITSTATUS(int);
int /*<<< orphan*/ execv(char *, char **);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ nsyslog(int /*<<< orphan*/, char *);
scalar_t__ stat(char *, struct stat *);
int wait(int *);
int mount_proc(void) {
  struct stat st;
  int pid, wst;
  char *args[] = {"mount", "-t", "proc", "none", "/proc", NULL};
  int did_mount = 0;
  if (stat("/proc/version", &st) < 0) {
    if ((pid = fork()) < 0) {
      nsyslog(LOG_ERR, "cannot fork");
      exit(1);
    }
    if (pid == 0) {
      execv("/sbin/mount", args);
      execv("/etc/mount", args);
      execv("/bin/mount", args);
      nsyslog(LOG_ERR, "cannot execute mount");
      exit(1);
    }
    while (wait(&wst) != pid)
      ;
    if (WEXITSTATUS(wst) != 0)
      nsyslog(LOG_ERR, "mount returned non-zero exit status");
    did_mount = 1;
  }
  if (stat("/proc/version", &st) < 0) {
    nsyslog(LOG_ERR, "/proc not mounted, failed to mount.");
    exit(1);
  }
  return did_mount;
}


x86 assembly (clang, -O0):
<mount_proc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1030 <memset@plt>
lea    0xeba(%rip),%rax
mov    %rax,-0x40(%rbp)
lea    0xe56(%rip),%rax
mov    %rax,-0x38(%rbp)
lea    0xe54(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    0xe43(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xe3d(%rip),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x44(%rbp)
lea    0xe31(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <stat@plt>
cmp    $0x0,%rax
jge    12c5 <mount_proc+0x145>
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    1222 <mount_proc+0xa2>
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
lea    0xe09(%rip),%rsi
call   1060 <nsyslog@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
cmpl   $0x0,-0xc(%rbp)
jne    127b <mount_proc+0xfb>
lea    -0x40(%rbp),%rsi
lea    0xdf1(%rip),%rdi
call   1090 <execv@plt>
lea    -0x40(%rbp),%rsi
lea    0xded(%rip),%rdi
call   1090 <execv@plt>
lea    -0x40(%rbp),%rsi
lea    0xde8(%rip),%rdi
call   1090 <execv@plt>
mov    0x2d75(%rip),%rax
mov    (%rax),%edi
lea    0xdde(%rip),%rsi
call   1060 <nsyslog@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    1280 <mount_proc+0x100>
lea    -0x10(%rbp),%rdi
call   1080 <wait@plt>
cmp    -0xc(%rbp),%eax
je     1297 <mount_proc+0x117>
jmp    1280 <mount_proc+0x100>
mov    -0x10(%rbp),%edi
call   1050 <WEXITSTATUS@plt>
cmp    $0x0,%rax
je     12be <mount_proc+0x13e>
mov    0x2d28(%rip),%rax
mov    (%rax),%edi
lea    0xda6(%rip),%rsi
call   1060 <nsyslog@plt>
movl   $0x1,-0x44(%rbp)
lea    0xd42(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <stat@plt>
cmp    $0x0,%rax
jge    12fe <mount_proc+0x17e>
mov    0x2cf2(%rip),%rax
mov    (%rax),%edi
lea    0xd94(%rip),%rsi
call   1060 <nsyslog@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x44(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mount_proc>:
push   %r14
push   %rbx
sub    $0x48,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x30(%rsp)
lea    0xed3(%rip),%rax
mov    %rax,0x10(%rsp)
lea    0xe6e(%rip),%rax
mov    %rax,0x18(%rsp)
lea    0xe6b(%rip),%rax
mov    %rax,0x20(%rsp)
lea    0xe59(%rip),%rax
mov    %rax,0x28(%rsp)
lea    0xe52(%rip),%rax
mov    %rax,0x30(%rsp)
lea    0xe4c(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1030 <stat@plt>
xor    %ebx,%ebx
test   %rax,%rax
jns    1224 <mount_proc+0xb4>
xor    %eax,%eax
call   1090 <fork@plt>
test   %eax,%eax
js     1256 <mount_proc+0xe6>
je     1268 <mount_proc+0xf8>
mov    %eax,%ebx
lea    0xc(%rsp),%r14
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1070 <wait@plt>
cmp    %ebx,%eax
jne    11f0 <mount_proc+0x80>
mov    0xc(%rsp),%edi
call   1040 <WEXITSTATUS@plt>
mov    $0x1,%ebx
test   %rax,%rax
je     1224 <mount_proc+0xb4>
mov    0x2dc2(%rip),%rax
mov    (%rax),%edi
lea    0xe40(%rip),%rsi
call   1050 <nsyslog@plt>
lea    0xde3(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1030 <stat@plt>
test   %rax,%rax
js     1244 <mount_proc+0xd4>
mov    %ebx,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2d8d(%rip),%rax
mov    (%rax),%edi
lea    0xe2f(%rip),%rsi
jmp    12aa <mount_proc+0x13a>
mov    0x2d7b(%rip),%rax
mov    (%rax),%edi
lea    0xdb6(%rip),%rsi
jmp    12aa <mount_proc+0x13a>
lea    0xdb9(%rip),%rdi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
call   1080 <execv@plt>
lea    0xdb1(%rip),%rdi
mov    %rbx,%rsi
call   1080 <execv@plt>
lea    0xdad(%rip),%rdi
mov    %rbx,%rsi
call   1080 <execv@plt>
mov    0x2d37(%rip),%rax
mov    (%rax),%edi
lea    0xda0(%rip),%rsi
call   1050 <nsyslog@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [6 x i8] c"mount\00"
@.str.1 = [3 x i8] c"-t\00"
@.str.2 = [5 x i8] c"proc\00"
@.str.3 = [5 x i8] c"none\00"
@.str.4 = [6 x i8] c"/proc\00"
@.str.5 = [14 x i8] c"/proc/version\00"
@LOG_ERR = global i32 0
@.str.6 = [12 x i8] c"cannot fork\00"
@.str.7 = [12 x i8] c"/sbin/mount\00"
@.str.8 = [11 x i8] c"/etc/mount\00"
@.str.9 = [11 x i8] c"/bin/mount\00"
@.str.10 = [21 x i8] c"cannot execute mount\00"
@.str.11 = [36 x i8] c"mount returned non-zero exit status\00"
@.str.12 = [36 x i8] c"/proc not mounted, failed to mount.\00"
define i32 @mount_proc() {
%1 = alloca %struct.stat
%2 = alloca i32
%3 = alloca i32
%4 = alloca [6 x i8*]
%5 = alloca i32
%6 = bitcast [6 x i8*]* %4 to i8*
%7 = bitcast i8* %6 to [6 x i8*]*
%8 = getelementptr inbounds [6 x i8*], [6 x i8*]* %7, i32 0, i32 0
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i32 0, i32 0), i8** %8
%9 = getelementptr inbounds [6 x i8*], [6 x i8*]* %7, i32 0, i32 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0), i8** %9
%10 = getelementptr inbounds [6 x i8*], [6 x i8*]* %7, i32 0, i32 2
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i32 0, i32 0), i8** %10
%11 = getelementptr inbounds [6 x i8*], [6 x i8*]* %7, i32 0, i32 3
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i32 0, i32 0), i8** %11
%12 = getelementptr inbounds [6 x i8*], [6 x i8*]* %7, i32 0, i32 4
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i32 0, i32 0), i8** %12
store i32 0, i32* %5
%13 = call i64 @stat(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), %struct.stat* %1)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %49
15: ; preds = %0
%16 = call i32 (...) @fork()
store i32 %16, i32* %2
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %15
%19 = load i32, i32* @LOG_ERR
%20 = call i32 @nsyslog(i32 %19, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %15
%23 = load i32, i32* %2
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %35
25: ; preds = %22
%26 = getelementptr inbounds [6 x i8*], [6 x i8*]* %4, i64 0, i64 0
%27 = call i32 @execv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), i8** %26)
%28 = getelementptr inbounds [6 x i8*], [6 x i8*]* %4, i64 0, i64 0
%29 = call i32 @execv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0), i8** %28)
%30 = getelementptr inbounds [6 x i8*], [6 x i8*]* %4, i64 0, i64 0
%31 = call i32 @execv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0), i8** %30)
%32 = load i32, i32* @LOG_ERR
%33 = call i32 @nsyslog(i32 %32, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.10, i64 0, i64 0))
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %22
br label %36
36: ; preds = %40, %35
%37 = call i32 @wait(i32* %3)
%38 = load i32, i32* %2
%39 = icmp ne i32 %37, %38
br i1 %39, label %40, label %41
40: ; preds = %36
br label %36
41: ; preds = %36
%42 = load i32, i32* %3
%43 = call i64 @WEXITSTATUS(i32 %42)
%44 = icmp ne i64 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %41
%46 = load i32, i32* @LOG_ERR
%47 = call i32 @nsyslog(i32 %46, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.11, i64 0, i64 0))
br label %48
48: ; preds = %45, %41
store i32 1, i32* %5
br label %49
49: ; preds = %48, %0
%50 = call i64 @stat(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), %struct.stat* %1)
%51 = icmp slt i64 %50, 0
br i1 %51, label %52, label %56
52: ; preds = %49
%53 = load i32, i32* @LOG_ERR
%54 = call i32 @nsyslog(i32 %53, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.12, i64 0, i64 0))
%55 = call i32 @exit(i32 1)
unreachable
56: ; preds = %49
%57 = load i32, i32* %5
ret i32 %57
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [6 x i8] c"mount\00"
@.str.1 = [3 x i8] c"-t\00"
@.str.2 = [5 x i8] c"proc\00"
@.str.3 = [5 x i8] c"none\00"
@.str.4 = [6 x i8] c"/proc\00"
@.str.5 = [14 x i8] c"/proc/version\00"
@LOG_ERR = global i32 0
@.str.6 = [12 x i8] c"cannot fork\00"
@.str.7 = [12 x i8] c"/sbin/mount\00"
@.str.8 = [11 x i8] c"/etc/mount\00"
@.str.9 = [11 x i8] c"/bin/mount\00"
@.str.10 = [21 x i8] c"cannot execute mount\00"
@.str.11 = [36 x i8] c"mount returned non-zero exit status\00"
@.str.12 = [36 x i8] c"/proc not mounted, failed to mount.\00"
define i32 @mount_proc() {
%1 = alloca %struct.stat
%2 = alloca i32
%3 = alloca [6 x i8*]
%4 = bitcast %struct.stat* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = bitcast [6 x i8*]* %3 to i8*
%7 = getelementptr inbounds [6 x i8*], [6 x i8*]* %3, i64 0, i64 4
%8 = bitcast i8** %7 to i8*
%9 = getelementptr inbounds [6 x i8*], [6 x i8*]* %3, i64 0, i64 0
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8** %9
%10 = getelementptr inbounds [6 x i8*], [6 x i8*]* %3, i64 0, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %10
%11 = getelementptr inbounds [6 x i8*], [6 x i8*]* %3, i64 0, i64 2
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8** %11
%12 = getelementptr inbounds [6 x i8*], [6 x i8*]* %3, i64 0, i64 3
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8** %12
%13 = getelementptr inbounds [6 x i8*], [6 x i8*]* %3, i64 0, i64 4
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8** %13
%14 = call i64 @stat(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), %struct.stat* %1)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %42
16: ; preds = %0
%17 = call i32 (...) @fork()
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %16
%20 = load i32, i32* @LOG_ERR
%21 = call i32 @nsyslog(i32 %20, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0))
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %16
%24 = icmp eq i32 %17, 0
br i1 %24, label %25, label %32
25: ; preds = %23
%26 = call i32 @execv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), i8** %9)
%27 = call i32 @execv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0), i8** %9)
%28 = call i32 @execv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0), i8** %9)
%29 = load i32, i32* @LOG_ERR
%30 = call i32 @nsyslog(i32 %29, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.10, i64 0, i64 0))
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %23, %32
%33 = call i32 @wait(i32* %2)
%34 = icmp eq i32 %33, %17
br i1 %34, label %35, label %32
35: ; preds = %32
%36 = load i32, i32* %2
%37 = call i64 @WEXITSTATUS(i32 %36)
%38 = icmp eq i64 %37, 0
br i1 %38, label %42, label %39
39: ; preds = %35
%40 = load i32, i32* @LOG_ERR
%41 = call i32 @nsyslog(i32 %40, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.11, i64 0, i64 0))
br label %42
42: ; preds = %35, %39, %0
%43 = phi i32 [ 0, %0 ], [ 1, %39 ], [ 1, %35 ]
%44 = call i64 @stat(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), %struct.stat* %1)
%45 = icmp slt i64 %44, 0
br i1 %45, label %46, label %50
46: ; preds = %42
%47 = load i32, i32* @LOG_ERR
%48 = call i32 @nsyslog(i32 %47, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.12, i64 0, i64 0))
%49 = call i32 @exit(i32 1)
unreachable
50: ; preds = %42
ret i32 %43
}