#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 int /*<<< orphan*/ dir;

/* Variables and functions */
scalar_t__ chdir(char *);
int /*<<< orphan*/ chmod(char *, int);
int /*<<< orphan*/ *getcwd(char *, int);
scalar_t__ mkdir(char *, int);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ rename(char *, char *);
scalar_t__ rmdir(char *);
int /*<<< orphan*/ scanf(char *);
int /*<<< orphan*/ umask(int);
int main() {
  umask(0022);
  if (mkdir("dira", 0777) == 0)
    puts("创建dira成功");
  scanf("%*c");
  umask(0700);
  if (!mkdir("dirb", 0777))
    puts("创建dirb成功");
  scanf("*[^\n]");
  if (!chmod("dirb", 0755))
    puts("修改权限成功");
  scanf("%*c");
  rename("dira", "dirb/abc");
  if (chdir("dira"))
    puts("进入dira失败");
  if (!chdir("dirb"))
    puts("进入dirb成功");
  char dir[200];
  if (getcwd(dir, sizeof(dir)) != NULL)
    puts(dir);
  chdir("..");
  if (rmdir("dirb"))
    puts("删除dirb失败");
  rmdir("dirb/abc");
  if (!rmdir("dirb"))
    puts("删除dirb成功");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x12,%edi
call   1080 <umask@plt>
lea    0xe4d(%rip),%rdi
mov    $0x1ff,%esi
call   1030 <mkdir@plt>
cmp    $0x0,%rax
jne    11d3 <main+0x43>
lea    0xe37(%rip),%rdi
call   1040 <puts@plt>
lea    0xe3c(%rip),%rdi
call   1090 <scanf@plt>
mov    $0x1c0,%edi
call   1080 <umask@plt>
lea    0xe2a(%rip),%rdi
mov    $0x1ff,%esi
call   1030 <mkdir@plt>
cmp    $0x0,%rax
jne    1210 <main+0x80>
lea    0xe14(%rip),%rdi
call   1040 <puts@plt>
lea    0xe19(%rip),%rdi
call   1090 <scanf@plt>
lea    0xdf7(%rip),%rdi
mov    $0x1ed,%esi
call   10a0 <chmod@plt>
cmp    $0x0,%eax
jne    1242 <main+0xb2>
lea    0xdf9(%rip),%rdi
call   1040 <puts@plt>
lea    0xdcd(%rip),%rdi
call   1090 <scanf@plt>
lea    0xdab(%rip),%rdi
lea    0xded(%rip),%rsi
call   10b0 <rename@plt>
lea    0xd98(%rip),%rdi
call   1060 <chdir@plt>
cmp    $0x0,%rax
je     1283 <main+0xf3>
lea    0xdd4(%rip),%rdi
call   1040 <puts@plt>
lea    0xd90(%rip),%rdi
call   1060 <chdir@plt>
cmp    $0x0,%rax
jne    12a5 <main+0x115>
lea    0xdc3(%rip),%rdi
call   1040 <puts@plt>
lea    -0xd0(%rbp),%rdi
mov    $0xc8,%esi
call   1070 <getcwd@plt>
cmp    $0x0,%rax
je     12cc <main+0x13c>
lea    -0xd0(%rbp),%rdi
call   1040 <puts@plt>
lea    0xda1(%rip),%rdi
call   1060 <chdir@plt>
lea    0xd3b(%rip),%rdi
call   1050 <rmdir@plt>
cmp    $0x0,%rax
je     12fa <main+0x16a>
lea    0xd82(%rip),%rdi
call   1040 <puts@plt>
lea    0xd48(%rip),%rdi
call   1050 <rmdir@plt>
lea    0xd0d(%rip),%rdi
call   1050 <rmdir@plt>
cmp    $0x0,%rax
jne    1328 <main+0x198>
lea    0xd65(%rip),%rdi
call   1040 <puts@plt>
mov    -0x4(%rbp),%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0xd0,%rsp
mov    $0x12,%edi
call   1080 <umask@plt>
lea    0xe57(%rip),%rdi
mov    $0x1ff,%esi
call   1030 <mkdir@plt>
test   %rax,%rax
jne    11c4 <main+0x34>
lea    0xe46(%rip),%rdi
call   1040 <puts@plt>
lea    0xe4b(%rip),%rdi
call   1090 <scanf@plt>
mov    $0x1c0,%edi
call   1080 <umask@plt>
lea    0xe39(%rip),%rdi
mov    $0x1ff,%esi
call   1030 <mkdir@plt>
test   %rax,%rax
jne    11fc <main+0x6c>
lea    0xe28(%rip),%rdi
call   1040 <puts@plt>
lea    0xe2d(%rip),%rdi
call   1090 <scanf@plt>
lea    0xe0b(%rip),%rdi
mov    $0x1ed,%esi
call   10a0 <chmod@plt>
test   %eax,%eax
jne    1229 <main+0x99>
lea    0xe12(%rip),%rdi
call   1040 <puts@plt>
lea    0xde6(%rip),%rdi
call   1090 <scanf@plt>
lea    0xdc4(%rip),%rbx
lea    0xe06(%rip),%rsi
mov    %rbx,%rdi
call   10b0 <rename@plt>
mov    %rbx,%rdi
call   1060 <chdir@plt>
test   %rax,%rax
je     1264 <main+0xd4>
lea    0xdf3(%rip),%rdi
call   1040 <puts@plt>
lea    0xdaf(%rip),%rdi
call   1060 <chdir@plt>
test   %rax,%rax
jne    1281 <main+0xf1>
lea    0xde7(%rip),%rdi
call   1040 <puts@plt>
mov    %rsp,%rdi
mov    $0xc8,%esi
call   1070 <getcwd@plt>
test   %rax,%rax
je     129b <main+0x10b>
mov    %rsp,%rdi
call   1040 <puts@plt>
lea    0xdd2(%rip),%rdi
call   1060 <chdir@plt>
lea    0xd6c(%rip),%rdi
call   1050 <rmdir@plt>
test   %rax,%rax
je     12c4 <main+0x134>
lea    0xdb8(%rip),%rdi
call   1040 <puts@plt>
lea    0xd7e(%rip),%rdi
call   1050 <rmdir@plt>
lea    0xd43(%rip),%rdi
call   1050 <rmdir@plt>
test   %rax,%rax
jne    12ed <main+0x15d>
lea    0xda0(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0xd0,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [5 x i8] c"dira\00"
@.str.1 = [17 x i8] c"\E5\88\9B\E5\BB\BAdira\E6\88\90\E5\8A\9F\00"
@.str.2 = [4 x i8] c"%*c\00"
@.str.3 = [5 x i8] c"dirb\00"
@.str.4 = [17 x i8] c"\E5\88\9B\E5\BB\BAdirb\E6\88\90\E5\8A\9F\00"
@.str.5 = [6 x i8] c"*[^\0A]\00"
@.str.6 = [19 x i8] c"\E4\BF\AE\E6\94\B9\E6\9D\83\E9\99\90\E6\88\90\E5\8A\9F\00"
@.str.7 = [9 x i8] c"dirb/abc\00"
@.str.8 = [17 x i8] c"\E8\BF\9B\E5\85\A5dira\E5\A4\B1\E8\B4\A5\00"
@.str.9 = [17 x i8] c"\E8\BF\9B\E5\85\A5dirb\E6\88\90\E5\8A\9F\00"
@.str.10 = [3 x i8] c"..\00"
@.str.11 = [17 x i8] c"\E5\88\A0\E9\99\A4dirb\E5\A4\B1\E8\B4\A5\00"
@.str.12 = [17 x i8] c"\E5\88\A0\E9\99\A4dirb\E6\88\90\E5\8A\9F\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [200 x i8]
store i32 0, i32* %1
%3 = call i32 @umask(i32 18)
%4 = call i64 @mkdir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 511)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 @puts(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
br label %8
8: ; preds = %6, %0
%9 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 @umask(i32 448)
%11 = call i64 @mkdir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 511)
%12 = icmp ne i64 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %8
%14 = call i32 @puts(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
br label %15
15: ; preds = %13, %8
%16 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%17 = call i32 @chmod(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 493)
%18 = icmp ne i32 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %15
%20 = call i32 @puts(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0))
br label %21
21: ; preds = %19, %15
%22 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%23 = call i32 @rename(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0))
%24 = call i64 @chdir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %21
%27 = call i32 @puts(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0))
br label %28
28: ; preds = %26, %21
%29 = call i64 @chdir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%30 = icmp ne i64 %29, 0
br i1 %30, label %33, label %31
31: ; preds = %28
%32 = call i32 @puts(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.9, i64 0, i64 0))
br label %33
33: ; preds = %31, %28
%34 = getelementptr inbounds [200 x i8], [200 x i8]* %2, i64 0, i64 0
%35 = call i32* @getcwd(i8* %34, i32 200)
%36 = icmp ne i32* %35, null
br i1 %36, label %37, label %40
37: ; preds = %33
%38 = getelementptr inbounds [200 x i8], [200 x i8]* %2, i64 0, i64 0
%39 = call i32 @puts(i8* %38)
br label %40
40: ; preds = %37, %33
%41 = call i64 @chdir(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0))
%42 = call i64 @rmdir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %40
%45 = call i32 @puts(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.11, i64 0, i64 0))
br label %46
46: ; preds = %44, %40
%47 = call i64 @rmdir(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0))
%48 = call i64 @rmdir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%49 = icmp ne i64 %48, 0
br i1 %49, label %52, label %50
50: ; preds = %46
%51 = call i32 @puts(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.12, i64 0, i64 0))
br label %52
52: ; preds = %50, %46
%53 = load i32, i32* %1
ret i32 %53
}

