#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_PRIVATE;
int MS_REC;
int /*<<< orphan*/ execlp(char *, char *, char *, char *, char *);
scalar_t__ getegid();
scalar_t__ geteuid();
scalar_t__ getpid();
scalar_t__ getppid();
int /*<<< orphan*/ mount(char *, char *, char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, long, ...);
int /*<<< orphan*/ sethostname(char *, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ umount(char *);
int child(void *arg) {
  char *newhostname = arg;
  sethostname(newhostname, strlen(newhostname));
  printf("My PID: %ld\n", (long)getpid());
  printf("My PPID: %ld\n", (long)getppid());
  printf("eUID = %ld;  eGID = %ld\n;  ", (long)geteuid(), (long)getegid());
  mount("", "/", "dontcare", MS_REC | MS_PRIVATE, NULL);
  umount("/proc");
  mount("proc", "/proc", "proc", 0, NULL);
  execlp("chroot", "chroot", "/opt/debian", "/bin/bash", (char *)NULL);
  return 0;
}


x86 assembly (clang, -O0):
<child>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x20(%rbp),%rdi
mov    %eax,%esi
call   1090 <sethostname@plt>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %rax,%rsi
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x0,%al
call   10b0 <getppid@plt>
mov    %rax,%rsi
lea    0xe14(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x0,%al
call   1080 <geteuid@plt>
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   10a0 <getegid@plt>
mov    -0x18(%rbp),%rsi
mov    %rax,%rdx
lea    0xdfb(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    0x2dba(%rip),%rax
mov    (%rax),%ecx
mov    0x2da1(%rip),%rax
or     (%rax),%ecx
lea    0xdcc(%rip),%rdi
lea    0xdf0(%rip),%rsi
lea    0xdeb(%rip),%rdx
xor    %eax,%eax
mov    %eax,%r8d
call   1060 <mount@plt>
lea    0xde3(%rip),%rdi
call   1030 <umount@plt>
lea    0xdd8(%rip),%rdx
lea    0xdd0(%rip),%rsi
xor    %ecx,%ecx
xor    %eax,%eax
mov    %eax,%r8d
mov    %rdx,%rdi
call   1060 <mount@plt>
lea    0xdc0(%rip),%rsi
lea    0xdc0(%rip),%rdx
lea    0xdc5(%rip),%rcx
xor    %eax,%eax
mov    %eax,%r8d
mov    %rsi,%rdi
call   10c0 <execlp@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<child>:
push   %rbx
mov    %rdi,%rbx
call   1050 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1090 <sethostname@plt>
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe3f(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %eax,%eax
call   10b0 <getppid@plt>
lea    0xe34(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %eax,%eax
call   1080 <geteuid@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   10a0 <getegid@plt>
lea    0xe20(%rip),%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x2dd9(%rip),%rax
mov    0x2dc2(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
lea    0xdeb(%rip),%rdi
lea    0xe0f(%rip),%rsi
lea    0xe0a(%rip),%rdx
xor    %r8d,%r8d
call   1060 <mount@plt>
lea    0xe04(%rip),%rbx
mov    %rbx,%rdi
call   1030 <umount@plt>
lea    0xdf6(%rip),%rdi
mov    %rbx,%rsi
mov    %rdi,%rdx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1060 <mount@plt>
lea    0xde4(%rip),%rdi
lea    0xde4(%rip),%rdx
lea    0xde9(%rip),%rcx
mov    %rdi,%rsi
xor    %r8d,%r8d
call   10c0 <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 = [28 x i8] c"eUID = %ld; eGID = %ld\0A; \00"
@.str.3 = [1 x i8] zeroinitializer
@.str.4 = [2 x i8] c"/\00"
@.str.5 = [9 x i8] c"dontcare\00"
@MS_REC = global i32 0
@MS_PRIVATE = global i32 0
@.str.6 = [6 x i8] c"/proc\00"
@.str.7 = [5 x i8] c"proc\00"
@.str.8 = [7 x i8] c"chroot\00"
@.str.9 = [12 x i8] c"/opt/debian\00"
@.str.10 = [10 x i8] c"/bin/bash\00"
define i32 @child(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
store i8* %4, i8** %3
%5 = load i8*, i8** %3
%6 = load i8*, i8** %3
%7 = call i32 @strlen(i8* %6)
%8 = call i32 @sethostname(i8* %5, i32 %7)
%9 = call i64 (...) @getpid()
%10 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i64 %9)
%11 = call i64 (...) @getppid()
%12 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i64 %11)
%13 = call i64 (...) @geteuid()
%14 = call i64 (...) @getegid()
%15 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i64 %13, i64 %14)
%16 = load i32, i32* @MS_REC
%17 = load i32, i32* @MS_PRIVATE
%18 = or i32 %16, %17
%19 = call i32 @mount(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %18, i32* null)
%20 = call i32 @umount(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%21 = call i32 @mount(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i32 0, i32* null)
%22 = call i32 @execlp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, 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 = [28 x i8] c"eUID = %ld; eGID = %ld\0A; \00"
@.str.3 = [1 x i8] zeroinitializer
@.str.4 = [2 x i8] c"/\00"
@.str.5 = [9 x i8] c"dontcare\00"
@MS_REC = global i32 0
@MS_PRIVATE = global i32 0
@.str.6 = [6 x i8] c"/proc\00"
@.str.7 = [5 x i8] c"proc\00"
@.str.8 = [7 x i8] c"chroot\00"
@.str.9 = [12 x i8] c"/opt/debian\00"
@.str.10 = [10 x i8] c"/bin/bash\00"
define i32 @child(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = tail call i32 @sethostname(i8* %0, i32 %2)
%4 = tail call i64 (...) @getpid()
%5 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i64 %4)
%6 = tail call i64 (...) @getppid()
%7 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i64 %6)
%8 = tail call i64 (...) @geteuid()
%9 = tail call i64 (...) @getegid()
%10 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i64 %8, i64 %9)
%11 = load i32, i32* @MS_REC
%12 = load i32, i32* @MS_PRIVATE
%13 = or i32 %12, %11
%14 = tail call i32 @mount(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %13, i32* null)
%15 = tail call i32 @umount(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%16 = tail call i32 @mount(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i32 0, i32* null)
%17 = tail call i32 @execlp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0), i8* null)
ret i32 0
}