#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 mkdir(char *, int);
char *strrchr(char *, char);
int recursiveMkdir(char *pathname, int mode) {
  char *p;
  int r;
  r = mkdir(pathname, mode);
  if (r != 0) {
    p = strrchr(pathname, '/');
    if (p != NULL) {
      *p = '\0';
      recursiveMkdir(pathname, 0755);
      *p = '/';
      r = mkdir(pathname, mode);
    }
  }
  return r;
}


x86 assembly (clang, -O0):
<recursiveMkdir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <mkdir@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     11a5 <recursiveMkdir+0x75>
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11a0 <recursiveMkdir+0x70>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
mov    $0x1ed,%esi
call   1040 <recursiveMkdir@plt>
mov    -0x18(%rbp),%rax
movb   $0x2f,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <mkdir@plt>
mov    %eax,-0x1c(%rbp)
jmp    11a5 <recursiveMkdir+0x75>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<recursiveMkdir>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%rbx
call   1030 <mkdir@plt>
test   %eax,%eax
je     1186 <recursiveMkdir+0x56>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
je     1188 <recursiveMkdir+0x58>
mov    %rax,%r15
movb   $0x0,(%rax)
mov    %rbx,%rdi
mov    $0x1ed,%esi
call   1040 <recursiveMkdir@plt>
movb   $0x2f,(%r15)
mov    %rbx,%rdi
mov    %r14d,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <mkdir@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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