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

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


x86 assembly (clang, -O0):
<mount_proc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1030 <memset@plt>
lea    0xeaa(%rip),%rax
mov    %rax,-0x40(%rbp)
lea    0xe56(%rip),%rax
mov    %rax,-0x38(%rbp)
lea    0xe4f(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    0xe44(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xe38(%rip),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x58(%rbp)
lea    0xe2c(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <stat@plt>
cmp    $0x0,%rax
jge    130f <mount_proc+0x18f>
mov    0x2de9(%rip),%rax
mov    (%rax),%rax
mov    0x2dc7(%rip),%rcx
cmp    (%rcx),%rax
jne    130f <mount_proc+0x18f>
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %rax,-0x48(%rbp)
cmp    $0x0,%rax
jge    123e <mount_proc+0xbe>
mov    0x2d9a(%rip),%rax
mov    (%rax),%edi
lea    0xde8(%rip),%rsi
call   1060 <nsyslog@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
cmpq   $0x0,-0x48(%rbp)
jne    1288 <mount_proc+0x108>
lea    -0x40(%rbp),%rsi
lea    0xdcf(%rip),%rdi
call   1090 <execv@plt>
lea    -0x40(%rbp),%rsi
lea    0xdcb(%rip),%rdi
call   1090 <execv@plt>
mov    0x2d50(%rip),%rax
mov    (%rax),%edi
lea    0xdc1(%rip),%rsi
call   1060 <nsyslog@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    128d <mount_proc+0x10d>
lea    -0x54(%rbp),%rdi
call   1080 <wait@plt>
mov    %rax,-0x50(%rbp)
cmp    -0x48(%rbp),%rax
je     12d3 <mount_proc+0x153>
cmpq   $0x0,-0x50(%rbp)
jge    12ce <mount_proc+0x14e>
mov    0x2d2a(%rip),%rax
mov    (%rax),%rax
mov    0x2d18(%rip),%rcx
cmp    (%rcx),%rax
jne    12ce <mount_proc+0x14e>
jmp    12d3 <mount_proc+0x153>
jmp    128d <mount_proc+0x10d>
mov    -0x50(%rbp),%rax
cmp    -0x48(%rbp),%rax
jne    12f3 <mount_proc+0x173>
mov    -0x54(%rbp),%edi
call   1050 <WEXITSTATUS@plt>
cmp    $0x0,%rax
je     1308 <mount_proc+0x188>
mov    0x2cc6(%rip),%rax
mov    (%rax),%edi
lea    0xd4c(%rip),%rsi
call   1060 <nsyslog@plt>
movl   $0x1,-0x58(%rbp)
lea    0xcf3(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <stat@plt>
cmp    $0x0,%rax
jge    137c <mount_proc+0x1fc>
mov    0x2cb0(%rip),%rax
mov    (%rax),%rax
mov    0x2c8e(%rip),%rcx
cmp    (%rcx),%rax
jne    135d <mount_proc+0x1dd>
mov    0x2c76(%rip),%rax
mov    (%rax),%edi
lea    0xd20(%rip),%rsi
call   1060 <nsyslog@plt>
jmp    1372 <mount_proc+0x1f2>
mov    0x2c5c(%rip),%rax
mov    (%rax),%edi
lea    0xd2a(%rip),%rsi
call   1060 <nsyslog@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x58(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mount_proc>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x48,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x30(%rsp)
lea    0xebf(%rip),%rax
mov    %rax,0x10(%rsp)
lea    0xe6a(%rip),%rax
mov    %rax,0x18(%rsp)
lea    0xe62(%rip),%rax
mov    %rax,0x20(%rsp)
mov    %rax,0x28(%rsp)
lea    0xe50(%rip),%rax
mov    %rax,0x30(%rsp)
lea    0xe4a(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1030 <stat@plt>
xor    %ebx,%ebx
test   %rax,%rax
jns    1265 <mount_proc+0xf5>
mov    0x2e05(%rip),%r15
mov    (%r15),%rax
mov    0x2de3(%rip),%rcx
cmp    (%rcx),%rax
jne    1265 <mount_proc+0xf5>
xor    %eax,%eax
call   1090 <fork@plt>
test   %rax,%rax
js     12c7 <mount_proc+0x157>
je     12d9 <mount_proc+0x169>
mov    %rax,%rbx
lea    0x4(%rsp),%rdi
call   1070 <wait@plt>
cmp    %rbx,%rax
jne    1222 <mount_proc+0xb2>
mov    0x4(%rsp),%edi
call   1040 <WEXITSTATUS@plt>
test   %rax,%rax
jne    124b <mount_proc+0xdb>
jmp    1260 <mount_proc+0xf0>
mov    0x2daf(%rip),%r12
lea    0x4(%rsp),%r14
jmp    123d <mount_proc+0xcd>
mov    %r14,%rdi
call   1070 <wait@plt>
cmp    %rbx,%rax
je     1212 <mount_proc+0xa2>
test   %rax,%rax
jns    1230 <mount_proc+0xc0>
mov    (%r15),%rax
cmp    (%r12),%rax
jne    1230 <mount_proc+0xc0>
mov    0x2d6e(%rip),%rax
mov    (%rax),%edi
lea    0xdf4(%rip),%rsi
call   1050 <nsyslog@plt>
mov    $0x1,%ebx
lea    0xd9d(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1030 <stat@plt>
test   %rax,%rax
js     1289 <mount_proc+0x119>
mov    %ebx,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2d50(%rip),%rax
mov    (%rax),%rax
mov    0x2d2e(%rip),%rcx
cmp    (%rcx),%rax
mov    0x2d1c(%rip),%rax
mov    (%rax),%edi
lea    0xdc6(%rip),%rax
lea    0xde3(%rip),%rsi
cmove  %rax,%rsi
call   1050 <nsyslog@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    0x2cf2(%rip),%rax
mov    (%rax),%edi
lea    0xd40(%rip),%rsi
jmp    12b8 <mount_proc+0x148>
lea    0xd43(%rip),%rdi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
call   1080 <execv@plt>
lea    0xd3b(%rip),%rdi
mov    %rbx,%rsi
call   1080 <execv@plt>
mov    0x2cbd(%rip),%rax
mov    (%rax),%edi
lea    0xd2e(%rip),%rsi
jmp    12b8 <mount_proc+0x148>

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 = [6 x i8] c"/proc\00"
@.str.4 = [14 x i8] c"/proc/version\00"
@errno = global i64 0
@ENOENT = global i64 0
@LOG_ERR = global i32 0
@.str.5 = [12 x i8] c"cannot fork\00"
@.str.6 = [12 x i8] c"/sbin/mount\00"
@.str.7 = [11 x i8] c"/bin/mount\00"
@.str.8 = [21 x i8] c"cannot execute mount\00"
@ECHILD = global i64 0
@.str.9 = [36 x i8] c"mount returned non-zero exit status\00"
@.str.10 = [36 x i8] c"/proc not mounted, failed to mount.\00"
@.str.11 = [19 x i8] c"/proc unavailable.\00"
define i32 @mount_proc() {
%1 = alloca %struct.stat
%2 = alloca [6 x i8*]
%3 = alloca i64
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
%7 = bitcast [6 x i8*]* %2 to i8*
%8 = bitcast i8* %7 to [6 x i8*]*
%9 = getelementptr inbounds [6 x i8*], [6 x i8*]* %8, i32 0, i32 0
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i32 0, i32 0), i8** %9
%10 = getelementptr inbounds [6 x i8*], [6 x i8*]* %8, i32 0, i32 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0), i8** %10
%11 = getelementptr inbounds [6 x i8*], [6 x i8*]* %8, i32 0, i32 2
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i32 0, i32 0), i8** %11
%12 = getelementptr inbounds [6 x i8*], [6 x i8*]* %8, i32 0, i32 3
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i32 0, i32 0), i8** %12
%13 = getelementptr inbounds [6 x i8*], [6 x i8*]* %8, i32 0, i32 4
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i32 0, i32 0), i8** %13
store i32 0, i32* %6
%14 = call i64 @stat(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), %struct.stat* %1)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %64
16: ; preds = %0
%17 = load i64, i64* @errno
%18 = load i64, i64* @ENOENT
%19 = icmp eq i64 %17, %18
br i1 %19, label %20, label %64
20: ; preds = %16
%21 = call i64 (...) @fork()
store i64 %21, i64* %3
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %20
%24 = load i32, i32* @LOG_ERR
%25 = call i32 @nsyslog(i32 %24, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %20
%28 = load i64, i64* %3
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %38
30: ; preds = %27
%31 = getelementptr inbounds [6 x i8*], [6 x i8*]* %2, i64 0, i64 0
%32 = call i32 @execv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i8** %31)
%33 = getelementptr inbounds [6 x i8*], [6 x i8*]* %2, i64 0, i64 0
%34 = call i32 @execv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), i8** %33)
%35 = load i32, i32* @LOG_ERR
%36 = call i32 @nsyslog(i32 %35, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0))
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %27
br label %39
39: ; preds = %51, %38
%40 = call i64 @wait(i32* %5)
store i64 %40, i64* %4
%41 = load i64, i64* %3
%42 = icmp ne i64 %40, %41
br i1 %42, label %43, label %52
43: ; preds = %39
%44 = load i64, i64* %4
%45 = icmp slt i64 %44, 0
br i1 %45, label %46, label %51
46: ; preds = %43
%47 = load i64, i64* @errno
%48 = load i64, i64* @ECHILD
%49 = icmp eq i64 %47, %48
br i1 %49, label %50, label %51
50: ; preds = %46
br label %52
51: ; preds = %46, %43
br label %39
52: ; preds = %50, %39
%53 = load i64, i64* %4
%54 = load i64, i64* %3
%55 = icmp ne i64 %53, %54
br i1 %55, label %60, label %56
56: ; preds = %52
%57 = load i32, i32* %5
%58 = call i64 @WEXITSTATUS(i32 %57)
%59 = icmp ne i64 %58, 0
br i1 %59, label %60, label %63
60: ; preds = %56, %52
%61 = load i32, i32* @LOG_ERR
%62 = call i32 @nsyslog(i32 %61, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.9, i64 0, i64 0))
br label %63
63: ; preds = %60, %56
store i32 1, i32* %6
br label %64
64: ; preds = %63, %16, %0
%65 = call i64 @stat(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), %struct.stat* %1)
%66 = icmp slt i64 %65, 0
br i1 %66, label %67, label %79
67: ; preds = %64
%68 = load i64, i64* @errno
%69 = load i64, i64* @ENOENT
%70 = icmp eq i64 %68, %69
br i1 %70, label %71, label %74
71: ; preds = %67
%72 = load i32, i32* @LOG_ERR
%73 = call i32 @nsyslog(i32 %72, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.10, i64 0, i64 0))
br label %77
74: ; preds = %67
%75 = load i32, i32* @LOG_ERR
%76 = call i32 @nsyslog(i32 %75, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.11, i64 0, i64 0))
br label %77
77: ; preds = %74, %71
%78 = call i32 @exit(i32 1)
unreachable
79: ; preds = %64
%80 = load i32, i32* %6
ret i32 %80
}

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