#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 */
typedef scalar_t__ pid_t;
typedef int /*<<< orphan*/ newmount;

/* Variables and functions */
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ MNT_FORCE;
int /*<<< orphan*/ O_RDONLY;
scalar_t__ chdir(char const *);
scalar_t__ chroot(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errmsg(int /*<<< orphan*/, int /*<<< orphan*/, int, char *,
                          ...);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
scalar_t__ mount(char const *, char *, int /*<<< orphan*/ *, int,
                 int /*<<< orphan*/ *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ recursiveRemove(int);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *, char const *);
int /*<<< orphan*/ umount2(char const *, int /*<<< orphan*/);
int switchroot(const char *newroot) {
  const char *umounts[] = {"/dev", "/proc", "/sys", NULL};
  int i;
  int cfd;
  pid_t pid;
  for (i = 0; umounts[i] != NULL; i++) {
    char newmount[4096];
    snprintf(newmount, sizeof(newmount), "%s%s", newroot, umounts[i]);
    if (mount(umounts[i], newmount, NULL, 8192, NULL) < 0) {
      errmsg(0, 0, 1, "failed to mount moving %s to %s", umounts[i], newmount);
      errmsg(0, 0, 0, "forcing unmount of %s", umounts[i]);
      umount2(umounts[i], MNT_FORCE);
    }
  }
  if (chdir(newroot)) {
    errmsg(0, 0, 1, "failed to change directory to %s", newroot);
    return -1;
  }
  cfd = open("/", O_RDONLY);
  if (mount(newroot, "/", NULL, 8192, NULL) < 0) {
    errmsg(0, 0, 1, "failed to mount moving %s to /", newroot);
    return -1;
  }
  if (chroot(".")) {
    errmsg(0, 0, 1, "failed to change root");
    return -1;
  }
  if (cfd >= 0) {
    pid = fork();
    if (pid <= 0) {
      recursiveRemove(cfd);
      if (pid == 0)
        exit(EXIT_SUCCESS);
    }
    close(cfd);
  }
  return 0;
}


x86 assembly (clang, -O0):
<switchroot>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1040,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2c1a(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0x2c17(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0x2c14(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0x2c11(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x34(%rbp)
movslq -0x34(%rbp),%rax
cmpq   $0x0,-0x30(%rbp,%rax,8)
je     12c1 <switchroot+0x111>
lea    -0x1040(%rbp),%rdi
mov    -0x10(%rbp),%rcx
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp,%rax,8),%r8
mov    $0x1000,%esi
lea    0xdee(%rip),%rdx
call   1070 <snprintf@plt>
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp,%rax,8),%rdi
lea    -0x1040(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    $0x2000,%ecx
mov    %r8,%rdx
call   1050 <mount@plt>
cmp    $0x0,%rax
jge    12ae <switchroot+0xfe>
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp,%rax,8),%r8
lea    -0x1040(%rbp),%r9
xor    %esi,%esi
mov    $0x1,%edx
lea    0xda4(%rip),%rcx
mov    %esi,%edi
mov    $0x0,%al
call   1090 <errmsg@plt>
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp,%rax,8),%r8
xor    %edx,%edx
lea    0xda9(%rip),%rcx
mov    %edx,%edi
mov    %edx,%esi
mov    $0x0,%al
call   1090 <errmsg@plt>
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp,%rax,8),%rdi
mov    0x2d31(%rip),%rax
mov    (%rax),%esi
call   1040 <umount2@plt>
jmp    12b3 <switchroot+0x103>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11f2 <switchroot+0x42>
mov    -0x10(%rbp),%rdi
call   1060 <chdir@plt>
cmp    $0x0,%rax
je     12fb <switchroot+0x14b>
mov    -0x10(%rbp),%r8
xor    %esi,%esi
mov    $0x1,%edx
lea    0xd65(%rip),%rcx
mov    %esi,%edi
mov    $0x0,%al
call   1090 <errmsg@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13ef <switchroot+0x23f>
mov    0x2cde(%rip),%rax
mov    (%rax),%esi
lea    0xd7e(%rip),%rdi
call   10b0 <open@plt>
mov    %eax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xd6b(%rip),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    $0x2000,%ecx
mov    %r8,%rdx
call   1050 <mount@plt>
cmp    $0x0,%rax
jge    1361 <switchroot+0x1b1>
mov    -0x10(%rbp),%r8
xor    %esi,%esi
mov    $0x1,%edx
lea    0xd20(%rip),%rcx
mov    %esi,%edi
mov    $0x0,%al
call   1090 <errmsg@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13ef <switchroot+0x23f>
lea    0xd23(%rip),%rdi
call   1030 <chroot@plt>
cmp    $0x0,%rax
je     139a <switchroot+0x1ea>
xor    %esi,%esi
mov    $0x1,%edx
lea    0xd08(%rip),%rcx
mov    %esi,%edi
mov    $0x0,%al
call   1090 <errmsg@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13ef <switchroot+0x23f>
cmpl   $0x0,-0x38(%rbp)
jl     13e8 <switchroot+0x238>
mov    $0x0,%al
call   10d0 <fork@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jg     13e0 <switchroot+0x230>
mov    -0x38(%rbp),%edi
call   10a0 <recursiveRemove@plt>
cmpq   $0x0,-0x40(%rbp)
jne    13db <switchroot+0x22b>
mov    0x2bf4(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
jmp    13e0 <switchroot+0x230>
mov    -0x38(%rbp),%edi
call   1080 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<switchroot>:
push   %rbp
push   %r14
push   %rbx
sub    $0x1000,%rsp
mov    %rdi,%r14
lea    0xe4b(%rip),%rdx
lea    0xe34(%rip),%rbp
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x1000,%esi
mov    %r14,%rcx
mov    %rbp,%r8
call   1070 <snprintf@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
mov    $0x2000,%ecx
xor    %r8d,%r8d
call   1050 <mount@plt>
test   %rax,%rax
jns    1248 <switchroot+0x98>
lea    0xe12(%rip),%rcx
lea    0xdf6(%rip),%rbx
mov    %rsp,%r9
xor    %edi,%edi
xor    %esi,%esi
mov    $0x1,%edx
mov    %rbx,%r8
xor    %eax,%eax
call   1090 <errmsg@plt>
lea    0xe0e(%rip),%rcx
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
mov    %rbx,%r8
xor    %eax,%eax
call   1090 <errmsg@plt>
mov    0x2da2(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1040 <umount2@plt>
lea    0xdc1(%rip),%rdx
lea    0xdaf(%rip),%rbx
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0x1000,%esi
mov    %r14,%rcx
mov    %rbx,%r8
call   1070 <snprintf@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
xor    %edx,%edx
mov    $0x2000,%ecx
xor    %r8d,%r8d
call   1050 <mount@plt>
test   %rax,%rax
jns    12d2 <switchroot+0x122>
lea    0xd88(%rip),%rcx
lea    0xd71(%rip),%rbx
mov    %rsp,%r9
xor    %edi,%edi
xor    %esi,%esi
mov    $0x1,%edx
mov    %rbx,%r8
xor    %eax,%eax
call   1090 <errmsg@plt>
lea    0xd84(%rip),%rcx
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
mov    %rbx,%r8
xor    %eax,%eax
call   1090 <errmsg@plt>
mov    0x2d18(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1040 <umount2@plt>
lea    0xd37(%rip),%rdx
lea    0xd2b(%rip),%rbx
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0x1000,%esi
mov    %r14,%rcx
mov    %rbx,%r8
call   1070 <snprintf@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
xor    %edx,%edx
mov    $0x2000,%ecx
xor    %r8d,%r8d
call   1050 <mount@plt>
test   %rax,%rax
jns    135c <switchroot+0x1ac>
lea    0xcfe(%rip),%rcx
lea    0xced(%rip),%rbx
mov    %rsp,%r9
xor    %edi,%edi
xor    %esi,%esi
mov    $0x1,%edx
mov    %rbx,%r8
xor    %eax,%eax
call   1090 <errmsg@plt>
lea    0xcfa(%rip),%rcx
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
mov    %rbx,%r8
xor    %eax,%eax
call   1090 <errmsg@plt>
mov    0x2c8e(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1040 <umount2@plt>
mov    %r14,%rdi
call   1060 <chdir@plt>
test   %rax,%rax
je     1396 <switchroot+0x1e6>
lea    0xcdb(%rip),%rcx
xor    %edi,%edi
xor    %esi,%esi
mov    $0x1,%edx
mov    %r14,%r8
xor    %eax,%eax
call   1090 <errmsg@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x1000,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2c4b(%rip),%rax
mov    (%rax),%esi
lea    0xce3(%rip),%rbx
mov    %rbx,%rdi
call   10b0 <open@plt>
mov    %eax,%ebp
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
mov    $0x2000,%ecx
xor    %r8d,%r8d
call   1050 <mount@plt>
test   %rax,%rax
js     13f4 <switchroot+0x244>
lea    0xcba(%rip),%rdi
call   1030 <chroot@plt>
test   %rax,%rax
je     1400 <switchroot+0x250>
lea    0xcab(%rip),%rcx
xor    %edi,%edi
xor    %esi,%esi
mov    $0x1,%edx
xor    %eax,%eax
call   1090 <errmsg@plt>
jmp    1383 <switchroot+0x1d3>
lea    0xc71(%rip),%rcx
jmp    1370 <switchroot+0x1c0>
xor    %ebx,%ebx
test   %ebp,%ebp
js     1388 <switchroot+0x1d8>
xor    %eax,%eax
call   10d0 <fork@plt>
test   %rax,%rax
jg     1421 <switchroot+0x271>
mov    %rax,%r14
mov    %ebp,%edi
call   10a0 <recursiveRemove@plt>
test   %r14,%r14
je     142d <switchroot+0x27d>
mov    %ebp,%edi
call   1080 <close@plt>
jmp    1388 <switchroot+0x1d8>
mov    0x2b9c(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"/dev\00"
@.str.1 = [6 x i8] c"/proc\00"
@.str.2 = [5 x i8] c"/sys\00"
@__const.switchroot.umounts = [4 x i8*] [i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i32 0, i32 0), i8* null]
@.str.3 = [5 x i8] c"%s%s\00"
@.str.4 = [32 x i8] c"failed to mount moving %s to %s\00"
@.str.5 = [22 x i8] c"forcing unmount of %s\00"
@MNT_FORCE = global i32 0
@.str.6 = [33 x i8] c"failed to change directory to %s\00"
@.str.7 = [2 x i8] c"/\00"
@O_RDONLY = global i32 0
@.str.8 = [31 x i8] c"failed to mount moving %s to /\00"
@.str.9 = [2 x i8] c".\00"
@.str.10 = [22 x i8] c"failed to change root\00"
@EXIT_SUCCESS = global i32 0
define i32 @switchroot(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [4 x i8*]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i64
%8 = alloca [4096 x i8]
store i8* %0, i8** %3
%9 = bitcast [4 x i8*]* %4 to i8*
store i32 0, i32* %5
br label %10
10: ; preds = %50, %1
%11 = load i32, i32* %5
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [4 x i8*], [4 x i8*]* %4, i64 0, i64 %12
%14 = load i8*, i8** %13
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %53
16: ; preds = %10
%17 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%18 = load i8*, i8** %3
%19 = load i32, i32* %5
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [4 x i8*], [4 x i8*]* %4, i64 0, i64 %20
%22 = load i8*, i8** %21
%23 = call i32 @snprintf(i8* %17, i32 4096, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %18, i8* %22)
%24 = load i32, i32* %5
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [4 x i8*], [4 x i8*]* %4, i64 0, i64 %25
%27 = load i8*, i8** %26
%28 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%29 = call i64 @mount(i8* %27, i8* %28, i32* null, i32 8192, i32* null)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %49
31: ; preds = %16
%32 = load i32, i32* %5
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [4 x i8*], [4 x i8*]* %4, i64 0, i64 %33
%35 = load i8*, i8** %34
%36 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%37 = call i32 (i32, i32, i32, i8*, ...) @errmsg(i32 0, i32 0, i32 1, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %35, i8* %36)
%38 = load i32, i32* %5
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [4 x i8*], [4 x i8*]* %4, i64 0, i64 %39
%41 = load i8*, i8** %40
%42 = call i32 (i32, i32, i32, i8*, ...) @errmsg(i32 0, i32 0, i32 0, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i8* %41)
%43 = load i32, i32* %5
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [4 x i8*], [4 x i8*]* %4, i64 0, i64 %44
%46 = load i8*, i8** %45
%47 = load i32, i32* @MNT_FORCE
%48 = call i32 @umount2(i8* %46, i32 %47)
br label %49
49: ; preds = %31, %16
br label %50
50: ; preds = %49
%51 = load i32, i32* %5
%52 = add nsw i32 %51, 1
store i32 %52, i32* %5
br label %10
53: ; preds = %10
%54 = load i8*, i8** %3
%55 = call i64 @chdir(i8* %54)
%56 = icmp ne i64 %55, 0
br i1 %56, label %57, label %60
57: ; preds = %53
%58 = load i8*, i8** %3
%59 = call i32 (i32, i32, i32, i8*, ...) @errmsg(i32 0, i32 0, i32 1, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0), i8* %58)
store i32 -1, i32* %2
br label %94
60: ; preds = %53
%61 = load i32, i32* @O_RDONLY
%62 = call i32 @open(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0), i32 %61)
store i32 %62, i32* %6
%63 = load i8*, i8** %3
%64 = call i64 @mount(i8* %63, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0), i32* null, i32 8192, i32* null)
%65 = icmp slt i64 %64, 0
br i1 %65, label %66, label %69
66: ; preds = %60
%67 = load i8*, i8** %3
%68 = call i32 (i32, i32, i32, i8*, ...) @errmsg(i32 0, i32 0, i32 1, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.8, i64 0, i64 0), i8* %67)
store i32 -1, i32* %2
br label %94
69: ; preds = %60
%70 = call i64 @chroot(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
%71 = icmp ne i64 %70, 0
br i1 %71, label %72, label %74
72: ; preds = %69
%73 = call i32 (i32, i32, i32, i8*, ...) @errmsg(i32 0, i32 0, i32 1, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.10, i64 0, i64 0))
store i32 -1, i32* %2
br label %94
74: ; preds = %69
%75 = load i32, i32* %6
%76 = icmp sge i32 %75, 0
br i1 %76, label %77, label %93
77: ; preds = %74
%78 = call i64 (...) @fork()
store i64 %78, i64* %7
%79 = load i64, i64* %7
%80 = icmp sle i64 %79, 0
br i1 %80, label %81, label %90
81: ; preds = %77
%82 = load i32, i32* %6
%83 = call i32 @recursiveRemove(i32 %82)
%84 = load i64, i64* %7
%85 = icmp eq i64 %84, 0
br i1 %85, label %86, label %89
86: ; preds = %81
%87 = load i32, i32* @EXIT_SUCCESS
%88 = call i32 @exit(i32 %87)
unreachable
89: ; preds = %81
br label %90
90: ; preds = %89, %77
%91 = load i32, i32* %6
%92 = call i32 @close(i32 %91)
br label %93
93: ; preds = %90, %74
store i32 0, i32* %2
br label %94
94: ; preds = %93, %72, %66, %57
%95 = load i32, i32* %2
ret i32 %95
}

LLVM IR (-O2):
@.str = [5 x i8] c"/dev\00"
@.str.1 = [6 x i8] c"/proc\00"
@.str.2 = [5 x i8] c"/sys\00"
@.str.3 = [5 x i8] c"%s%s\00"
@.str.4 = [32 x i8] c"failed to mount moving %s to %s\00"
@.str.5 = [22 x i8] c"forcing unmount of %s\00"
@MNT_FORCE = global i32 0
@.str.6 = [33 x i8] c"failed to change directory to %s\00"
@.str.7 = [2 x i8] c"/\00"
@O_RDONLY = global i32 0
@.str.8 = [31 x i8] c"failed to mount moving %s to /\00"
@.str.9 = [2 x i8] c".\00"
@.str.10 = [22 x i8] c"failed to change root\00"
@EXIT_SUCCESS = global i32 0
define i32 @switchroot(i8* %0) {
%2 = alloca [4096 x i8]
%3 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%4 = call i32 @snprintf(i8* %3, i32 4096, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%5 = call i64 @mount(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %3, i32* null, i32 8192, i32* null)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %12
7: ; preds = %1
%8 = call i32 (i32, i32, i32, i8*, ...) @errmsg(i32 0, i32 0, i32 1, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %3)
%9 = call i32 (i32, i32, i32, i8*, ...) @errmsg(i32 0, i32 0, i32 0, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* @MNT_FORCE
%11 = call i32 @umount2(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %10)
br label %12
12: ; preds = %7, %1
%13 = call i32 @snprintf(i8* %3, i32 4096, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%14 = call i64 @mount(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %3, i32* null, i32 8192, i32* null)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %12
%17 = call i32 (i32, i32, i32, i8*, ...) @errmsg(i32 0, i32 0, i32 1, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%18 = call i32 (i32, i32, i32, i8*, ...) @errmsg(i32 0, i32 0, i32 0, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%19 = load i32, i32* @MNT_FORCE
%20 = call i32 @umount2(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %19)
br label %21
21: ; preds = %16, %12
%22 = call i32 @snprintf(i8* %3, i32 4096, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%23 = call i64 @mount(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %3, i32* null, i32 8192, i32* null)
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %21
%26 = call i32 (i32, i32, i32, i8*, ...) @errmsg(i32 0, i32 0, i32 1, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %3)
%27 = call i32 (i32, i32, i32, i8*, ...) @errmsg(i32 0, i32 0, i32 0, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%28 = load i32, i32* @MNT_FORCE
%29 = call i32 @umount2(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %28)
br label %30
30: ; preds = %25, %21
%31 = call i64 @chdir(i8* %0)
%32 = icmp eq i64 %31, 0
br i1 %32, label %35, label %33
33: ; preds = %30
%34 = call i32 (i32, i32, i32, i8*, ...) @errmsg(i32 0, i32 0, i32 1, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0), i8* %0)
br label %60
35: ; preds = %30
%36 = load i32, i32* @O_RDONLY
%37 = call i32 @open(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0), i32 %36)
%38 = call i64 @mount(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0), i32* null, i32 8192, i32* null)
%39 = icmp slt i64 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %35
%41 = call i32 (i32, i32, i32, i8*, ...) @errmsg(i32 0, i32 0, i32 1, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.8, i64 0, i64 0), i8* %0)
br label %60
42: ; preds = %35
%43 = call i64 @chroot(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
%44 = icmp eq i64 %43, 0
br i1 %44, label %47, label %45
45: ; preds = %42
%46 = call i32 (i32, i32, i32, i8*, ...) @errmsg(i32 0, i32 0, i32 1, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.10, i64 0, i64 0))
br label %60
47: ; preds = %42
%48 = icmp sgt i32 %37, -1
br i1 %48, label %49, label %60
49: ; preds = %47
%50 = call i64 (...) @fork()
%51 = icmp slt i64 %50, 1
br i1 %51, label %52, label %58
52: ; preds = %49
%53 = call i32 @recursiveRemove(i32 %37)
%54 = icmp eq i64 %50, 0
br i1 %54, label %55, label %58
55: ; preds = %52
%56 = load i32, i32* @EXIT_SUCCESS
%57 = call i32 @exit(i32 %56)
unreachable
58: ; preds = %52, %49
%59 = call i32 @close(i32 %37)
br label %60
60: ; preds = %47, %58, %45, %40, %33
%61 = phi i32 [ -1, %33 ], [ -1, %40 ], [ -1, %45 ], [ 0, %58 ], [ 0, %47 ]
ret i32 %61
}