#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;
scalar_t__ errno;
int /*<<< orphan*/ kpccfatal(char *, char *, int /*<<< orphan*/);
int mkdir(char *, int);
char *strchr(char *, char);
int /*<<< orphan*/ strerror(scalar_t__);
void make_dirs(char *path) {
  int rv;
  char *delim, *p = path + 1;
  while ((delim = strchr(p, '/')) != NULL) {
    *delim = '\0';
    rv = mkdir(path, 0755);
    if (rv == -1 && errno != EEXIST)
      kpccfatal("can't makedir %s: %s\n", path, strerror(errno));
    *delim = '/';
    p = delim + 1;
  }
}


x86 assembly (clang, -O0):
<make_dirs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11f1 <make_dirs+0xb1>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    11d9 <make_dirs+0x99>
mov    0x2e3b(%rip),%rax
mov    (%rax),%rax
mov    0x2e39(%rip),%rcx
cmp    (%rcx),%rax
je     11d9 <make_dirs+0x99>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e19(%rip),%rax
mov    (%rax),%rdi
call   1060 <strerror@plt>
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
lea    0xe2c(%rip),%rdi
call   1050 <kpccfatal@plt>
mov    -0x18(%rbp),%rax
movb   $0x2f,(%rax)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1158 <make_dirs+0x18>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_dirs>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r14
add    $0x1,%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11cf <make_dirs+0x8f>
mov    %rax,%rbx
mov    0x2e6f(%rip),%r12
mov    0x2e70(%rip),%r13
lea    0xe89(%rip),%r15
jmp    119c <make_dirs+0x5c>
nopl   0x0(%rax)
movb   $0x2f,(%rbx)
add    $0x1,%rbx
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11cf <make_dirs+0x8f>
movb   $0x0,(%rbx)
mov    %r14,%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
cmp    $0xffffffff,%eax
jne    1180 <make_dirs+0x40>
mov    (%r12),%rdi
cmp    0x0(%r13),%rdi
je     1180 <make_dirs+0x40>
call   1060 <strerror@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1050 <kpccfatal@plt>
jmp    1180 <make_dirs+0x40>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@errno = global i64 0
@EEXIST = global i64 0
@.str = [22 x i8] c"can't makedir %s: %s\0A\00"
define void @make_dirs(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = getelementptr inbounds i8, i8* %6, i64 1
store i8* %7, i8** %5
br label %8
8: ; preds = %27, %1
%9 = load i8*, i8** %5
%10 = call i8* @strchr(i8* %9, i8 signext 47)
store i8* %10, i8** %4
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %31
12: ; preds = %8
%13 = load i8*, i8** %4
store i8 0, i8* %13
%14 = load i8*, i8** %2
%15 = call i32 @mkdir(i8* %14, i32 493)
store i32 %15, i32* %3
%16 = load i32, i32* %3
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %27
18: ; preds = %12
%19 = load i64, i64* @errno
%20 = load i64, i64* @EEXIST
%21 = icmp ne i64 %19, %20
br i1 %21, label %22, label %27
22: ; preds = %18
%23 = load i8*, i8** %2
%24 = load i64, i64* @errno
%25 = call i32 @strerror(i64 %24)
%26 = call i32 @kpccfatal(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %23, i32 %25)
br label %27
27: ; preds = %22, %18, %12
%28 = load i8*, i8** %4
store i8 47, i8* %28
%29 = load i8*, i8** %4
%30 = getelementptr inbounds i8, i8* %29, i64 1
store i8* %30, i8** %5
br label %8
31: ; preds = %8
ret void
}

LLVM IR (-O2):
@errno = global i64 0
@EEXIST = global i64 0
@.str = [22 x i8] c"can't makedir %s: %s\0A\00"
define void @make_dirs(i8* %0) {
%2 = getelementptr inbounds i8, i8* %0, i64 1
%3 = tail call i8* @strchr(i8* %2, i8 signext 47)
%4 = icmp eq i8* %3, null
br i1 %4, label %20, label %5
5: ; preds = %1, %16
%6 = phi i8* [ %18, %16 ], [ %3, %1 ]
store i8 0, i8* %6
%7 = tail call i32 @mkdir(i8* %0, i32 493)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %16
9: ; preds = %5
%10 = load i64, i64* @errno
%11 = load i64, i64* @EEXIST
%12 = icmp eq i64 %10, %11
br i1 %12, label %16, label %13
13: ; preds = %9
%14 = tail call i32 @strerror(i64 %10)
%15 = tail call i32 @kpccfatal(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %14)
br label %16
16: ; preds = %13, %9, %5
store i8 47, i8* %6
%17 = getelementptr inbounds i8, i8* %6, i64 1
%18 = tail call i8* @strchr(i8* %17, i8 signext 47)
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %5
20: ; preds = %16, %1
ret void
}