#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 chdir(char *);
int checked_mount(char *, char *);
int chroot(char *);
int execvp(char *, char **);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
int main(int argc, char **argv) {
  if ((chdir(argv[1])) == -1) {
    perror("chdir(argv[1])");
    exit(1);
  };
  if ((checked_mount("/dev", "./dev")) == -1) {
    perror("checked_mount(\"/dev\", \"./dev\")");
    exit(1);
  };
  if ((checked_mount("/proc", "./proc")) == -1) {
    perror("checked_mount(\"/proc\", \"./proc\")");
    exit(1);
  };
  if ((checked_mount("/sys", "./sys")) == -1) {
    perror("checked_mount(\"/sys\", \"./sys\")");
    exit(1);
  };
  if ((chroot(".")) == -1) {
    perror("chroot(\".\")");
    exit(1);
  };
  if ((execvp(argv[2], argv + 2)) == -1) {
    perror("execvp(argv[2], argv+2)");
    exit(1);
  };
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <chdir@plt>
cmp    $0xffffffff,%eax
jne    119b <main+0x3b>
lea    0xe74(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    0xe6e(%rip),%rdi
lea    0xe66(%rip),%rsi
call   1050 <checked_mount@plt>
cmp    $0xffffffff,%eax
jne    11cd <main+0x6d>
lea    0xe57(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    0xe61(%rip),%rdi
lea    0xe59(%rip),%rsi
call   1050 <checked_mount@plt>
cmp    $0xffffffff,%eax
jne    11ff <main+0x9f>
lea    0xe4b(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    0xe57(%rip),%rdi
lea    0xe4f(%rip),%rsi
call   1050 <checked_mount@plt>
cmp    $0xffffffff,%eax
jne    1231 <main+0xd1>
lea    0xe40(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    0xe49(%rip),%rdi
call   1030 <chroot@plt>
cmp    $0xffffffff,%eax
jne    125c <main+0xfc>
lea    0xe36(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    -0x10(%rbp),%rsi
add    $0x10,%rsi
call   1070 <execvp@plt>
cmp    $0xffffffff,%eax
jne    1290 <main+0x130>
lea    0xe0e(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1040 <chdir@plt>
cmp    $0xffffffff,%eax
je     11e4 <main+0x84>
lea    0xe97(%rip),%rdi
lea    0xe8f(%rip),%rsi
call   1050 <checked_mount@plt>
cmp    $0xffffffff,%eax
je     11ed <main+0x8d>
lea    0xea4(%rip),%rdi
lea    0xe9c(%rip),%rsi
call   1050 <checked_mount@plt>
cmp    $0xffffffff,%eax
je     11f6 <main+0x96>
lea    0xeb4(%rip),%rdi
lea    0xeac(%rip),%rsi
call   1050 <checked_mount@plt>
cmp    $0xffffffff,%eax
je     11ff <main+0x9f>
lea    0xec0(%rip),%rdi
call   1030 <chroot@plt>
cmp    $0xffffffff,%eax
je     1208 <main+0xa8>
mov    0x10(%rbx),%rdi
add    $0x10,%rbx
mov    %rbx,%rsi
call   1070 <execvp@plt>
cmp    $0xffffffff,%eax
je     1211 <main+0xb1>
xor    %eax,%eax
pop    %rbx
ret
lea    0xe15(%rip),%rdi
jmp    1218 <main+0xb8>
lea    0xe21(%rip),%rdi
jmp    1218 <main+0xb8>
lea    0xe3e(%rip),%rdi
jmp    1218 <main+0xb8>
lea    0xe5c(%rip),%rdi
jmp    1218 <main+0xb8>
lea    0xe74(%rip),%rdi
jmp    1218 <main+0xb8>
lea    0xe77(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"chdir(argv[1])\00"
@.str.1 = [5 x i8] c"/dev\00"
@.str.2 = [6 x i8] c"./dev\00"
@.str.3 = [31 x i8] c"checked_mount(\22/dev\22, \22./dev\22)\00"
@.str.4 = [6 x i8] c"/proc\00"
@.str.5 = [7 x i8] c"./proc\00"
@.str.6 = [33 x i8] c"checked_mount(\22/proc\22, \22./proc\22)\00"
@.str.7 = [5 x i8] c"/sys\00"
@.str.8 = [6 x i8] c"./sys\00"
@.str.9 = [31 x i8] c"checked_mount(\22/sys\22, \22./sys\22)\00"
@.str.10 = [2 x i8] c".\00"
@.str.11 = [12 x i8] c"chroot(\22.\22)\00"
@.str.12 = [24 x i8] c"execvp(argv[2], argv+2)\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
store i32 %0, i32* %3
store i8** %1, i8*** %4
%5 = load i8**, i8*** %4
%6 = getelementptr inbounds i8*, i8** %5, i64 1
%7 = load i8*, i8** %6
%8 = call i32 @chdir(i8* %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = call i32 @checked_mount(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))
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %13
%20 = call i32 @checked_mount(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0))
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %19
%26 = call i32 @checked_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.8, i64 0, i64 0))
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.9, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %25
%32 = call i32 @chroot(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %37
34: ; preds = %31
%35 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.11, i64 0, i64 0))
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %31
%38 = load i8**, i8*** %4
%39 = getelementptr inbounds i8*, i8** %38, i64 2
%40 = load i8*, i8** %39
%41 = load i8**, i8*** %4
%42 = getelementptr inbounds i8*, i8** %41, i64 2
%43 = call i32 @execvp(i8* %40, i8** %42)
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %48
45: ; preds = %37
%46 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.12, i64 0, i64 0))
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %37
ret i32 0
}

LLVM IR (-O2):
@.str = [15 x i8] c"chdir(argv[1])\00"
@.str.1 = [5 x i8] c"/dev\00"
@.str.2 = [6 x i8] c"./dev\00"
@.str.3 = [31 x i8] c"checked_mount(\22/dev\22, \22./dev\22)\00"
@.str.4 = [6 x i8] c"/proc\00"
@.str.5 = [7 x i8] c"./proc\00"
@.str.6 = [33 x i8] c"checked_mount(\22/proc\22, \22./proc\22)\00"
@.str.7 = [5 x i8] c"/sys\00"
@.str.8 = [6 x i8] c"./sys\00"
@.str.9 = [31 x i8] c"checked_mount(\22/sys\22, \22./sys\22)\00"
@.str.10 = [2 x i8] c".\00"
@.str.11 = [12 x i8] c"chroot(\22.\22)\00"
@.str.12 = [24 x i8] c"execvp(argv[2], argv+2)\00"
define i32 @main(i32 %0, i8** %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = tail call i32 @chdir(i8* %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = tail call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = tail call i32 @checked_mount(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))
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = tail call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %10
%17 = tail call i32 @checked_mount(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = tail call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0))
%21 = tail call i32 @exit(i32 1)
unreachable
22: ; preds = %16
%23 = tail call i32 @checked_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.8, i64 0, i64 0))
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = tail call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.9, i64 0, i64 0))
%27 = tail call i32 @exit(i32 1)
unreachable
28: ; preds = %22
%29 = tail call i32 @chroot(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.11, i64 0, i64 0))
%33 = tail call i32 @exit(i32 1)
unreachable
34: ; preds = %28
%35 = getelementptr inbounds i8*, i8** %1, i64 2
%36 = load i8*, i8** %35
%37 = tail call i32 @execvp(i8* %36, i8** %35)
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %42
39: ; preds = %34
%40 = tail call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.12, i64 0, i64 0))
%41 = tail call i32 @exit(i32 1)
unreachable
42: ; preds = %34
ret i32 0
}