#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*/ execlp(char *, char *, char *);
scalar_t__ getpid();
scalar_t__ getppid();
int /*<<< orphan*/ mkdir(char *, int);
int /*<<< orphan*/ mount(char *, char *, char *, int /*<<< orphan*/,
                         int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int child(void *arg) {
  printf("My PID: %ld\n", (long)getpid());
  printf("My PPID: %ld\n", (long)getppid());
  char *mount_point = arg;
  if (mount_point != NULL) {
    mkdir(mount_point, 0555);
    mount("proc", mount_point, "proc", 0, NULL);
    printf("Mountinf procfs at %s\n", mount_point);
  }
  execlp("bash", "bash", (char *)NULL);
  return 0;
}


x86 assembly (clang, -O0):
<child>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %rax,%rsi
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   1070 <getppid@plt>
mov    %rax,%rsi
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11e9 <child+0x89>
mov    -0x10(%rbp),%rdi
mov    $0x16d,%esi
call   1030 <mkdir@plt>
mov    -0x10(%rbp),%rsi
lea    0xe53(%rip),%rdx
xor    %ecx,%ecx
xor    %eax,%eax
mov    %eax,%r8d
mov    %rdx,%rdi
call   1050 <mount@plt>
mov    -0x10(%rbp),%rsi
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe47(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
mov    %rsi,%rdi
call   1080 <execlp@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<child>:
push   %rbx
mov    %rdi,%rbx
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe8e(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   1070 <getppid@plt>
lea    0xe83(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
test   %rbx,%rbx
je     11ce <child+0x6e>
mov    %rbx,%rdi
mov    $0x16d,%esi
call   1030 <mkdir@plt>
lea    0xe6e(%rip),%rdi
mov    %rbx,%rsi
mov    %rdi,%rdx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1050 <mount@plt>
lea    0xe5c(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe62(%rip),%rdi
mov    %rdi,%rsi
xor    %edx,%edx
call   1080 <execlp@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [13 x i8] c"My PID: %ld\0A\00"
@.str.1 = [14 x i8] c"My PPID: %ld\0A\00"
@.str.2 = [5 x i8] c"proc\00"
@.str.3 = [23 x i8] c"Mountinf procfs at %s\0A\00"
@.str.4 = [5 x i8] c"bash\00"
define i32 @child(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
%4 = call i64 (...) @getpid()
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i64 %4)
%6 = call i64 (...) @getppid()
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i64 %6)
%8 = load i8*, i8** %2
store i8* %8, i8** %3
%9 = load i8*, i8** %3
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %18
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = call i32 @mkdir(i8* %12, i32 365)
%14 = load i8*, i8** %3
%15 = call i32 @mount(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 0, i32* null)
%16 = load i8*, i8** %3
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %16)
br label %18
18: ; preds = %11, %1
%19 = call i32 @execlp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* null)
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"My PID: %ld\0A\00"
@.str.1 = [14 x i8] c"My PPID: %ld\0A\00"
@.str.2 = [5 x i8] c"proc\00"
@.str.3 = [23 x i8] c"Mountinf procfs at %s\0A\00"
@.str.4 = [5 x i8] c"bash\00"
define i32 @child(i8* %0) {
%2 = tail call i64 (...) @getpid()
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 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 ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i64 %4)
%6 = icmp eq i8* %0, null
br i1 %6, label %11, 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 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br label %11
11: ; preds = %7, %1
%12 = tail call i32 @execlp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* null)
ret i32 0
}