#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*/ die(char *, char *);
int /*<<< orphan*/ dir_exists(char *);
scalar_t__ mkdir(char *, int);
char *strchr(char *, char);
void make_dir(char *path) {
  char *sep = (path[0] == '/' ? path + 1 : path);
  for (;;) {
    sep = strchr(sep, '/');
    if (sep)
      *sep = 0;
    if (!dir_exists(path) && mkdir(path, 0777) < 0)
      die("Cannot create directory %s: %m\n", path);
    if (!sep)
      return;
    *sep++ = '/';
  }
}


x86 assembly (clang, -O0):
<make_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    116d <make_dir+0x2d>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1175 <make_dir+0x35>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strchr@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11a1 <make_dir+0x61>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
call   1030 <dir_exists@plt>
cmp    $0x0,%eax
jne    11db <make_dir+0x9b>
mov    -0x8(%rbp),%rdi
mov    $0x1ff,%esi
call   1040 <mkdir@plt>
cmp    $0x0,%rax
jge    11db <make_dir+0x9b>
mov    -0x8(%rbp),%rsi
lea    0xe2a(%rip),%rdi
call   1060 <die@plt>
cmpq   $0x0,-0x10(%rbp)
jne    11ec <make_dir+0xac>
add    $0x20,%rsp
pop    %rbp
ret
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x2f,(%rax)
jmp    117d <make_dir+0x3d>

x86 assembly (clang, -O2):
<make_dir>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
xor    %edi,%edi
cmpb   $0x2f,(%r15)
sete   %dil
add    %r15,%rdi
lea    0xea4(%rip),%r14
nopl   0x0(%rax)
mov    $0x2f,%esi
call   1050 <strchr@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1175 <make_dir+0x35>
movb   $0x0,(%rbx)
mov    %r15,%rdi
call   1030 <dir_exists@plt>
test   %eax,%eax
jne    11a0 <make_dir+0x60>
mov    %r15,%rdi
mov    $0x1ff,%esi
call   1040 <mkdir@plt>
test   %rax,%rax
jns    11a0 <make_dir+0x60>
mov    %r14,%rdi
mov    %r15,%rsi
call   1060 <die@plt>
xchg   %ax,%ax
test   %rbx,%rbx
je     11b1 <make_dir+0x71>
mov    %rbx,%rdi
add    $0x1,%rdi
movb   $0x2f,(%rbx)
jmp    1160 <make_dir+0x20>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [32 x i8] c"Cannot create directory %s: %m\0A\00"
define void @make_dir(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = getelementptr inbounds i8, i8* %4, i64 0
%6 = load i8, i8* %5
%7 = sext i8 %6 to i32
%8 = icmp eq i32 %7, 47
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = load i8*, i8** %2
%11 = getelementptr inbounds i8, i8* %10, i64 1
br label %14
12: ; preds = %1
%13 = load i8*, i8** %2
br label %14
14: ; preds = %12, %9
%15 = phi i8* [ %11, %9 ], [ %13, %12 ]
store i8* %15, i8** %3
br label %16
16: ; preds = %38, %14
%17 = load i8*, i8** %3
%18 = call i8* @strchr(i8* %17, i8 signext 47)
store i8* %18, i8** %3
%19 = load i8*, i8** %3
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = load i8*, i8** %3
store i8 0, i8* %22
br label %23
23: ; preds = %21, %16
%24 = load i8*, i8** %2
%25 = call i32 @dir_exists(i8* %24)
%26 = icmp ne i32 %25, 0
br i1 %26, label %34, label %27
27: ; preds = %23
%28 = load i8*, i8** %2
%29 = call i64 @mkdir(i8* %28, i32 511)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %27
%32 = load i8*, i8** %2
%33 = call i32 @die(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %32)
br label %34
34: ; preds = %31, %27, %23
%35 = load i8*, i8** %3
%36 = icmp ne i8* %35, null
br i1 %36, label %38, label %37
37: ; preds = %34
ret void
38: ; preds = %34
%39 = load i8*, i8** %3
%40 = getelementptr inbounds i8, i8* %39, i32 1
store i8* %40, i8** %3
store i8 47, i8* %39
br label %16
}

LLVM IR (-O2):
@.str = [32 x i8] c"Cannot create directory %s: %m\0A\00"
define void @make_dir(i8* %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 47
%4 = zext i1 %3 to i64
%5 = getelementptr i8, i8* %0, i64 %4
br label %6
6: ; preds = %21, %1
%7 = phi i8* [ %5, %1 ], [ %22, %21 ]
%8 = tail call i8* @strchr(i8* dereferenceable(1) %7, i8 signext 47)
%9 = icmp eq i8* %8, null
br i1 %9, label %11, label %10
10: ; preds = %6
store i8 0, i8* %8
br label %11
11: ; preds = %10, %6
%12 = tail call i32 @dir_exists(i8* %0)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %11
%15 = tail call i64 @mkdir(i8* %0, i32 511)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = tail call i32 @die(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %19
19: ; preds = %17, %14, %11
br i1 %9, label %20, label %21
20: ; preds = %19
ret void
21: ; preds = %19
%22 = getelementptr inbounds i8, i8* %8, i64 1
store i8 47, i8* %8
br label %6
}