#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 MS_REC;
int MS_SLAVE;
int /*<<< orphan*/ chdir(char *);
int /*<<< orphan*/ chroot(char *);
int /*<<< orphan*/ execlp(char *, char *, char *);
scalar_t__ getpid();
scalar_t__ getppid();
int /*<<< orphan*/ mount(char *, char *, char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, long);
int child(void *arg) {
  arg = (void *)arg;
  printf("My PID: %ld\n", (long)getpid());
  printf("My PPID: %ld\n", (long)getppid());
  mount("", "/", "dontcare", MS_REC | MS_SLAVE, NULL);
  chroot("/opt/debian");
  mount("proc", "/proc", "proc", 0, NULL);
  chdir("/");
  execlp("/bin/bash", "/bin/bash", (char *)NULL);
  return 0;
}


x86 assembly (clang, -O0):
<child>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %rax,%rsi
lea    0xe6b(%rip),%rdi
call   1070 <printf@plt>
mov    $0x0,%al
call   1080 <getppid@plt>
mov    %rax,%rsi
lea    0xe62(%rip),%rdi
call   1070 <printf@plt>
mov    0x2e31(%rip),%rax
mov    (%rax),%ecx
mov    0x2e18(%rip),%rax
or     (%rax),%ecx
lea    0xe43(%rip),%rdi
lea    0xe4b(%rip),%rsi
lea    0xe46(%rip),%rdx
xor    %eax,%eax
mov    %eax,%r8d
call   1050 <mount@plt>
lea    0xe3e(%rip),%rdi
call   1030 <chroot@plt>
lea    0xe3f(%rip),%rdx
lea    0xe37(%rip),%rsi
xor    %ecx,%ecx
xor    %eax,%eax
mov    %eax,%r8d
mov    %rdx,%rdi
call   1050 <mount@plt>
lea    0xe0a(%rip),%rdi
call   1060 <chdir@plt>
lea    0xe1b(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
mov    %rsi,%rdi
call   1090 <execlp@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<child>:
push   %rbx
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe81(%rip),%rdi
mov    %rax,%rsi
call   1070 <printf@plt>
xor    %eax,%eax
call   1080 <getppid@plt>
lea    0xe78(%rip),%rdi
mov    %rax,%rsi
call   1070 <printf@plt>
mov    0x2e44(%rip),%rax
mov    0x2e2d(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
lea    0xe56(%rip),%rdi
lea    0xe5e(%rip),%rbx
lea    0xe59(%rip),%rdx
mov    %rbx,%rsi
xor    %r8d,%r8d
call   1050 <mount@plt>
lea    0xe50(%rip),%rdi
call   1030 <chroot@plt>
lea    0xe50(%rip),%rsi
lea    0xe4a(%rip),%rdi
mov    %rdi,%rdx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1050 <mount@plt>
mov    %rbx,%rdi
call   1060 <chdir@plt>
lea    0xe33(%rip),%rdi
mov    %rdi,%rsi
xor    %edx,%edx
call   1090 <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 = [1 x i8] zeroinitializer
@.str.3 = [2 x i8] c"/\00"
@.str.4 = [9 x i8] c"dontcare\00"
@MS_REC = global i32 0
@MS_SLAVE = global i32 0
@.str.5 = [12 x i8] c"/opt/debian\00"
@.str.6 = [5 x i8] c"proc\00"
@.str.7 = [6 x i8] c"/proc\00"
@.str.8 = [10 x i8] c"/bin/bash\00"
define i32 @child(i8* %0) {
%2 = alloca i8*
store i8* %0, i8** %2
%3 = load i8*, i8** %2
store i8* %3, i8** %2
%4 = call i64 (...) @getpid()
%5 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i64 %4)
%6 = call i64 (...) @getppid()
%7 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i64 %6)
%8 = load i32, i32* @MS_REC
%9 = load i32, i32* @MS_SLAVE
%10 = or i32 %8, %9
%11 = call i32 @mount(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %10, i32* null)
%12 = call i32 @chroot(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
%13 = call i32 @mount(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i32 0, i32* null)
%14 = call i32 @chdir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%15 = call i32 @execlp(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, 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 = [1 x i8] zeroinitializer
@.str.3 = [2 x i8] c"/\00"
@.str.4 = [9 x i8] c"dontcare\00"
@MS_REC = global i32 0
@MS_SLAVE = global i32 0
@.str.5 = [12 x i8] c"/opt/debian\00"
@.str.6 = [5 x i8] c"proc\00"
@.str.7 = [6 x i8] c"/proc\00"
@.str.8 = [10 x i8] c"/bin/bash\00"
define i32 @child(i8* nocapture readnone %0) {
%2 = tail call i64 (...) @getpid()
%3 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i64 %2)
%4 = tail call i64 (...) @getppid()
%5 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i64 %4)
%6 = load i32, i32* @MS_REC
%7 = load i32, i32* @MS_SLAVE
%8 = or i32 %7, %6
%9 = tail call i32 @mount(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %8, i32* null)
%10 = tail call i32 @chroot(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
%11 = tail call i32 @mount(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i32 0, i32* null)
%12 = tail call i32 @chdir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%13 = tail call i32 @execlp(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i8* null)
ret i32 0
}