#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;
char *dirname(char *);
scalar_t__ errno;
int /*<<< orphan*/ free(char *);
int mkdir(char *, int /*<<< orphan*/);
int /*<<< orphan*/ strcmp(char const *, char *);
char *strdup(char const *);
int mkpath(const char *s, mode_t mode) {
  char *q = NULL, *r = NULL, *path = NULL, *up = NULL;
  int rv;
  rv = 1;
  if (!strcmp(s, ".") || !strcmp(s, "/")) {
    return 0;
  }
  if ((path = strdup(s)) == NULL) {
    return 1;
  }
  if ((q = strdup(s)) == NULL) {
    goto out;
  }
  if ((r = dirname(q)) == NULL) {
    goto out;
  }
  if ((up = strdup(r)) == NULL) {
    goto out;
  }
  if ((mkpath(up, mode) == -1) && (errno != EEXIST)) {
    goto out;
  }
  if ((mkdir(path, mode) == -1) && (errno != EEXIST)) {
    goto out;
  }
  rv = 0;
out:
  if (up != NULL) {
    free(up);
  }
  if (q != NULL) {
    free(q);
  }
  if (path != NULL) {
    free(path);
  }
  return rv;
}


x86 assembly (clang, -O0):
<mkpath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movl   $0x1,-0x3c(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe5f(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
je     11c8 <mkpath+0x68>
mov    -0x10(%rbp),%rdi
lea    0xe48(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    11d4 <mkpath+0x74>
movl   $0x0,-0x4(%rbp)
jmp    12fc <mkpath+0x19c>
mov    -0x10(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    11f7 <mkpath+0x97>
movl   $0x1,-0x4(%rbp)
jmp    12fc <mkpath+0x19c>
mov    -0x10(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1213 <mkpath+0xb3>
jmp    12ba <mkpath+0x15a>
mov    -0x20(%rbp),%rdi
call   1050 <dirname@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    122f <mkpath+0xcf>
jmp    12ba <mkpath+0x15a>
mov    -0x28(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    124b <mkpath+0xeb>
jmp    12ba <mkpath+0x15a>
mov    -0x38(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1070 <mkpath@plt>
cmp    $0xffffffff,%eax
jne    127f <mkpath+0x11f>
mov    0x2d71(%rip),%rax
mov    (%rax),%rax
mov    0x2d6f(%rip),%rcx
cmp    (%rcx),%rax
je     127f <mkpath+0x11f>
jmp    12ba <mkpath+0x15a>
mov    -0x30(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <mkdir@plt>
cmp    $0xffffffff,%eax
jne    12b3 <mkpath+0x153>
mov    0x2d3d(%rip),%rax
mov    (%rax),%rax
mov    0x2d3b(%rip),%rcx
cmp    (%rcx),%rax
je     12b3 <mkpath+0x153>
jmp    12ba <mkpath+0x15a>
movl   $0x0,-0x3c(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     12ce <mkpath+0x16e>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x20(%rbp)
je     12e2 <mkpath+0x182>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x30(%rbp)
je     12f6 <mkpath+0x196>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%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,%r13d
mov    %rdi,%rbp
lea    0xe88(%rip),%rsi
call   1060 <strcmp@plt>
xor    %ebx,%ebx
test   %eax,%eax
je     123e <mkpath+0xde>
lea    0xe74(%rip),%rsi
mov    %rbp,%rdi
call   1060 <strcmp@plt>
test   %eax,%eax
je     123e <mkpath+0xde>
mov    %rbp,%rdi
call   1080 <strdup@plt>
test   %rax,%rax
je     122a <mkpath+0xca>
mov    %rax,%r14
mov    %rbp,%rdi
call   1080 <strdup@plt>
test   %rax,%rax
je     1231 <mkpath+0xd1>
mov    %rax,%r15
mov    %rax,%rdi
call   1050 <dirname@plt>
mov    $0x1,%ebx
test   %rax,%rax
je     1220 <mkpath+0xc0>
mov    %rax,%rdi
call   1080 <strdup@plt>
test   %rax,%rax
je     1220 <mkpath+0xc0>
mov    %rax,%r12
mov    %rax,%rdi
mov    %r13d,%esi
call   1070 <mkpath@plt>
mov    %r14,%rdi
mov    %r13d,%esi
call   1040 <mkdir@plt>
cmp    $0xffffffff,%eax
jne    1216 <mkpath+0xb6>
mov    0x2dd6(%rip),%rax
mov    (%rax),%rax
mov    0x2dd4(%rip),%rcx
mov    $0x1,%ebx
cmp    (%rcx),%rax
jne    1218 <mkpath+0xb8>
xor    %ebx,%ebx
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
jmp    1236 <mkpath+0xd6>
mov    $0x1,%ebx
jmp    123e <mkpath+0xde>
mov    $0x1,%ebx
mov    %r14,%rdi
call   1030 <free@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
@.str.1 = [2 x i8] c"/\00"
@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*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* null, i8** %6
store i8* null, i8** %7
store i8* null, i8** %8
store i8* null, i8** %9
store i32 1, i32* %10
%11 = load i8*, i8** %4
%12 = call i32 @strcmp(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = load i8*, i8** %4
%16 = call i32 @strcmp(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp ne i32 %16, 0
br i1 %17, label %19, label %18
18: ; preds = %14, %2
store i32 0, i32* %3
br label %80
19: ; preds = %14
%20 = load i8*, i8** %4
%21 = call i8* @strdup(i8* %20)
store i8* %21, i8** %8
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %24
23: ; preds = %19
store i32 1, i32* %3
br label %80
24: ; preds = %19
%25 = load i8*, i8** %4
%26 = call i8* @strdup(i8* %25)
store i8* %26, i8** %6
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %29
28: ; preds = %24
br label %60
29: ; preds = %24
%30 = load i8*, i8** %6
%31 = call i8* @dirname(i8* %30)
store i8* %31, i8** %7
%32 = icmp eq i8* %31, null
br i1 %32, label %33, label %34
33: ; preds = %29
br label %60
34: ; preds = %29
%35 = load i8*, i8** %7
%36 = call i8* @strdup(i8* %35)
store i8* %36, i8** %9
%37 = icmp eq i8* %36, null
br i1 %37, label %38, label %39
38: ; preds = %34
br label %60
39: ; preds = %34
%40 = load i8*, i8** %9
%41 = load i32, i32* %5
%42 = call i32 @mkpath(i8* %40, i32 %41)
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %49
44: ; preds = %39
%45 = load i64, i64* @errno
%46 = load i64, i64* @EEXIST
%47 = icmp ne i64 %45, %46
br i1 %47, label %48, label %49
48: ; preds = %44
br label %60
49: ; preds = %44, %39
%50 = load i8*, i8** %8
%51 = load i32, i32* %5
%52 = call i32 @mkdir(i8* %50, i32 %51)
%53 = icmp eq i32 %52, -1
br i1 %53, label %54, label %59
54: ; preds = %49
%55 = load i64, i64* @errno
%56 = load i64, i64* @EEXIST
%57 = icmp ne i64 %55, %56
br i1 %57, label %58, label %59
58: ; preds = %54
br label %60
59: ; preds = %54, %49
store i32 0, i32* %10
br label %60
60: ; preds = %59, %58, %48, %38, %33, %28
%61 = load i8*, i8** %9
%62 = icmp ne i8* %61, null
br i1 %62, label %63, label %66
63: ; preds = %60
%64 = load i8*, i8** %9
%65 = call i32 @free(i8* %64)
br label %66
66: ; preds = %63, %60
%67 = load i8*, i8** %6
%68 = icmp ne i8* %67, null
br i1 %68, label %69, label %72
69: ; preds = %66
%70 = load i8*, i8** %6
%71 = call i32 @free(i8* %70)
br label %72
72: ; preds = %69, %66
%73 = load i8*, i8** %8
%74 = icmp ne i8* %73, null
br i1 %74, label %75, label %78
75: ; preds = %72
%76 = load i8*, i8** %8
%77 = call i32 @free(i8* %76)
br label %78
78: ; preds = %75, %72
%79 = load i32, i32* %10
store i32 %79, i32* %3
br label %80
80: ; preds = %78, %23, %18
%81 = load i32, i32* %3
ret i32 %81
}

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
@.str.1 = [2 x i8] c"/\00"
@errno = global i64 0
@EEXIST = global i64 0
define i32 @mkpath(i8* nocapture %0, i32 %1) {
%3 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32 %3, 0
br i1 %4, label %38, label %5
5: ; preds = %2
%6 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32 %6, 0
br i1 %7, label %38, label %8
8: ; preds = %5
%9 = tail call i8* @strdup(i8* %0)
%10 = icmp eq i8* %9, null
br i1 %10, label %38, label %11
11: ; preds = %8
%12 = tail call i8* @strdup(i8* %0)
%13 = icmp eq i8* %12, null
br i1 %13, label %35, label %14
14: ; preds = %11
%15 = tail call i8* @dirname(i8* %12)
%16 = icmp eq i8* %15, null
br i1 %16, label %32, label %17
17: ; preds = %14
%18 = tail call i8* @strdup(i8* %15)
%19 = icmp eq i8* %18, null
br i1 %19, label %32, label %20
20: ; preds = %17
%21 = tail call i32 @mkpath(i8* %18, i32 %1)
%22 = tail call i32 @mkdir(i8* %9, i32 %1)
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %28
24: ; preds = %20
%25 = load i64, i64* @errno
%26 = load i64, i64* @EEXIST
%27 = icmp eq i64 %25, %26
br i1 %27, label %28, label %29
28: ; preds = %24, %20
br label %29
29: ; preds = %24, %28
%30 = phi i32 [ 1, %24 ], [ 0, %28 ]
%31 = tail call i32 @free(i8* %18)
br label %32
32: ; preds = %17, %14, %29
%33 = phi i32 [ %30, %29 ], [ 1, %14 ], [ 1, %17 ]
%34 = tail call i32 @free(i8* %12)
br label %35
35: ; preds = %11, %32
%36 = phi i32 [ %33, %32 ], [ 1, %11 ]
%37 = tail call i32 @free(i8* %9)
br label %38
38: ; preds = %8, %2, %5, %35
%39 = phi i32 [ %36, %35 ], [ 0, %5 ], [ 0, %2 ], [ 1, %8 ]
ret i32 %39
}