#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 /*<<< orphan*/ uid_t;
typedef int /*<<< orphan*/ tmp;
typedef int /*<<< orphan*/ gid_t;

/* Variables and functions */
int PATH_MAX;
int mkdir_as(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *);
size_t strlen(char *);
int mkdir_p_as(const char *dir, uid_t uid, gid_t gid) {
  char tmp[PATH_MAX];
  char *p = NULL;
  size_t len;
  int rv;
  snprintf(tmp, sizeof(tmp), "%s", dir);
  len = strlen(tmp);
  if (tmp[len - 1] == '/')
    tmp[len - 1] = 0;
  for (p = tmp + 1; *p; p++) {
    if (*p == '/') {
      *p = 0;
      rv = mkdir_as(tmp, uid, gid);
      if (rv == -1) {
        return rv;
      }
      *p = '/';
    }
  }
  return mkdir_as(tmp, uid, gid);
}


x86 assembly (clang, -O0):
<mkdir_p_as>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    0x2ea7(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x48(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    %eax,%esi
mov    -0x10(%rbp),%rcx
lea    0xe7d(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x48(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x48(%rbp),%rax
mov    %rcx,-0x38(%rbp)
mov    -0x38(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    11c1 <mkdir_p_as+0x91>
mov    -0x48(%rbp),%rax
mov    -0x38(%rbp),%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmpb   $0x0,(%rax)
je     123c <mkdir_p_as+0x10c>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    1226 <mkdir_p_as+0xf6>
mov    -0x48(%rbp),%rdi
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1050 <mkdir_as@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0xffffffff,-0x3c(%rbp)
jne    121f <mkdir_p_as+0xef>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x40(%rbp)
jmp    1255 <mkdir_p_as+0x125>
mov    -0x30(%rbp),%rax
movb   $0x2f,(%rax)
jmp    122b <mkdir_p_as+0xfb>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    11cd <mkdir_p_as+0x9d>
mov    -0x48(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1050 <mkdir_as@plt>
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x40(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mkdir_p_as>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r14d
mov    %esi,%r15d
mov    %rdi,%rcx
mov    0x2ea5(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%r12
mov    %rsi,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
lea    0xe98(%rip),%rdx
mov    %r12,%rdi
call   1040 <snprintf@plt>
mov    %r12,%rdi
call   1030 <strlen@plt>
cmpb   $0x2f,-0x1(%rax,%r12,1)
jne    1186 <mkdir_p_as+0x56>
movb   $0x0,-0x1(%r12,%rax,1)
lea    0x1(%r12),%rbx
nopl   0x0(%rax,%rax,1)
movzbl (%rbx),%eax
cmp    $0x2f,%al
je     11b0 <mkdir_p_as+0x80>
test   %al,%al
je     11cf <mkdir_p_as+0x9f>
add    $0x1,%rbx
jmp    1190 <mkdir_p_as+0x60>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movb   $0x0,(%rbx)
mov    %r12,%rdi
mov    %r15d,%esi
mov    %r14d,%edx
call   1050 <mkdir_as@plt>
cmp    $0xffffffff,%eax
je     11df <mkdir_p_as+0xaf>
movb   $0x2f,(%rbx)
add    $0x1,%rbx
jmp    1190 <mkdir_p_as+0x60>
mov    %r12,%rdi
mov    %r15d,%esi
mov    %r14d,%edx
call   1050 <mkdir_as@plt>
jmp    11e4 <mkdir_p_as+0xb4>
mov    $0xffffffff,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [3 x i8] c"%s\00"
define i32 @mkdir_p_as(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%14 = load i32, i32* @PATH_MAX
%15 = zext i32 %14 to i64
%16 = call i8* @llvm.stacksave()
store i8* %16, i8** %8
%17 = alloca i8, i64 %15
store i64 %15, i64* %9
store i8* null, i8** %10
%18 = trunc i64 %15 to i32
%19 = load i8*, i8** %5
%20 = call i32 @snprintf(i8* %17, i32 %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = call i64 @strlen(i8* %17)
store i64 %21, i64* %11
%22 = load i64, i64* %11
%23 = sub i64 %22, 1
%24 = getelementptr inbounds i8, i8* %17, i64 %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 47
br i1 %27, label %28, label %32
28: ; preds = %3
%29 = load i64, i64* %11
%30 = sub i64 %29, 1
%31 = getelementptr inbounds i8, i8* %17, i64 %30
store i8 0, i8* %31
br label %32
32: ; preds = %28, %3
%33 = getelementptr inbounds i8, i8* %17, i64 1
store i8* %33, i8** %10
br label %34
34: ; preds = %55, %32
%35 = load i8*, i8** %10
%36 = load i8, i8* %35
%37 = icmp ne i8 %36, 0
br i1 %37, label %38, label %58
38: ; preds = %34
%39 = load i8*, i8** %10
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp eq i32 %41, 47
br i1 %42, label %43, label %54
43: ; preds = %38
%44 = load i8*, i8** %10
store i8 0, i8* %44
%45 = load i32, i32* %6
%46 = load i32, i32* %7
%47 = call i32 @mkdir_as(i8* %17, i32 %45, i32 %46)
store i32 %47, i32* %12
%48 = load i32, i32* %12
%49 = icmp eq i32 %48, -1
br i1 %49, label %50, label %52
50: ; preds = %43
%51 = load i32, i32* %12
store i32 %51, i32* %4
store i32 1, i32* %13
br label %62
52: ; preds = %43
%53 = load i8*, i8** %10
store i8 47, i8* %53
br label %54
54: ; preds = %52, %38
br label %55
55: ; preds = %54
%56 = load i8*, i8** %10
%57 = getelementptr inbounds i8, i8* %56, i32 1
store i8* %57, i8** %10
br label %34
58: ; preds = %34
%59 = load i32, i32* %6
%60 = load i32, i32* %7
%61 = call i32 @mkdir_as(i8* %17, i32 %59, i32 %60)
store i32 %61, i32* %4
store i32 1, i32* %13
br label %62
62: ; preds = %58, %50
%63 = load i8*, i8** %8
%64 = load i32, i32* %4
ret i32 %64
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [3 x i8] c"%s\00"
define i32 @mkdir_p_as(i8* %0, i32 %1, i32 %2) {
%4 = load i32, i32* @PATH_MAX
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = call i32 @snprintf(i8* %6, i32 %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %0)
%8 = call i64 @strlen(i8* %6)
%9 = add i64 %8, -1
%10 = getelementptr inbounds i8, i8* %6, i64 %9
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 47
br i1 %12, label %13, label %14
13: ; preds = %3
store i8 0, i8* %10
br label %14
14: ; preds = %13, %3
br label %15
15: ; preds = %19, %14
%16 = phi i8* [ %6, %14 ], [ %17, %19 ]
%17 = getelementptr inbounds i8, i8* %16, i64 1
%18 = load i8, i8* %17
switch i8 %18, label %19 [
i8 0, label %24
i8 47, label %20
]
19: ; preds = %15, %23
br label %15
20: ; preds = %15
store i8 0, i8* %17
%21 = call i32 @mkdir_as(i8* %6, i32 %1, i32 %2)
%22 = icmp eq i32 %21, -1
br i1 %22, label %26, label %23
23: ; preds = %20
store i8 47, i8* %17
br label %19
24: ; preds = %15
%25 = call i32 @mkdir_as(i8* %6, i32 %1, i32 %2)
br label %26
26: ; preds = %20, %24
%27 = phi i32 [ %25, %24 ], [ -1, %20 ]
ret i32 %27
}