#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 */
scalar_t__ EPERM;
int chroot(char *);
scalar_t__ errno;
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ setbuf(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ stdout;
int main() {
  setbuf(stdout, NULL);
  printf("checkpoint1\n");
  if (chroot("./") == -1) {
    printf("checkpoint2\n");
    if (errno == EPERM) {
      printf("checkpoint3\n");
    } else {
      printf("fail1");
    }
  } else {
    printf("fail2");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e92(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <setbuf@plt>
lea    0xea8(%rip),%rdi
call   1050 <printf@plt>
lea    0xea9(%rip),%rdi
call   1030 <chroot@plt>
cmp    $0xffffffff,%eax
jne    11ba <main+0x8a>
lea    0xe97(%rip),%rdi
call   1050 <printf@plt>
mov    0x2e5b(%rip),%rax
mov    (%rax),%rax
mov    0x2e39(%rip),%rcx
cmp    (%rcx),%rax
jne    11a9 <main+0x79>
lea    0xe7e(%rip),%rdi
call   1050 <printf@plt>
jmp    11b5 <main+0x85>
lea    0xe7a(%rip),%rdi
call   1050 <printf@plt>
jmp    11c6 <main+0x96>
lea    0xe6f(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    0x2e90(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1050 <setbuf@plt>
lea    0xeb7(%rip),%rdi
call   1040 <puts@plt>
lea    0xe9c(%rip),%rdi
call   1030 <chroot@plt>
cmp    $0xffffffff,%eax
je     1177 <main+0x37>
lea    0xe94(%rip),%rdi
jmp    11ae <main+0x6e>
lea    0xe9d(%rip),%rdi
call   1040 <puts@plt>
mov    0x2e56(%rip),%rax
mov    (%rax),%rax
mov    0x2e34(%rip),%rcx
cmp    (%rcx),%rax
jne    11a7 <main+0x67>
lea    0xe87(%rip),%rdi
call   1040 <puts@plt>
jmp    11b3 <main+0x73>
lea    0xe55(%rip),%rdi
call   1060 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@stdout = global i32 0
@.str = [13 x i8] c"checkpoint1\0A\00"
@.str.1 = [3 x i8] c"./\00"
@.str.2 = [13 x i8] c"checkpoint2\0A\00"
@errno = global i64 0
@EPERM = global i64 0
@.str.3 = [13 x i8] c"checkpoint3\0A\00"
@.str.4 = [6 x i8] c"fail1\00"
@.str.5 = [6 x i8] c"fail2\00"
define i32 @main() {
%1 = alloca i32
store i32 0, i32* %1
%2 = load i32, i32* @stdout
%3 = call i32 @setbuf(i32 %2, i32* null)
%4 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @chroot(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %17
7: ; preds = %0
%8 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%9 = load i64, i64* @errno
%10 = load i64, i64* @EPERM
%11 = icmp eq i64 %9, %10
br i1 %11, label %12, label %14
12: ; preds = %7
%13 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %16
14: ; preds = %7
%15 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
br label %16
16: ; preds = %14, %12
br label %19
17: ; preds = %0
%18 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
br label %19
19: ; preds = %17, %16
ret i32 0
}

LLVM IR (-O2):
@stdout = global i32 0
@.str.1 = [3 x i8] c"./\00"
@errno = global i64 0
@EPERM = global i64 0
@.str.4 = [6 x i8] c"fail1\00"
@.str.5 = [6 x i8] c"fail2\00"
@str = [12 x i8] c"checkpoint1\00"
@str.6 = [12 x i8] c"checkpoint2\00"
@str.7 = [12 x i8] c"checkpoint3\00"
define i32 @main() {
%1 = load i32, i32* @stdout
%2 = tail call i32 @setbuf(i32 %1, i32* null)
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 @chroot(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %15
6: ; preds = %0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.6, i64 0, i64 0))
%8 = load i64, i64* @errno
%9 = load i64, i64* @EPERM
%10 = icmp eq i64 %8, %9
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.7, i64 0, i64 0))
br label %17
13: ; preds = %6
%14 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
br label %17
15: ; preds = %0
%16 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
br label %17
17: ; preds = %11, %13, %15
ret i32 0
}