#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*/ MNT_DETACH;
int /*<<< orphan*/ SYS_pivot_root;
int /*<<< orphan*/ chdir(char *);
int /*<<< orphan*/ check(int /*<<< orphan*/, char *);
int /*<<< orphan*/ copy_file(char *, char *);
int /*<<< orphan*/ mkdir(char *, int);
int /*<<< orphan*/ mount(char *, char *, char *, int /*<<< orphan*/, char *);
int /*<<< orphan*/ symlink(char *, char *);
int /*<<< orphan*/ syscall(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ umount2(char *, int /*<<< orphan*/);
void setup_chroot() {
  check(mount("", "/tmp", "tmpfs", 0, ""), "mount(/tmp)");
  check(mkdir("/tmp/lib", 0700), "mkdir(/lib)");
  check(mkdir("/tmp/lib64", 0700), "mkdir(/lib64)");
  check(mkdir("/tmp/proc", 0700), "mkdir(/proc)");
  check(mount("", "/tmp/proc", "proc", 0, ""), "mount(/proc)");
  copy_file("/lib64/ld-linux-x86-64.so.2", "/tmp"
                                           "/lib64/ld-linux-x86-64.so.2");
  check(symlink("/lib64/ld-linux-x86-64.so.2", "/tmp/lib/ld-linux-x86-64.so.2"),
        "symlink(ld)");
  check(syscall(SYS_pivot_root, "/tmp", "/tmp"), "pivot_root");
  check(umount2("/", MNT_DETACH), "umount(/)");
  check(chdir("/"), "chdir(/)");
}


x86 assembly (clang, -O0):
<setup_chroot>:
push   %rbp
mov    %rsp,%rbp
lea    0xf47(%rip),%r8
lea    0xe6e(%rip),%rsi
lea    0xe6c(%rip),%rdx
xor    %ecx,%ecx
mov    %r8,%rdi
call   1060 <mount@plt>
mov    %eax,%edi
lea    0xe5f(%rip),%rsi
call   10a0 <check@plt>
lea    0xe5f(%rip),%rdi
mov    $0x1c0,%esi
call   1040 <mkdir@plt>
mov    %eax,%edi
lea    0xe55(%rip),%rsi
call   10a0 <check@plt>
lea    0xe55(%rip),%rdi
mov    $0x1c0,%esi
call   1040 <mkdir@plt>
mov    %eax,%edi
lea    0xe4d(%rip),%rsi
call   10a0 <check@plt>
lea    0xe4f(%rip),%rdi
mov    $0x1c0,%esi
call   1040 <mkdir@plt>
mov    %eax,%edi
lea    0xe46(%rip),%rsi
call   10a0 <check@plt>
lea    0xebd(%rip),%r8
lea    0xe29(%rip),%rsi
lea    0xe27(%rip),%rdx
xor    %ecx,%ecx
mov    %r8,%rdi
call   1060 <mount@plt>
mov    %eax,%edi
lea    0xe26(%rip),%rsi
call   10a0 <check@plt>
lea    0xe2b(%rip),%rdi
lea    0xe20(%rip),%rsi
call   1030 <copy_file@plt>
lea    0xe18(%rip),%rdi
lea    0xe2d(%rip),%rsi
call   1080 <symlink@plt>
mov    %eax,%edi
lea    0xe3d(%rip),%rsi
call   10a0 <check@plt>
mov    0x2d62(%rip),%rax
mov    (%rax),%edi
lea    0xd81(%rip),%rdx
mov    %rdx,%rsi
call   1090 <syscall@plt>
mov    %eax,%edi
lea    0xe23(%rip),%rsi
call   10a0 <check@plt>
mov    0x2d44(%rip),%rax
mov    (%rax),%esi
lea    0xe19(%rip),%rdi
call   1050 <umount2@plt>
mov    %eax,%edi
lea    0xe0d(%rip),%rsi
call   10a0 <check@plt>
lea    0xdff(%rip),%rdi
call   1070 <chdir@plt>
mov    %eax,%edi
lea    0xdfd(%rip),%rsi
call   10a0 <check@plt>
pop    %rbp
ret

x86 assembly (clang, -O2):
<setup_chroot>:
push   %r15
push   %r14
push   %rbx
lea    0xe74(%rip),%r14
lea    0xe72(%rip),%rdx
lea    0xf38(%rip),%r15
mov    %r15,%rdi
mov    %r14,%rsi
xor    %ecx,%ecx
mov    %r15,%r8
call   1060 <mount@plt>
lea    0xe5a(%rip),%rsi
mov    %eax,%edi
call   10a0 <check@plt>
lea    0xe58(%rip),%rdi
mov    $0x1c0,%esi
call   1040 <mkdir@plt>
lea    0xe50(%rip),%rsi
mov    %eax,%edi
call   10a0 <check@plt>
lea    0xe4e(%rip),%rdi
mov    $0x1c0,%esi
call   1040 <mkdir@plt>
lea    0xe48(%rip),%rsi
mov    %eax,%edi
call   10a0 <check@plt>
lea    0xe48(%rip),%rbx
mov    %rbx,%rdi
mov    $0x1c0,%esi
call   1040 <mkdir@plt>
lea    0xe3e(%rip),%rsi
mov    %eax,%edi
call   10a0 <check@plt>
lea    0xe2b(%rip),%rdx
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %ecx,%ecx
mov    %r15,%r8
call   1060 <mount@plt>
lea    0xe26(%rip),%rsi
mov    %eax,%edi
call   10a0 <check@plt>
lea    0xe29(%rip),%rbx
lea    0xe1e(%rip),%rsi
mov    %rbx,%rdi
call   1030 <copy_file@plt>
lea    0xe2f(%rip),%rsi
mov    %rbx,%rdi
call   1080 <symlink@plt>
lea    0xe3e(%rip),%rsi
mov    %eax,%edi
call   10a0 <check@plt>
mov    0x2d61(%rip),%rax
mov    (%rax),%edi
mov    %r14,%rsi
mov    %r14,%rdx
call   1090 <syscall@plt>
lea    0xe28(%rip),%rsi
mov    %eax,%edi
call   10a0 <check@plt>
mov    0x2d47(%rip),%rax
mov    (%rax),%esi
lea    0xe1c(%rip),%rbx
mov    %rbx,%rdi
call   1050 <umount2@plt>
lea    0xe0f(%rip),%rsi
mov    %eax,%edi
call   10a0 <check@plt>
mov    %rbx,%rdi
call   1070 <chdir@plt>
lea    0xe03(%rip),%rsi
mov    %eax,%edi
pop    %rbx
pop    %r14
pop    %r15
jmp    10a0 <check@plt>

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [5 x i8] c"/tmp\00"
@.str.2 = [6 x i8] c"tmpfs\00"
@.str.3 = [12 x i8] c"mount(/tmp)\00"
@.str.4 = [9 x i8] c"/tmp/lib\00"
@.str.5 = [12 x i8] c"mkdir(/lib)\00"
@.str.6 = [11 x i8] c"/tmp/lib64\00"
@.str.7 = [14 x i8] c"mkdir(/lib64)\00"
@.str.8 = [10 x i8] c"/tmp/proc\00"
@.str.9 = [13 x i8] c"mkdir(/proc)\00"
@.str.10 = [5 x i8] c"proc\00"
@.str.11 = [13 x i8] c"mount(/proc)\00"
@.str.12 = [28 x i8] c"/lib64/ld-linux-x86-64.so.2\00"
@.str.13 = [32 x i8] c"/tmp/lib64/ld-linux-x86-64.so.2\00"
@.str.14 = [30 x i8] c"/tmp/lib/ld-linux-x86-64.so.2\00"
@.str.15 = [12 x i8] c"symlink(ld)\00"
@SYS_pivot_root = global i32 0
@.str.16 = [11 x i8] c"pivot_root\00"
@.str.17 = [2 x i8] c"/\00"
@MNT_DETACH = global i32 0
@.str.18 = [10 x i8] c"umount(/)\00"
@.str.19 = [9 x i8] c"chdir(/)\00"
define void @setup_chroot() {
%1 = call i32 @mount(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 0, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%2 = call i32 @check(i32 %1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%3 = call i32 @mkdir(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 448)
%4 = call i32 @check(i32 %3, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
%5 = call i32 @mkdir(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i32 448)
%6 = call i32 @check(i32 %5, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0))
%7 = call i32 @mkdir(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i32 448)
%8 = call i32 @check(i32 %7, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i64 0, i64 0))
%9 = call i32 @mount(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0), i32 0, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @check(i32 %9, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.11, i64 0, i64 0))
%11 = call i32 @copy_file(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.12, i64 0, i64 0), i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.13, i64 0, i64 0))
%12 = call i32 @symlink(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.12, i64 0, i64 0), i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.14, i64 0, i64 0))
%13 = call i32 @check(i32 %12, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.15, i64 0, i64 0))
%14 = load i32, i32* @SYS_pivot_root
%15 = call i32 @syscall(i32 %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @check(i32 %15, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.16, i64 0, i64 0))
%17 = load i32, i32* @MNT_DETACH
%18 = call i32 @umount2(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.17, i64 0, i64 0), i32 %17)
%19 = call i32 @check(i32 %18, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.18, i64 0, i64 0))
%20 = call i32 @chdir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.17, i64 0, i64 0))
%21 = call i32 @check(i32 %20, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.19, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [5 x i8] c"/tmp\00"
@.str.2 = [6 x i8] c"tmpfs\00"
@.str.3 = [12 x i8] c"mount(/tmp)\00"
@.str.4 = [9 x i8] c"/tmp/lib\00"
@.str.5 = [12 x i8] c"mkdir(/lib)\00"
@.str.6 = [11 x i8] c"/tmp/lib64\00"
@.str.7 = [14 x i8] c"mkdir(/lib64)\00"
@.str.8 = [10 x i8] c"/tmp/proc\00"
@.str.9 = [13 x i8] c"mkdir(/proc)\00"
@.str.10 = [5 x i8] c"proc\00"
@.str.11 = [13 x i8] c"mount(/proc)\00"
@.str.12 = [28 x i8] c"/lib64/ld-linux-x86-64.so.2\00"
@.str.13 = [32 x i8] c"/tmp/lib64/ld-linux-x86-64.so.2\00"
@.str.14 = [30 x i8] c"/tmp/lib/ld-linux-x86-64.so.2\00"
@.str.15 = [12 x i8] c"symlink(ld)\00"
@SYS_pivot_root = global i32 0
@.str.16 = [11 x i8] c"pivot_root\00"
@.str.17 = [2 x i8] c"/\00"
@MNT_DETACH = global i32 0
@.str.18 = [10 x i8] c"umount(/)\00"
@.str.19 = [9 x i8] c"chdir(/)\00"
define void @setup_chroot() {
%1 = tail call i32 @mount(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 0, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%2 = tail call i32 @check(i32 %1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%3 = tail call i32 @mkdir(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 448)
%4 = tail call i32 @check(i32 %3, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
%5 = tail call i32 @mkdir(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i32 448)
%6 = tail call i32 @check(i32 %5, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0))
%7 = tail call i32 @mkdir(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i32 448)
%8 = tail call i32 @check(i32 %7, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i64 0, i64 0))
%9 = tail call i32 @mount(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0), i32 0, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @check(i32 %9, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.11, i64 0, i64 0))
%11 = tail call i32 @copy_file(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.12, i64 0, i64 0), i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.13, i64 0, i64 0))
%12 = tail call i32 @symlink(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.12, i64 0, i64 0), i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.14, i64 0, i64 0))
%13 = tail call i32 @check(i32 %12, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.15, i64 0, i64 0))
%14 = load i32, i32* @SYS_pivot_root
%15 = tail call i32 @syscall(i32 %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%16 = tail call i32 @check(i32 %15, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.16, i64 0, i64 0))
%17 = load i32, i32* @MNT_DETACH
%18 = tail call i32 @umount2(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.17, i64 0, i64 0), i32 %17)
%19 = tail call i32 @check(i32 %18, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.18, i64 0, i64 0))
%20 = tail call i32 @chdir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.17, i64 0, i64 0))
%21 = tail call i32 @check(i32 %20, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.19, i64 0, i64 0))
ret void
}