#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 */
struct stat {
  int /*<<< orphan*/ st_mode;
};

/* Variables and functions */
int /*<<< orphan*/ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, int, int);
int /*<<< orphan*/ mkdir(char *, int);
int /*<<< orphan*/ stat(char const *, struct stat *);
int strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
void make_dir_needed(const char *szFileSpec) {
  char strDir[256] = {0};
  int len = strlen(szFileSpec);
  strncpy(strDir, szFileSpec, len);
  for (int nIndex = 0; nIndex < len; nIndex++) {
    if ('/' == strDir[nIndex]) {
      struct stat info;
      stat(szFileSpec, &info);
      if (!S_ISDIR(info.st_mode)) {
        strDir[nIndex] = 0;
        mkdir(strDir, 0755);
        memset(strDir, 0x00, 256);
        strncpy(strDir, szFileSpec, len);
      }
    }
  }
}


x86 assembly (clang, -O0):
<make_dir_needed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1070 <memset@plt>
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x114(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x114(%rbp),%edx
call   1030 <strncpy@plt>
movl   $0x0,-0x118(%rbp)
mov    -0x118(%rbp),%eax
cmp    -0x114(%rbp),%eax
jge    126a <make_dir_needed+0x10a>
movslq -0x118(%rbp),%rax
movsbl -0x110(%rbp,%rax,1),%ecx
ff
mov    $0x2f,%eax
cmp    %ecx,%eax
jne    1251 <make_dir_needed+0xf1>
mov    -0x8(%rbp),%rdi
lea    -0x120(%rbp),%rsi
call   1080 <stat@plt>
mov    -0x120(%rbp),%edi
call   1060 <S_ISDIR@plt>
cmp    $0x0,%eax
jne    124c <make_dir_needed+0xec>
movslq -0x118(%rbp),%rax
movb   $0x0,-0x110(%rbp,%rax,1)
lea    -0x110(%rbp),%rdi
mov    $0x1ed,%esi
call   1040 <mkdir@plt>
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1070 <memset@plt>
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x114(%rbp),%edx
call   1030 <strncpy@plt>
jmp    1251 <make_dir_needed+0xf1>
jmp    1256 <make_dir_needed+0xf6>
mov    -0x118(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x118(%rbp)
jmp    11b1 <make_dir_needed+0x51>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_dir_needed>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    %rdi,%r13
xorps  %xmm0,%xmm0
movaps %xmm0,0x100(%rsp)
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
call   1050 <strlen@plt>
mov    %eax,%r15d
lea    0x10(%rsp),%rdi
mov    %r13,%rsi
mov    %eax,%edx
call   1030 <strncpy@plt>
test   %r15d,%r15d
jle    1269 <make_dir_needed+0x109>
mov    %r15d,%ebp
xor    %ebx,%ebx
lea    0x8(%rsp),%r14
lea    0x10(%rsp),%r12
jmp    1219 <make_dir_needed+0xb9>
nop
add    $0x1,%rbx
cmp    %rbx,%rbp
je     1269 <make_dir_needed+0x109>
cmpb   $0x2f,0x10(%rsp,%rbx,1)
jne    1210 <make_dir_needed+0xb0>
mov    %r13,%rdi
mov    %r14,%rsi
call   1080 <stat@plt>
mov    0x8(%rsp),%edi
call   1060 <S_ISDIR@plt>
test   %eax,%eax
jne    1210 <make_dir_needed+0xb0>
movb   $0x0,0x10(%rsp,%rbx,1)
mov    %r12,%rdi
mov    $0x1ed,%esi
call   1040 <mkdir@plt>
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1070 <memset@plt>
mov    %r12,%rdi
mov    %r13,%rsi
mov    %r15d,%edx
call   1030 <strncpy@plt>
jmp    1210 <make_dir_needed+0xb0>
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
define void @make_dir_needed(i8* %0) {
%2 = alloca i8*
%3 = alloca [256 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.stat
store i8* %0, i8** %2
%7 = bitcast [256 x i8]* %3 to i8*
%8 = load i8*, i8** %2
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %4
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%11 = load i8*, i8** %2
%12 = load i32, i32* %4
%13 = call i32 @strncpy(i8* %10, i8* %11, i32 %12)
store i32 0, i32* %5
br label %14
14: ; preds = %46, %1
%15 = load i32, i32* %5
%16 = load i32, i32* %4
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %49
18: ; preds = %14
%19 = load i32, i32* %5
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %20
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 47, %23
br i1 %24, label %25, label %45
25: ; preds = %18
%26 = load i8*, i8** %2
%27 = call i32 @stat(i8* %26, %struct.stat* %6)
%28 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%29 = load i32, i32* %28
%30 = call i32 @S_ISDIR(i32 %29)
%31 = icmp ne i32 %30, 0
br i1 %31, label %44, label %32
32: ; preds = %25
%33 = load i32, i32* %5
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %34
store i8 0, i8* %35
%36 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%37 = call i32 @mkdir(i8* %36, i32 493)
%38 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%39 = call i32 @memset(i8* %38, i32 0, i32 256)
%40 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%41 = load i8*, i8** %2
%42 = load i32, i32* %4
%43 = call i32 @strncpy(i8* %40, i8* %41, i32 %42)
br label %44
44: ; preds = %32, %25
br label %45
45: ; preds = %44, %18
br label %46
46: ; preds = %45
%47 = load i32, i32* %5
%48 = add nsw i32 %47, 1
store i32 %48, i32* %5
br label %14
49: ; preds = %14
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
define void @make_dir_needed(i8* %0) {
%2 = alloca [256 x i8]
%3 = alloca %struct.stat
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%5 = tail call i32 @strlen(i8* %0)
%6 = call i32 @strncpy(i8* %4, i8* %0, i32 %5)
%7 = icmp sgt i32 %5, 0
br i1 %7, label %8, label %12
8: ; preds = %1
%9 = bitcast %struct.stat* %3 to i8*
%10 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%11 = zext i32 %5 to i64
br label %13
12: ; preds = %28, %1
ret void
13: ; preds = %8, %28
%14 = phi i64 [ 0, %8 ], [ %29, %28 ]
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 %14
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 47
br i1 %17, label %18, label %28
18: ; preds = %13
%19 = call i32 @stat(i8* %0, %struct.stat* %3)
%20 = load i32, i32* %10
%21 = call i32 @S_ISDIR(i32 %20)
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %18
store i8 0, i8* %15
%24 = call i32 @mkdir(i8* %4, i32 493)
%25 = call i32 @memset(i8* %4, i32 0, i32 256)
%26 = call i32 @strncpy(i8* %4, i8* %0, i32 %5)
br label %27
27: ; preds = %23, %18
br label %28
28: ; preds = %13, %27
%29 = add nuw nsw i64 %14, 1
%30 = icmp eq i64 %29, %11
br i1 %30, label %12, label %13
}