#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 scalar_t__ mode_t;

/* Variables and functions */
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ mkdir(char *, scalar_t__);
char *strdup(char const *);
size_t strlen(char *);
scalar_t__ umask(scalar_t__);
void mkpath(const char *path) {
  char *pathcp = strdup(path);
  size_t len = strlen(pathcp);
  mode_t mask = umask(0);
  umask(mask);
  mask = 0777 - mask;
  int i;
  for (i = 1; i < len; ++i) {
    if (pathcp[i] == '/') {
      pathcp[i] = 0;
      mkdir(pathcp, mask);
      pathcp[i] = '/';
    }
  }
  free(pathcp);
}


x86 assembly (clang, -O0):
<mkpath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <umask@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <umask@plt>
mov    $0x1ff,%eax
sub    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x1,-0x24(%rbp)
movslq -0x24(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11fb <mkpath+0xab>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    11e8 <mkpath+0x98>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <mkdir@plt>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x2f,(%rax,%rcx,1)
jmp    11ed <mkpath+0x9d>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11a0 <mkpath+0x50>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mkpath>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
call   1070 <strdup@plt>
mov    %rax,%r13
mov    %rax,%rdi
call   1050 <strlen@plt>
mov    %rax,%r14
xor    %edi,%edi
call   1060 <umask@plt>
mov    %rax,%r12
mov    %rax,%rdi
call   1060 <umask@plt>
cmp    $0x2,%r14
jb     11ca <mkpath+0x7a>
mov    $0x1ff,%r15d
sub    %r12,%r15
mov    $0x1,%ebx
jmp    11a9 <mkpath+0x59>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%rbx
cmp    %rbx,%r14
je     11ca <mkpath+0x7a>
cmpb   $0x2f,0x0(%r13,%rbx,1)
jne    11a0 <mkpath+0x50>
movb   $0x0,0x0(%r13,%rbx,1)
mov    %r13,%rdi
mov    %r15,%rsi
call   1040 <mkdir@plt>
movb   $0x2f,0x0(%r13,%rbx,1)
jmp    11a0 <mkpath+0x50>
mov    %r13,%rdi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <free@plt>

LLVM IR (-O0):
define void @mkpath(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i32
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = call i8* @strdup(i8* %7)
store i8* %8, i8** %3
%9 = load i8*, i8** %3
%10 = call i64 @strlen(i8* %9)
store i64 %10, i64* %4
%11 = call i64 @umask(i64 0)
store i64 %11, i64* %5
%12 = load i64, i64* %5
%13 = call i64 @umask(i64 %12)
%14 = load i64, i64* %5
%15 = sub nsw i64 511, %14
store i64 %15, i64* %5
store i32 1, i32* %6
br label %16
16: ; preds = %42, %1
%17 = load i32, i32* %6
%18 = sext i32 %17 to i64
%19 = load i64, i64* %4
%20 = icmp ult i64 %18, %19
br i1 %20, label %21, label %45
21: ; preds = %16
%22 = load i8*, i8** %3
%23 = load i32, i32* %6
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 47
br i1 %28, label %29, label %41
29: ; preds = %21
%30 = load i8*, i8** %3
%31 = load i32, i32* %6
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
store i8 0, i8* %33
%34 = load i8*, i8** %3
%35 = load i64, i64* %5
%36 = call i32 @mkdir(i8* %34, i64 %35)
%37 = load i8*, i8** %3
%38 = load i32, i32* %6
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
store i8 47, i8* %40
br label %41
41: ; preds = %29, %21
br label %42
42: ; preds = %41
%43 = load i32, i32* %6
%44 = add nsw i32 %43, 1
store i32 %44, i32* %6
br label %16
45: ; preds = %16
%46 = load i8*, i8** %3
%47 = call i32 @free(i8* %46)
ret void
}

LLVM IR (-O2):
define void @mkpath(i8* nocapture %0) {
%2 = tail call i8* @strdup(i8* %0)
%3 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%4 = tail call i64 @umask(i64 0)
%5 = tail call i64 @umask(i64 %4)
%6 = sub nsw i64 511, %4
%7 = icmp ugt i64 %3, 1
br i1 %7, label %8, label %18
8: ; preds = %1, %15
%9 = phi i64 [ %16, %15 ], [ 1, %1 ]
%10 = getelementptr inbounds i8, i8* %2, i64 %9
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 47
br i1 %12, label %13, label %15
13: ; preds = %8
store i8 0, i8* %10
%14 = tail call i32 @mkdir(i8* %2, i64 %6)
store i8 47, i8* %10
br label %15
15: ; preds = %8, %13
%16 = add nuw i64 %9, 1
%17 = icmp eq i64 %16, %3
br i1 %17, label %18, label %8
18: ; preds = %15, %1
%19 = tail call i32 @free(i8* %2)
ret void
}