int main(int argc, char *argv[]) {
  char *shell[] = {"/bin/sh", "-i", (void *)0};
  if (argc == 1)
    return 1;
  if (chroot(argv[1]) || chdir("/"))
    die();
  if (argc > 2) {
    execvp(argv[2], argv + 2);
  } else {
    execvp("/bin/sh", shell);
  }
  die();
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2ca3(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0x2ca0(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0x2c9d(%rip),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    118d <main+0x4d>
movl   $0x1,-0x4(%rbp)
jmp    1209 <main+0xc9>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    $0x0,%al
call   1030 <chroot@plt>
cmp    $0x0,%eax
jne    11bc <main+0x7c>
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1040 <chdir@plt>
cmp    $0x0,%eax
je     11c3 <main+0x83>
mov    $0x0,%al
call   1050 <die@plt>
cmpl   $0x2,-0x8(%rbp)
jle    11e9 <main+0xa9>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    -0x10(%rbp),%rsi
add    $0x10,%rsi
mov    $0x0,%al
call   1060 <execvp@plt>
jmp    11fb <main+0xbb>
lea    -0x30(%rbp),%rsi
lea    0xe0c(%rip),%rdi
mov    $0x0,%al
call   1060 <execvp@plt>
mov    $0x0,%al
call   1050 <die@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    0x2cc3(%rip),%rax
mov    %rax,0x10(%rsp)
movaps 0x2ca7(%rip),%xmm0
movaps %xmm0,(%rsp)
cmp    $0x1,%edi
je     11b9 <main+0x79>
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x8(%rsi),%rdi
xor    %eax,%eax
call   1030 <chroot@plt>
test   %eax,%eax
jne    1188 <main+0x48>
lea    0xe8e(%rip),%rdi
xor    %eax,%eax
call   1040 <chdir@plt>
test   %eax,%eax
je     118f <main+0x4f>
xor    %eax,%eax
call   1050 <die@plt>
cmp    $0x3,%ebp
jl     11a1 <main+0x61>
mov    0x10(%rbx),%rdi
add    $0x10,%rbx
mov    %rbx,%rsi
jmp    11ab <main+0x6b>
lea    0xe58(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1060 <execvp@plt>
xor    %eax,%eax
call   1050 <die@plt>
mov    $0x1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"/bin/sh\00"
@.str.1 = [3 x i8] c"-i\00"
@__const.main.shell = [3 x i8*] [i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0), i8* null]
@.str.2 = [2 x i8] c"/\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [3 x i8*]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = bitcast [3 x i8*]* %6 to i8*
%8 = load i32, i32* %4
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %11
10: ; preds = %2
store i32 1, i32* %3
br label %37
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i32 (i8*, ...) bitcast (i32 (...)* @chroot to i32 (i8*, ...)*)(i8* %14)
%16 = icmp ne i32 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %11
%18 = call i32 (i8*, ...) bitcast (i32 (...)* @chdir to i32 (i8*, ...)*)(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %17, %11
%21 = call i32 (...) @die()
br label %22
22: ; preds = %20, %17
%23 = load i32, i32* %4
%24 = icmp sgt i32 %23, 2
br i1 %24, label %25, label %32
25: ; preds = %22
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 2
%28 = load i8*, i8** %27
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 2
%31 = call i32 (i8*, i8**, ...) bitcast (i32 (...)* @execvp to i32 (i8*, i8**, ...)*)(i8* %28, i8** %30)
br label %35
32: ; preds = %22
%33 = getelementptr inbounds [3 x i8*], [3 x i8*]* %6, i64 0, i64 0
%34 = call i32 (i8*, i8**, ...) bitcast (i32 (...)* @execvp to i32 (i8*, i8**, ...)*)(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %33)
br label %35
35: ; preds = %32, %25
%36 = call i32 (...) @die()
store i32 1, i32* %3
br label %37
37: ; preds = %35, %10
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
@.str = [8 x i8] c"/bin/sh\00"
@.str.1 = [3 x i8] c"-i\00"
@__const.main.shell = [3 x i8*] [i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0), i8* null]
@.str.2 = [2 x i8] c"/\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [3 x i8*]
%4 = bitcast [3 x i8*]* %3 to i8*
%5 = icmp eq i32 %0, 1
br i1 %5, label %27, label %6
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 (i8*, ...) bitcast (i32 (...)* @chroot to i32 (i8*, ...)*)(i8* %8)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %6
%12 = tail call i32 (i8*, ...) bitcast (i32 (...)* @chdir to i32 (i8*, ...)*)(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp eq i32 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %11, %6
%15 = tail call i32 (...) @die()
br label %16
16: ; preds = %14, %11
%17 = icmp sgt i32 %0, 2
br i1 %17, label %18, label %22
18: ; preds = %16
%19 = getelementptr inbounds i8*, i8** %1, i64 2
%20 = load i8*, i8** %19
%21 = tail call i32 (i8*, i8**, ...) bitcast (i32 (...)* @execvp to i32 (i8*, i8**, ...)*)(i8* %20, i8** %19)
br label %25
22: ; preds = %16
%23 = getelementptr inbounds [3 x i8*], [3 x i8*]* %3, i64 0, i64 0
%24 = call i32 (i8*, i8**, ...) bitcast (i32 (...)* @execvp to i32 (i8*, i8**, ...)*)(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %23)
br label %25
25: ; preds = %22, %18
%26 = call i32 (...) @die()
br label %27
27: ; preds = %2, %25
ret i32 1
}