#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 _chroot_error(char const *, int);
scalar_t__ chroot(char const *);
int /*<<< orphan*/ execl(char const *, char const *, char *, ...);
char *getenv(char *);
int _chroot(char const *pathname, char const *command) {
  char const *shell;
  if (chroot(pathname) != 0)
    return _chroot_error(pathname, 2);
  if ((shell = getenv("SHELL")) == NULL)
    shell = "/bin/sh";
  if (command != NULL)
    execl(shell, shell, "-c", command, NULL);
  else
    execl(shell, shell, NULL);
  return 0;
}


x86 assembly (clang, -O0):
<_chroot>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <chroot@plt>
cmp    $0x0,%rax
je     1179 <_chroot+0x39>
mov    -0x10(%rbp),%rdi
mov    $0x2,%esi
call   1050 <_chroot_error@plt>
mov    %eax,-0x4(%rbp)
jmp    11e7 <_chroot+0xa7>
lea    0xe80(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    119e <_chroot+0x5e>
lea    0xe6c(%rip),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11cd <_chroot+0x8d>
mov    -0x20(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rcx
lea    0xe52(%rip),%rdx
xor    %eax,%eax
mov    %eax,%r8d
mov    $0x0,%al
call   1060 <execl@plt>
jmp    11e0 <_chroot+0xa0>
mov    -0x20(%rbp),%rdi
mov    -0x20(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
mov    $0x0,%al
call   1060 <execl@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_chroot>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <chroot@plt>
test   %rax,%rax
je     1168 <_chroot+0x28>
mov    %rbx,%rdi
mov    $0x2,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <_chroot_error@plt>
lea    0xe91(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
lea    0xe88(%rip),%rdi
cmovne %rax,%rdi
test   %r14,%r14
je     11a0 <_chroot+0x60>
lea    0xe80(%rip),%rdx
mov    %rdi,%rsi
mov    %r14,%rcx
xor    %r8d,%r8d
xor    %eax,%eax
call   1060 <execl@plt>
jmp    11ac <_chroot+0x6c>
mov    %rdi,%rsi
xor    %edx,%edx
xor    %eax,%eax
call   1060 <execl@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [6 x i8] c"SHELL\00"
@.str.1 = [8 x i8] c"/bin/sh\00"
@.str.2 = [3 x i8] c"-c\00"
define i32 @_chroot(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %4
%8 = call i64 @chroot(i8* %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i8*, i8** %4
%12 = call i32 @_chroot_error(i8* %11, i32 2)
store i32 %12, i32* %3
br label %30
13: ; preds = %2
%14 = call i8* @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i8* %14, i8** %6
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %17
16: ; preds = %13
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8** %6
br label %17
17: ; preds = %16, %13
%18 = load i8*, i8** %5
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %25
20: ; preds = %17
%21 = load i8*, i8** %6
%22 = load i8*, i8** %6
%23 = load i8*, i8** %5
%24 = call i32 (i8*, i8*, i8*, ...) @execl(i8* %21, i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %23, i8* null)
br label %29
25: ; preds = %17
%26 = load i8*, i8** %6
%27 = load i8*, i8** %6
%28 = call i32 (i8*, i8*, i8*, ...) @execl(i8* %26, i8* %27, i8* null)
br label %29
29: ; preds = %25, %20
store i32 0, i32* %3
br label %30
30: ; preds = %29, %10
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
@.str = [6 x i8] c"SHELL\00"
@.str.1 = [8 x i8] c"/bin/sh\00"
@.str.2 = [3 x i8] c"-c\00"
define i32 @_chroot(i8* %0, i8* %1) {
%3 = tail call i64 @chroot(i8* %0)
%4 = icmp eq i64 %3, 0
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 @_chroot_error(i8* %0, i32 2)
br label %16
7: ; preds = %2
%8 = tail call i8* @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i8* %8, null
%10 = select i1 %9, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %8
%11 = icmp eq i8* %1, null
br i1 %11, label %14, label %12
12: ; preds = %7
%13 = tail call i32 (i8*, i8*, i8*, ...) @execl(i8* %10, i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %1, i8* null)
br label %16
14: ; preds = %7
%15 = tail call i32 (i8*, i8*, i8*, ...) @execl(i8* %10, i8* %10, i8* null)
br label %16
16: ; preds = %12, %14, %5
%17 = phi i32 [ %6, %5 ], [ 0, %14 ], [ 0, %12 ]
ret i32 %17
}