#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*/ ACCESSPERMS;
int /*<<< orphan*/ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
int mkdir(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
scalar_t__ stat(char *, struct stat *);
char *strchr(char *, char);
char *strdup(char const *);
int make_dirs(const char *FileName) {
  int result = 1;
  char *s = strdup(FileName);
  char *p = s;
  if (*p == '/')
    p++;
  while ((p = strchr(p, '/')) != NULL) {
    struct stat fs;
    if (p)
      *p = 0;
    if (stat(s, &fs) != 0 || !S_ISDIR(fs.st_mode)) {
      if (mkdir(s, ACCESSPERMS) == -1) {
        perror(s);
        result = 0;
        break;
      }
    }
    if (p)
      *p++ = '/';
    else
      break;
  }
  free(s);
  return result;
}


x86 assembly (clang, -O0):
<make_dirs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1090 <strdup@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    11b4 <make_dirs+0x44>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11b9 <make_dirs+0x49>
mov    -0x20(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1270 <make_dirs+0x100>
cmpq   $0x0,-0x20(%rbp)
je     11e7 <make_dirs+0x77>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1070 <stat@plt>
cmp    $0x0,%rax
jne    120f <make_dirs+0x9f>
mov    -0x28(%rbp),%edi
call   1060 <S_ISDIR@plt>
cmp    $0x0,%eax
jne    1244 <make_dirs+0xd4>
mov    -0x18(%rbp),%rdi
mov    0x2dce(%rip),%rax
mov    (%rax),%esi
call   1040 <mkdir@plt>
cmp    $0xffffffff,%eax
jne    123f <make_dirs+0xcf>
mov    -0x18(%rbp),%rdi
call   1080 <perror@plt>
movl   $0x0,-0xc(%rbp)
jmp    1270 <make_dirs+0x100>
jmp    1244 <make_dirs+0xd4>
cmpq   $0x0,-0x20(%rbp)
je     1266 <make_dirs+0xf6>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x2f,(%rax)
jmp    126b <make_dirs+0xfb>
jmp    1270 <make_dirs+0x100>
jmp    11b9 <make_dirs+0x49>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0xc(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_dirs>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
call   1090 <strdup@plt>
mov    %rax,%rbx
xor    %edi,%edi
cmpb   $0x2f,(%rax)
sete   %dil
add    %rax,%rdi
mov    $0x2f,%esi
call   1050 <strchr@plt>
mov    $0x1,%r14d
test   %rax,%rax
je     121c <make_dirs+0xac>
mov    %rax,%rbp
lea    0x8(%rsp),%r15
mov    0x2e34(%rip),%r12
jmp    11ee <make_dirs+0x7e>
cs nopw 0x0(%rax,%rax,1)
mov    (%r12),%esi
mov    %rbx,%rdi
call   1040 <mkdir@plt>
cmp    $0xffffffff,%eax
je     1211 <make_dirs+0xa1>
movb   $0x2f,0x0(%rbp)
add    $0x1,%rbp
mov    %rbp,%rdi
mov    $0x2f,%esi
call   1050 <strchr@plt>
mov    %rax,%rbp
test   %rax,%rax
je     121c <make_dirs+0xac>
movb   $0x0,0x0(%rbp)
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <stat@plt>
test   %rax,%rax
jne    11c0 <make_dirs+0x50>
mov    0x8(%rsp),%edi
call   1060 <S_ISDIR@plt>
test   %eax,%eax
jne    11d1 <make_dirs+0x61>
jmp    11c0 <make_dirs+0x50>
mov    %rbx,%rdi
call   1080 <perror@plt>
xor    %r14d,%r14d
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@ACCESSPERMS = global i32 0
define i32 @make_dirs(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca %struct.stat
store i8* %0, i8** %2
store i32 1, i32* %3
%7 = load i8*, i8** %2
%8 = call i8* @strdup(i8* %7)
store i8* %8, i8** %4
%9 = load i8*, i8** %4
store i8* %9, i8** %5
%10 = load i8*, i8** %5
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, 47
br i1 %13, label %14, label %17
14: ; preds = %1
%15 = load i8*, i8** %5
%16 = getelementptr inbounds i8, i8* %15, i32 1
store i8* %16, i8** %5
br label %17
17: ; preds = %14, %1
br label %18
18: ; preds = %52, %17
%19 = load i8*, i8** %5
%20 = call i8* @strchr(i8* %19, i8 signext 47)
store i8* %20, i8** %5
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %53
22: ; preds = %18
%23 = load i8*, i8** %5
%24 = icmp ne i8* %23, null
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = load i8*, i8** %5
store i8 0, i8* %26
br label %27
27: ; preds = %25, %22
%28 = load i8*, i8** %4
%29 = call i64 @stat(i8* %28, %struct.stat* %6)
%30 = icmp ne i64 %29, 0
br i1 %30, label %36, label %31
31: ; preds = %27
%32 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%33 = load i32, i32* %32
%34 = call i32 @S_ISDIR(i32 %33)
%35 = icmp ne i32 %34, 0
br i1 %35, label %45, label %36
36: ; preds = %31, %27
%37 = load i8*, i8** %4
%38 = load i32, i32* @ACCESSPERMS
%39 = call i32 @mkdir(i8* %37, i32 %38)
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %44
41: ; preds = %36
%42 = load i8*, i8** %4
%43 = call i32 @perror(i8* %42)
store i32 0, i32* %3
br label %53
44: ; preds = %36
br label %45
45: ; preds = %44, %31
%46 = load i8*, i8** %5
%47 = icmp ne i8* %46, null
br i1 %47, label %48, label %51
48: ; preds = %45
%49 = load i8*, i8** %5
%50 = getelementptr inbounds i8, i8* %49, i32 1
store i8* %50, i8** %5
store i8 47, i8* %49
br label %52
51: ; preds = %45
br label %53
52: ; preds = %48
br label %18
53: ; preds = %51, %41, %18
%54 = load i8*, i8** %4
%55 = call i32 @free(i8* %54)
%56 = load i32, i32* %3
ret i32 %56
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@ACCESSPERMS = global i32 0
define i32 @make_dirs(i8* nocapture %0) {
%2 = alloca %struct.stat
%3 = tail call i8* @strdup(i8* %0)
%4 = load i8, i8* %3
%5 = icmp eq i8 %4, 47
%6 = zext i1 %5 to i64
%7 = getelementptr i8, i8* %3, i64 %6
%8 = call i8* @strchr(i8* dereferenceable(1) %7, i8 signext 47)
%9 = icmp eq i8* %8, null
br i1 %9, label %31, label %10
10: ; preds = %1
%11 = bitcast %struct.stat* %2 to i8*
%12 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
br label %13
13: ; preds = %10, %27
%14 = phi i8* [ %8, %10 ], [ %29, %27 ]
store i8 0, i8* %14
%15 = call i64 @stat(i8* %3, %struct.stat* %2)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %13
%18 = load i32, i32* %12
%19 = call i32 @S_ISDIR(i32 %18)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %27
21: ; preds = %17, %13
%22 = load i32, i32* @ACCESSPERMS
%23 = call i32 @mkdir(i8* %3, i32 %22)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = call i32 @perror(i8* %3)
br label %31
27: ; preds = %21, %17
%28 = getelementptr inbounds i8, i8* %14, i64 1
store i8 47, i8* %14
%29 = call i8* @strchr(i8* dereferenceable(1) %28, i8 signext 47)
%30 = icmp eq i8* %29, null
br i1 %30, label %31, label %13
31: ; preds = %27, %1, %25
%32 = phi i32 [ 0, %25 ], [ 1, %1 ], [ 1, %27 ]
%33 = call i32 @free(i8* %3)
ret i32 %32
}