#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 */
scalar_t__ iposix_access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ iposix_mkdir(char *, int);
int /*<<< orphan*/ memcpy(char *, char const *, int);
scalar_t__ strlen(char const *);
int iposix_path_mkdir(const char *path, int mode) {
  int i, len;
  char str[((1024) + 8)];
  len = (int)strlen(path);
  if (len > 1024)
    len = 1024;
  memcpy(str, path, len);
  str[len] = 0;
  for (i = 0; i < len; i++) {
    if (str[i] == '/' || str[i] == '\\') {
      str[i] = '\0';
      if (iposix_access(str, 0) != 0) {
        iposix_mkdir(str, mode);
      }
      str[i] = '/';
    }
  }
  if (len > 0 && iposix_access(str, 0) != 0) {
    iposix_mkdir(str, mode);
  }
  return 0;
}


x86 assembly (clang, -O0):
<iposix_path_mkdir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x400,-0x14(%rbp)
jle    1172 <iposix_path_mkdir+0x32>
movl   $0x400,-0x14(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1050 <memcpy@plt>
movslq -0x14(%rbp),%rax
movb   $0x0,-0x420(%rbp,%rax,1)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1220 <iposix_path_mkdir+0xe0>
movslq -0x10(%rbp),%rax
movsbl -0x420(%rbp,%rax,1),%eax
ff
cmp    $0x2f,%eax
je     11ce <iposix_path_mkdir+0x8e>
movslq -0x10(%rbp),%rax
movsbl -0x420(%rbp,%rax,1),%eax
ff
cmp    $0x5c,%eax
jne    120d <iposix_path_mkdir+0xcd>
movslq -0x10(%rbp),%rax
movb   $0x0,-0x420(%rbp,%rax,1)
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
call   1040 <iposix_access@plt>
cmp    $0x0,%rax
je     1201 <iposix_path_mkdir+0xc1>
lea    -0x420(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1060 <iposix_mkdir@plt>
movslq -0x10(%rbp),%rax
movb   $0x2f,-0x420(%rbp,%rax,1)
2f
jmp    1212 <iposix_path_mkdir+0xd2>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1198 <iposix_path_mkdir+0x58>
cmpl   $0x0,-0x14(%rbp)
jle    1251 <iposix_path_mkdir+0x111>
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
call   1040 <iposix_access@plt>
cmp    $0x0,%rax
je     1251 <iposix_path_mkdir+0x111>
lea    -0x420(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1060 <iposix_mkdir@plt>
xor    %eax,%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iposix_path_mkdir>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x410,%rsp
mov    %esi,%r12d
mov    %rdi,%r15
call   1030 <strlen@plt>
mov    %rax,%r14
cmp    $0x400,%r14d
mov    $0x400,%ebx
cmovl  %r14d,%ebx
mov    %rsp,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1050 <memcpy@plt>
movslq %ebx,%rax
movb   $0x0,(%rsp,%rax,1)
test   %r14d,%r14d
jle    11f8 <iposix_path_mkdir+0xb8>
cmp    $0x2,%ebx
mov    $0x1,%ebp
cmovge %ebx,%ebp
xor    %ebx,%ebx
mov    %rsp,%r15
jmp    11ad <iposix_path_mkdir+0x6d>
nopl   0x0(%rax,%rax,1)
movb   $0x2f,(%rsp,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%rbp
je     11d9 <iposix_path_mkdir+0x99>
movzbl (%rsp,%rbx,1),%eax
cmp    $0x5c,%al
je     11b9 <iposix_path_mkdir+0x79>
cmp    $0x2f,%al
jne    11a4 <iposix_path_mkdir+0x64>
movb   $0x0,(%rsp,%rbx,1)
mov    %r15,%rdi
xor    %esi,%esi
call   1040 <iposix_access@plt>
test   %rax,%rax
je     11a0 <iposix_path_mkdir+0x60>
mov    %r15,%rdi
mov    %r12d,%esi
call   1060 <iposix_mkdir@plt>
jmp    11a0 <iposix_path_mkdir+0x60>
test   %r14d,%r14d
jle    11f8 <iposix_path_mkdir+0xb8>
mov    %rsp,%rdi
xor    %esi,%esi
call   1040 <iposix_access@plt>
test   %rax,%rax
je     11f8 <iposix_path_mkdir+0xb8>
mov    %rsp,%rdi
mov    %r12d,%esi
call   1060 <iposix_mkdir@plt>
xor    %eax,%eax
add    $0x410,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @iposix_path_mkdir(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [1032 x i8]
store i8* %0, i8** %3
store i32 %1, i32* %4
%8 = load i8*, i8** %3
%9 = call i64 @strlen(i8* %8)
%10 = trunc i64 %9 to i32
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = icmp sgt i32 %11, 1024
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 1024, i32* %6
br label %14
14: ; preds = %13, %2
%15 = getelementptr inbounds [1032 x i8], [1032 x i8]* %7, i64 0, i64 0
%16 = load i8*, i8** %3
%17 = load i32, i32* %6
%18 = call i32 @memcpy(i8* %15, i8* %16, i32 %17)
%19 = load i32, i32* %6
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [1032 x i8], [1032 x i8]* %7, i64 0, i64 %20
store i8 0, i8* %21
store i32 0, i32* %5
br label %22
22: ; preds = %56, %14
%23 = load i32, i32* %5
%24 = load i32, i32* %6
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %59
26: ; preds = %22
%27 = load i32, i32* %5
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [1032 x i8], [1032 x i8]* %7, i64 0, i64 %28
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 47
br i1 %32, label %40, label %33
33: ; preds = %26
%34 = load i32, i32* %5
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [1032 x i8], [1032 x i8]* %7, i64 0, i64 %35
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp eq i32 %38, 92
br i1 %39, label %40, label %55
40: ; preds = %33, %26
%41 = load i32, i32* %5
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [1032 x i8], [1032 x i8]* %7, i64 0, i64 %42
store i8 0, i8* %43
%44 = getelementptr inbounds [1032 x i8], [1032 x i8]* %7, i64 0, i64 0
%45 = call i64 @iposix_access(i8* %44, i32 0)
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %51
47: ; preds = %40
%48 = getelementptr inbounds [1032 x i8], [1032 x i8]* %7, i64 0, i64 0
%49 = load i32, i32* %4
%50 = call i32 @iposix_mkdir(i8* %48, i32 %49)
br label %51
51: ; preds = %47, %40
%52 = load i32, i32* %5
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [1032 x i8], [1032 x i8]* %7, i64 0, i64 %53
store i8 47, i8* %54
br label %55
55: ; preds = %51, %33
br label %56
56: ; preds = %55
%57 = load i32, i32* %5
%58 = add nsw i32 %57, 1
store i32 %58, i32* %5
br label %22
59: ; preds = %22
%60 = load i32, i32* %6
%61 = icmp sgt i32 %60, 0
br i1 %61, label %62, label %70
62: ; preds = %59
%63 = getelementptr inbounds [1032 x i8], [1032 x i8]* %7, i64 0, i64 0
%64 = call i64 @iposix_access(i8* %63, i32 0)
%65 = icmp ne i64 %64, 0
br i1 %65, label %66, label %70
66: ; preds = %62
%67 = getelementptr inbounds [1032 x i8], [1032 x i8]* %7, i64 0, i64 0
%68 = load i32, i32* %4
%69 = call i32 @iposix_mkdir(i8* %67, i32 %68)
br label %70
70: ; preds = %66, %62, %59
ret i32 0
}

LLVM IR (-O2):
define i32 @iposix_path_mkdir(i8* %0, i32 %1) {
%3 = alloca [1032 x i8]
%4 = getelementptr inbounds [1032 x i8], [1032 x i8]* %3, i64 0, i64 0
%5 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%6 = trunc i64 %5 to i32
%7 = icmp slt i32 %6, 1024
%8 = select i1 %7, i32 %6, i32 1024
%9 = call i32 @memcpy(i8* %4, i8* %0, i32 %8)
%10 = sext i32 %8 to i64
%11 = getelementptr inbounds [1032 x i8], [1032 x i8]* %3, i64 0, i64 %10
store i8 0, i8* %11
%12 = icmp sgt i32 %6, 0
br i1 %12, label %13, label %35
13: ; preds = %2
%14 = call i32 @llvm.smax.i32(i32 %8, i32 1)
%15 = zext i32 %14 to i64
br label %16
16: ; preds = %13, %26
%17 = phi i64 [ 0, %13 ], [ %27, %26 ]
%18 = getelementptr inbounds [1032 x i8], [1032 x i8]* %3, i64 0, i64 %17
%19 = load i8, i8* %18
switch i8 %19, label %26 [
i8 47, label %20
i8 92, label %20
]
20: ; preds = %16, %16
store i8 0, i8* %18
%21 = call i64 @iposix_access(i8* %4, i32 0)
%22 = icmp eq i64 %21, 0
br i1 %22, label %25, label %23
23: ; preds = %20
%24 = call i32 @iposix_mkdir(i8* %4, i32 %1)
br label %25
25: ; preds = %23, %20
store i8 47, i8* %18
br label %26
26: ; preds = %16, %25
%27 = add nuw nsw i64 %17, 1
%28 = icmp eq i64 %27, %15
br i1 %28, label %29, label %16
29: ; preds = %26
br i1 %12, label %30, label %35
30: ; preds = %29
%31 = call i64 @iposix_access(i8* %4, i32 0)
%32 = icmp eq i64 %31, 0
br i1 %32, label %35, label %33
33: ; preds = %30
%34 = call i32 @iposix_mkdir(i8* %4, i32 %1)
br label %35
35: ; preds = %2, %33, %30, %29
ret i32 0
}