#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 */
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int mkdir(char *, int);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ printf(char *, ...);
void local_mkdir(char *path) {
  DIR *dir;
  if (NULL == (dir = opendir(path))) {
    if (-1 == mkdir(path, 0777)) {
      printf("please check disk can write or dir has exist???");
      printf("mkdir %s fail\n", path);
      return;
    }
  } else
    closedir(dir);
}


x86 assembly (clang, -O0):
<local_mkdir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <opendir@plt>
mov    %rax,%rcx
mov    %rcx,-0x10(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
jne    11ae <local_mkdir+0x6e>
mov    -0x8(%rbp),%rdi
mov    $0x1ff,%esi
call   1030 <mkdir@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    11a9 <local_mkdir+0x69>
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%rsi
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11b7 <local_mkdir+0x77>
jmp    11b7 <local_mkdir+0x77>
mov    -0x10(%rbp),%rdi
call   1060 <closedir@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<local_mkdir>:
push   %rbx
mov    %rdi,%rbx
call   1040 <opendir@plt>
test   %rax,%rax
je     1157 <local_mkdir+0x17>
mov    %rax,%rdi
pop    %rbx
jmp    1060 <closedir@plt>
mov    %rbx,%rdi
mov    $0x1ff,%esi
call   1030 <mkdir@plt>
cmp    $0xffffffff,%eax
je     116b <local_mkdir+0x2b>
pop    %rbx
ret
lea    0xe8e(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xeb0(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
pop    %rbx
jmp    1050 <printf@plt>

LLVM IR (-O0):
@.str = [48 x i8] c"please check disk can write or dir has exist???\00"
@.str.1 = [15 x i8] c"mkdir %s fail\0A\00"
define void @local_mkdir(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i32* @opendir(i8* %4)
store i32* %5, i32** %3
%6 = icmp eq i32* null, %5
br i1 %6, label %7, label %16
7: ; preds = %1
%8 = load i8*, i8** %2
%9 = call i32 @mkdir(i8* %8, i32 511)
%10 = icmp eq i32 -1, %9
br i1 %10, label %11, label %15
11: ; preds = %7
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
%13 = load i8*, i8** %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %13)
br label %19
15: ; preds = %7
br label %19
16: ; preds = %1
%17 = load i32*, i32** %3
%18 = call i32 @closedir(i32* %17)
br label %19
19: ; preds = %11, %16, %15
ret void
}

LLVM IR (-O2):
@.str = [48 x i8] c"please check disk can write or dir has exist???\00"
@.str.1 = [15 x i8] c"mkdir %s fail\0A\00"
define void @local_mkdir(i8* %0) {
%2 = tail call i32* @opendir(i8* %0)
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %10
4: ; preds = %1
%5 = tail call i32 @mkdir(i8* %0, i32 511)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %12
7: ; preds = %4
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %12
10: ; preds = %1
%11 = tail call i32 @closedir(i32* %2)
br label %12
12: ; preds = %10, %4, %7
ret void
}