LLVM IR (-O2):
@.str = [5 x i8] c"dira\00"
@.str.1 = [17 x i8] c"\E5\88\9B\E5\BB\BAdira\E6\88\90\E5\8A\9F\00"
@.str.2 = [4 x i8] c"%*c\00"
@.str.3 = [5 x i8] c"dirb\00"
@.str.4 = [17 x i8] c"\E5\88\9B\E5\BB\BAdirb\E6\88\90\E5\8A\9F\00"
@.str.5 = [6 x i8] c"*[^\0A]\00"
@.str.6 = [19 x i8] c"\E4\BF\AE\E6\94\B9\E6\9D\83\E9\99\90\E6\88\90\E5\8A\9F\00"
@.str.7 = [9 x i8] c"dirb/abc\00"
@.str.8 = [17 x i8] c"\E8\BF\9B\E5\85\A5dira\E5\A4\B1\E8\B4\A5\00"
@.str.9 = [17 x i8] c"\E8\BF\9B\E5\85\A5dirb\E6\88\90\E5\8A\9F\00"
@.str.10 = [3 x i8] c"..\00"
@.str.11 = [17 x i8] c"\E5\88\A0\E9\99\A4dirb\E5\A4\B1\E8\B4\A5\00"
@.str.12 = [17 x i8] c"\E5\88\A0\E9\99\A4dirb\E6\88\90\E5\8A\9F\00"
define i32 @main() {
%1 = alloca [200 x i8]
%2 = tail call i32 @umask(i32 18)
%3 = tail call i64 @mkdir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 511)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
br label %7
7: ; preds = %5, %0
%8 = tail call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%9 = tail call i32 @umask(i32 448)
%10 = tail call i64 @mkdir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 511)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %7
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
br label %14
14: ; preds = %12, %7
%15 = tail call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%16 = tail call i32 @chmod(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 493)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0))
br label %20
20: ; preds = %18, %14
%21 = tail call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%22 = tail call i32 @rename(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0))
%23 = tail call i64 @chdir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %20
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0))
br label %27
27: ; preds = %25, %20
%28 = tail call i64 @chdir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %27
%31 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.9, i64 0, i64 0))
br label %32
32: ; preds = %30, %27
%33 = getelementptr inbounds [200 x i8], [200 x i8]* %1, i64 0, i64 0
%34 = call i32* @getcwd(i8* %33, i32 200)
%35 = icmp eq i32* %34, null
br i1 %35, label %38, label %36
36: ; preds = %32
%37 = call i32 @puts(i8* %33)
br label %38
38: ; preds = %36, %32
%39 = call i64 @chdir(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0))
%40 = call i64 @rmdir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%41 = icmp eq i64 %40, 0
br i1 %41, label %44, label %42
42: ; preds = %38
%43 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.11, i64 0, i64 0))
br label %44
44: ; preds = %42, %38
%45 = call i64 @rmdir(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0))
%46 = call i64 @rmdir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%47 = icmp eq i64 %46, 0
br i1 %47, label %48, label %50
48: ; preds = %44
%49 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.12, i64 0, i64 0))
br label %50
50: ; preds = %48, %44
ret i32 0
}