#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 */
typedef int /*<<< orphan*/ path;

/* Variables and functions */
int EACCES;
int EFAULT;
int EPERM;
scalar_t__ chroot(char const *);
int errno;
int /*<<< orphan*/ getcwd(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  const char root[64] = "../";
  char path[64];
  if (chroot(root) == 0) {
    printf("%s\n", root);
    getcwd(path, sizeof(path));
    printf("%s\n", path);
  } else {
    if (errno == EACCES) {
      printf("EACCES Search permission is denied on a component of the path "
             "prefix.\n");
    }
    if (errno == EFAULT) {
      printf("EFAULT path points outside your accessible address space.\n");
    }
    if (errno == EPERM) {
      printf("EPERM  The caller has insufficient privilege.\n");
    }
    printf("error %d\n", errno);
    perror("chroot error");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1050 <memset@plt>
movb   $0x2e,-0x50(%rbp)
movb   $0x2e,-0x4f(%rbp)
movb   $0x2f,-0x4e(%rbp)
lea    -0x50(%rbp),%rdi
call   1030 <chroot@plt>
cmp    $0x0,%rax
jne    11ce <main+0x7e>
lea    -0x50(%rbp),%rsi
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x90(%rbp),%rdi
mov    $0x40,%esi
call   1060 <getcwd@plt>
lea    -0x90(%rbp),%rsi
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1263 <main+0x113>
mov    0x2dfb(%rip),%rax
mov    (%rax),%eax
mov    0x2e02(%rip),%rcx
cmp    (%rcx),%eax
jne    11f4 <main+0xa4>
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2dd5(%rip),%rax
mov    (%rax),%eax
mov    0x2df4(%rip),%rcx
cmp    (%rcx),%eax
jne    121a <main+0xca>
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2daf(%rip),%rax
mov    (%rax),%eax
mov    0x2d96(%rip),%rcx
cmp    (%rcx),%eax
jne    1240 <main+0xf0>
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2d89(%rip),%rax
mov    (%rax),%esi
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe61(%rip),%rdi
call   1070 <perror@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x80,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movw   $0x2e2e,(%rsp)
movb   $0x2f,0x2(%rsp)
mov    %rsp,%rdi
call   1030 <chroot@plt>
test   %rax,%rax
jne    11b3 <main+0x63>
mov    %rsp,%rdi
call   1040 <puts@plt>
lea    0x40(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x40,%esi
call   1060 <getcwd@plt>
mov    %rbx,%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
ret
mov    0x2e16(%rip),%rbx
mov    (%rbx),%esi
mov    0x2e1d(%rip),%rax
cmp    (%rax),%esi
jne    11d5 <main+0x85>
lea    0xeb1(%rip),%rdi
call   1040 <puts@plt>
mov    (%rbx),%esi
mov    0x2e1c(%rip),%rax
cmp    (%rax),%esi
jne    11ee <main+0x9e>
lea    0xe5e(%rip),%rdi
call   1040 <puts@plt>
mov    (%rbx),%esi
mov    0x2dcb(%rip),%rax
cmp    (%rax),%esi
jne    1207 <main+0xb7>
lea    0xe17(%rip),%rdi
call   1040 <puts@plt>
mov    (%rbx),%esi
lea    0xdf2(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xdee(%rip),%rdi
call   1070 <perror@plt>
jmp    11a8 <main+0x58>

LLVM IR (-O0):
@.str = [4 x i8] c"%s\0A\00"
@errno = global i32 0
@EACCES = global i32 0
@.str.1 = [71 x i8] c"EACCES Search permission is denied on a component of the path prefix.\0A\00"
@EFAULT = global i32 0
@.str.2 = [59 x i8] c"EFAULT path points outside your accessible address space.\0A\00"
@EPERM = global i32 0
@.str.3 = [47 x i8] c"EPERM The caller has insufficient privilege.\0A\00"
@.str.4 = [10 x i8] c"error %d\0A\00"
@.str.5 = [13 x i8] c"chroot error\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [64 x i8]
%3 = alloca [64 x i8]
store i32 0, i32* %1
%4 = bitcast [64 x i8]* %2 to i8*
%5 = bitcast i8* %4 to [64 x i8]*
%6 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i32 0, i32 0
store i8 46, i8* %6
%7 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i32 0, i32 1
store i8 46, i8* %7
%8 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i32 0, i32 2
store i8 47, i8* %8
%9 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%10 = call i64 @chroot(i8* %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %19
12: ; preds = %0
%13 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%16 = call i32 @getcwd(i8* %15, i32 64)
%17 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %17)
br label %41
19: ; preds = %0
%20 = load i32, i32* @errno
%21 = load i32, i32* @EACCES
%22 = icmp eq i32 %20, %21
br i1 %22, label %23, label %25
23: ; preds = %19
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.1, i64 0, i64 0))
br label %25
25: ; preds = %23, %19
%26 = load i32, i32* @errno
%27 = load i32, i32* @EFAULT
%28 = icmp eq i32 %26, %27
br i1 %28, label %29, label %31
29: ; preds = %25
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.2, i64 0, i64 0))
br label %31
31: ; preds = %29, %25
%32 = load i32, i32* @errno
%33 = load i32, i32* @EPERM
%34 = icmp eq i32 %32, %33
br i1 %34, label %35, label %37
35: ; preds = %31
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0))
br label %37
37: ; preds = %35, %31
%38 = load i32, i32* @errno
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %38)
%40 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
br label %41
41: ; preds = %37, %12
ret i32 0
}

