#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 */
struct stat {
  int /*<<< orphan*/ st_mode;
};

/* Variables and functions */
scalar_t__ S_ISDIR(int /*<<< orphan*/);
int _tar_error(char *, int);
int mkdir(char *, int);
scalar_t__ stat(char *, struct stat *);
int _tar_mkdir_parent(char *filename) {
  char *p;
  struct stat st;
  if (filename[0] == '\0')
    return 0;
  for (p = &filename[1]; *p != '\0'; p++) {
    if (*p != '/')
      continue;
    *p = '\0';
    if (!(stat(filename, &st) == 0 && S_ISDIR(st.st_mode)) &&
        mkdir(filename, 0777) == -1) {
      *p = '/';
      return _tar_error(filename, 1);
    }
    for (*p++ = '/'; *p == '/'; p++)
      ;
    if (*p == '\0')
      return 0;
  }
  return 0;
}


x86 assembly (clang, -O0):
<_tar_mkdir_parent>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1168 <_tar_mkdir_parent+0x28>
movl   $0x0,-0x4(%rbp)
jmp    126e <_tar_mkdir_parent+0x12e>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1267 <_tar_mkdir_parent+0x127>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     1199 <_tar_mkdir_parent+0x59>
jmp    1256 <_tar_mkdir_parent+0x116>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1060 <stat@plt>
cmp    $0x0,%rax
jne    11c9 <_tar_mkdir_parent+0x89>
mov    -0x20(%rbp),%edi
call   1050 <S_ISDIR@plt>
cmp    $0x0,%rax
jne    11fd <_tar_mkdir_parent+0xbd>
mov    -0x10(%rbp),%rdi
mov    $0x1ff,%esi
call   1040 <mkdir@plt>
cmp    $0xffffffff,%eax
jne    11fd <_tar_mkdir_parent+0xbd>
mov    -0x18(%rbp),%rax
movb   $0x2f,(%rax)
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   1030 <_tar_error@plt>
mov    %eax,-0x4(%rbp)
jmp    126e <_tar_mkdir_parent+0x12e>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x2f,(%rax)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    1235 <_tar_mkdir_parent+0xf5>
jmp    1224 <_tar_mkdir_parent+0xe4>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    120f <_tar_mkdir_parent+0xcf>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1251 <_tar_mkdir_parent+0x111>
movl   $0x0,-0x4(%rbp)
jmp    126e <_tar_mkdir_parent+0x12e>
jmp    1256 <_tar_mkdir_parent+0x116>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1174 <_tar_mkdir_parent+0x34>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_tar_mkdir_parent>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
xor    %r15d,%r15d
cmpb   $0x0,(%rdi)
je     11e1 <_tar_mkdir_parent+0xa1>
mov    %rdi,%r12
lea    0x8(%rsp),%r14
mov    %rdi,%rbx
lea    0x1(%rbx),%rbp
mov    0x1(%rbx),%al
cmp    $0x2f,%al
je     1180 <_tar_mkdir_parent+0x40>
mov    %rbp,%rbx
test   %al,%al
jne    1163 <_tar_mkdir_parent+0x23>
jmp    11e1 <_tar_mkdir_parent+0xa1>
nopw   0x0(%rax,%rax,1)
movb   $0x0,0x0(%rbp)
mov    %r12,%rdi
mov    %r14,%rsi
call   1060 <stat@plt>
test   %rax,%rax
je     11a8 <_tar_mkdir_parent+0x68>
mov    %r12,%rdi
mov    $0x1ff,%esi
call   1040 <mkdir@plt>
cmp    $0xffffffff,%eax
jne    11b6 <_tar_mkdir_parent+0x76>
jmp    11cd <_tar_mkdir_parent+0x8d>
mov    0x8(%rsp),%edi
call   1050 <S_ISDIR@plt>
test   %rax,%rax
je     1194 <_tar_mkdir_parent+0x54>
movb   $0x2f,0x1(%rbx)
add    $0x2,%rbx
xchg   %ax,%ax
movzbl (%rbx),%eax
cmp    $0x2f,%al
jne    1171 <_tar_mkdir_parent+0x31>
add    $0x1,%rbx
jmp    11c0 <_tar_mkdir_parent+0x80>
movb   $0x2f,0x0(%rbp)
mov    %r12,%rdi
mov    $0x1,%esi
call   1030 <_tar_error@plt>
mov    %eax,%r15d
mov    %r15d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
define i32 @_tar_mkdir_parent(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca %struct.stat
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = getelementptr inbounds i8, i8* %6, i64 0
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %1
store i32 0, i32* %2
br label %67
12: ; preds = %1
%13 = load i8*, i8** %3
%14 = getelementptr inbounds i8, i8* %13, i64 1
store i8* %14, i8** %4
br label %15
15: ; preds = %63, %12
%16 = load i8*, i8** %4
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %66
20: ; preds = %15
%21 = load i8*, i8** %4
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp ne i32 %23, 47
br i1 %24, label %25, label %26
25: ; preds = %20
br label %63
26: ; preds = %20
%27 = load i8*, i8** %4
store i8 0, i8* %27
%28 = load i8*, i8** %3
%29 = call i64 @stat(i8* %28, %struct.stat* %5)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %36
31: ; preds = %26
%32 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%33 = load i32, i32* %32
%34 = call i64 @S_ISDIR(i32 %33)
%35 = icmp ne i64 %34, 0
br i1 %35, label %44, label %36
36: ; preds = %31, %26
%37 = load i8*, i8** %3
%38 = call i32 @mkdir(i8* %37, i32 511)
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %44
40: ; preds = %36
%41 = load i8*, i8** %4
store i8 47, i8* %41
%42 = load i8*, i8** %3
%43 = call i32 @_tar_error(i8* %42, i32 1)
store i32 %43, i32* %2
br label %67
44: ; preds = %36, %31
%45 = load i8*, i8** %4
%46 = getelementptr inbounds i8, i8* %45, i32 1
store i8* %46, i8** %4
store i8 47, i8* %45
br label %47
47: ; preds = %53, %44
%48 = load i8*, i8** %4
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = icmp eq i32 %50, 47
br i1 %51, label %52, label %56
52: ; preds = %47
br label %53
53: ; preds = %52
%54 = load i8*, i8** %4
%55 = getelementptr inbounds i8, i8* %54, i32 1
store i8* %55, i8** %4
br label %47
56: ; preds = %47
%57 = load i8*, i8** %4
%58 = load i8, i8* %57
%59 = sext i8 %58 to i32
%60 = icmp eq i32 %59, 0
br i1 %60, label %61, label %62
61: ; preds = %56
store i32 0, i32* %2
br label %67
62: ; preds = %56
br label %63
63: ; preds = %62, %25
%64 = load i8*, i8** %4
%65 = getelementptr inbounds i8, i8* %64, i32 1
store i8* %65, i8** %4
br label %15
66: ; preds = %15
store i32 0, i32* %2
br label %67
67: ; preds = %66, %61, %40, %11
%68 = load i32, i32* %2
ret i32 %68
}

