#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 */
char *index(char *, char);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ mkdir(char *, int);
void makeparents(char *path) {
  static char c[100];
  char *s = path;
  int l;
  while (1) {
    char *e = index(s, '/');
    if (!e)
      return;
    l = e - path;
    memcpy(c, path, l);
    c[l] = 0;
    mkdir(c, 0755);
    s = e + 1;
  }
}


x86 assembly (clang, -O0):
<makeparents>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <index@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1167 <makeparents+0x37>
add    $0x20,%rsp
pop    %rbp
ret
mov    -0x20(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%edx
lea    0x2ecd(%rip),%rdi
call   1050 <memcpy@plt>
movslq -0x14(%rbp),%rcx
lea    0x2ebd(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
lea    0x2eb2(%rip),%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1144 <makeparents+0x14>

x86 assembly (clang, -O2):
<makeparents>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x2f,%esi
call   1040 <index@plt>
test   %rax,%rax
je     11a2 <makeparents+0x72>
mov    %rax,%rbx
lea    0x2efc(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%r12
sub    %r14,%r12
mov    %r15,%rdi
mov    %r14,%rsi
mov    %r12d,%edx
call   1050 <memcpy@plt>
movslq %r12d,%rax
movb   $0x0,(%rax,%r15,1)
mov    %r15,%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
add    $0x1,%rbx
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1040 <index@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1160 <makeparents+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@makeparents.c = internal global [100 x i8] zeroinitializer
define void @makeparents(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
store i8* %6, i8** %3
br label %7
7: ; preds = %1, %13
%8 = load i8*, i8** %3
%9 = call i8* @index(i8* %8, i8 signext 47)
store i8* %9, i8** %5
%10 = load i8*, i8** %5
%11 = icmp ne i8* %10, null
br i1 %11, label %13, label %12
12: ; preds = %7
ret void
13: ; preds = %7
%14 = load i8*, i8** %5
%15 = load i8*, i8** %2
%16 = ptrtoint i8* %14 to i64
%17 = ptrtoint i8* %15 to i64
%18 = sub i64 %16, %17
%19 = trunc i64 %18 to i32
store i32 %19, i32* %4
%20 = load i8*, i8** %2
%21 = load i32, i32* %4
%22 = call i32 @memcpy(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @makeparents.c, i64 0, i64 0), i8* %20, i32 %21)
%23 = load i32, i32* %4
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [100 x i8], [100 x i8]* @makeparents.c, i64 0, i64 %24
store i8 0, i8* %25
%26 = call i32 @mkdir(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @makeparents.c, i64 0, i64 0), i32 493)
%27 = load i8*, i8** %5
%28 = getelementptr inbounds i8, i8* %27, i64 1
store i8* %28, i8** %3
br label %7
}

LLVM IR (-O2):
@makeparents.c = internal global [100 x i8] zeroinitializer
define void @makeparents(i8* %0) {
%2 = tail call i8* @index(i8* %0, i8 signext 47)
%3 = icmp eq i8* %2, null
br i1 %3, label %19, label %4
4: ; preds = %1
%5 = ptrtoint i8* %0 to i64
br label %6
6: ; preds = %4, %6
%7 = phi i8* [ %2, %4 ], [ %17, %6 ]
%8 = ptrtoint i8* %7 to i64
%9 = sub i64 %8, %5
%10 = trunc i64 %9 to i32
%11 = tail call i32 @memcpy(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @makeparents.c, i64 0, i64 0), i8* %0, i32 %10)
%12 = shl i64 %9, 32
%13 = ashr exact i64 %12, 32
%14 = getelementptr inbounds [100 x i8], [100 x i8]* @makeparents.c, i64 0, i64 %13
store i8 0, i8* %14
%15 = tail call i32 @mkdir(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @makeparents.c, i64 0, i64 0), i32 493)
%16 = getelementptr inbounds i8, i8* %7, i64 1
%17 = tail call i8* @index(i8* %16, i8 signext 47)
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %6
19: ; preds = %6, %1
ret void
}