#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 */
struct test {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ EPERM;
int chroot(char *);
int /*<<< orphan*/ expect(char *, int, int, int /*<<< orphan*/);
void priv_vfs_chroot(int asroot, int injail, struct test *test) {
  int error;
  error = chroot("/");
  if (asroot && injail)
    expect("priv_vfs_chroot(asroot, injail)", error, 0, 0);
  if (asroot && !injail)
    expect("priv_vfs_chroot(asroot, !injail)", error, 0, 0);
  if (!asroot && injail)
    expect("priv_vfs_chroot(!asroot, injail)", error, -1, EPERM);
  if (!asroot && !injail)
    expect("priv_vfs_chroot(!asroot, !injail)", error, -1, EPERM);
}


x86 assembly (clang, -O0):
<priv_vfs_chroot>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
lea    0xec7(%rip),%rdi
call   1030 <chroot@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     1168 <priv_vfs_chroot+0x48>
cmpl   $0x0,-0x8(%rbp)
je     1168 <priv_vfs_chroot+0x48>
mov    -0x14(%rbp),%esi
lea    0xea3(%rip),%rdi
xor    %ecx,%ecx
mov    %ecx,%edx
call   1040 <expect@plt>
cmpl   $0x0,-0x4(%rbp)
je     118f <priv_vfs_chroot+0x6f>
cmpl   $0x0,-0x8(%rbp)
jne    118f <priv_vfs_chroot+0x6f>
mov    -0x14(%rbp),%esi
lea    0xe9c(%rip),%rdi
xor    %ecx,%ecx
mov    %ecx,%edx
call   1040 <expect@plt>
cmpl   $0x0,-0x4(%rbp)
jne    11c0 <priv_vfs_chroot+0xa0>
cmpl   $0x0,-0x8(%rbp)
je     11c0 <priv_vfs_chroot+0xa0>
mov    -0x14(%rbp),%esi
mov    0x2e2b(%rip),%rax
mov    (%rax),%ecx
lea    0xe8d(%rip),%rdi
mov    $0xffffffff,%edx
call   1040 <expect@plt>
cmpl   $0x0,-0x4(%rbp)
jne    11f1 <priv_vfs_chroot+0xd1>
cmpl   $0x0,-0x8(%rbp)
jne    11f1 <priv_vfs_chroot+0xd1>
mov    -0x14(%rbp),%esi
mov    0x2dfa(%rip),%rax
mov    (%rax),%ecx
lea    0xe7d(%rip),%rdi
mov    $0xffffffff,%edx
call   1040 <expect@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<priv_vfs_chroot>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %edi,%ebx
lea    0xed1(%rip),%rdi
call   1030 <chroot@plt>
mov    %eax,%r14d
test   %ebx,%ebx
je     1152 <priv_vfs_chroot+0x32>
test   %ebp,%ebp
je     1152 <priv_vfs_chroot+0x32>
lea    0xebc(%rip),%rdi
mov    %r14d,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1040 <expect@plt>
test   %ebx,%ebx
je     116d <priv_vfs_chroot+0x4d>
test   %ebp,%ebp
jne    116d <priv_vfs_chroot+0x4d>
lea    0xec1(%rip),%rdi
mov    %r14d,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1040 <expect@plt>
test   %ebx,%ebx
jne    1192 <priv_vfs_chroot+0x72>
test   %ebp,%ebp
je     1192 <priv_vfs_chroot+0x72>
mov    0x2e5c(%rip),%rax
mov    (%rax),%ecx
lea    0xebe(%rip),%rdi
mov    %r14d,%esi
mov    $0xffffffff,%edx
call   1040 <expect@plt>
or     %ebx,%ebp
je     119b <priv_vfs_chroot+0x7b>
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2e36(%rip),%rax
mov    (%rax),%ecx
lea    0xeb9(%rip),%rdi
mov    %r14d,%esi
mov    $0xffffffff,%edx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <expect@plt>

LLVM IR (-O0):
%struct.test = type { i32 }
@.str = [2 x i8] c"/\00"
@.str.1 = [32 x i8] c"priv_vfs_chroot(asroot, injail)\00"
@.str.2 = [33 x i8] c"priv_vfs_chroot(asroot, !injail)\00"
@.str.3 = [33 x i8] c"priv_vfs_chroot(!asroot, injail)\00"
@EPERM = global i32 0
@.str.4 = [34 x i8] c"priv_vfs_chroot(!asroot, !injail)\00"
define void @priv_vfs_chroot(i32 %0, i32 %1, %struct.test* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.test*
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store %struct.test* %2, %struct.test** %6
%8 = call i32 @chroot(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32 %8, i32* %7
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %3
%12 = load i32, i32* %5
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = load i32, i32* %7
%16 = call i32 @expect(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 %15, i32 0, i32 0)
br label %17
17: ; preds = %14, %11, %3
%18 = load i32, i32* %4
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %26
20: ; preds = %17
%21 = load i32, i32* %5
%22 = icmp ne i32 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %20
%24 = load i32, i32* %7
%25 = call i32 @expect(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %24, i32 0, i32 0)
br label %26
26: ; preds = %23, %20, %17
%27 = load i32, i32* %4
%28 = icmp ne i32 %27, 0
br i1 %28, label %36, label %29
29: ; preds = %26
%30 = load i32, i32* %5
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %29
%33 = load i32, i32* %7
%34 = load i32, i32* @EPERM
%35 = call i32 @expect(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i32 %33, i32 -1, i32 %34)
br label %36
36: ; preds = %32, %29, %26
%37 = load i32, i32* %4
%38 = icmp ne i32 %37, 0
br i1 %38, label %46, label %39
39: ; preds = %36
%40 = load i32, i32* %5
%41 = icmp ne i32 %40, 0
br i1 %41, label %46, label %42
42: ; preds = %39
%43 = load i32, i32* %7
%44 = load i32, i32* @EPERM
%45 = call i32 @expect(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i32 %43, i32 -1, i32 %44)
br label %46
46: ; preds = %42, %39, %36
ret void
}

LLVM IR (-O2):
%struct.test = type { i32 }
@.str = [2 x i8] c"/\00"
@.str.1 = [32 x i8] c"priv_vfs_chroot(asroot, injail)\00"
@.str.2 = [33 x i8] c"priv_vfs_chroot(asroot, !injail)\00"
@.str.3 = [33 x i8] c"priv_vfs_chroot(!asroot, injail)\00"
@EPERM = global i32 0
@.str.4 = [34 x i8] c"priv_vfs_chroot(!asroot, !injail)\00"
define void @priv_vfs_chroot(i32 %0, i32 %1, %struct.test* nocapture readnone %2) {
%4 = tail call i32 @chroot(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp ne i32 %0, 0
%6 = icmp ne i32 %1, 0
%7 = and i1 %5, %6
br i1 %7, label %8, label %10
8: ; preds = %3
%9 = tail call i32 @expect(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 %4, i32 0, i32 0)
br label %10
10: ; preds = %8, %3
%11 = icmp eq i32 %0, 0
%12 = or i1 %11, %6
br i1 %12, label %15, label %13
13: ; preds = %10
%14 = tail call i32 @expect(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %4, i32 0, i32 0)
br label %15
15: ; preds = %13, %10
%16 = and i1 %11, %6
br i1 %16, label %17, label %20
17: ; preds = %15
%18 = load i32, i32* @EPERM
%19 = tail call i32 @expect(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i32 %4, i32 -1, i32 %18)
br label %20
20: ; preds = %17, %15
%21 = or i32 %1, %0
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = load i32, i32* @EPERM
%25 = tail call i32 @expect(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i32 %4, i32 -1, i32 %24)
br label %26
26: ; preds = %23, %20
ret void
}