LLVM IR (-O2):
%struct.stat = type { i32 }
define i32 @_tar_mkdir_parent(i8* %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %33, label %6
6: ; preds = %1
%7 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
br label %8
8: ; preds = %12, %6
%9 = phi i8* [ %0, %6 ], [ %13, %12 ]
%10 = getelementptr inbounds i8, i8* %9, i64 1
%11 = load i8, i8* %10
switch i8 %11, label %12 [
i8 0, label %33
i8 47, label %14
]
12: ; preds = %28, %8
%13 = phi i8* [ %10, %8 ], [ %29, %28 ]
br label %8
14: ; preds = %8
store i8 0, i8* %10
%15 = call i64 @stat(i8* %0, %struct.stat* %2)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %14
%18 = load i32, i32* %7
%19 = call i64 @S_ISDIR(i32 %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %17, %14
%22 = call i32 @mkdir(i8* %0, i32 511)
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %26
24: ; preds = %21
store i8 47, i8* %10
%25 = call i32 @_tar_error(i8* %0, i32 1)
br label %33
26: ; preds = %21, %17
%27 = getelementptr inbounds i8, i8* %9, i64 2
store i8 47, i8* %10
br label %28
28: ; preds = %31, %26
%29 = phi i8* [ %27, %26 ], [ %32, %31 ]
%30 = load i8, i8* %29
switch i8 %30, label %12 [
i8 47, label %31
i8 0, label %33
]
31: ; preds = %28
%32 = getelementptr inbounds i8, i8* %29, i64 1
br label %28
33: ; preds = %8, %28, %1, %24
%34 = phi i32 [ %25, %24 ], [ 0, %1 ], [ 0, %28 ], [ 0, %8 ]
ret i32 %34
}