#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 */
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ errors_2p(int /*<<< orphan*/ *, int /*<<< orphan*/ *, char *,
                             char *, int, int, int);
int mk_dir(char const *, int);
int /*<<< orphan*/ *opendir(char const *);
int strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
void make_directories(const char *dir) {
  int i;
  char aux[strlen(dir) + 1];
  DIR *directory;
  for (i = 0; i < strlen(dir); i++) {
    if (dir[i] == '/' && i > 1) {
      strncpy(aux, dir, i);
      aux[i] = '\0';
      if ((directory = opendir(aux)) == NULL) {
        if (mk_dir(aux, 0777) == 1) {
          errors_2p(NULL, NULL, "ERROR creating the directory", aux, 4, 1, 1);
        }
      } else
        closedir(directory);
    }
  }
  if ((directory = opendir(dir)) == NULL) {
    if (mk_dir(dir, 0777) == 1) {
      errors_2p(NULL, NULL, "ERROR creating the directory", aux, 4, 1, 1);
    }
  } else
    closedir(directory);
}


x86 assembly (clang, -O0):
<make_directories>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <strlen@plt>
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
cmp    %ecx,%eax
jge    127b <make_directories+0x11b>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    1268 <make_directories+0x108>
cmpl   $0x1,-0xc(%rbp)
jle    1268 <make_directories+0x108>
mov    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1040 <strncpy@plt>
mov    -0x30(%rbp),%rdi
movslq -0xc(%rbp),%rax
movb   $0x0,(%rdi,%rax,1)
call   1050 <opendir@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    125a <make_directories+0xfa>
mov    -0x30(%rbp),%rdi
mov    $0x1ff,%esi
call   1030 <mk_dir@plt>
cmp    $0x1,%eax
jne    1255 <make_directories+0xf5>
mov    -0x30(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%esi
lea    0xdce(%rip),%rdx
mov    $0x4,%r8d
mov    $0x1,%r9d
sub    $0x10,%rsp
mov    %rsi,%rdi
movl   $0x1,(%rsp)
call   1080 <errors_2p@plt>
add    $0x10,%rsp
jmp    1263 <make_directories+0x103>
mov    -0x28(%rbp),%rdi
call   1070 <closedir@plt>
jmp    1268 <make_directories+0x108>
jmp    126d <make_directories+0x10d>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11a2 <make_directories+0x42>
mov    -0x8(%rbp),%rdi
call   1050 <opendir@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    12e0 <make_directories+0x180>
mov    -0x8(%rbp),%rdi
mov    $0x1ff,%esi
call   1030 <mk_dir@plt>
cmp    $0x1,%eax
jne    12db <make_directories+0x17b>
mov    -0x30(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%esi
lea    0xd48(%rip),%rdx
mov    $0x4,%r8d
mov    $0x1,%r9d
sub    $0x10,%rsp
mov    %rsi,%rdi
movl   $0x1,(%rsp)
call   1080 <errors_2p@plt>
add    $0x10,%rsp
jmp    12e9 <make_directories+0x189>
mov    -0x28(%rbp),%rdi
call   1070 <closedir@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_directories>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r15
call   1060 <strlen@plt>
add    $0x1,%eax
mov    %rsp,%r14
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    %r15,%rdi
call   1060 <strlen@plt>
test   %eax,%eax
jle    1230 <make_directories+0xd0>
xor    %ebx,%ebx
lea    0xe60(%rip),%r12
jmp    11cb <make_directories+0x6b>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rax,%rdi
call   1070 <closedir@plt>
add    $0x1,%rbx
mov    %r15,%rdi
call   1060 <strlen@plt>
cltq
cmp    %rax,%rbx
jge    1230 <make_directories+0xd0>
cmpb   $0x2f,(%r15,%rbx,1)
jne    11b8 <make_directories+0x58>
cmp    $0x2,%rbx
jb     11b8 <make_directories+0x58>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1040 <strncpy@plt>
movb   $0x0,(%r14,%rbx,1)
mov    %r14,%rdi
call   1050 <opendir@plt>
test   %rax,%rax
jne    11b0 <make_directories+0x50>
mov    %r14,%rdi
mov    $0x1ff,%esi
call   1030 <mk_dir@plt>
cmp    $0x1,%eax
jne    11b8 <make_directories+0x58>
sub    $0x8,%rsp
xor    %edi,%edi
xor    %esi,%esi
mov    %r12,%rdx
mov    %r14,%rcx
mov    $0x4,%r8d
mov    $0x1,%r9d
push   $0x1
call   1080 <errors_2p@plt>
add    $0x10,%rsp
jmp    11b8 <make_directories+0x58>
mov    %r15,%rdi
call   1050 <opendir@plt>
test   %rax,%rax
je     1247 <make_directories+0xe7>
mov    %rax,%rdi
call   1070 <closedir@plt>
jmp    1282 <make_directories+0x122>
mov    %r15,%rdi
mov    $0x1ff,%esi
call   1030 <mk_dir@plt>
cmp    $0x1,%eax
jne    1282 <make_directories+0x122>
sub    $0x8,%rsp
lea    0xd9c(%rip),%rdx
xor    %edi,%edi
xor    %esi,%esi
mov    %r14,%rcx
mov    $0x4,%r8d
mov    $0x1,%r9d
push   $0x1
call   1080 <errors_2p@plt>
add    $0x10,%rsp
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [29 x i8] c"ERROR creating the directory\00"
define void @make_directories(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32*
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = call i32 @strlen(i8* %7)
%9 = add nsw i32 %8, 1
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %4
%12 = alloca i8, i64 %10
store i64 %10, i64* %5
store i32 0, i32* %3
br label %13
13: ; preds = %49, %1
%14 = load i32, i32* %3
%15 = load i8*, i8** %2
%16 = call i32 @strlen(i8* %15)
%17 = icmp slt i32 %14, %16
br i1 %17, label %18, label %52
18: ; preds = %13
%19 = load i8*, i8** %2
%20 = load i32, i32* %3
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 47
br i1 %25, label %26, label %48
26: ; preds = %18
%27 = load i32, i32* %3
%28 = icmp sgt i32 %27, 1
br i1 %28, label %29, label %48
29: ; preds = %26
%30 = load i8*, i8** %2
%31 = load i32, i32* %3
%32 = call i32 @strncpy(i8* %12, i8* %30, i32 %31)
%33 = load i32, i32* %3
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %12, i64 %34
store i8 0, i8* %35
%36 = call i32* @opendir(i8* %12)
store i32* %36, i32** %6
%37 = icmp eq i32* %36, null
br i1 %37, label %38, label %44
38: ; preds = %29
%39 = call i32 @mk_dir(i8* %12, i32 511)
%40 = icmp eq i32 %39, 1
br i1 %40, label %41, label %43
41: ; preds = %38
%42 = call i32 @errors_2p(i32* null, i32* null, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %12, i32 4, i32 1, i32 1)
br label %43
43: ; preds = %41, %38
br label %47
44: ; preds = %29
%45 = load i32*, i32** %6
%46 = call i32 @closedir(i32* %45)
br label %47
47: ; preds = %44, %43
br label %48
48: ; preds = %47, %26, %18
br label %49
49: ; preds = %48
%50 = load i32, i32* %3
%51 = add nsw i32 %50, 1
store i32 %51, i32* %3
br label %13
52: ; preds = %13
%53 = load i8*, i8** %2
%54 = call i32* @opendir(i8* %53)
store i32* %54, i32** %6
%55 = icmp eq i32* %54, null
br i1 %55, label %56, label %63
56: ; preds = %52
%57 = load i8*, i8** %2
%58 = call i32 @mk_dir(i8* %57, i32 511)
%59 = icmp eq i32 %58, 1
br i1 %59, label %60, label %62
60: ; preds = %56
%61 = call i32 @errors_2p(i32* null, i32* null, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %12, i32 4, i32 1, i32 1)
br label %62
62: ; preds = %60, %56
br label %66
63: ; preds = %52
%64 = load i32*, i32** %6
%65 = call i32 @closedir(i32* %64)
br label %66
66: ; preds = %63, %62
%67 = load i8*, i8** %4
ret void
}

LLVM IR (-O2):
@.str = [29 x i8] c"ERROR creating the directory\00"
define void @make_directories(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = add nsw i32 %2, 1
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = call i32 @strlen(i8* %0)
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %33
8: ; preds = %1, %28
%9 = phi i64 [ %29, %28 ], [ 0, %1 ]
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 47
%13 = icmp ugt i64 %9, 1
%14 = select i1 %12, i1 %13, i1 false
br i1 %14, label %15, label %28
15: ; preds = %8
%16 = trunc i64 %9 to i32
%17 = call i32 @strncpy(i8* %5, i8* %0, i32 %16)
%18 = getelementptr inbounds i8, i8* %5, i64 %9
store i8 0, i8* %18
%19 = call i32* @opendir(i8* %5)
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %26
21: ; preds = %15
%22 = call i32 @mk_dir(i8* %5, i32 511)
%23 = icmp eq i32 %22, 1
br i1 %23, label %24, label %28
24: ; preds = %21
%25 = call i32 @errors_2p(i32* null, i32* null, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %5, i32 4, i32 1, i32 1)
br label %28
26: ; preds = %15
%27 = call i32 @closedir(i32* %19)
br label %28
28: ; preds = %8, %21, %24, %26
%29 = add nuw nsw i64 %9, 1
%30 = call i32 @strlen(i8* %0)
%31 = sext i32 %30 to i64
%32 = icmp slt i64 %29, %31
br i1 %32, label %8, label %33
33: ; preds = %28, %1
%34 = call i32* @opendir(i8* %0)
%35 = icmp eq i32* %34, null
br i1 %35, label %36, label %41
36: ; preds = %33
%37 = call i32 @mk_dir(i8* %0, i32 511)
%38 = icmp eq i32 %37, 1
br i1 %38, label %39, label %43
39: ; preds = %36
%40 = call i32 @errors_2p(i32* null, i32* null, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %5, i32 4, i32 1, i32 1)
br label %43
41: ; preds = %33
%42 = call i32 @closedir(i32* %34)
br label %43
43: ; preds = %36, %39, %41
ret void
}