#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 S_IRGRP;
int S_IROTH;
int S_IRWXU;
int S_IXGRP;
int S_IXOTH;
int /*<<< orphan*/ free(char *);
char *malloc(size_t);
int mkdir(char *, int);
int /*<<< orphan*/ snprintf(char *, size_t, char *, char *, char *, char *);
int strlen(char *);
int create_directory(char *output_dir, char *slug) {
  if (!slug) {
    return -1;
  }
  size_t len = strlen(output_dir) + strlen(slug) + 2;
  char *path = malloc(len);
  if (!path) {
    return -1;
  }
  snprintf(path, len, "%s%s%s", output_dir, "/", slug);
  mkdir(output_dir, S_IRWXU | S_IRGRP | S_IROTH | S_IXOTH | S_IXGRP);
  const int r = mkdir(path, S_IRWXU | S_IRGRP | S_IROTH | S_IXOTH | S_IXGRP);
  free(path);
  return r;
}


x86 assembly (clang, -O0):
<create_directory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1177 <create_directory+0x27>
movl   $0xffffffff,-0x4(%rbp)
jmp    1261 <create_directory+0x111>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
add    %ecx,%eax
add    $0x2,%eax
cltq
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11c0 <create_directory+0x70>
movl   $0xffffffff,-0x4(%rbp)
jmp    1261 <create_directory+0x111>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%r9
lea    0xe29(%rip),%rdx
lea    0xe29(%rip),%r8
call   1060 <snprintf@plt>
mov    -0x10(%rbp),%rdi
mov    0x2dfa(%rip),%rax
mov    (%rax),%esi
mov    0x2dd1(%rip),%rax
or     (%rax),%esi
mov    0x2dc0(%rip),%rax
or     (%rax),%esi
mov    0x2dd7(%rip),%rax
or     (%rax),%esi
mov    0x2dc6(%rip),%rax
or     (%rax),%esi
call   1040 <mkdir@plt>
mov    -0x28(%rbp),%rdi
mov    0x2dc4(%rip),%rax
mov    (%rax),%esi
mov    0x2d9b(%rip),%rax
or     (%rax),%esi
mov    0x2d8a(%rip),%rax
or     (%rax),%esi
mov    0x2da1(%rip),%rax
or     (%rax),%esi
mov    0x2d90(%rip),%rax
or     (%rax),%esi
call   1040 <mkdir@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_directory>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rsi,%rsi
je     121c <create_directory+0xcc>
mov    %rsi,%rbx
mov    %rdi,%r14
call   1050 <strlen@plt>
mov    %eax,%r15d
mov    %rbx,%rdi
call   1050 <strlen@plt>
add    %r15d,%eax
add    $0x2,%eax
movslq %eax,%r12
mov    %r12,%rdi
call   1070 <malloc@plt>
test   %rax,%rax
je     121c <create_directory+0xcc>
mov    %rax,%r15
lea    0xe62(%rip),%rdx
lea    0xe62(%rip),%r8
mov    %rax,%rdi
mov    %r12,%rsi
mov    %r14,%rcx
mov    %rbx,%r9
call   1060 <snprintf@plt>
mov    0x2e2b(%rip),%rax
mov    0x2e04(%rip),%rbx
mov    (%rbx),%esi
or     (%rax),%esi
mov    0x2df1(%rip),%r13
or     0x0(%r13),%esi
mov    0x2e06(%rip),%rbp
or     0x0(%rbp),%esi
mov    0x2df4(%rip),%r12
or     (%r12),%esi
mov    %r14,%rdi
call   1040 <mkdir@plt>
mov    (%rbx),%esi
mov    0x2def(%rip),%rax
or     (%rax),%esi
or     0x0(%r13),%esi
or     0x0(%rbp),%esi
or     (%r12),%esi
mov    %r15,%rdi
call   1040 <mkdir@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1030 <free@plt>
mov    %ebx,%eax
jmp    1221 <create_directory+0xd1>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%s%s%s\00"
@.str.1 = [2 x i8] c"/\00"
@S_IRWXU = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@S_IXOTH = global i32 0
@S_IXGRP = global i32 0
define i32 @create_directory(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %5
%10 = icmp ne i8* %9, null
br i1 %10, label %12, label %11
11: ; preds = %2
store i32 -1, i32* %3
br label %56
12: ; preds = %2
%13 = load i8*, i8** %4
%14 = call i32 @strlen(i8* %13)
%15 = load i8*, i8** %5
%16 = call i32 @strlen(i8* %15)
%17 = add nsw i32 %14, %16
%18 = add nsw i32 %17, 2
%19 = sext i32 %18 to i64
store i64 %19, i64* %6
%20 = load i64, i64* %6
%21 = call i8* @malloc(i64 %20)
store i8* %21, i8** %7
%22 = load i8*, i8** %7
%23 = icmp ne i8* %22, null
br i1 %23, label %25, label %24
24: ; preds = %12
store i32 -1, i32* %3
br label %56
25: ; preds = %12
%26 = load i8*, i8** %7
%27 = load i64, i64* %6
%28 = load i8*, i8** %4
%29 = load i8*, i8** %5
%30 = call i32 @snprintf(i8* %26, i64 %27, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %29)
%31 = load i8*, i8** %4
%32 = load i32, i32* @S_IRWXU
%33 = load i32, i32* @S_IRGRP
%34 = or i32 %32, %33
%35 = load i32, i32* @S_IROTH
%36 = or i32 %34, %35
%37 = load i32, i32* @S_IXOTH
%38 = or i32 %36, %37
%39 = load i32, i32* @S_IXGRP
%40 = or i32 %38, %39
%41 = call i32 @mkdir(i8* %31, i32 %40)
%42 = load i8*, i8** %7
%43 = load i32, i32* @S_IRWXU
%44 = load i32, i32* @S_IRGRP
%45 = or i32 %43, %44
%46 = load i32, i32* @S_IROTH
%47 = or i32 %45, %46
%48 = load i32, i32* @S_IXOTH
%49 = or i32 %47, %48
%50 = load i32, i32* @S_IXGRP
%51 = or i32 %49, %50
%52 = call i32 @mkdir(i8* %42, i32 %51)
store i32 %52, i32* %8
%53 = load i8*, i8** %7
%54 = call i32 @free(i8* %53)
%55 = load i32, i32* %8
store i32 %55, i32* %3
br label %56
56: ; preds = %25, %24, %11
%57 = load i32, i32* %3
ret i32 %57
}

