#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 errno;
int makepath(char *);
size_t strlen(char *);
int mkparent(char *pathname) {
  char *pathend = &pathname[strlen(pathname)];
  while (pathend > pathname && *--pathend != '/')
    ;
  if (pathend > pathname) {
    *pathend = '\0';
    errno = makepath(pathname);
    *pathend = '/';
  } else
    errno = 0;
  return (errno);
}


x86 assembly (clang, -O0):
<mkparent>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rcx
xor    %eax,%eax
cmp    -0x8(%rbp),%rcx
mov    %al,-0x19(%rbp)
jbe    117a <mkparent+0x5a>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x10(%rbp)
movsbl -0x1(%rax),%eax
cmp    $0x2f,%eax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    118a <mkparent+0x6a>
jmp    118f <mkparent+0x6f>
jmp    114b <mkparent+0x2b>
mov    -0x10(%rbp),%rax
cmp    -0x8(%rbp),%rax
jbe    11c4 <mkparent+0xa4>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
call   1040 <makepath@plt>
mov    %eax,%ecx
mov    0x2e2a(%rip),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
movb   $0x2f,(%rax)
jmp    11d1 <mkparent+0xb1>
mov    0x2e15(%rip),%rax
movl   $0x0,(%rax)
mov    0x2e08(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mkparent>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <strlen@plt>
add    %r14,%rax
nop
cmp    %r14,%rax
jbe    1162 <mkparent+0x42>
lea    -0x1(%rax),%rbx
cmpb   $0x2f,-0x1(%rax)
mov    %rbx,%rax
jne    1130 <mkparent+0x10>
cmp    %r14,%rbx
jbe    116a <mkparent+0x4a>
movb   $0x0,(%rbx)
mov    %r14,%rdi
call   1040 <makepath@plt>
mov    0x2e87(%rip),%rcx
mov    %eax,(%rcx)
movb   $0x2f,(%rbx)
mov    (%rcx),%eax
jmp    1179 <mkparent+0x59>
mov    %rax,%rbx
cmp    %r14,%rbx
ja     1147 <mkparent+0x27>
mov    0x2e6f(%rip),%rax
movl   $0x0,(%rax)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@errno = global i32 0
define i32 @mkparent(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = load i8*, i8** %2
%6 = call i64 @strlen(i8* %5)
%7 = getelementptr inbounds i8, i8* %4, i64 %6
store i8* %7, i8** %3
br label %8
8: ; preds = %20, %1
%9 = load i8*, i8** %3
%10 = load i8*, i8** %2
%11 = icmp ugt i8* %9, %10
br i1 %11, label %12, label %18
12: ; preds = %8
%13 = load i8*, i8** %3
%14 = getelementptr inbounds i8, i8* %13, i32 -1
store i8* %14, i8** %3
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 47
br label %18
18: ; preds = %12, %8
%19 = phi i1 [ false, %8 ], [ %17, %12 ]
br i1 %19, label %20, label %21
20: ; preds = %18
br label %8
21: ; preds = %18
%22 = load i8*, i8** %3
%23 = load i8*, i8** %2
%24 = icmp ugt i8* %22, %23
br i1 %24, label %25, label %30
25: ; preds = %21
%26 = load i8*, i8** %3
store i8 0, i8* %26
%27 = load i8*, i8** %2
%28 = call i32 @makepath(i8* %27)
store i32 %28, i32* @errno
%29 = load i8*, i8** %3
store i8 47, i8* %29
br label %31
30: ; preds = %21
store i32 0, i32* @errno
br label %31
31: ; preds = %30, %25
%32 = load i32, i32* @errno
ret i32 %32
}

LLVM IR (-O2):
@errno = global i32 0
define i32 @mkparent(i8* %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = getelementptr inbounds i8, i8* %0, i64 %2
br label %4
4: ; preds = %7, %1
%5 = phi i8* [ %3, %1 ], [ %8, %7 ]
%6 = icmp ugt i8* %5, %0
br i1 %6, label %7, label %11
7: ; preds = %4
%8 = getelementptr inbounds i8, i8* %5, i64 -1
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 47
br i1 %10, label %11, label %4
11: ; preds = %4, %7
%12 = phi i8* [ %8, %7 ], [ %5, %4 ]
%13 = icmp ugt i8* %12, %0
br i1 %13, label %14, label %17
14: ; preds = %11
store i8 0, i8* %12
%15 = tail call i32 @makepath(i8* %0)
store i32 %15, i32* @errno
store i8 47, i8* %12
%16 = load i32, i32* @errno
br label %18
17: ; preds = %11
store i32 0, i32* @errno
br label %18
18: ; preds = %17, %14
%19 = phi i32 [ 0, %17 ], [ %16, %14 ]
ret i32 %19
}