#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 */
int /*<<< orphan*/ ALLPERMS;
scalar_t__ EEXIST;
scalar_t__ errno;
int mkdir(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int main(int argc, char *argv[]) {
  int ret = mkdir("test", ALLPERMS);
  if (ret == -1) {
    if (errno == EEXIST) {
      printf("文件已经存在\n");
    } else {
      perror("mkdir");
    }
    return errno;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e8b(%rip),%rax
mov    (%rax),%esi
lea    0xeaa(%rip),%rdi
call   1030 <mkdir@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11b1 <main+0x81>
mov    0x2e61(%rip),%rax
mov    (%rax),%rax
mov    0x2e67(%rip),%rcx
cmp    (%rcx),%rax
jne    1193 <main+0x63>
lea    0xe7c(%rip),%rdi
call   1040 <printf@plt>
jmp    119f <main+0x6f>
lea    0xe7f(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e2a(%rip),%rax
mov    (%rax),%rax
mov    %eax,-0x4(%rbp)
jmp    11b8 <main+0x88>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2ea0(%rip),%rax
mov    (%rax),%esi
lea    0xebf(%rip),%rdi
call   1030 <mkdir@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
je     1151 <main+0x21>
pop    %rbx
ret
mov    0x2e78(%rip),%rbx
mov    (%rbx),%rax
mov    0x2e7e(%rip),%rcx
cmp    (%rcx),%rax
jne    1177 <main+0x47>
lea    0xe9d(%rip),%rdi
call   1040 <puts@plt>
mov    (%rbx),%eax
pop    %rbx
ret
lea    0xe87(%rip),%rdi
call   1050 <perror@plt>
jmp    1173 <main+0x43>

LLVM IR (-O0):
@.str = [5 x i8] c"test\00"
@ALLPERMS = global i32 0
@errno = global i64 0
@EEXIST = global i64 0
@.str.1 = [20 x i8] c"\E6\96\87\E4\BB\B6\E5\B7\B2\E7\BB\8F\E5\AD\98\E5\9C\A8\0A\00"
@.str.2 = [6 x i8] c"mkdir\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* @ALLPERMS
%8 = call i32 @mkdir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %7)
store i32 %8, i32* %6
%9 = load i32, i32* %6
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %22
11: ; preds = %2
%12 = load i64, i64* @errno
%13 = load i64, i64* @EEXIST
%14 = icmp eq i64 %12, %13
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %19
17: ; preds = %11
%18 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %19
19: ; preds = %17, %15
%20 = load i64, i64* @errno
%21 = trunc i64 %20 to i32
store i32 %21, i32* %3
br label %23
22: ; preds = %2
store i32 0, i32* %3
br label %23
23: ; preds = %22, %19
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
@.str = [5 x i8] c"test\00"
@ALLPERMS = global i32 0
@errno = global i64 0
@EEXIST = global i64 0
@.str.2 = [6 x i8] c"mkdir\00"
@str = [19 x i8] c"\E6\96\87\E4\BB\B6\E5\B7\B2\E7\BB\8F\E5\AD\98\E5\9C\A8\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @ALLPERMS
%4 = tail call i32 @mkdir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %17
6: ; preds = %2
%7 = load i64, i64* @errno
%8 = load i64, i64* @EEXIST
%9 = icmp eq i64 %7, %8
br i1 %9, label %10, label %12
10: ; preds = %6
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
br label %14
12: ; preds = %6
%13 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %14
14: ; preds = %12, %10
%15 = load i64, i64* @errno
%16 = trunc i64 %15 to i32
br label %17
17: ; preds = %2, %14
%18 = phi i32 [ %16, %14 ], [ 0, %2 ]
ret i32 %18
}