#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(char const *);
char *get_current_dir_name();
int /*<<< orphan*/ pl_chdir(char *);
scalar_t__ pl_fatal(char *, ...);
void pl_chroot(const char *rootfs) {
  char *origpwd = get_current_dir_name();
  if (!origpwd)
    pl_fatal("get_current_dir_name");
  chroot(rootfs) != -1 || pl_fatal("could not chroot to %s", rootfs);
  pl_chdir(origpwd);
}


x86 assembly (clang, -O0):
<pl_chroot>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1050 <get_current_dir_name@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1170 <pl_chroot+0x30>
lea    0xe97(%rip),%rdi
mov    $0x0,%al
call   1060 <pl_fatal@plt>
mov    -0x8(%rbp),%rdi
call   1030 <chroot@plt>
mov    %eax,%ecx
mov    $0x1,%al
cmp    $0xffffffff,%ecx
mov    %al,-0x11(%rbp)
jne    11a5 <pl_chroot+0x65>
mov    -0x8(%rbp),%rsi
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1060 <pl_fatal@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
mov    -0x10(%rbp),%rdi
call   1040 <pl_chdir@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pl_chroot>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %eax,%eax
call   1050 <get_current_dir_name@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1164 <pl_chroot+0x24>
lea    0xea3(%rip),%rdi
xor    %eax,%eax
call   1060 <pl_fatal@plt>
mov    %r14,%rdi
call   1030 <chroot@plt>
cmp    $0xffffffff,%eax
jne    1182 <pl_chroot+0x42>
lea    0xe9d(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <pl_fatal@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <pl_chdir@plt>

LLVM IR (-O0):
@.str = [21 x i8] c"get_current_dir_name\00"
@.str.1 = [23 x i8] c"could not chroot to %s\00"
define void @pl_chroot(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
%4 = call i8* (...) @get_current_dir_name()
store i8* %4, i8** %3
%5 = load i8*, i8** %3
%6 = icmp ne i8* %5, null
br i1 %6, label %9, label %7
7: ; preds = %1
%8 = call i64 (i8*, ...) @pl_fatal(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %1
%10 = load i8*, i8** %2
%11 = call i32 @chroot(i8* %10)
%12 = icmp ne i32 %11, -1
br i1 %12, label %17, label %13
13: ; preds = %9
%14 = load i8*, i8** %2
%15 = call i64 (i8*, ...) @pl_fatal(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%16 = icmp ne i64 %15, 0
br label %17
17: ; preds = %13, %9
%18 = phi i1 [ true, %9 ], [ %16, %13 ]
%19 = zext i1 %18 to i32
%20 = load i8*, i8** %3
%21 = call i32 @pl_chdir(i8* %20)
ret void
}

LLVM IR (-O2):
@.str = [21 x i8] c"get_current_dir_name\00"
@.str.1 = [23 x i8] c"could not chroot to %s\00"
define void @pl_chroot(i8* %0) {
%2 = tail call i8* (...) @get_current_dir_name()
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i64 (i8*, ...) @pl_fatal(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %4, %1
%7 = tail call i32 @chroot(i8* %0)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = tail call i64 (i8*, ...) @pl_fatal(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %11
11: ; preds = %9, %6
%12 = tail call i32 @pl_chdir(i8* %2)
ret void
}