#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 */
typedef int mode_t;

/* Variables and functions */
scalar_t__ EEXIST;
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, scalar_t__, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ memcpy(char *, char const *, int const);
int mkdir(char *, int);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
scalar_t__ xcmalloc(int const);
int c_mkdir_(const char *dirname, const int *length) {
  int retval = -1;
  mode_t mode = 0777;
  char *ldir = (char *)xcmalloc((*length) + 1);
  memcpy(ldir, dirname, *length);
  ldir[*length] = '\0';
  retval = mkdir(ldir, mode);
  if (retval == -1 && errno != EEXIST)
    fprintf(stderr, "mkdir fail: [%d] %s\n", errno, strerror(errno));
  free(ldir);
  return retval;
}


x86 assembly (clang, -O0):
<c_mkdir_>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
movl   $0x1ff,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
add    $0x1,%edi
call   1070 <xcmalloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
call   1060 <memcpy@plt>
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq (%rcx),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1040 <mkdir@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1224 <c_mkdir_+0xc4>
mov    0x2dfe(%rip),%rax
mov    (%rax),%rax
mov    0x2e04(%rip),%rcx
cmp    (%rcx),%rax
je     1224 <c_mkdir_+0xc4>
mov    0x2dec(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2dd8(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    0x2dca(%rip),%rax
mov    (%rax),%rdi
call   1080 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rdx
mov    %rax,%rcx
lea    0xde1(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<c_mkdir_>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbp
mov    %rdi,%r14
mov    (%rsi),%edi
add    $0x1,%edi
call   1070 <xcmalloc@plt>
mov    %rax,%rbx
mov    0x0(%rbp),%edx
mov    %rax,%rdi
mov    %r14,%rsi
call   1060 <memcpy@plt>
movslq 0x0(%rbp),%rax
movb   $0x0,(%rbx,%rax,1)
mov    %rbx,%rdi
mov    $0x1ff,%esi
call   1040 <mkdir@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    11e1 <c_mkdir_+0x81>
mov    0x2e25(%rip),%rax
mov    (%rax),%r14
mov    0x2e2b(%rip),%rax
cmp    (%rax),%r14
je     11e1 <c_mkdir_+0x81>
mov    0x2e17(%rip),%rax
mov    (%rax),%r15d
mov    %r14,%rdi
call   1080 <strerror@plt>
lea    0xe2d(%rip),%rsi
mov    %r15d,%edi
mov    %r14,%rdx
mov    %rax,%rcx
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
@EEXIST = global i64 0
@stderr = global i32 0
@.str = [21 x i8] c"mkdir fail: [%d] %s\0A\00"
define i32 @c_mkdir_(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %3
store i32* %1, i32** %4
store i32 -1, i32* %5
store i32 511, i32* %6
%8 = load i32*, i32** %4
%9 = load i32, i32* %8
%10 = add nsw i32 %9, 1
%11 = call i64 @xcmalloc(i32 %10)
%12 = inttoptr i64 %11 to i8*
store i8* %12, i8** %7
%13 = load i8*, i8** %7
%14 = load i8*, i8** %3
%15 = load i32*, i32** %4
%16 = load i32, i32* %15
%17 = call i32 @memcpy(i8* %13, i8* %14, i32 %16)
%18 = load i8*, i8** %7
%19 = load i32*, i32** %4
%20 = load i32, i32* %19
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %18, i64 %21
store i8 0, i8* %22
%23 = load i8*, i8** %7
%24 = load i32, i32* %6
%25 = call i32 @mkdir(i8* %23, i32 %24)
store i32 %25, i32* %5
%26 = load i32, i32* %5
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %38
28: ; preds = %2
%29 = load i64, i64* @errno
%30 = load i64, i64* @EEXIST
%31 = icmp ne i64 %29, %30
br i1 %31, label %32, label %38
32: ; preds = %28
%33 = load i32, i32* @stderr
%34 = load i64, i64* @errno
%35 = load i64, i64* @errno
%36 = call i8* @strerror(i64 %35)
%37 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i64 %34, i8* %36)
br label %38
38: ; preds = %32, %28, %2
%39 = load i8*, i8** %7
%40 = call i32 @free(i8* %39)
%41 = load i32, i32* %5
ret i32 %41
}

LLVM IR (-O2):
@errno = global i64 0
@EEXIST = global i64 0
@stderr = global i32 0
@.str = [21 x i8] c"mkdir fail: [%d] %s\0A\00"
define i32 @c_mkdir_(i8* %0, i32* nocapture %1) {
%3 = load i32, i32* %1
%4 = add nsw i32 %3, 1
%5 = tail call i64 @xcmalloc(i32 %4)
%6 = inttoptr i64 %5 to i8*
%7 = load i32, i32* %1
%8 = tail call i32 @memcpy(i8* %6, i8* %0, i32 %7)
%9 = load i32, i32* %1
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %6, i64 %10
store i8 0, i8* %11
%12 = tail call i32 @mkdir(i8* %6, i32 511)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %22
14: ; preds = %2
%15 = load i64, i64* @errno
%16 = load i64, i64* @EEXIST
%17 = icmp eq i64 %15, %16
br i1 %17, label %22, label %18
18: ; preds = %14
%19 = load i32, i32* @stderr
%20 = tail call i8* @strerror(i64 %15)
%21 = tail call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i64 %15, i8* %20)
br label %22
22: ; preds = %18, %14, %2
%23 = tail call i32 @free(i8* %6)
ret i32 %12
}