#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__ calloc(int, long);
int f77_return(int);
int /*<<< orphan*/ free(void *);
int /*<<< orphan*/ memcpy(void *, void *, long);
int mkdir(char *, int);
int umask(int);
int mkdir_(char *directory, long int dir_len) {
  char *dir;
  char *cp;
  mode_t old_mode;
  mode_t new_mode;
  int stat;
  dir = (char *)calloc(1, dir_len + 1);
  if (dir != (char *)NULL) {
    new_mode = 0000000;
    old_mode = umask(new_mode);
    new_mode = old_mode;
    old_mode = umask(new_mode);
    (void)memcpy((void *)dir, (void *)directory, dir_len);
    cp = (char *)&dir[dir_len];
    while ((*cp == ' ') || (*cp == '\t') || (*cp == '\0')) {
      --cp;
    }
    ++cp;
    *cp = '\0';
    stat = mkdir(dir, new_mode);
  } else {
    stat = -1;
  }
  (void)free((void *)dir);
  return f77_return(stat);
}


x86 assembly (clang, -O0):
<mkdir_>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
add    $0x1,%rsi
mov    $0x1,%edi
call   1060 <calloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1253 <mkdir_+0xf3>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%edi
call   1070 <umask@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%edi
call   1070 <umask@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1080 <memcpy@plt>
mov    -0x18(%rbp),%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0x20,%ecx
mov    %al,-0x2d(%rbp)
je     120b <mkdir_+0xab>
mov    -0x20(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0x9,%ecx
mov    %al,-0x2d(%rbp)
je     120b <mkdir_+0xab>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
sete   %al
mov    %al,-0x2d(%rbp)
mov    -0x2d(%rbp),%al
test   $0x1,%al
jne    121b <mkdir_+0xbb>
jmp    122c <mkdir_+0xcc>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    11d1 <mkdir_+0x71>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%esi
call   1040 <mkdir@plt>
mov    %eax,-0x2c(%rbp)
jmp    125a <mkdir_+0xfa>
movl   $0xffffffff,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x2c(%rbp),%edi
call   1050 <f77_return@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mkdir_>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbp
mov    %rdi,%r15
add    $0x1,%rsi
mov    $0x1,%edi
call   1060 <calloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11e8 <mkdir_+0x88>
xor    %edi,%edi
call   1070 <umask@plt>
mov    %eax,%r14d
mov    %eax,%edi
call   1070 <umask@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %rbp,%rdx
call   1080 <memcpy@plt>
lea    (%rbx,%rbp,1),%rax
add    $0x1,%rax
movabs $0x100000201,%rcx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl -0x1(%rax),%edx
cmp    $0x20,%rdx
ja     11d6 <mkdir_+0x76>
bt     %rdx,%rcx
jae    11d6 <mkdir_+0x76>
add    $0xffffffffffffffff,%rax
jmp    11c0 <mkdir_+0x60>
movb   $0x0,(%rax)
mov    %rbx,%rdi
mov    %r14d,%esi
call   1040 <mkdir@plt>
mov    %eax,%ebp
jmp    11ed <mkdir_+0x8d>
mov    $0xffffffff,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <f77_return@plt>

LLVM IR (-O0):
define i32 @mkdir_(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %3
store i64 %1, i64* %4
%10 = load i64, i64* %4
%11 = add nsw i64 %10, 1
%12 = call i64 @calloc(i32 1, i64 %11)
%13 = inttoptr i64 %12 to i8*
store i8* %13, i8** %5
%14 = load i8*, i8** %5
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %56
16: ; preds = %2
store i32 0, i32* %8
%17 = load i32, i32* %8
%18 = call i32 @umask(i32 %17)
store i32 %18, i32* %7
%19 = load i32, i32* %7
store i32 %19, i32* %8
%20 = load i32, i32* %8
%21 = call i32 @umask(i32 %20)
store i32 %21, i32* %7
%22 = load i8*, i8** %5
%23 = load i8*, i8** %3
%24 = load i64, i64* %4
%25 = call i32 @memcpy(i8* %22, i8* %23, i64 %24)
%26 = load i8*, i8** %5
%27 = load i64, i64* %4
%28 = getelementptr inbounds i8, i8* %26, i64 %27
store i8* %28, i8** %6
br label %29
29: ; preds = %46, %16
%30 = load i8*, i8** %6
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 32
br i1 %33, label %44, label %34
34: ; preds = %29
%35 = load i8*, i8** %6
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 9
br i1 %38, label %44, label %39
39: ; preds = %34
%40 = load i8*, i8** %6
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = icmp eq i32 %42, 0
br label %44
44: ; preds = %39, %34, %29
%45 = phi i1 [ true, %34 ], [ true, %29 ], [ %43, %39 ]
br i1 %45, label %46, label %49
46: ; preds = %44
%47 = load i8*, i8** %6
%48 = getelementptr inbounds i8, i8* %47, i32 -1
store i8* %48, i8** %6
br label %29
49: ; preds = %44
%50 = load i8*, i8** %6
%51 = getelementptr inbounds i8, i8* %50, i32 1
store i8* %51, i8** %6
%52 = load i8*, i8** %6
store i8 0, i8* %52
%53 = load i8*, i8** %5
%54 = load i32, i32* %8
%55 = call i32 @mkdir(i8* %53, i32 %54)
store i32 %55, i32* %9
br label %57
56: ; preds = %2
store i32 -1, i32* %9
br label %57
57: ; preds = %56, %49
%58 = load i8*, i8** %5
%59 = call i32 @free(i8* %58)
%60 = load i32, i32* %9
%61 = call i32 @f77_return(i32 %60)
ret i32 %61
}

LLVM IR (-O2):
define i32 @mkdir_(i8* %0, i64 %1) {
%3 = add nsw i64 %1, 1
%4 = tail call i64 @calloc(i32 1, i64 %3)
%5 = inttoptr i64 %4 to i8*
%6 = icmp eq i64 %4, 0
br i1 %6, label %20, label %7
7: ; preds = %2
%8 = tail call i32 @umask(i32 0)
%9 = tail call i32 @umask(i32 %8)
%10 = tail call i32 @memcpy(i8* %5, i8* %0, i64 %1)
%11 = getelementptr inbounds i8, i8* %5, i64 %1
br label %12
12: ; preds = %15, %7
%13 = phi i8* [ %11, %7 ], [ %16, %15 ]
%14 = load i8, i8* %13
switch i8 %14, label %17 [
i8 32, label %15
i8 9, label %15
i8 0, label %15
]
15: ; preds = %12, %12, %12
%16 = getelementptr inbounds i8, i8* %13, i64 -1
br label %12
17: ; preds = %12
%18 = getelementptr inbounds i8, i8* %13, i64 1
store i8 0, i8* %18
%19 = tail call i32 @mkdir(i8* %5, i32 %8)
br label %20
20: ; preds = %2, %17
%21 = phi i32 [ %19, %17 ], [ -1, %2 ]
%22 = tail call i32 @free(i8* %5)
%23 = tail call i32 @f77_return(i32 %21)
ret i32 %23
}