#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 const *);
int chroot(char *);
int /*<<< orphan*/ sysf_printf(char *, char *);
void do_chroot(const char *dest) {
  int rc;
  rc = chdir(dest);
  do {
    if ((rc < 0))
      sysf_printf("chdir()", "");
  } while (0);
  rc = chroot(".");
  do {
    if ((rc < 0))
      sysf_printf("Error chrooting", "");
  } while (0);
  rc = chdir("/");
  do {
    if ((rc < 0))
      sysf_printf("chdir(/)", "");
  } while (0);
}


x86 assembly (clang, -O0):
<do_chroot>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <chdir@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1165 <do_chroot+0x35>
lea    0xea7(%rip),%rdi
lea    0xea7(%rip),%rsi
call   1050 <sysf_printf@plt>
jmp    116a <do_chroot+0x3a>
lea    0xe97(%rip),%rdi
call   1030 <chroot@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1196 <do_chroot+0x66>
lea    0xe80(%rip),%rdi
lea    0xe76(%rip),%rsi
call   1050 <sysf_printf@plt>
jmp    119b <do_chroot+0x6b>
lea    0xe78(%rip),%rdi
call   1040 <chdir@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    11c7 <do_chroot+0x97>
lea    0xe61(%rip),%rdi
lea    0xe45(%rip),%rsi
call   1050 <sysf_printf@plt>
jmp    11cc <do_chroot+0x9c>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_chroot>:
push   %rax
call   1040 <chdir@plt>
test   %eax,%eax
jns    114d <do_chroot+0x1d>
lea    0xebf(%rip),%rdi
lea    0xebf(%rip),%rsi
call   1050 <sysf_printf@plt>
lea    0xeb4(%rip),%rdi
call   1030 <chroot@plt>
test   %eax,%eax
jns    1170 <do_chroot+0x40>
lea    0xea6(%rip),%rdi
lea    0xe9c(%rip),%rsi
call   1050 <sysf_printf@plt>
lea    0xea3(%rip),%rdi
call   1040 <chdir@plt>
test   %eax,%eax
js     1182 <do_chroot+0x52>
pop    %rax
ret
lea    0xe93(%rip),%rdi
lea    0xe77(%rip),%rsi
pop    %rax
jmp    1050 <sysf_printf@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"chdir()\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [2 x i8] c".\00"
@.str.3 = [16 x i8] c"Error chrooting\00"
@.str.4 = [2 x i8] c"/\00"
@.str.5 = [9 x i8] c"chdir(/)\00"
define void @do_chroot(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i32 @chdir(i8* %4)
store i32 %5, i32* %3
br label %6
6: ; preds = %1
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = call i32 @sysf_printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
br label %11
11: ; preds = %9, %6
br label %12
12: ; preds = %11
%13 = call i32 @chroot(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32 %13, i32* %3
br label %14
14: ; preds = %12
%15 = load i32, i32* %3
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = call i32 @sysf_printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %17, %14
br label %20
20: ; preds = %19
%21 = call i32 @chdir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32 %21, i32* %3
br label %22
22: ; preds = %20
%23 = load i32, i32* %3
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = call i32 @sysf_printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
br label %27
27: ; preds = %25, %22
br label %28
28: ; preds = %27
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"chdir()\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [2 x i8] c".\00"
@.str.3 = [16 x i8] c"Error chrooting\00"
@.str.4 = [2 x i8] c"/\00"
@.str.5 = [9 x i8] c"chdir(/)\00"
define void @do_chroot(i8* %0) {
%2 = tail call i32 @chdir(i8* %0)
%3 = icmp slt i32 %2, 0
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 @sysf_printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
br label %6
6: ; preds = %4, %1
%7 = tail call i32 @chroot(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = tail call i32 @sysf_printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
br label %11
11: ; preds = %9, %6
%12 = tail call i32 @chdir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = tail call i32 @sysf_printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %14, %11
ret void
}