#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 */
scalar_t__ chdir(char *);
int /*<<< orphan*/ die(char *);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ mkdir(char *, int);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *strstr(char *, char *);
void make_directory(char *dir) {
  char buf[128];
  char *t = dir;
  int depth = 0;
  while (1) {
    char *e = strstr(t, "/");
    if (e) {
      memcpy(buf, t, e - t);
      buf[e - t] = 0;
    } else {
      strcpy(buf, t);
    }
    if (strcmp(buf, ".") == 0) {
    } else {
      mkdir(buf, 0777);
      if (chdir(buf) < 0)
        die("mkdir+chdir");
      depth++;
    }
    if (e) {
      t = e + 1;
    } else {
      break;
    }
  }
  for (int i = 0; i < depth; i++)
    chdir("..");
}


x86 assembly (clang, -O0):
<make_directory>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x98(%rbp)
movl   $0x0,-0x9c(%rbp)
mov    -0x98(%rbp),%rdi
lea    0xe5e(%rip),%rsi
call   1090 <strstr@plt>
mov    %rax,-0xa8(%rbp)
cmpq   $0x0,-0xa8(%rbp)
je     1200 <make_directory+0x90>
lea    -0x90(%rbp),%rdi
mov    -0x98(%rbp),%rsi
mov    -0xa8(%rbp),%rax
mov    -0x98(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1070 <memcpy@plt>
mov    -0xa8(%rbp),%rax
mov    -0x98(%rbp),%rcx
sub    %rcx,%rax
movb   $0x0,-0x90(%rbp,%rax,1)
jmp    1213 <make_directory+0xa3>
lea    -0x90(%rbp),%rdi
mov    -0x98(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x90(%rbp),%rdi
lea    0xdee(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1235 <make_directory+0xc5>
jmp    1277 <make_directory+0x107>
lea    -0x90(%rbp),%rdi
mov    $0x1ff,%esi
call   1040 <mkdir@plt>
lea    -0x90(%rbp),%rdi
call   1050 <chdir@plt>
cmp    $0x0,%rax
jge    1268 <make_directory+0xf8>
lea    0xd9f(%rip),%rdi
call   1080 <die@plt>
mov    -0x9c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x9c(%rbp)
cmpq   $0x0,-0xa8(%rbp)
je     129c <make_directory+0x12c>
mov    -0xa8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x98(%rbp)
jmp    12a1 <make_directory+0x131>
jmp    12a6 <make_directory+0x136>
jmp    1194 <make_directory+0x24>
movl   $0x0,-0xac(%rbp)
mov    -0xac(%rbp),%eax
cmp    -0x9c(%rbp),%eax
jge    12e2 <make_directory+0x172>
lea    0xd45(%rip),%rdi
call   1050 <chdir@plt>
mov    -0xac(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xac(%rbp)
jmp    12b0 <make_directory+0x140>
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_directory>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    %rdi,%rbx
xor    %r15d,%r15d
mov    %rsp,%r12
lea    0xe7c(%rip),%r14
jmp    11ad <make_directory+0x3d>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%r15d
lea    0x1(%r13),%rbx
test   %r13,%r13
je     1226 <make_directory+0xb6>
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1060 <strchr@plt>
mov    %rax,%r13
test   %rax,%rax
je     11e0 <make_directory+0x70>
mov    %r13,%rbp
sub    %rbx,%rbp
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1080 <memcpy@plt>
movb   $0x0,(%rsp,%rbp,1)
jmp    11eb <make_directory+0x7b>
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %r12,%rdi
mov    %r14,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     11a4 <make_directory+0x34>
mov    %r12,%rdi
mov    $0x1ff,%esi
call   1040 <mkdir@plt>
mov    %r12,%rdi
call   1050 <chdir@plt>
test   %rax,%rax
jns    11a0 <make_directory+0x30>
lea    0xde4(%rip),%rdi
call   1090 <die@plt>
jmp    11a0 <make_directory+0x30>
test   %r15d,%r15d
jle    124e <make_directory+0xde>
lea    0xdda(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1050 <chdir@plt>
add    $0xffffffff,%r15d
jne    1240 <make_directory+0xd0>
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [12 x i8] c"mkdir+chdir\00"
@.str.3 = [3 x i8] c"..\00"
define void @make_directory(i8* %0) {
%2 = alloca i8*
%3 = alloca [128 x i8]
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %2
%8 = load i8*, i8** %2
store i8* %8, i8** %4
store i32 0, i32* %5
br label %9
9: ; preds = %1, %57
%10 = load i8*, i8** %4
%11 = call i8* @strstr(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %11, i8** %6
%12 = load i8*, i8** %6
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %30
14: ; preds = %9
%15 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%16 = load i8*, i8** %4
%17 = load i8*, i8** %6
%18 = load i8*, i8** %4
%19 = ptrtoint i8* %17 to i64
%20 = ptrtoint i8* %18 to i64
%21 = sub i64 %19, %20
%22 = trunc i64 %21 to i32
%23 = call i32 @memcpy(i8* %15, i8* %16, i32 %22)
%24 = load i8*, i8** %6
%25 = load i8*, i8** %4
%26 = ptrtoint i8* %24 to i64
%27 = ptrtoint i8* %25 to i64
%28 = sub i64 %26, %27
%29 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 %28
store i8 0, i8* %29
br label %34
30: ; preds = %9
%31 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%32 = load i8*, i8** %4
%33 = call i32 @strcpy(i8* %31, i8* %32)
br label %34
34: ; preds = %30, %14
%35 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%36 = call i64 @strcmp(i8* %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %34
br label %50
39: ; preds = %34
%40 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%41 = call i32 @mkdir(i8* %40, i32 511)
%42 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%43 = call i64 @chdir(i8* %42)
%44 = icmp slt i64 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %39
%46 = call i32 @die(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %47
47: ; preds = %45, %39
%48 = load i32, i32* %5
%49 = add nsw i32 %48, 1
store i32 %49, i32* %5
br label %50
50: ; preds = %47, %38
%51 = load i8*, i8** %6
%52 = icmp ne i8* %51, null
br i1 %52, label %53, label %56
53: ; preds = %50
%54 = load i8*, i8** %6
%55 = getelementptr inbounds i8, i8* %54, i64 1
store i8* %55, i8** %4
br label %57
56: ; preds = %50
br label %58
57: ; preds = %53
br label %9
58: ; preds = %56
store i32 0, i32* %7
br label %59
59: ; preds = %65, %58
%60 = load i32, i32* %7
%61 = load i32, i32* %5
%62 = icmp slt i32 %60, %61
br i1 %62, label %63, label %68
63: ; preds = %59
%64 = call i64 @chdir(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %65
65: ; preds = %63
%66 = load i32, i32* %7
%67 = add nsw i32 %66, 1
store i32 %67, i32* %7
br label %59
68: ; preds = %59
ret void
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c".\00"
@.str.2 = [12 x i8] c"mkdir+chdir\00"
@.str.3 = [3 x i8] c"..\00"
define void @make_directory(i8* %0) {
%2 = alloca [128 x i8]
%3 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
br label %4
4: ; preds = %29, %1
%5 = phi i32 [ 0, %1 ], [ %30, %29 ]
%6 = phi i8* [ %0, %1 ], [ %31, %29 ]
%7 = call i8* @strchr(i8* dereferenceable(1) %6, i32 47)
%8 = icmp eq i8* %7, null
br i1 %8, label %16, label %9
9: ; preds = %4
%10 = ptrtoint i8* %7 to i64
%11 = ptrtoint i8* %6 to i64
%12 = sub i64 %10, %11
%13 = trunc i64 %12 to i32
%14 = call i32 @memcpy(i8* %3, i8* %6, i32 %13)
%15 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 %12
store i8 0, i8* %15
br label %18
16: ; preds = %4
%17 = call i32 @strcpy(i8* %3, i8* %6)
br label %18
18: ; preds = %16, %9
%19 = call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %29, label %21
21: ; preds = %18
%22 = call i32 @mkdir(i8* %3, i32 511)
%23 = call i64 @chdir(i8* %3)
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = call i32 @die(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %27
27: ; preds = %25, %21
%28 = add nsw i32 %5, 1
br label %29
29: ; preds = %18, %27
%30 = phi i32 [ %5, %18 ], [ %28, %27 ]
%31 = getelementptr inbounds i8, i8* %7, i64 1
br i1 %8, label %32, label %4
32: ; preds = %29
%33 = icmp sgt i32 %30, 0
br i1 %33, label %35, label %34
34: ; preds = %35, %32
ret void
35: ; preds = %32, %35
%36 = phi i32 [ %38, %35 ], [ 0, %32 ]
%37 = call i64 @chdir(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%38 = add nuw nsw i32 %36, 1
%39 = icmp eq i32 %38, %30
br i1 %39, label %34, label %35
}