#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 */
scalar_t__ EEXIST;
int /*<<< orphan*/ chdir(char *);
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int makepath(char *);
int mkdir(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
char *strchr(char const *, char);
int /*<<< orphan*/ strncpy(char *, char const *, int);
int _makepath(const char *path) {
  int len;
  char *p;
  char dir[128];
  while (*path == '/')
    path++;
  p = strchr(path, '/');
  if (!p)
    return 1;
  len = p - path;
  if (len >= 128) {
    do {
      fprintf(stderr,
              "upackddir: "
              "Directory name '%s` too long\n",
              path);
    } while (0);
    return 0;
  }
  strncpy(dir, path, len);
  dir[len] = '\0';
  if (mkdir(dir, 0777) == -1) {
    if (errno == EEXIST)
      goto cont;
    do {
      fprintf(stderr,
              "upackddir: "
              "%s: ",
              dir);
    } while (0);
    perror("mkdir");
    return 0;
  }
cont:
  chdir(dir);
  return makepath(p + 1);
}


x86 assembly (clang, -O0):
<_makepath>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    11a0 <_makepath+0x30>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    117f <_makepath+0xf>
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1060 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11c9 <_makepath+0x59>
movl   $0x1,-0x4(%rbp)
jmp    12c0 <_makepath+0x150>
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x14(%rbp)
cmpl   $0x80,-0x14(%rbp)
jl     120e <_makepath+0x9e>
jmp    11e9 <_makepath+0x79>
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe03(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12c0 <_makepath+0x150>
lea    -0xa0(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <strncpy@plt>
movslq -0x14(%rbp),%rax
movb   $0x0,-0xa0(%rbp,%rax,1)
lea    -0xa0(%rbp),%rdi
mov    $0x1ff,%esi
call   1040 <mkdir@plt>
cmp    $0xffffffff,%eax
jne    129f <_makepath+0x12f>
mov    0x2d82(%rip),%rax
mov    (%rax),%rax
mov    0x2d88(%rip),%rcx
cmp    (%rcx),%rax
jne    1266 <_makepath+0xf6>
jmp    12a4 <_makepath+0x134>
jmp    126b <_makepath+0xfb>
mov    0x2d66(%rip),%rax
mov    (%rax),%edi
lea    -0xa0(%rbp),%rdx
lea    0xda7(%rip),%rsi
call   1070 <fprintf@plt>
lea    0xdab(%rip),%rdi
call   1080 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    12c0 <_makepath+0x150>
jmp    12a4 <_makepath+0x134>
lea    -0xa0(%rbp),%rdi
call   1050 <chdir@plt>
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
call   1090 <makepath@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_makepath>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    %rdi,%rbx
lea    -0x1(%rdi),%r12
add    $0xffffffff,%ebx
mov    %r12,%r15
nopl   0x0(%rax,%rax,1)
add    $0x1,%r12
add    $0x1,%rbx
cmpb   $0x2f,0x1(%r15)
lea    0x1(%r15),%r15
je     1190 <_makepath+0x20>
mov    %r15,%rdi
mov    $0x2f,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     11e2 <_makepath+0x72>
mov    %rax,%r14
mov    %rax,%rdx
sub    %rbx,%rdx
cmp    $0x80,%edx
jl     11e9 <_makepath+0x79>
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
lea    0xe2a(%rip),%rsi
mov    %r15,%rdx
call   1070 <fprintf@plt>
xor    %eax,%eax
jmp    1240 <_makepath+0xd0>
mov    $0x1,%eax
jmp    1240 <_makepath+0xd0>
mov    %r14,%rbx
sub    %r12,%rbx
mov    %rsp,%r12
mov    %r12,%rdi
mov    %r15,%rsi
call   1030 <strncpy@plt>
movslq %ebx,%rax
movb   $0x0,(%rsp,%rax,1)
mov    %r12,%rdi
mov    $0x1ff,%esi
call   1040 <mkdir@plt>
cmp    $0xffffffff,%eax
jne    122c <_makepath+0xbc>
mov    0x2db3(%rip),%rax
mov    (%rax),%rax
mov    0x2db9(%rip),%rcx
cmp    (%rcx),%rax
jne    124f <_makepath+0xdf>
mov    %rsp,%rdi
call   1050 <chdir@plt>
add    $0x1,%r14
mov    %r14,%rdi
call   1090 <makepath@plt>
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2d82(%rip),%rax
mov    (%rax),%edi
lea    0xdca(%rip),%rsi
mov    %rsp,%rdx
call   1070 <fprintf@plt>
lea    0xdcb(%rip),%rdi
call   1080 <perror@plt>
xor    %eax,%eax
jmp    1240 <_makepath+0xd0>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [41 x i8] c"upackddir: Directory name '%s` too long\0A\00"
@errno = global i64 0
@EEXIST = global i64 0
@.str.1 = [16 x i8] c"upackddir: %s: \00"
@.str.2 = [6 x i8] c"mkdir\00"
define i32 @_makepath(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca [128 x i8]
store i8* %0, i8** %3
br label %7
7: ; preds = %12, %1
%8 = load i8*, i8** %3
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
%11 = icmp eq i32 %10, 47
br i1 %11, label %12, label %15
12: ; preds = %7
%13 = load i8*, i8** %3
%14 = getelementptr inbounds i8, i8* %13, i32 1
store i8* %14, i8** %3
br label %7
15: ; preds = %7
%16 = load i8*, i8** %3
%17 = call i8* @strchr(i8* %16, i8 signext 47)
store i8* %17, i8** %5
%18 = load i8*, i8** %5
%19 = icmp ne i8* %18, null
br i1 %19, label %21, label %20
20: ; preds = %15
store i32 1, i32* %2
br label %66
21: ; preds = %15
%22 = load i8*, i8** %5
%23 = load i8*, i8** %3
%24 = ptrtoint i8* %22 to i64
%25 = ptrtoint i8* %23 to i64
%26 = sub i64 %24, %25
%27 = trunc i64 %26 to i32
store i32 %27, i32* %4
%28 = load i32, i32* %4
%29 = icmp sge i32 %28, 128
br i1 %29, label %30, label %36
30: ; preds = %21
br label %31
31: ; preds = %30
%32 = load i32, i32* @stderr
%33 = load i8*, i8** %3
%34 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* %33)
br label %35
35: ; preds = %31
store i32 0, i32* %2
br label %66
36: ; preds = %21
%37 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%38 = load i8*, i8** %3
%39 = load i32, i32* %4
%40 = call i32 @strncpy(i8* %37, i8* %38, i32 %39)
%41 = load i32, i32* %4
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 %42
store i8 0, i8* %43
%44 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%45 = call i32 @mkdir(i8* %44, i32 511)
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %59
47: ; preds = %36
%48 = load i64, i64* @errno
%49 = load i64, i64* @EEXIST
%50 = icmp eq i64 %48, %49
br i1 %50, label %51, label %52
51: ; preds = %47
br label %60
52: ; preds = %47
br label %53
53: ; preds = %52
%54 = load i32, i32* @stderr
%55 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%56 = call i32 @fprintf(i32 %54, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %55)
br label %57
57: ; preds = %53
%58 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %2
br label %66
59: ; preds = %36
br label %60
60: ; preds = %59, %51
%61 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%62 = call i32 @chdir(i8* %61)
%63 = load i8*, i8** %5
%64 = getelementptr inbounds i8, i8* %63, i64 1
%65 = call i32 @makepath(i8* %64)
store i32 %65, i32* %2
br label %66
66: ; preds = %60, %57, %35, %20
%67 = load i32, i32* %2
ret i32 %67
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [41 x i8] c"upackddir: Directory name '%s` too long\0A\00"
@errno = global i64 0
@EEXIST = global i64 0
@.str.1 = [16 x i8] c"upackddir: %s: \00"
@.str.2 = [6 x i8] c"mkdir\00"
define i32 @_makepath(i8* %0) {
%2 = alloca [128 x i8]
%3 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
br label %4
4: ; preds = %4, %1
%5 = phi i8* [ %0, %1 ], [ %8, %4 ]
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, 47
%8 = getelementptr inbounds i8, i8* %5, i64 1
br i1 %7, label %4, label %9
9: ; preds = %4
%10 = tail call i8* @strchr(i8* %5, i8 signext 47)
%11 = icmp eq i8* %10, null
br i1 %11, label %40, label %12
12: ; preds = %9
%13 = ptrtoint i8* %10 to i64
%14 = ptrtoint i8* %5 to i64
%15 = sub i64 %13, %14
%16 = trunc i64 %15 to i32
%17 = icmp sgt i32 %16, 127
br i1 %17, label %18, label %21
18: ; preds = %12
%19 = load i32, i32* @stderr
%20 = tail call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %40
21: ; preds = %12
%22 = call i32 @strncpy(i8* %3, i8* %5, i32 %16)
%23 = shl i64 %15, 32
%24 = ashr exact i64 %23, 32
%25 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 %24
store i8 0, i8* %25
%26 = call i32 @mkdir(i8* %3, i32 511)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %36
28: ; preds = %21
%29 = load i64, i64* @errno
%30 = load i64, i64* @EEXIST
%31 = icmp eq i64 %29, %30
br i1 %31, label %36, label %32
32: ; preds = %28
%33 = load i32, i32* @stderr
%34 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%35 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %40
36: ; preds = %21, %28
%37 = call i32 @chdir(i8* %3)
%38 = getelementptr inbounds i8, i8* %10, i64 1
%39 = call i32 @makepath(i8* %38)
br label %40
40: ; preds = %9, %36, %32, %18
%41 = phi i32 [ 0, %18 ], [ %39, %36 ], [ 0, %32 ], [ 1, %9 ]
ret i32 %41
}