#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 */

/* Variables and functions */
int os_mkdir(char *);
char *strrchr(char *, char);
int recursive_mkdir(char *path) {
  char *last_slash;
  int ret;
  ret = os_mkdir(path);
  if (ret != -1)
    return ret;
  last_slash = strrchr(path, '/');
  if (!last_slash)
    return -1;
  *last_slash = 0;
  ret = recursive_mkdir(path);
  *last_slash = '/';
  if (ret == -1)
    return -1;
  ret = os_mkdir(path);
  return ret;
}


x86 assembly (clang, -O0):
<recursive_mkdir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <os_mkdir@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
je     115d <recursive_mkdir+0x2d>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11c8 <recursive_mkdir+0x98>
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1186 <recursive_mkdir+0x56>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c8 <recursive_mkdir+0x98>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
call   1030 <recursive_mkdir@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
movb   $0x2f,(%rax)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11b6 <recursive_mkdir+0x86>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c8 <recursive_mkdir+0x98>
mov    -0x10(%rbp),%rdi
call   1040 <os_mkdir@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<recursive_mkdir>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1040 <os_mkdir@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
je     114a <recursive_mkdir+0x1a>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
je     1143 <recursive_mkdir+0x13>
mov    %rax,%r14
movb   $0x0,(%rax)
mov    %rbx,%rdi
call   1030 <recursive_mkdir@plt>
movb   $0x2f,(%r14)
cmp    $0xffffffff,%eax
je     1143 <recursive_mkdir+0x13>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <os_mkdir@plt>

LLVM IR (-O0):
define i32 @recursive_mkdir(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i32 @os_mkdir(i8* %6)
store i32 %7, i32* %5
%8 = load i32, i32* %5
%9 = icmp ne i32 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = load i32, i32* %5
store i32 %11, i32* %2
br label %30
12: ; preds = %1
%13 = load i8*, i8** %3
%14 = call i8* @strrchr(i8* %13, i8 signext 47)
store i8* %14, i8** %4
%15 = load i8*, i8** %4
%16 = icmp ne i8* %15, null
br i1 %16, label %18, label %17
17: ; preds = %12
store i32 -1, i32* %2
br label %30
18: ; preds = %12
%19 = load i8*, i8** %4
store i8 0, i8* %19
%20 = load i8*, i8** %3
%21 = call i32 @recursive_mkdir(i8* %20)
store i32 %21, i32* %5
%22 = load i8*, i8** %4
store i8 47, i8* %22
%23 = load i32, i32* %5
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %26
25: ; preds = %18
store i32 -1, i32* %2
br label %30
26: ; preds = %18
%27 = load i8*, i8** %3
%28 = call i32 @os_mkdir(i8* %27)
store i32 %28, i32* %5
%29 = load i32, i32* %5
store i32 %29, i32* %2
br label %30
30: ; preds = %26, %25, %17, %10
%31 = load i32, i32* %2
ret i32 %31
}

LLVM IR (-O2):
define i32 @recursive_mkdir(i8* %0) {
%2 = tail call i32 @os_mkdir(i8* %0)
%3 = icmp eq i32 %2, -1
br i1 %3, label %4, label %12
4: ; preds = %1
%5 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%6 = icmp eq i8* %5, null
br i1 %6, label %12, label %7
7: ; preds = %4
store i8 0, i8* %5
%8 = tail call i32 @recursive_mkdir(i8* %0)
store i8 47, i8* %5
%9 = icmp eq i32 %8, -1
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = tail call i32 @os_mkdir(i8* %0)
br label %12
12: ; preds = %7, %4, %1, %10
%13 = phi i32 [ %11, %10 ], [ %2, %1 ], [ -1, %4 ], [ -1, %7 ]
ret i32 %13
}