#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__ EEXIST;
int /*<<< orphan*/ assert_perror(scalar_t__);
char *dirname(int /*<<< orphan*/);
scalar_t__ errno;
int mkdir(char const *, int);
scalar_t__ strcmp(char const *, char *);
int /*<<< orphan*/ strdupa(char const *);
void mkdir_p(const char *directory) {
  if (strcmp(directory, "/") != 0) {
    char *parent = dirname(strdupa(directory));
    mkdir_p(parent);
    int err = mkdir(directory, 0700);
    if (err < 0 && errno != EEXIST)
      assert_perror(errno);
  }
}


x86 assembly (clang, -O0):
<mkdir_p>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe89(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     11ec <mkdir_p+0x8c>
mov    -0x8(%rbp),%rdi
call   1080 <strdupa@plt>
mov    %eax,%edi
call   1050 <dirname@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <mkdir_p@plt>
mov    -0x8(%rbp),%rdi
mov    $0x1c0,%esi
call   1030 <mkdir@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11e7 <mkdir_p+0x87>
mov    0x2e13(%rip),%rax
mov    (%rax),%rax
mov    0x2e11(%rip),%rcx
cmp    (%rcx),%rax
je     11e7 <mkdir_p+0x87>
mov    0x2df9(%rip),%rax
mov    (%rax),%rdi
call   1040 <assert_perror@plt>
jmp    11ec <mkdir_p+0x8c>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mkdir_p>:
push   %rbx
mov    %rdi,%rbx
lea    0xe95(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11b3 <mkdir_p+0x53>
mov    %rbx,%rdi
call   1080 <strdupa@plt>
mov    %eax,%edi
call   1050 <dirname@plt>
mov    %rax,%rdi
call   1070 <mkdir_p@plt>
mov    %rbx,%rdi
mov    $0x1c0,%esi
call   1030 <mkdir@plt>
test   %eax,%eax
jns    11b3 <mkdir_p+0x53>
mov    0x2e34(%rip),%rax
mov    (%rax),%rdi
mov    0x2e32(%rip),%rax
cmp    (%rax),%rdi
jne    11b5 <mkdir_p+0x55>
pop    %rbx
ret
pop    %rbx
jmp    1040 <assert_perror@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
@errno = global i64 0
@EEXIST = global i64 0
define void @mkdir_p(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %25
8: ; preds = %1
%9 = load i8*, i8** %2
%10 = call i32 @strdupa(i8* %9)
%11 = call i8* @dirname(i32 %10)
store i8* %11, i8** %3
%12 = load i8*, i8** %3
%13 = load i8*, i8** %2
%14 = call i32 @mkdir(i8* %13, i32 448)
store i32 %14, i32* %4
%15 = load i32, i32* %4
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %24
17: ; preds = %8
%18 = load i64, i64* @errno
%19 = load i64, i64* @EEXIST
%20 = icmp ne i64 %18, %19
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = load i64, i64* @errno
%23 = call i32 @assert_perror(i64 %22)
br label %24
24: ; preds = %21, %17, %8
br label %25
25: ; preds = %24, %1
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
@errno = global i64 0
@EEXIST = global i64 0
define void @mkdir_p(i8* %0) {
%2 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i64 %2, 0
br i1 %3, label %15, label %4
4: ; preds = %1
%5 = tail call i32 @strdupa(i8* %0)
%6 = tail call i8* @dirname(i32 %5)
tail call void @mkdir_p(i8* %6)
%7 = tail call i32 @mkdir(i8* %0, i32 448)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %15
9: ; preds = %4
%10 = load i64, i64* @errno
%11 = load i64, i64* @EEXIST
%12 = icmp eq i64 %10, %11
br i1 %12, label %15, label %13
13: ; preds = %9
%14 = tail call i32 @assert_perror(i64 %10)
br label %15
15: ; preds = %4, %9, %13, %1
ret void
}