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

/* Variables and functions */
int /*<<< orphan*/ mkdir(char *, int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *);
size_t strlen(char *);
void ut_mkdir_r(const char *dir, mode_t mode) {
  char tmp[256];
  char *p = NULL;
  size_t len;
  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;
        mkdir(tmp, mode);
        *p = '/';
      }
  }
  mkdir(tmp, mode);
}


x86 assembly (clang, -O0):
<ut_mkdir_r>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movq   $0x0,-0x118(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x100,%esi
lea    0xe9c(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x110(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x120(%rbp)
mov    -0x120(%rbp),%rax
sub    $0x1,%rax
movsbl -0x110(%rbp,%rax,1),%eax
ff
cmp    $0x2f,%eax
jne    1224 <ut_mkdir_r+0xf4>
mov    -0x120(%rbp),%rax
sub    $0x1,%rax
movb   $0x0,-0x110(%rbp,%rax,1)
lea    -0x110(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x118(%rbp)
mov    -0x118(%rbp),%rax
cmpb   $0x0,(%rax)
je     121f <ut_mkdir_r+0xef>
mov    -0x118(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    1203 <ut_mkdir_r+0xd3>
mov    -0x118(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x110(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <mkdir@plt>
mov    -0x118(%rbp),%rax
movb   $0x2f,(%rax)
jmp    1208 <ut_mkdir_r+0xd8>
mov    -0x118(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x118(%rbp)
jmp    11bd <ut_mkdir_r+0x8d>
jmp    1224 <ut_mkdir_r+0xf4>
lea    -0x110(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <mkdir@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ut_mkdir_r>:
push   %rbp
push   %r14
push   %rbx
sub    $0x100,%rsp
mov    %esi,%ebp
mov    %rdi,%rcx
lea    0xeb9(%rip),%rdx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x100,%esi
call   1050 <snprintf@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
cmpb   $0x2f,-0x1(%rax,%r14,1)
jne    119f <ut_mkdir_r+0x6f>
movb   $0x0,-0x1(%rsp,%rax,1)
lea    0x1(%rsp),%rbx
mov    %rsp,%r14
jmp    1194 <ut_mkdir_r+0x64>
cs nopw 0x0(%rax,%rax,1)
movb   $0x0,(%rbx)
mov    %r14,%rdi
mov    %ebp,%esi
call   1030 <mkdir@plt>
movb   $0x2f,(%rbx)
add    $0x1,%rbx
movzbl (%rbx),%eax
cmp    $0x2f,%al
je     1180 <ut_mkdir_r+0x50>
test   %al,%al
jne    1190 <ut_mkdir_r+0x60>
mov    %rsp,%rdi
mov    %ebp,%esi
call   1030 <mkdir@plt>
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
define void @ut_mkdir_r(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [256 x i8]
%6 = alloca i8*
%7 = alloca i64
store i8* %0, i8** %3
store i32 %1, i32* %4
store i8* null, i8** %6
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%9 = load i8*, i8** %3
%10 = call i32 @snprintf(i8* %8, i32 256, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%12 = call i64 @strlen(i8* %11)
store i64 %12, i64* %7
%13 = load i64, i64* %7
%14 = sub i64 %13, 1
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 %14
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 47
br i1 %18, label %19, label %45
19: ; preds = %2
%20 = load i64, i64* %7
%21 = sub i64 %20, 1
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 %21
store i8 0, i8* %22
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%24 = getelementptr inbounds i8, i8* %23, i64 1
store i8* %24, i8** %6
br label %25
25: ; preds = %41, %19
%26 = load i8*, i8** %6
%27 = load i8, i8* %26
%28 = icmp ne i8 %27, 0
br i1 %28, label %29, label %44
29: ; preds = %25
%30 = load i8*, i8** %6
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 47
br i1 %33, label %34, label %40
34: ; preds = %29
%35 = load i8*, i8** %6
store i8 0, i8* %35
%36 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%37 = load i32, i32* %4
%38 = call i32 @mkdir(i8* %36, i32 %37)
%39 = load i8*, i8** %6
store i8 47, i8* %39
br label %40
40: ; preds = %34, %29
br label %41
41: ; preds = %40
%42 = load i8*, i8** %6
%43 = getelementptr inbounds i8, i8* %42, i32 1
store i8* %43, i8** %6
br label %25
44: ; preds = %25
br label %45
45: ; preds = %44, %2
%46 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%47 = load i32, i32* %4
%48 = call i32 @mkdir(i8* %46, i32 %47)
ret void
}

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