#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 F_OK;
int R_OK;
int W_OK;
int access(char const *, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(char *);
char *get_dir(char *);
int mkdir_r(char const *, int);
int /*<<< orphan*/ stderr;
char *strdup(char const *);
scalar_t__ strstr(char const *, char *);
void check_dir(const char *path) {
  char *path_org = NULL;
  const char *dir = NULL;
  if (strstr(path, "/")) {
    path_org = strdup(path);
    dir = get_dir(path_org);
    if (-1 == access(dir, F_OK | W_OK | R_OK)) {
      if (-1 == mkdir_r(dir, 0775)) {
        fprintf(stderr, "mkdir %s failed\n", path_org);
      }
    }
    free(path_org);
  }
}


x86 assembly (clang, -O0):
<check_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe69(%rip),%rsi
call   1090 <strstr@plt>
cmp    $0x0,%rax
je     1237 <check_dir+0xc7>
mov    -0x8(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <get_dir@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2df5(%rip),%rax
mov    (%rax),%esi
mov    0x2e14(%rip),%rax
or     (%rax),%esi
mov    0x2df3(%rip),%rax
or     (%rax),%esi
call   1070 <access@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    122e <check_dir+0xbe>
mov    -0x18(%rbp),%rdi
mov    $0x1fd,%esi
call   1060 <mkdir_r@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    1229 <check_dir+0xb9>
mov    0x2dc1(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xdde(%rip),%rsi
call   1050 <fprintf@plt>
jmp    122e <check_dir+0xbe>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_dir>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xe82(%rip),%rsi
call   1090 <strstr@plt>
test   %rax,%rax
je     11ff <check_dir+0x8f>
mov    %rbx,%rdi
call   1080 <strdup@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1040 <get_dir@plt>
mov    0x2e1e(%rip),%rcx
mov    0x2e3f(%rip),%rdx
mov    (%rdx),%esi
or     (%rcx),%esi
mov    %rax,%rbx
mov    0x2e19(%rip),%rax
or     (%rax),%esi
mov    %rbx,%rdi
call   1070 <access@plt>
cmp    $0xffffffff,%eax
jne    11f0 <check_dir+0x80>
mov    %rbx,%rdi
mov    $0x1fd,%esi
call   1060 <mkdir_r@plt>
cmp    $0xffffffff,%eax
jne    11f0 <check_dir+0x80>
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
lea    0xe1a(%rip),%rsi
mov    %r14,%rdx
call   1050 <fprintf@plt>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <free@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
@F_OK = global i32 0
@W_OK = global i32 0
@R_OK = global i32 0
@stderr = global i32 0
@.str.1 = [17 x i8] c"mkdir %s failed\0A\00"
define void @check_dir(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %2
store i8* null, i8** %3
store i8* null, i8** %4
%5 = load i8*, i8** %2
%6 = call i64 @strstr(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %33
8: ; preds = %1
%9 = load i8*, i8** %2
%10 = call i8* @strdup(i8* %9)
store i8* %10, i8** %3
%11 = load i8*, i8** %3
%12 = call i8* @get_dir(i8* %11)
store i8* %12, i8** %4
%13 = load i8*, i8** %4
%14 = load i32, i32* @F_OK
%15 = load i32, i32* @W_OK
%16 = or i32 %14, %15
%17 = load i32, i32* @R_OK
%18 = or i32 %16, %17
%19 = call i32 @access(i8* %13, i32 %18)
%20 = icmp eq i32 -1, %19
br i1 %20, label %21, label %30
21: ; preds = %8
%22 = load i8*, i8** %4
%23 = call i32 @mkdir_r(i8* %22, i32 509)
%24 = icmp eq i32 -1, %23
br i1 %24, label %25, label %29
25: ; preds = %21
%26 = load i32, i32* @stderr
%27 = load i8*, i8** %3
%28 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %27)
br label %29
29: ; preds = %25, %21
br label %30
30: ; preds = %29, %8
%31 = load i8*, i8** %3
%32 = call i32 @free(i8* %31)
br label %33
33: ; preds = %30, %1
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
@F_OK = global i32 0
@W_OK = global i32 0
@R_OK = global i32 0
@stderr = global i32 0
@.str.1 = [17 x i8] c"mkdir %s failed\0A\00"
define void @check_dir(i8* %0) {
%2 = tail call i64 @strstr(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i64 %2, 0
br i1 %3, label %22, label %4
4: ; preds = %1
%5 = tail call i8* @strdup(i8* %0)
%6 = tail call i8* @get_dir(i8* %5)
%7 = load i32, i32* @F_OK
%8 = load i32, i32* @W_OK
%9 = or i32 %8, %7
%10 = load i32, i32* @R_OK
%11 = or i32 %9, %10
%12 = tail call i32 @access(i8* %6, i32 %11)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %20
14: ; preds = %4
%15 = tail call i32 @mkdir_r(i8* %6, i32 509)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = load i32, i32* @stderr
%19 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %5)
br label %20
20: ; preds = %14, %17, %4
%21 = tail call i32 @free(i8* %5)
br label %22
22: ; preds = %20, %1
ret void
}