#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 stat {
  scalar_t__ st_dev;
  scalar_t__ st_ino;
};

/* Variables and functions */
scalar_t__ EPERM;
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ O_RDONLY;
scalar_t__ chdir(char *);
scalar_t__ chroot(char *);
scalar_t__ close(int);
scalar_t__ errno;
int /*<<< orphan*/ fatal(char *);
scalar_t__ fchdir(int);
char *mkdtemp(char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ rmdir(char *);
scalar_t__ stat(char *, struct stat *);
int main() {
  struct stat before, after;
  int fd;
  int status = EXIT_FAILURE;
  char tmpdir_template[] = "/tmp/chtest.tmp.chroot.XXXXXX";
  char *tmpdir_name;
  if (stat("/", &before))
    fatal("stat before");
  tmpdir_name = mkdtemp(tmpdir_template);
  if (tmpdir_name == NULL)
    fatal("mkdtemp");
  if ((fd = open(".", O_RDONLY)) < 0)
    fatal("open");
  if (chroot(tmpdir_name)) {
    if (errno == EPERM) {
      printf("SAFE\tchroot(2) failed with EPERM\n");
      status = EXIT_SUCCESS;
    } else {
      fatal("chroot");
    }
  } else {
    if (fchdir(fd))
      fatal("fchdir");
    if (close(fd))
      fatal("close");
    for (int i = 0; i < 1024; i++)
      if (chdir(".."))
        fatal("chdir");
    if (chroot("."))
      fatal("chroot");
    if (stat("/", &after))
      fatal("stat after");
    if (before.st_dev == after.st_dev && before.st_ino == after.st_ino) {
      printf("SAFE\t");
      status = EXIT_SUCCESS;
    } else {
      printf("RISK\t");
      status = EXIT_FAILURE;
    }
    printf("dev/inode before %lu/%lu, after %lu/%lu\n", before.st_dev,
           before.st_ino, after.st_dev, after.st_ino);
  }
  if (rmdir(tmpdir_name))
    fatal("rmdir");
  return status;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e1a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0xe3e(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    0xe3b(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    0xe38(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xe36(%rip),%eax
mov    %eax,-0x38(%rbp)
mov    0xe30(%rip),%ax
mov    %ax,-0x34(%rbp)
lea    0xe27(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1080 <stat@plt>
cmp    $0x0,%rax
je     1216 <main+0x76>
lea    0xe0f(%rip),%rdi
call   10c0 <fatal@plt>
lea    -0x50(%rbp),%rdi
call   10a0 <mkdtemp@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
jne    123a <main+0x9a>
lea    0xdf7(%rip),%rdi
call   10c0 <fatal@plt>
mov    0x2da7(%rip),%rax
mov    (%rax),%esi
lea    0xe26(%rip),%rdi
call   10b0 <open@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
jge    1267 <main+0xc7>
lea    0xdd2(%rip),%rdi
call   10c0 <fatal@plt>
mov    -0x58(%rbp),%rdi
call   1030 <chroot@plt>
cmp    $0x0,%rax
je     12c4 <main+0x124>
mov    0x2d57(%rip),%rax
mov    (%rax),%rax
mov    0x2d2d(%rip),%rcx
cmp    (%rcx),%rax
jne    12b3 <main+0x113>
lea    0xd9e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2d1f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
jmp    12bf <main+0x11f>
lea    0xda1(%rip),%rdi
call   10c0 <fatal@plt>
jmp    1404 <main+0x264>
mov    -0x2c(%rbp),%edi
call   1090 <fchdir@plt>
cmp    $0x0,%rax
je     12e2 <main+0x142>
lea    0xd85(%rip),%rdi
call   10c0 <fatal@plt>
mov    -0x2c(%rbp),%edi
call   1070 <close@plt>
cmp    $0x0,%rax
je     1300 <main+0x160>
lea    0xd6e(%rip),%rdi
call   10c0 <fatal@plt>
movl   $0x0,-0x5c(%rbp)
cmpl   $0x400,-0x5c(%rbp)
jge    1349 <main+0x1a9>
lea    0xd54(%rip),%rdi
call   1050 <chdir@plt>
cmp    $0x0,%rax
je     1336 <main+0x196>
lea    0xd32(%rip),%rdi
call   10c0 <fatal@plt>
jmp    133b <main+0x19b>
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    1307 <main+0x167>
lea    0xd20(%rip),%rdi
call   1030 <chroot@plt>
cmp    $0x0,%rax
je     136b <main+0x1cb>
lea    0xcf5(%rip),%rdi
call   10c0 <fatal@plt>
lea    0xcac(%rip),%rdi
lea    -0x28(%rbp),%rsi
call   1080 <stat@plt>
cmp    $0x0,%rax
je     1391 <main+0x1f1>
lea    0xce6(%rip),%rdi
call   10c0 <fatal@plt>
mov    -0x18(%rbp),%rax
cmp    -0x28(%rbp),%rax
jne    13cc <main+0x22c>
mov    -0x10(%rbp),%rax
cmp    -0x20(%rbp),%rax
jne    13cc <main+0x22c>
lea    0xcc9(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2c06(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
jmp    13e6 <main+0x246>
lea    0xcb0(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2bef(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x20(%rbp),%r8
lea    0xc8c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x58(%rbp),%rdi
call   1040 <rmdir@plt>
cmp    $0x0,%rax
je     1423 <main+0x283>
lea    0xc94(%rip),%rdi
call   10c0 <fatal@plt>
mov    -0x30(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x40,%rsp
mov    0x2e0d(%rip),%r15
mov    (%r15),%ebp
movups 0xe41(%rip),%xmm0
movups %xmm0,0x2e(%rsp)
movaps 0xe27(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
lea    0xe39(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1090 <stat@plt>
test   %rax,%rax
je     1200 <main+0x50>
lea    0xe25(%rip),%rdi
call   10d0 <fatal@plt>
lea    0x20(%rsp),%rdi
call   10b0 <mkdtemp@plt>
mov    %rax,%r14
test   %rax,%rax
jne    121e <main+0x6e>
lea    0xe13(%rip),%rdi
call   10d0 <fatal@plt>
mov    0x2dc3(%rip),%rax
mov    (%rax),%esi
lea    0xe20(%rip),%rdi
call   10c0 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    1245 <main+0x95>
lea    0xdf4(%rip),%rdi
call   10d0 <fatal@plt>
mov    %r14,%rdi
call   1030 <chroot@plt>
test   %rax,%rax
je     1286 <main+0xd6>
mov    0x2d7f(%rip),%rax
mov    (%rax),%rax
mov    0x2d55(%rip),%rcx
cmp    (%rcx),%rax
jne    1350 <main+0x1a0>
lea    0xe23(%rip),%rdi
call   1040 <puts@plt>
mov    0x2d49(%rip),%rax
mov    (%rax),%ebp
jmp    1390 <main+0x1e0>
mov    %ebx,%edi
call   10a0 <fchdir@plt>
test   %rax,%rax
je     129e <main+0xee>
lea    0xda7(%rip),%rdi
call   10d0 <fatal@plt>
mov    %ebx,%edi
call   1080 <close@plt>
test   %rax,%rax
je     12b6 <main+0x106>
lea    0xd96(%rip),%rdi
call   10d0 <fatal@plt>
mov    $0x400,%ebp
lea    0xd8b(%rip),%rbx
lea    0xd78(%rip),%r12
jmp    12d5 <main+0x125>
nopl   0x0(%rax,%rax,1)
add    $0xffffffff,%ebp
je     12ec <main+0x13c>
mov    %rbx,%rdi
call   1060 <chdir@plt>
test   %rax,%rax
je     12d0 <main+0x120>
mov    %r12,%rdi
call   10d0 <fatal@plt>
jmp    12d0 <main+0x120>
lea    0xd5b(%rip),%rdi
call   1030 <chroot@plt>
test   %rax,%rax
je     1309 <main+0x159>
lea    0xd35(%rip),%rdi
call   10d0 <fatal@plt>
lea    0xd0e(%rip),%rdi
mov    %rsp,%rsi
call   1090 <stat@plt>
test   %rax,%rax
je     1329 <main+0x179>
lea    0xd2c(%rip),%rdi
call   10d0 <fatal@plt>
mov    0x10(%rsp),%rax
cmp    (%rsp),%rax
jne    135e <main+0x1ae>
mov    0x18(%rsp),%rax
cmp    0x8(%rsp),%rax
jne    135e <main+0x1ae>
mov    0x2c81(%rip),%r15
lea    0xd0d(%rip),%rdi
jmp    1365 <main+0x1b5>
lea    0xce2(%rip),%rdi
call   10d0 <fatal@plt>
jmp    1390 <main+0x1e0>
lea    0xcfc(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    (%r15),%ebp
mov    0x10(%rsp),%rsi
mov    0x18(%rsp),%rdx
mov    (%rsp),%rcx
mov    0x8(%rsp),%r8
lea    0xcde(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r14,%rdi
call   1050 <rmdir@plt>
test   %rax,%rax
je     13a9 <main+0x1f9>
lea    0xcec(%rip),%rdi
call   10d0 <fatal@plt>
mov    %ebp,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i64, i64 }
@EXIT_FAILURE = global i32 0
@__const.main.tmpdir_template = [30 x i8] c"/tmp/chtest.tmp.chroot.XXXXXX\00"
@.str = [2 x i8] c"/\00"
@.str.1 = [12 x i8] c"stat before\00"
@.str.2 = [8 x i8] c"mkdtemp\00"
@.str.3 = [2 x i8] c".\00"
@O_RDONLY = global i32 0
@.str.4 = [5 x i8] c"open\00"
@errno = global i64 0
@EPERM = global i64 0
@.str.5 = [34 x i8] c"SAFE\09chroot(2) failed with EPERM\0A\00"
@EXIT_SUCCESS = global i32 0
@.str.6 = [7 x i8] c"chroot\00"
@.str.7 = [7 x i8] c"fchdir\00"
@.str.8 = [6 x i8] c"close\00"
@.str.9 = [3 x i8] c"..\00"
@.str.10 = [6 x i8] c"chdir\00"
@.str.11 = [11 x i8] c"stat after\00"
@.str.12 = [6 x i8] c"SAFE\09\00"
@.str.13 = [6 x i8] c"RISK\09\00"
@.str.14 = [41 x i8] c"dev/inode before %lu/%lu, after %lu/%lu\0A\00"
@.str.15 = [6 x i8] c"rmdir\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.stat
%3 = alloca %struct.stat
%4 = alloca i32
%5 = alloca i32
%6 = alloca [30 x i8]
%7 = alloca i8*
%8 = alloca i32
store i32 0, i32* %1
%9 = load i32, i32* @EXIT_FAILURE
store i32 %9, i32* %5
%10 = bitcast [30 x i8]* %6 to i8*
%11 = call i64 @stat(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), %struct.stat* %2)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %0
%14 = call i32 @fatal(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %13, %0
%16 = getelementptr inbounds [30 x i8], [30 x i8]* %6, i64 0, i64 0
%17 = call i8* @mkdtemp(i8* %16)
store i8* %17, i8** %7
%18 = load i8*, i8** %7
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = call i32 @fatal(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %22
22: ; preds = %20, %15
%23 = load i32, i32* @O_RDONLY
%24 = call i32 @open(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 %23)
store i32 %24, i32* %4
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %22
%27 = call i32 @fatal(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %28
28: ; preds = %26, %22
%29 = load i8*, i8** %7
%30 = call i64 @chroot(i8* %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %42
32: ; preds = %28
%33 = load i64, i64* @errno
%34 = load i64, i64* @EPERM
%35 = icmp eq i64 %33, %34
br i1 %35, label %36, label %39
36: ; preds = %32
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0))
%38 = load i32, i32* @EXIT_SUCCESS
store i32 %38, i32* %5
br label %41
39: ; preds = %32
%40 = call i32 @fatal(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
br label %41
41: ; preds = %39, %36
br label %105
42: ; preds = %28
%43 = load i32, i32* %4
%44 = call i64 @fchdir(i32 %43)
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %42
%47 = call i32 @fatal(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
br label %48
48: ; preds = %46, %42
%49 = load i32, i32* %4
%50 = call i64 @close(i32 %49)
%51 = icmp ne i64 %50, 0
br i1 %51, label %52, label %54
52: ; preds = %48
%53 = call i32 @fatal(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
br label %54
54: ; preds = %52, %48
store i32 0, i32* %8
br label %55
55: ; preds = %64, %54
%56 = load i32, i32* %8
%57 = icmp slt i32 %56, 1024
br i1 %57, label %58, label %67
58: ; preds = %55
%59 = call i64 @chdir(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0))
%60 = icmp ne i64 %59, 0
br i1 %60, label %61, label %63
61: ; preds = %58
%62 = call i32 @fatal(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0))
br label %63
63: ; preds = %61, %58
br label %64
64: ; preds = %63
%65 = load i32, i32* %8
%66 = add nsw i32 %65, 1
store i32 %66, i32* %8
br label %55
67: ; preds = %55
%68 = call i64 @chroot(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%69 = icmp ne i64 %68, 0
br i1 %69, label %70, label %72
70: ; preds = %67
%71 = call i32 @fatal(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
br label %72
72: ; preds = %70, %67
%73 = call i64 @stat(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), %struct.stat* %3)
%74 = icmp ne i64 %73, 0
br i1 %74, label %75, label %77
75: ; preds = %72
%76 = call i32 @fatal(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.11, i64 0, i64 0))
br label %77
77: ; preds = %75, %72
%78 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 0
%79 = load i64, i64* %78
%80 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%81 = load i64, i64* %80
%82 = icmp eq i64 %79, %81
br i1 %82, label %83, label %92
83: ; preds = %77
%84 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 1
%85 = load i64, i64* %84
%86 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 1
%87 = load i64, i64* %86
%88 = icmp eq i64 %85, %87
br i1 %88, label %89, label %92
89: ; preds = %83
%90 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.12, i64 0, i64 0))
%91 = load i32, i32* @EXIT_SUCCESS
store i32 %91, i32* %5
br label %95
92: ; preds = %83, %77
%93 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.13, i64 0, i64 0))
%94 = load i32, i32* @EXIT_FAILURE
store i32 %94, i32* %5
br label %95
95: ; preds = %92, %89
%96 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 0
%97 = load i64, i64* %96
%98 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 1
%99 = load i64, i64* %98
%100 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%101 = load i64, i64* %100
%102 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 1
%103 = load i64, i64* %102
%104 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.14, i64 0, i64 0), i64 %97, i64 %99, i64 %101, i64 %103)
br label %105
105: ; preds = %95, %41
%106 = load i8*, i8** %7
%107 = call i64 @rmdir(i8* %106)
%108 = icmp ne i64 %107, 0
br i1 %108, label %109, label %111
109: ; preds = %105
%110 = call i32 @fatal(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.15, i64 0, i64 0))
br label %111
111: ; preds = %109, %105
%112 = load i32, i32* %5
ret i32 %112
}

LLVM IR (-O2):
%struct.stat = type { i64, i64 }
@EXIT_FAILURE = global i32 0
@__const.main.tmpdir_template = [30 x i8] c"/tmp/chtest.tmp.chroot.XXXXXX\00"
@.str = [2 x i8] c"/\00"
@.str.1 = [12 x i8] c"stat before\00"
@.str.2 = [8 x i8] c"mkdtemp\00"
@.str.3 = [2 x i8] c".\00"
@O_RDONLY = global i32 0
@.str.4 = [5 x i8] c"open\00"
@errno = global i64 0
@EPERM = global i64 0
@EXIT_SUCCESS = global i32 0
@.str.6 = [7 x i8] c"chroot\00"
@.str.7 = [7 x i8] c"fchdir\00"
@.str.8 = [6 x i8] c"close\00"
@.str.9 = [3 x i8] c"..\00"
@.str.10 = [6 x i8] c"chdir\00"
@.str.11 = [11 x i8] c"stat after\00"
@.str.12 = [6 x i8] c"SAFE\09\00"
@.str.13 = [6 x i8] c"RISK\09\00"
@.str.14 = [41 x i8] c"dev/inode before %lu/%lu, after %lu/%lu\0A\00"
@.str.15 = [6 x i8] c"rmdir\00"
@str = [33 x i8] c"SAFE\09chroot(2) failed with EPERM\00"
define i32 @main() {
%1 = alloca %struct.stat
%2 = alloca %struct.stat
%3 = alloca [30 x i8]
%4 = bitcast %struct.stat* %1 to i8*
%5 = bitcast %struct.stat* %2 to i8*
%6 = load i32, i32* @EXIT_FAILURE
%7 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 0
%8 = call i64 @stat(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), %struct.stat* %1)
%9 = icmp eq i64 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %0
%11 = call i32 @fatal(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %10, %0
%13 = call i8* @mkdtemp(i8* %7)
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i32 @fatal(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %17
17: ; preds = %15, %12
%18 = load i32, i32* @O_RDONLY
%19 = call i32 @open(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 %18)
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = call i32 @fatal(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %23
23: ; preds = %21, %17
%24 = call i64 @chroot(i8* %13)
%25 = icmp eq i64 %24, 0
br i1 %25, label %35, label %26
26: ; preds = %23
%27 = load i64, i64* @errno
%28 = load i64, i64* @EPERM
%29 = icmp eq i64 %27, %28
br i1 %29, label %30, label %33
30: ; preds = %26
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
%32 = load i32, i32* @EXIT_SUCCESS
br label %90
33: ; preds = %26
%34 = call i32 @fatal(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
br label %90
35: ; preds = %23
%36 = call i64 @fchdir(i32 %19)
%37 = icmp eq i64 %36, 0
br i1 %37, label %40, label %38
38: ; preds = %35
%39 = call i32 @fatal(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
br label %40
40: ; preds = %38, %35
%41 = call i64 @close(i32 %19)
%42 = icmp eq i64 %41, 0
br i1 %42, label %43, label %44
43: ; preds = %44, %40
br label %49
44: ; preds = %40
%45 = call i32 @fatal(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
br label %43
46: ; preds = %55
%47 = call i64 @chroot(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%48 = icmp eq i64 %47, 0
br i1 %48, label %60, label %58
49: ; preds = %43, %55
%50 = phi i32 [ %56, %55 ], [ 0, %43 ]
%51 = call i64 @chdir(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0))
%52 = icmp eq i64 %51, 0
br i1 %52, label %55, label %53
53: ; preds = %49
%54 = call i32 @fatal(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0))
br label %55
55: ; preds = %49, %53
%56 = add nuw nsw i32 %50, 1
%57 = icmp eq i32 %56, 1024
br i1 %57, label %46, label %49
58: ; preds = %46
%59 = call i32 @fatal(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
br label %60
60: ; preds = %58, %46
%61 = call i64 @stat(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), %struct.stat* %2)
%62 = icmp eq i64 %61, 0
br i1 %62, label %65, label %63
63: ; preds = %60
%64 = call i32 @fatal(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.11, i64 0, i64 0))
br label %65
65: ; preds = %63, %60
%66 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 0
%67 = load i64, i64* %66
%68 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%69 = load i64, i64* %68
%70 = icmp eq i64 %67, %69
br i1 %70, label %71, label %77
71: ; preds = %65
%72 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 1
%73 = load i64, i64* %72
%74 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 1
%75 = load i64, i64* %74
%76 = icmp eq i64 %73, %75
br i1 %76, label %78, label %77
77: ; preds = %71, %65
br label %78
78: ; preds = %71, %77
%79 = phi i8* [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.13, i64 0, i64 0), %77 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.12, i64 0, i64 0), %71 ]
%80 = phi i32* [ @EXIT_FAILURE, %77 ], [ @EXIT_SUCCESS, %71 ]
%81 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %79)
%82 = load i32, i32* %80
%83 = load i64, i64* %66
%84 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 1
%85 = load i64, i64* %84
%86 = load i64, i64* %68
%87 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 1
%88 = load i64, i64* %87
%89 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.14, i64 0, i64 0), i64 %83, i64 %85, i64 %86, i64 %88)
br label %90
90: ; preds = %30, %33, %78
%91 = phi i32 [ %32, %30 ], [ %6, %33 ], [ %82, %78 ]
%92 = call i64 @rmdir(i8* %13)
%93 = icmp eq i64 %92, 0
br i1 %93, label %96, label %94
94: ; preds = %90
%95 = call i32 @fatal(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.15, i64 0, i64 0))
br label %96
96: ; preds = %94, %90
ret i32 %91
}