LLVM IR (-O2):
@errno = global i32 0
@EACCES = global i32 0
@EFAULT = global i32 0
@EPERM = global i32 0
@.str.4 = [10 x i8] c"error %d\0A\00"
@.str.5 = [13 x i8] c"chroot error\00"
@str = [46 x i8] c"EPERM The caller has insufficient privilege.\00"
@str.6 = [58 x i8] c"EFAULT path points outside your accessible address space.\00"
@str.7 = [70 x i8] c"EACCES Search permission is denied on a component of the path prefix.\00"
define i32 @main() {
%1 = alloca [64 x i8]
%2 = alloca [64 x i8]
%3 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 0
store i8 46, i8* %3
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 1
store i8 46, i8* %4
%5 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 2
store i8 47, i8* %5
%6 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%7 = call i64 @chroot(i8* %3)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %0
%10 = call i32 @puts(i8* %3)
%11 = call i32 @getcwd(i8* %6, i32 64)
%12 = call i32 @puts(i8* %6)
br label %38
13: ; preds = %0
%14 = load i32, i32* @errno
%15 = load i32, i32* @EACCES
%16 = icmp eq i32 %14, %15
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([70 x i8], [70 x i8]* @str.7, i64 0, i64 0))
%19 = load i32, i32* @errno
br label %20
20: ; preds = %17, %13
%21 = phi i32 [ %19, %17 ], [ %14, %13 ]
%22 = load i32, i32* @EFAULT
%23 = icmp eq i32 %21, %22
br i1 %23, label %24, label %27
24: ; preds = %20
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @str.6, i64 0, i64 0))
%26 = load i32, i32* @errno
br label %27
27: ; preds = %24, %20
%28 = phi i32 [ %26, %24 ], [ %21, %20 ]
%29 = load i32, i32* @EPERM
%30 = icmp eq i32 %28, %29
br i1 %30, label %31, label %34
31: ; preds = %27
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str, i64 0, i64 0))
%33 = load i32, i32* @errno
br label %34
34: ; preds = %31, %27
%35 = phi i32 [ %33, %31 ], [ %28, %27 ]
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %35)
%37 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
br label %38
38: ; preds = %34, %9
ret i32 0
}