#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*/ fprintf(int /*<<< orphan*/, char *, char *);
int mkdir(char *, int);
int /*<<< orphan*/ stderr;
int strlen(char *);
char *strrchr(char *, char);
void create_dir(char *pathname, int mode) {
  char *p;
  int r;
  if (pathname[strlen(pathname) - 1] == '/')
    pathname[strlen(pathname) - 1] = '\0';
  r = mkdir(pathname, mode);
  if (r != 0) {
    p = strrchr(pathname, '/');
    if (p != NULL) {
      *p = '\0';
      create_dir(pathname, 0755);
      *p = '/';
      r = mkdir(pathname, mode);
    }
  }
  if (r != 0)
    fprintf(stderr, "Could not create directory %s\n", pathname);
}


x86 assembly (clang, -O0):
<create_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    11aa <create_dir+0x5a>
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <mkdir@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1210 <create_dir+0xc0>
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     120b <create_dir+0xbb>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
mov    $0x1ed,%esi
call   1070 <create_dir@plt>
mov    -0x18(%rbp),%rax
movb   $0x2f,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <mkdir@plt>
mov    %eax,-0x1c(%rbp)
jmp    1210 <create_dir+0xc0>
cmpl   $0x0,-0x1c(%rbp)
je     1233 <create_dir+0xe3>
mov    0x2dbf(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xdd2(%rip),%rsi
call   1060 <fprintf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_dir>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %rdi,%rbx
call   1040 <strlen@plt>
cltq
cmpb   $0x2f,-0x1(%rax,%rbx,1)
jne    1177 <create_dir+0x27>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %rbx,%rdi
mov    %r14d,%esi
call   1030 <mkdir@plt>
test   %eax,%eax
je     11da <create_dir+0x8a>
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
je     11be <create_dir+0x6e>
mov    %rax,%rbp
movb   $0x0,(%rax)
mov    %rbx,%rdi
mov    $0x1ed,%esi
call   1070 <create_dir@plt>
movb   $0x2f,0x0(%rbp)
mov    %rbx,%rdi
mov    %r14d,%esi
call   1030 <mkdir@plt>
test   %eax,%eax
je     11da <create_dir+0x8a>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
lea    0xe32(%rip),%rsi
mov    %rbx,%rdx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1060 <fprintf@plt>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [31 x i8] c"Could not create directory %s\0A\00"
define void @create_dir(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = load i8*, i8** %3
%8 = load i8*, i8** %3
%9 = call i32 @strlen(i8* %8)
%10 = sub nsw i32 %9, 1
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %7, i64 %11
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 47
br i1 %15, label %16, label %23
16: ; preds = %2
%17 = load i8*, i8** %3
%18 = load i8*, i8** %3
%19 = call i32 @strlen(i8* %18)
%20 = sub nsw i32 %19, 1
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %17, i64 %21
store i8 0, i8* %22
br label %23
23: ; preds = %16, %2
%24 = load i8*, i8** %3
%25 = load i32, i32* %4
%26 = call i32 @mkdir(i8* %24, i32 %25)
store i32 %26, i32* %6
%27 = load i32, i32* %6
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %42
29: ; preds = %23
%30 = load i8*, i8** %3
%31 = call i8* @strrchr(i8* %30, i8 signext 47)
store i8* %31, i8** %5
%32 = load i8*, i8** %5
%33 = icmp ne i8* %32, null
br i1 %33, label %34, label %41
34: ; preds = %29
%35 = load i8*, i8** %5
store i8 0, i8* %35
%36 = load i8*, i8** %3
%37 = load i8*, i8** %5
store i8 47, i8* %37
%38 = load i8*, i8** %3
%39 = load i32, i32* %4
%40 = call i32 @mkdir(i8* %38, i32 %39)
store i32 %40, i32* %6
br label %41
41: ; preds = %34, %29
br label %42
42: ; preds = %41, %23
%43 = load i32, i32* %6
%44 = icmp ne i32 %43, 0
br i1 %44, label %45, label %49
45: ; preds = %42
%46 = load i32, i32* @stderr
%47 = load i8*, i8** %3
%48 = call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %47)
br label %49
49: ; preds = %45, %42
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [31 x i8] c"Could not create directory %s\0A\00"
define void @create_dir(i8* %0, i32 %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = add nsw i32 %3, -1
%5 = sext i32 %4 to i64
%6 = getelementptr inbounds i8, i8* %0, i64 %5
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 47
br i1 %8, label %9, label %14
9: ; preds = %2
%10 = tail call i32 @strlen(i8* %0)
%11 = add nsw i32 %10, -1
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %0, i64 %12
store i8 0, i8* %13
br label %14
14: ; preds = %9, %2
%15 = tail call i32 @mkdir(i8* %0, i32 %1)
%16 = icmp eq i32 %15, 0
br i1 %16, label %26, label %17
17: ; preds = %14
%18 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%19 = icmp eq i8* %18, null
br i1 %19, label %23, label %20
20: ; preds = %17
store i8 0, i8* %18
tail call void @create_dir(i8* %0, i32 493)
store i8 47, i8* %18
%21 = tail call i32 @mkdir(i8* %0, i32 %1)
%22 = icmp eq i32 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %17, %20
%24 = load i32, i32* @stderr
%25 = tail call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %26
26: ; preds = %14, %23, %20
ret void
}