#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__ ENOENT;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ F_OK;
int /*<<< orphan*/ O_RDWR;
int access(char *, int /*<<< orphan*/);
int chdir(char *);
int /*<<< orphan*/ close(int);
int creat(char *, int /*<<< orphan*/);
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
char *get_current_dir_name();
scalar_t__ memcmp(char *, char *, int /*<<< orphan*/);
int mkdir(char *, int);
char *mkdtemp(int /*<<< orphan*/);
char *mktemp(int /*<<< orphan*/);
int rename(char *, char *);
int rmdir(char *);
int /*<<< orphan*/ strdup(char *);
int /*<<< orphan*/ strlen(char *);
int unlink(char *);
int main() {
  char *path1;
  char *path2;
  char *cwd;
  int status;
  path1 = mkdtemp(strdup("/tmp/proot-test-5bed7143-XXXXXX"));
  if (path1 == NULL)
    exit(EXIT_FAILURE);
  status = chdir(path1);
  if (status < 0)
    exit(EXIT_FAILURE);
  status = mkdir("2fde3df3558fa30bec1b8ebad42df20f", 0777);
  if (status < 0)
    exit(EXIT_FAILURE);
  status = chdir("2fde3df3558fa30bec1b8ebad42df20f");
  if (status < 0)
    exit(EXIT_FAILURE);
  status = creat("2ba90289e48d1896e0601239ac25f764", O_RDWR);
  if (status < 0)
    exit(EXIT_FAILURE);
  close(status);
  path2 = mktemp(strdup("/tmp/proot-test-5bed7143-XXXXXX"));
  status = rename(path1, path2);
  if (status < 0)
    exit(EXIT_FAILURE);
  status = access("2ba90289e48d1896e0601239ac25f764", F_OK);
  if (status < 0)
    exit(EXIT_FAILURE);
  cwd = get_current_dir_name();
  if (cwd == NULL || memcmp(cwd, path2, strlen(path2)) != 0)
    exit(EXIT_FAILURE);
  status = unlink("2ba90289e48d1896e0601239ac25f764");
  if (status < 0)
    exit(EXIT_FAILURE);
  status = rmdir(cwd);
  if (status < 0)
    exit(EXIT_FAILURE);
  if (get_current_dir_name() != NULL || errno != ENOENT)
    exit(EXIT_FAILURE);
  status = rmdir(path2);
  if (status < 0)
    exit(EXIT_FAILURE);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xdfa(%rip),%rdi
call   1100 <strdup@plt>
mov    %eax,%edi
call   10b0 <mkdtemp@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    122f <main+0x3f>
mov    0x2da8(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    -0x10(%rbp),%rdi
call   1070 <chdir@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1253 <main+0x63>
mov    0x2d84(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
lea    0xdc6(%rip),%rdi
mov    $0x1ff,%esi
call   1040 <mkdir@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    127f <main+0x8f>
mov    0x2d58(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
lea    0xd9a(%rip),%rdi
call   1070 <chdir@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    12a6 <main+0xb6>
mov    0x2d31(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    0x2d3b(%rip),%rax
mov    (%rax),%esi
lea    0xd8b(%rip),%rdi
call   10e0 <creat@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    12d6 <main+0xe6>
mov    0x2d01(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    -0x24(%rbp),%edi
call   1080 <close@plt>
lea    0xd1b(%rip),%rdi
call   1100 <strdup@plt>
mov    %eax,%edi
call   1110 <mktemp@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10d0 <rename@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    131d <main+0x12d>
mov    0x2cba(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    0x2c8c(%rip),%rax
mov    (%rax),%esi
lea    0xd14(%rip),%rdi
call   10c0 <access@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    134d <main+0x15d>
mov    0x2c8a(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    $0x0,%al
call   10a0 <get_current_dir_name@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1395 <main+0x1a5>
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
call   1090 <memcmp@plt>
cmp    $0x0,%rax
je     13a3 <main+0x1b3>
mov    0x2c34(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
lea    0xc97(%rip),%rdi
call   1030 <unlink@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    13ca <main+0x1da>
mov    0x2c0d(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    -0x20(%rbp),%rdi
call   1050 <rmdir@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    13ee <main+0x1fe>
mov    0x2be9(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    $0x0,%al
call   10a0 <get_current_dir_name@plt>
cmp    $0x0,%rax
jne    1419 <main+0x229>
mov    0x2bd2(%rip),%rax
mov    (%rax),%rax
mov    0x2ba8(%rip),%rcx
cmp    (%rcx),%rax
je     1427 <main+0x237>
mov    0x2bb0(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    -0x18(%rbp),%rdi
call   1050 <rmdir@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    144b <main+0x25b>
mov    0x2b8c(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    0x2b76(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xe05(%rip),%rdi
call   1100 <strdup@plt>
mov    %eax,%edi
call   10b0 <mkdtemp@plt>
test   %rax,%rax
je     1329 <main+0x139>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <chdir@plt>
test   %eax,%eax
js     1329 <main+0x139>
lea    0xdf6(%rip),%rdi
mov    $0x1ff,%esi
call   1040 <mkdir@plt>
test   %eax,%eax
js     1329 <main+0x139>
lea    0xddd(%rip),%rdi
call   1070 <chdir@plt>
test   %eax,%eax
js     1329 <main+0x139>
mov    0x2d91(%rip),%rax
mov    (%rax),%esi
lea    0xde1(%rip),%rdi
call   10e0 <creat@plt>
test   %eax,%eax
js     1329 <main+0x139>
mov    %eax,%edi
call   1080 <close@plt>
lea    0xd85(%rip),%rdi
call   1100 <strdup@plt>
mov    %eax,%edi
call   1110 <mktemp@plt>
mov    %rax,%r14
mov    %rbx,%rdi
mov    %rax,%rsi
call   10d0 <rename@plt>
test   %eax,%eax
js     1329 <main+0x139>
mov    0x2d0c(%rip),%rax
mov    (%rax),%esi
lea    0xd94(%rip),%rdi
call   10c0 <access@plt>
test   %eax,%eax
js     1329 <main+0x139>
xor    %eax,%eax
call   10a0 <get_current_dir_name@plt>
test   %rax,%rax
je     1329 <main+0x139>
mov    %rax,%rbx
mov    %r14,%rdi
call   1060 <strlen@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1090 <memcmp@plt>
test   %rax,%rax
jne    1329 <main+0x139>
lea    0xd5b(%rip),%rdi
call   1030 <unlink@plt>
test   %eax,%eax
js     1329 <main+0x139>
mov    %rbx,%rdi
call   1050 <rmdir@plt>
test   %eax,%eax
js     1329 <main+0x139>
xor    %eax,%eax
call   10a0 <get_current_dir_name@plt>
test   %rax,%rax
jne    1329 <main+0x139>
mov    0x2cca(%rip),%rax
mov    (%rax),%rax
mov    0x2ca0(%rip),%rcx
cmp    (%rcx),%rax
jne    1329 <main+0x139>
mov    %r14,%rdi
call   1050 <rmdir@plt>
test   %eax,%eax
jns    1337 <main+0x147>
mov    0x2ca0(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    0x2c8a(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
@.str = [32 x i8] c"/tmp/proot-test-5bed7143-XXXXXX\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [33 x i8] c"2fde3df3558fa30bec1b8ebad42df20f\00"
@.str.2 = [33 x i8] c"2ba90289e48d1896e0601239ac25f764\00"
@O_RDWR = global i32 0
@F_OK = global i32 0
@errno = global i64 0
@ENOENT = global i64 0
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 @strdup(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%7 = call i8* @mkdtemp(i32 %6)
store i8* %7, i8** %2
%8 = load i8*, i8** %2
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = load i32, i32* @EXIT_FAILURE
%12 = call i32 @exit(i32 %11)
unreachable
13: ; preds = %0
%14 = load i8*, i8** %2
%15 = call i32 @chdir(i8* %14)
store i32 %15, i32* %5
%16 = load i32, i32* %5
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %13
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %13
%22 = call i32 @mkdir(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 511)
store i32 %22, i32* %5
%23 = load i32, i32* %5
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %21
%26 = load i32, i32* @EXIT_FAILURE
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %21
%29 = call i32 @chdir(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
store i32 %29, i32* %5
%30 = load i32, i32* %5
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %28
%33 = load i32, i32* @EXIT_FAILURE
%34 = call i32 @exit(i32 %33)
unreachable
35: ; preds = %28
%36 = load i32, i32* @O_RDWR
%37 = call i32 @creat(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %36)
store i32 %37, i32* %5
%38 = load i32, i32* %5
%39 = icmp slt i32 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %35
%41 = load i32, i32* @EXIT_FAILURE
%42 = call i32 @exit(i32 %41)
unreachable
43: ; preds = %35
%44 = load i32, i32* %5
%45 = call i32 @close(i32 %44)
%46 = call i32 @strdup(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%47 = call i8* @mktemp(i32 %46)
store i8* %47, i8** %3
%48 = load i8*, i8** %2
%49 = load i8*, i8** %3
%50 = call i32 @rename(i8* %48, i8* %49)
store i32 %50, i32* %5
%51 = load i32, i32* %5
%52 = icmp slt i32 %51, 0
br i1 %52, label %53, label %56
53: ; preds = %43
%54 = load i32, i32* @EXIT_FAILURE
%55 = call i32 @exit(i32 %54)
unreachable
56: ; preds = %43
%57 = load i32, i32* @F_OK
%58 = call i32 @access(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %57)
store i32 %58, i32* %5
%59 = load i32, i32* %5
%60 = icmp slt i32 %59, 0
br i1 %60, label %61, label %64
61: ; preds = %56
%62 = load i32, i32* @EXIT_FAILURE
%63 = call i32 @exit(i32 %62)
unreachable
64: ; preds = %56
%65 = call i8* (...) @get_current_dir_name()
store i8* %65, i8** %4
%66 = load i8*, i8** %4
%67 = icmp eq i8* %66, null
br i1 %67, label %75, label %68
68: ; preds = %64
%69 = load i8*, i8** %4
%70 = load i8*, i8** %3
%71 = load i8*, i8** %3
%72 = call i32 @strlen(i8* %71)
%73 = call i64 @memcmp(i8* %69, i8* %70, i32 %72)
%74 = icmp ne i64 %73, 0
br i1 %74, label %75, label %78
75: ; preds = %68, %64
%76 = load i32, i32* @EXIT_FAILURE
%77 = call i32 @exit(i32 %76)
unreachable
78: ; preds = %68
%79 = call i32 @unlink(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
store i32 %79, i32* %5
%80 = load i32, i32* %5
%81 = icmp slt i32 %80, 0
br i1 %81, label %82, label %85
82: ; preds = %78
%83 = load i32, i32* @EXIT_FAILURE
%84 = call i32 @exit(i32 %83)
unreachable
85: ; preds = %78
%86 = load i8*, i8** %4
%87 = call i32 @rmdir(i8* %86)
store i32 %87, i32* %5
%88 = load i32, i32* %5
%89 = icmp slt i32 %88, 0
br i1 %89, label %90, label %93
90: ; preds = %85
%91 = load i32, i32* @EXIT_FAILURE
%92 = call i32 @exit(i32 %91)
unreachable
93: ; preds = %85
%94 = call i8* (...) @get_current_dir_name()
%95 = icmp ne i8* %94, null
br i1 %95, label %100, label %96
96: ; preds = %93
%97 = load i64, i64* @errno
%98 = load i64, i64* @ENOENT
%99 = icmp ne i64 %97, %98
br i1 %99, label %100, label %103
100: ; preds = %96, %93
%101 = load i32, i32* @EXIT_FAILURE
%102 = call i32 @exit(i32 %101)
unreachable
103: ; preds = %96
%104 = load i8*, i8** %3
%105 = call i32 @rmdir(i8* %104)
store i32 %105, i32* %5
%106 = load i32, i32* %5
%107 = icmp slt i32 %106, 0
br i1 %107, label %108, label %111
108: ; preds = %103
%109 = load i32, i32* @EXIT_FAILURE
%110 = call i32 @exit(i32 %109)
unreachable
111: ; preds = %103
%112 = load i32, i32* @EXIT_SUCCESS
%113 = call i32 @exit(i32 %112)
unreachable
}

LLVM IR (-O2):
@.str = [32 x i8] c"/tmp/proot-test-5bed7143-XXXXXX\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [33 x i8] c"2fde3df3558fa30bec1b8ebad42df20f\00"
@.str.2 = [33 x i8] c"2ba90289e48d1896e0601239ac25f764\00"
@O_RDWR = global i32 0
@F_OK = global i32 0
@errno = global i64 0
@ENOENT = global i64 0
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = tail call i32 @strdup(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%2 = tail call i8* @mkdtemp(i32 %1)
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %7
4: ; preds = %0
%5 = load i32, i32* @EXIT_FAILURE
%6 = tail call i32 @exit(i32 %5)
unreachable
7: ; preds = %0
%8 = tail call i32 @chdir(i8* %2)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %7
%11 = load i32, i32* @EXIT_FAILURE
%12 = tail call i32 @exit(i32 %11)
unreachable
13: ; preds = %7
%14 = tail call i32 @mkdir(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 511)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = load i32, i32* @EXIT_FAILURE
%18 = tail call i32 @exit(i32 %17)
unreachable
19: ; preds = %13
%20 = tail call i32 @chdir(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = load i32, i32* @EXIT_FAILURE
%24 = tail call i32 @exit(i32 %23)
unreachable
25: ; preds = %19
%26 = load i32, i32* @O_RDWR
%27 = tail call i32 @creat(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %26)
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %25
%30 = load i32, i32* @EXIT_FAILURE
%31 = tail call i32 @exit(i32 %30)
unreachable
32: ; preds = %25
%33 = tail call i32 @close(i32 %27)
%34 = tail call i32 @strdup(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%35 = tail call i8* @mktemp(i32 %34)
%36 = tail call i32 @rename(i8* %2, i8* %35)
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %32
%39 = load i32, i32* @EXIT_FAILURE
%40 = tail call i32 @exit(i32 %39)
unreachable
41: ; preds = %32
%42 = load i32, i32* @F_OK
%43 = tail call i32 @access(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %42)
%44 = icmp slt i32 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %41
%46 = load i32, i32* @EXIT_FAILURE
%47 = tail call i32 @exit(i32 %46)
unreachable
48: ; preds = %41
%49 = tail call i8* (...) @get_current_dir_name()
%50 = icmp eq i8* %49, null
br i1 %50, label %55, label %51
51: ; preds = %48
%52 = tail call i32 @strlen(i8* %35)
%53 = tail call i64 @memcmp(i8* %49, i8* %35, i32 %52)
%54 = icmp eq i64 %53, 0
br i1 %54, label %58, label %55
55: ; preds = %51, %48
%56 = load i32, i32* @EXIT_FAILURE
%57 = tail call i32 @exit(i32 %56)
unreachable
58: ; preds = %51
%59 = tail call i32 @unlink(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
%60 = icmp slt i32 %59, 0
br i1 %60, label %61, label %64
61: ; preds = %58
%62 = load i32, i32* @EXIT_FAILURE
%63 = tail call i32 @exit(i32 %62)
unreachable
64: ; preds = %58
%65 = tail call i32 @rmdir(i8* %49)
%66 = icmp slt i32 %65, 0
br i1 %66, label %67, label %70
67: ; preds = %64
%68 = load i32, i32* @EXIT_FAILURE
%69 = tail call i32 @exit(i32 %68)
unreachable
70: ; preds = %64
%71 = tail call i8* (...) @get_current_dir_name()
%72 = icmp eq i8* %71, null
br i1 %72, label %73, label %77
73: ; preds = %70
%74 = load i64, i64* @errno
%75 = load i64, i64* @ENOENT
%76 = icmp eq i64 %74, %75
br i1 %76, label %80, label %77
77: ; preds = %73, %70
%78 = load i32, i32* @EXIT_FAILURE
%79 = tail call i32 @exit(i32 %78)
unreachable
80: ; preds = %73
%81 = tail call i32 @rmdir(i8* %35)
%82 = icmp slt i32 %81, 0
br i1 %82, label %83, label %86
83: ; preds = %80
%84 = load i32, i32* @EXIT_FAILURE
%85 = tail call i32 @exit(i32 %84)
unreachable
86: ; preds = %80
%87 = load i32, i32* @EXIT_SUCCESS
%88 = tail call i32 @exit(i32 %87)
unreachable
}