#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_FAILURE;
int /*<<< orphan*/ execlp(char *, char *, char *, char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ getpid();
scalar_t__ getppid();
int /*<<< orphan*/ mkdir(char *, int);
int mount(char *, char *, char *, int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int childFunc(void *arg) {
  printf("childFunc(): PID  = %ld\n", (long)getpid());
  printf("childFunc(): PPID = %ld\n", (long)getppid());
  char *mount_point = arg;
  if (mount_point != NULL) {
    mkdir(mount_point, 0555);
    if (mount("proc", mount_point, "proc", 0, NULL) == -1)
      do {
        perror("mount");
        exit(EXIT_FAILURE);
      } while (0);
    printf("Mounting procfs at %s\n", mount_point);
  }
  execlp("sleep", "sleep", "600", (char *)NULL);
  do {
    perror("execlp");
    exit(EXIT_FAILURE);
  } while (0);
}


x86 assembly (clang, -O0):
<childFunc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %rax,%rsi
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   1080 <getppid@plt>
mov    %rax,%rsi
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1231 <childFunc+0xb1>
mov    -0x18(%rbp),%rdi
mov    $0x16d,%esi
call   1030 <mkdir@plt>
mov    -0x18(%rbp),%rsi
lea    0xe4a(%rip),%rdx
xor    %ecx,%ecx
xor    %eax,%eax
mov    %eax,%r8d
mov    %rdx,%rdi
call   1050 <mount@plt>
cmp    $0xffffffff,%eax
jne    121f <childFunc+0x9f>
jmp    1205 <childFunc+0x85>
lea    0xe2b(%rip),%rdi
call   1070 <perror@plt>
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x18(%rbp),%rsi
lea    0xe13(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe1c(%rip),%rsi
lea    0xe1b(%rip),%rdx
xor    %eax,%eax
mov    %eax,%ecx
mov    %rsi,%rdi
call   10a0 <execlp@plt>
lea    0xe0c(%rip),%rdi
call   1070 <perror@plt>
mov    0x2d82(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<childFunc>:
push   %rbx
mov    %rdi,%rbx
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe6e(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   1080 <getppid@plt>
lea    0xe6f(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
test   %rbx,%rbx
je     11fc <childFunc+0x7c>
mov    %rbx,%rdi
mov    $0x16d,%esi
call   1030 <mkdir@plt>
lea    0xe65(%rip),%rdi
mov    %rbx,%rsi
mov    %rdi,%rdx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1050 <mount@plt>
cmp    $0xffffffff,%eax
jne    11eb <childFunc+0x6b>
lea    0xe4e(%rip),%rdi
jmp    121b <childFunc+0x9b>
lea    0xe4b(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe51(%rip),%rdi
lea    0xe50(%rip),%rdx
mov    %rdi,%rsi
xor    %ecx,%ecx
call   10a0 <execlp@plt>
lea    0xe43(%rip),%rdi
call   1070 <perror@plt>
mov    0x2db9(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [25 x i8] c"childFunc(): PID = %ld\0A\00"
@.str.1 = [25 x i8] c"childFunc(): PPID = %ld\0A\00"
@.str.2 = [5 x i8] c"proc\00"
@.str.3 = [6 x i8] c"mount\00"
@EXIT_FAILURE = global i32 0
@.str.4 = [23 x i8] c"Mounting procfs at %s\0A\00"
@.str.5 = [6 x i8] c"sleep\00"
@.str.6 = [4 x i8] c"600\00"
@.str.7 = [7 x i8] c"execlp\00"
define i32 @childFunc(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = call i64 (...) @getpid()
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i64 %5)
%7 = call i64 (...) @getppid()
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i64 %7)
%9 = load i8*, i8** %3
store i8* %9, i8** %4
%10 = load i8*, i8** %4
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %27
12: ; preds = %1
%13 = load i8*, i8** %4
%14 = call i32 @mkdir(i8* %13, i32 365)
%15 = load i8*, i8** %4
%16 = call i32 @mount(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 0, i32* null)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %24
18: ; preds = %12
br label %19
19: ; preds = %18
%20 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; No predecessors!
br label %24
24: ; preds = %23, %12
%25 = load i8*, i8** %4
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* %25)
br label %27
27: ; preds = %24, %1
%28 = call i32 @execlp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* null)
br label %29
29: ; preds = %27
%30 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
%31 = load i32, i32* @EXIT_FAILURE
%32 = call i32 @exit(i32 %31)
unreachable
33: ; No predecessors!
%34 = load i32, i32* %2
ret i32 %34
}

LLVM IR (-O2):
@.str = [25 x i8] c"childFunc(): PID = %ld\0A\00"
@.str.1 = [25 x i8] c"childFunc(): PPID = %ld\0A\00"
@.str.2 = [5 x i8] c"proc\00"
@.str.3 = [6 x i8] c"mount\00"
@EXIT_FAILURE = global i32 0
@.str.4 = [23 x i8] c"Mounting procfs at %s\0A\00"
@.str.5 = [6 x i8] c"sleep\00"
@.str.6 = [4 x i8] c"600\00"
@.str.7 = [7 x i8] c"execlp\00"
define i32 @childFunc(i8* %0) {
%2 = tail call i64 (...) @getpid()
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i64 %2)
%4 = tail call i64 (...) @getppid()
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i64 %4)
%6 = icmp eq i8* %0, null
br i1 %6, label %17, label %7
7: ; preds = %1
%8 = tail call i32 @mkdir(i8* %0, i32 365)
%9 = tail call i32 @mount(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 0, i32* null)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %15
11: ; preds = %7
%12 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @exit(i32 %13)
unreachable
15: ; preds = %7
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* %0)
br label %17
17: ; preds = %15, %1
%18 = tail call i32 @execlp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* null)
%19 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
%20 = load i32, i32* @EXIT_FAILURE
%21 = tail call i32 @exit(i32 %20)
unreachable
}