#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*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ mkdir(char *, int);
int strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
void recursive_mkdir(const char *filename) {
  char *pathname;
  int i, e;
  for (i = 1, e = strlen(filename); i != e; ++i) {
    if (filename[i] == '/') {
      pathname = malloc(i + 1);
      strncpy(pathname, filename, i);
      pathname[i] = '\0';
      mkdir(pathname, 0750);
      free(pathname);
    }
  }
}


x86 assembly (clang, -O0):
<recursive_mkdir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
je     11e5 <recursive_mkdir+0x95>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    11d2 <recursive_mkdir+0x82>
mov    -0x14(%rbp),%edi
add    $0x1,%edi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <strncpy@plt>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
mov    $0x1e8,%esi
call   1050 <mkdir@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
jmp    11d7 <recursive_mkdir+0x87>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    116f <recursive_mkdir+0x1f>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<recursive_mkdir>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
call   1060 <strlen@plt>
cmp    $0x1,%eax
jne    1177 <recursive_mkdir+0x27>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%r12d
mov    $0x1,%ebx
mov    $0x2,%ebp
jmp    119b <recursive_mkdir+0x4b>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%ebp
mov    %r13,%rbx
cmp    %r13,%r12
je     1168 <recursive_mkdir+0x18>
lea    0x1(%rbx),%r13
cmpb   $0x2f,(%r14,%rbx,1)
jne    1190 <recursive_mkdir+0x40>
mov    %ebp,%edi
call   1070 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1040 <strncpy@plt>
movb   $0x0,(%r15,%rbx,1)
mov    %r15,%rdi
mov    $0x1e8,%esi
call   1050 <mkdir@plt>
mov    %r15,%rdi
call   1030 <free@plt>
jmp    1190 <recursive_mkdir+0x40>

LLVM IR (-O0):
define void @recursive_mkdir(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
store i32 1, i32* %4
%6 = load i8*, i8** %2
%7 = call i32 @strlen(i8* %6)
store i32 %7, i32* %5
br label %8
8: ; preds = %37, %1
%9 = load i32, i32* %4
%10 = load i32, i32* %5
%11 = icmp ne i32 %9, %10
br i1 %11, label %12, label %40
12: ; preds = %8
%13 = load i8*, i8** %2
%14 = load i32, i32* %4
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %13, i64 %15
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 47
br i1 %19, label %20, label %36
20: ; preds = %12
%21 = load i32, i32* %4
%22 = add nsw i32 %21, 1
%23 = call i8* @malloc(i32 %22)
store i8* %23, i8** %3
%24 = load i8*, i8** %3
%25 = load i8*, i8** %2
%26 = load i32, i32* %4
%27 = call i32 @strncpy(i8* %24, i8* %25, i32 %26)
%28 = load i8*, i8** %3
%29 = load i32, i32* %4
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
store i8 0, i8* %31
%32 = load i8*, i8** %3
%33 = call i32 @mkdir(i8* %32, i32 488)
%34 = load i8*, i8** %3
%35 = call i32 @free(i8* %34)
br label %36
36: ; preds = %20, %12
br label %37
37: ; preds = %36
%38 = load i32, i32* %4
%39 = add nsw i32 %38, 1
store i32 %39, i32* %4
br label %8
40: ; preds = %8
ret void
}

LLVM IR (-O2):
define void @recursive_mkdir(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp eq i32 %2, 1
br i1 %3, label %22, label %4
4: ; preds = %1
%5 = zext i32 %2 to i64
br label %6
6: ; preds = %4, %20
%7 = phi i64 [ 1, %4 ], [ %11, %20 ]
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 47
%11 = add nuw nsw i64 %7, 1
br i1 %10, label %12, label %20
12: ; preds = %6
%13 = trunc i64 %11 to i32
%14 = tail call i8* @malloc(i32 %13)
%15 = trunc i64 %7 to i32
%16 = tail call i32 @strncpy(i8* %14, i8* %0, i32 %15)
%17 = getelementptr inbounds i8, i8* %14, i64 %7
store i8 0, i8* %17
%18 = tail call i32 @mkdir(i8* %14, i32 488)
%19 = tail call i32 @free(i8* %14)
br label %20
20: ; preds = %6, %12
%21 = icmp eq i64 %11, %5
br i1 %21, label %22, label %6
22: ; preds = %20, %1
ret void
}