LLVM IR (-O2):
@.str = [7 x i8] c"%s%s%s\00"
@.str.1 = [2 x i8] c"/\00"
@S_IRWXU = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@S_IXOTH = global i32 0
@S_IXGRP = global i32 0
define i32 @create_directory(i8* %0, i8* %1) {
%3 = icmp eq i8* %1, null
br i1 %3, label %35, label %4
4: ; preds = %2
%5 = tail call i32 @strlen(i8* %0)
%6 = tail call i32 @strlen(i8* %1)
%7 = add i32 %5, 2
%8 = add i32 %7, %6
%9 = sext i32 %8 to i64
%10 = tail call i8* @malloc(i64 %9)
%11 = icmp eq i8* %10, null
br i1 %11, label %35, label %12
12: ; preds = %4
%13 = tail call i32 @snprintf(i8* %10, i64 %9, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%14 = load i32, i32* @S_IRWXU
%15 = load i32, i32* @S_IRGRP
%16 = or i32 %15, %14
%17 = load i32, i32* @S_IROTH
%18 = or i32 %16, %17
%19 = load i32, i32* @S_IXOTH
%20 = or i32 %18, %19
%21 = load i32, i32* @S_IXGRP
%22 = or i32 %20, %21
%23 = tail call i32 @mkdir(i8* %0, i32 %22)
%24 = load i32, i32* @S_IRWXU
%25 = load i32, i32* @S_IRGRP
%26 = or i32 %25, %24
%27 = load i32, i32* @S_IROTH
%28 = or i32 %26, %27
%29 = load i32, i32* @S_IXOTH
%30 = or i32 %28, %29
%31 = load i32, i32* @S_IXGRP
%32 = or i32 %30, %31
%33 = tail call i32 @mkdir(i8* %10, i32 %32)
%34 = tail call i32 @free(i8* %10)
br label %35
35: ; preds = %12, %4, %2
%36 = phi i32 [ -1, %2 ], [ %33, %12 ], [ -1, %4 ]
ret i32 %36
}