#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*/ F_OK;
scalar_t__ access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ my_mkdir(char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
void my_mkdir_r(char *path) {
  int i, len;
  char str[512];
  strncpy(str, path, 512);
  len = strlen(str);
  for (i = 0; i < len; i++) {
    if (str[i] == '/' && i != 0) {
      str[i] = '\0';
      if (access(str, F_OK) != 0) {
        my_mkdir(str);
      }
      str[i] = '/';
    }
  }
  if (len > 0 && access(str, F_OK) != 0) {
    my_mkdir(str);
  }
}


x86 assembly (clang, -O0):
<my_mkdir_r>:
push   %rbp
mov    %rsp,%rbp
sub    $0x210,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x210(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x200,%edx
call   1030 <strncpy@plt>
lea    -0x210(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11fb <my_mkdir_r+0xbb>
movslq -0xc(%rbp),%rax
movsbl -0x210(%rbp,%rax,1),%eax
ff
cmp    $0x2f,%eax
jne    11e8 <my_mkdir_r+0xa8>
cmpl   $0x0,-0xc(%rbp)
je     11e8 <my_mkdir_r+0xa8>
movslq -0xc(%rbp),%rax
movb   $0x0,-0x210(%rbp,%rax,1)
lea    -0x210(%rbp),%rdi
mov    0x2e19(%rip),%rax
mov    (%rax),%esi
call   1060 <access@plt>
cmp    $0x0,%rax
je     11dc <my_mkdir_r+0x9c>
lea    -0x210(%rbp),%rdi
call   1050 <my_mkdir@plt>
movslq -0xc(%rbp),%rax
movb   $0x2f,-0x210(%rbp,%rax,1)
2f
jmp    11ed <my_mkdir_r+0xad>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    117a <my_mkdir_r+0x3a>
cmpl   $0x0,-0x10(%rbp)
jle    1230 <my_mkdir_r+0xf0>
lea    -0x210(%rbp),%rdi
mov    0x2dc5(%rip),%rax
mov    (%rax),%esi
call   1060 <access@plt>
cmp    $0x0,%rax
je     1230 <my_mkdir_r+0xf0>
lea    -0x210(%rbp),%rdi
call   1050 <my_mkdir@plt>
add    $0x210,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_mkdir_r>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x200,%rsp
mov    %rdi,%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x200,%edx
call   1030 <strncpy@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    11e3 <my_mkdir_r+0xa3>
mov    %eax,%r14d
mov    %eax,%ebp
xor    %ebx,%ebx
mov    0x2e5c(%rip),%r15
mov    %rsp,%r12
jmp    119d <my_mkdir_r+0x5d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movb   $0x2f,(%rsp,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%rbp
je     11c6 <my_mkdir_r+0x86>
cmpb   $0x2f,(%rsp,%rbx,1)
jne    1194 <my_mkdir_r+0x54>
test   %rbx,%rbx
je     1194 <my_mkdir_r+0x54>
movb   $0x0,(%rsp,%rbx,1)
mov    (%r15),%esi
mov    %r12,%rdi
call   1060 <access@plt>
test   %rax,%rax
je     1190 <my_mkdir_r+0x50>
mov    %r12,%rdi
call   1050 <my_mkdir@plt>
jmp    1190 <my_mkdir_r+0x50>
test   %r14d,%r14d
jle    11e3 <my_mkdir_r+0xa3>
mov    (%r15),%esi
mov    %rsp,%rdi
call   1060 <access@plt>
test   %rax,%rax
je     11e3 <my_mkdir_r+0xa3>
mov    %rsp,%rdi
call   1050 <my_mkdir@plt>
add    $0x200,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@F_OK = global i32 0
define void @my_mkdir_r(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca [512 x i8]
store i8* %0, i8** %2
%6 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%7 = load i8*, i8** %2
%8 = call i32 @strncpy(i8* %6, i8* %7, i32 512)
%9 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %4
store i32 0, i32* %3
br label %11
11: ; preds = %41, %1
%12 = load i32, i32* %3
%13 = load i32, i32* %4
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %44
15: ; preds = %11
%16 = load i32, i32* %3
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 %17
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 47
br i1 %21, label %22, label %40
22: ; preds = %15
%23 = load i32, i32* %3
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %40
25: ; preds = %22
%26 = load i32, i32* %3
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 %27
store i8 0, i8* %28
%29 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%30 = load i32, i32* @F_OK
%31 = call i64 @access(i8* %29, i32 %30)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %25
%34 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%35 = call i32 @my_mkdir(i8* %34)
br label %36
36: ; preds = %33, %25
%37 = load i32, i32* %3
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 %38
store i8 47, i8* %39
br label %40
40: ; preds = %36, %22, %15
br label %41
41: ; preds = %40
%42 = load i32, i32* %3
%43 = add nsw i32 %42, 1
store i32 %43, i32* %3
br label %11
44: ; preds = %11
%45 = load i32, i32* %4
%46 = icmp sgt i32 %45, 0
br i1 %46, label %47, label %55
47: ; preds = %44
%48 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%49 = load i32, i32* @F_OK
%50 = call i64 @access(i8* %48, i32 %49)
%51 = icmp ne i64 %50, 0
br i1 %51, label %52, label %55
52: ; preds = %47
%53 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%54 = call i32 @my_mkdir(i8* %53)
br label %55
55: ; preds = %52, %47, %44
ret void
}

LLVM IR (-O2):
@F_OK = global i32 0
define void @my_mkdir_r(i8* %0) {
%2 = alloca [512 x i8]
%3 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%4 = call i32 @strncpy(i8* %3, i8* %0, i32 512)
%5 = call i32 @strlen(i8* %3)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %33
7: ; preds = %1
%8 = zext i32 %5 to i64
br label %9
9: ; preds = %7, %23
%10 = phi i64 [ 0, %7 ], [ %24, %23 ]
%11 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 %10
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 47
%14 = icmp ne i64 %10, 0
%15 = select i1 %13, i1 %14, i1 false
br i1 %15, label %16, label %23
16: ; preds = %9
store i8 0, i8* %11
%17 = load i32, i32* @F_OK
%18 = call i64 @access(i8* %3, i32 %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %16
%21 = call i32 @my_mkdir(i8* %3)
br label %22
22: ; preds = %20, %16
store i8 47, i8* %11
br label %23
23: ; preds = %9, %22
%24 = add nuw nsw i64 %10, 1
%25 = icmp eq i64 %24, %8
br i1 %25, label %26, label %9
26: ; preds = %23
br i1 %6, label %27, label %33
27: ; preds = %26
%28 = load i32, i32* @F_OK
%29 = call i64 @access(i8* %3, i32 %28)
%30 = icmp eq i64 %29, 0
br i1 %30, label %33, label %31
31: ; preds = %27
%32 = call i32 @my_mkdir(i8* %3)
br label %33
33: ; preds = %1, %31, %27, %26
ret void
}