#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 */
struct stat {
  int dummy;
};

/* Variables and functions */
int BUFSIZ;
int /*<<< orphan*/ S_IRWXU;
int /*<<< orphan*/ debug(int, char *, char const *);
int /*<<< orphan*/ true_mkdir(char *, int /*<<< orphan*/);
scalar_t__ true_stat(char *, struct stat *);
int make_path(const char *path) {
  char checkdir[BUFSIZ];
  struct stat inode;
  int i = 0;
  debug(2, "===== make_path: %s\n", path);
  while (path[i] != '\0') {
    checkdir[i] = path[i];
    if (checkdir[i] == '/') {
      checkdir[i + 1] = '\0';
      if (true_stat(checkdir, &inode) < 0)
        true_mkdir(checkdir, S_IRWXU);
    }
    i++;
  }
  return 0;
}


x86 assembly (clang, -O0):
<make_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e95(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%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,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x8(%rbp),%rdx
mov    $0x2,%edi
lea    0xe81(%rip),%rsi
call   1030 <debug@plt>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     1208 <make_path+0xd8>
mov    -0x30(%rbp),%rax
mov    -0x8(%rbp),%rcx
movslq -0x24(%rbp),%rdx
mov    (%rcx,%rdx,1),%dl
movslq -0x24(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    11fa <make_path+0xca>
mov    -0x30(%rbp),%rdi
mov    -0x24(%rbp),%eax
add    $0x1,%eax
cltq
movb   $0x0,(%rdi,%rax,1)
lea    -0x20(%rbp),%rsi
call   1040 <true_stat@plt>
cmp    $0x0,%rax
jge    11f5 <make_path+0xc5>
mov    -0x30(%rbp),%rdi
mov    0x2dfa(%rip),%rax
mov    (%rax),%esi
call   1050 <true_mkdir@plt>
jmp    11fa <make_path+0xca>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1184 <make_path+0x54>
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
xor    %eax,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_path>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    0x2e90(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r12
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
lea    0xe9e(%rip),%rsi
mov    $0x2,%edi
mov    %r14,%rdx
call   1030 <debug@plt>
mov    (%r14),%al
test   %al,%al
je     11c9 <make_path+0x99>
mov    $0x1,%ebx
lea    -0x30(%rbp),%r15
mov    0x2e62(%rip),%r13
jmp    119d <make_path+0x6d>
nopl   0x0(%rax,%rax,1)
movzbl (%r14,%rbx,1),%eax
add    $0x1,%rbx
test   %al,%al
je     11c9 <make_path+0x99>
mov    %al,-0x1(%r12,%rbx,1)
cmp    $0x2f,%al
jne    1190 <make_path+0x60>
movb   $0x0,(%r12,%rbx,1)
mov    %r12,%rdi
mov    %r15,%rsi
call   1040 <true_stat@plt>
test   %rax,%rax
jns    1190 <make_path+0x60>
mov    0x0(%r13),%esi
mov    %r12,%rdi
call   1050 <true_mkdir@plt>
jmp    1190 <make_path+0x60>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@BUFSIZ = global i32 0
@.str = [21 x i8] c"===== make_path: %s\0A\00"
@S_IRWXU = global i32 0
define i32 @make_path(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca %struct.stat
%6 = alloca i32
store i8* %0, i8** %2
%7 = load i32, i32* @BUFSIZ
%8 = zext i32 %7 to i64
%9 = call i8* @llvm.stacksave()
store i8* %9, i8** %3
%10 = alloca i8, i64 %8
store i64 %8, i64* %4
store i32 0, i32* %6
%11 = load i8*, i8** %2
%12 = call i32 @debug(i32 2, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %11)
br label %13
13: ; preds = %47, %1
%14 = load i8*, i8** %2
%15 = load i32, i32* %6
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %50
21: ; preds = %13
%22 = load i8*, i8** %2
%23 = load i32, i32* %6
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load i8, i8* %25
%27 = load i32, i32* %6
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %10, i64 %28
store i8 %26, i8* %29
%30 = load i32, i32* %6
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %10, i64 %31
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 47
br i1 %35, label %36, label %47
36: ; preds = %21
%37 = load i32, i32* %6
%38 = add nsw i32 %37, 1
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %10, i64 %39
store i8 0, i8* %40
%41 = call i64 @true_stat(i8* %10, %struct.stat* %5)
%42 = icmp slt i64 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %36
%44 = load i32, i32* @S_IRWXU
%45 = call i32 @true_mkdir(i8* %10, i32 %44)
br label %46
46: ; preds = %43, %36
br label %47
47: ; preds = %46, %21
%48 = load i32, i32* %6
%49 = add nsw i32 %48, 1
store i32 %49, i32* %6
br label %13
50: ; preds = %13
%51 = load i8*, i8** %3
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@BUFSIZ = global i32 0
@.str = [21 x i8] c"===== make_path: %s\0A\00"
@S_IRWXU = global i32 0
define i32 @make_path(i8* %0) {
%2 = alloca %struct.stat
%3 = load i32, i32* @BUFSIZ
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = bitcast %struct.stat* %2 to i8*
%7 = tail call i32 @debug(i32 2, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %0)
%8 = load i8, i8* %0
%9 = icmp eq i8 %8, 0
br i1 %9, label %27, label %10
10: ; preds = %1, %23
%11 = phi i64 [ %15, %23 ], [ 0, %1 ]
%12 = phi i8 [ %25, %23 ], [ %8, %1 ]
%13 = getelementptr inbounds i8, i8* %5, i64 %11
store i8 %12, i8* %13
%14 = icmp eq i8 %12, 47
%15 = add nuw i64 %11, 1
br i1 %14, label %16, label %23
16: ; preds = %10
%17 = getelementptr inbounds i8, i8* %5, i64 %15
store i8 0, i8* %17
%18 = call i64 @true_stat(i8* %5, %struct.stat* %2)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = load i32, i32* @S_IRWXU
%22 = call i32 @true_mkdir(i8* %5, i32 %21)
br label %23
23: ; preds = %10, %16, %20
%24 = getelementptr inbounds i8, i8* %0, i64 %15
%25 = load i8, i8* %24
%26 = icmp eq i8 %25, 0
br i1 %26, label %27, label %10
27: ; preds = %23, %1
ret i32 0
}