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

/* Variables and functions */
scalar_t__ EEXIST;
scalar_t__ errno;
int mkdir(char *, int);
char *strchr(char *, char);
scalar_t__ strlen(char *);
int mkpath(char *file_path, mode_t mode) {
  int retval = 1;
  if (mode == 0) {
    mode = 0755;
  }
  if (file_path != NULL) {
    if (strlen(file_path) > 0) {
      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 = '/';
            retval = 0;
            break;
          }
        }
        *p = '/';
      }
    }
  }
  return (retval);
}


x86 assembly (clang, -O0):
<mkpath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1157 <mkpath+0x27>
movl   $0x1ed,-0xc(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1210 <mkpath+0xe0>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
jle    120b <mkpath+0xdb>
mov    -0x8(%rbp),%rdi
add    $0x1,%rdi
mov    $0x2f,%esi
call   1050 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1206 <mkpath+0xd6>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <mkdir@plt>
cmp    $0xffffffff,%eax
jne    11e4 <mkpath+0xb4>
mov    0x2e1f(%rip),%rax
mov    (%rax),%rax
mov    0x2e1d(%rip),%rcx
cmp    (%rcx),%rax
je     11df <mkpath+0xaf>
mov    -0x18(%rbp),%rax
movb   $0x2f,(%rax)
movl   $0x0,-0x10(%rbp)
jmp    1206 <mkpath+0xd6>
jmp    11e4 <mkpath+0xb4>
mov    -0x18(%rbp),%rax
movb   $0x2f,(%rax)
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
mov    $0x2f,%esi
call   1050 <strchr@plt>
mov    %rax,-0x18(%rbp)
jmp    118b <mkpath+0x5b>
jmp    120b <mkpath+0xdb>
jmp    1210 <mkpath+0xe0>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mkpath>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
mov    $0x1ed,%ebp
cmovne %esi,%ebp
mov    $0x1,%r14d
test   %rdi,%rdi
je     11ce <mkpath+0x9e>
mov    %rdi,%r15
call   1040 <strlen@plt>
test   %rax,%rax
jle    11ce <mkpath+0x9e>
lea    0x1(%r15),%rdi
mov    $0x2f,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11ce <mkpath+0x9e>
mov    %rax,%rbx
mov    0x2e5e(%rip),%r12
mov    0x2e5f(%rip),%r13
jmp    11ac <mkpath+0x7c>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movb   $0x2f,(%rbx)
add    $0x1,%rbx
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1050 <strchr@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11ce <mkpath+0x9e>
movb   $0x0,(%rbx)
mov    %r15,%rdi
mov    %ebp,%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,(%rbx)
xor    %r14d,%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 i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 1, i32* %5
%7 = load i32, i32* %4
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %2
store i32 493, i32* %4
br label %10
10: ; preds = %9, %2
%11 = load i8*, i8** %3
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %45
13: ; preds = %10
%14 = load i8*, i8** %3
%15 = call i64 @strlen(i8* %14)
%16 = icmp sgt i64 %15, 0
br i1 %16, label %17, label %44
17: ; preds = %13
%18 = load i8*, i8** %3
%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, %17
%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** %3
%27 = load i32, i32* %4
%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 0, i32* %5
br label %43
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 = %34, %21
br label %44
44: ; preds = %43, %13
br label %45
45: ; preds = %44, %10
%46 = load i32, i32* %5
ret i32 %46
}

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