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

/* Variables and functions */
scalar_t__ EEXIST;
int /*<<< orphan*/ assert(int /*<<< orphan*/);
scalar_t__ errno;
int mkdir(char *, int /*<<< orphan*/);
char *strchr(char *, char);
int mkpath(char *file_path, mode_t mode) {
  assert(file_path && *file_path);
  char *p;
  for (p = strchr(file_path + 1, '/'); p; p = strchr(p + 1, '/')) {
    *p = '\0';
    if (mkdir(file_path, mode) == -1) {
      if (errno != EEXIST) {
        *p = '/';
        return -1;
      }
    }
    *p = '/';
  }
  return 0;
}


x86 assembly (clang, -O0):
<mkpath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x10(%rbp)
mov    %al,-0x21(%rbp)
je     115f <mkpath+0x2f>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11fd <mkpath+0xcd>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <mkdir@plt>
cmp    $0xffffffff,%eax
jne    11db <mkpath+0xab>
mov    0x2e28(%rip),%rax
mov    (%rax),%rax
mov    0x2e26(%rip),%rcx
cmp    (%rcx),%rax
je     11d6 <mkpath+0xa6>
mov    -0x20(%rbp),%rax
movb   $0x2f,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    1204 <mkpath+0xd4>
jmp    11db <mkpath+0xab>
mov    -0x20(%rbp),%rax
movb   $0x2f,(%rax)
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
mov    %rax,-0x20(%rbp)
jmp    1182 <mkpath+0x52>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mkpath>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rdi,%rbx
xor    %r14d,%r14d
mov    $0x0,%edi
test   %rbx,%rbx
je     1157 <mkpath+0x27>
xor    %edi,%edi
cmpb   $0x0,(%rbx)
setne  %dil
call   1050 <assert@plt>
lea    0x1(%rbx),%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11d5 <mkpath+0xa5>
mov    %rax,%rbp
mov    0x2e5f(%rip),%r12
mov    0x2e60(%rip),%r13
jmp    11ad <mkpath+0x7d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movb   $0x2f,0x0(%rbp)
add    $0x1,%rbp
mov    %rbp,%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
mov    %rax,%rbp
test   %rax,%rax
je     11d5 <mkpath+0xa5>
movb   $0x0,0x0(%rbp)
mov    %rbx,%rdi
mov    %r15d,%esi
call   1030 <mkdir@plt>
cmp    $0xffffffff,%eax
jne    1190 <mkpath+0x60>
mov    (%r12),%rax
cmp    0x0(%r13),%rax
je     1190 <mkpath+0x60>
movb   $0x2f,0x0(%rbp)
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
@EEXIST = global i64 0
define i32 @mkpath(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
%7 = load i8*, i8** %4
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %14
9: ; preds = %2
%10 = load i8*, i8** %4
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp ne i32 %12, 0
br label %14
14: ; preds = %9, %2
%15 = phi i1 [ false, %2 ], [ %13, %9 ]
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
%18 = load i8*, i8** %4
%19 = getelementptr inbounds i8, i8* %18, i64 1
%20 = call i8* @strchr(i8* %19, i8 signext 47)
store i8* %20, i8** %6
br label %21
21: ; preds = %39, %14
%22 = load i8*, i8** %6
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %43
24: ; preds = %21
%25 = load i8*, i8** %6
store i8 0, i8* %25
%26 = load i8*, i8** %4
%27 = load i32, i32* %5
%28 = call i32 @mkdir(i8* %26, i32 %27)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %37
30: ; preds = %24
%31 = load i64, i64* @errno
%32 = load i64, i64* @EEXIST
%33 = icmp ne i64 %31, %32
br i1 %33, label %34, label %36
34: ; preds = %30
%35 = load i8*, i8** %6
store i8 47, i8* %35
store i32 -1, i32* %3
br label %44
36: ; preds = %30
br label %37
37: ; preds = %36, %24
%38 = load i8*, i8** %6
store i8 47, i8* %38
br label %39
39: ; preds = %37
%40 = load i8*, i8** %6
%41 = getelementptr inbounds i8, i8* %40, i64 1
%42 = call i8* @strchr(i8* %41, i8 signext 47)
store i8* %42, i8** %6
br label %21
43: ; preds = %21
store i32 0, i32* %3
br label %44
44: ; preds = %43, %34
%45 = load i32, i32* %3
ret i32 %45
}

LLVM IR (-O2):
@errno = global i64 0
@EEXIST = global i64 0
define i32 @mkpath(i8* %0, i32 %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i8, i8* %0
%6 = icmp ne i8 %5, 0
%7 = zext i1 %6 to i32
br label %8
8: ; preds = %4, %2
%9 = phi i32 [ 0, %2 ], [ %7, %4 ]
%10 = tail call i32 @assert(i32 %9)
%11 = getelementptr inbounds i8, i8* %0, i64 1
%12 = tail call i8* @strchr(i8* %11, i8 signext 47)
%13 = icmp eq i8* %12, null
br i1 %13, label %27, label %14
14: ; preds = %8, %23
%15 = phi i8* [ %25, %23 ], [ %12, %8 ]
store i8 0, i8* %15
%16 = tail call i32 @mkdir(i8* %0, i32 %1)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %23
18: ; preds = %14
%19 = load i64, i64* @errno
%20 = load i64, i64* @EEXIST
%21 = icmp eq i64 %19, %20
br i1 %21, label %23, label %22
22: ; preds = %18
store i8 47, i8* %15
br label %27
23: ; preds = %18, %14
store i8 47, i8* %15
%24 = getelementptr inbounds i8, i8* %15, i64 1
%25 = tail call i8* @strchr(i8* %24, i8 signext 47)
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %14
27: ; preds = %23, %8, %22
%28 = phi i32 [ -1, %22 ], [ 0, %8 ], [ 0, %23 ]
ret i32 %28
}