#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 */
#define EEXIST 128
int errno;
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ mkdir(char *, int);
char *strchr(char *, char);
void make_home_directory(char *dst) {
  char *p;
  p = dst + 1;
  errno = 0;
  while (1) {
    p = strchr(p, '/');
    if (!p)
      break;
    *p = 0;
    mkdir(dst, 0755);
    switch (errno) {
    case EEXIST:
      errno = 0;
      break;
    case 0:
      break;
    default:
      error("Failed to create home directory.\n");
    }
    *p = '/';
    ++p;
  }
  errno = 0;
  mkdir(dst, 0755);
  if (errno != 0 && errno != EEXIST)
    error("Failed to create home directory.\n");
}


x86 assembly (clang, -O0):
<make_home_directory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    0x2e91(%rip),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1177 <make_home_directory+0x47>
jmp    11f3 <make_home_directory+0xc3>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
mov    0x2e4d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
test   %eax,%eax
je     11ca <make_home_directory+0x9a>
jmp    11a5 <make_home_directory+0x75>
mov    -0x14(%rbp),%eax
sub    $0x80,%eax
jne    11cf <make_home_directory+0x9f>
jmp    11b8 <make_home_directory+0x88>
mov    0x2e21(%rip),%rax
movl   $0x0,(%rax)
jmp    11db <make_home_directory+0xab>
jmp    11db <make_home_directory+0xab>
lea    0xe2a(%rip),%rdi
call   1050 <error@plt>
mov    -0x10(%rbp),%rax
movb   $0x2f,(%rax)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1155 <make_home_directory+0x25>
mov    0x2de6(%rip),%rax
movl   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
mov    0x2dcb(%rip),%rax
cmpl   $0x0,(%rax)
je     123d <make_home_directory+0x10d>
mov    0x2dbb(%rip),%rax
cmpl   $0x80,(%rax)
je     123d <make_home_directory+0x10d>
lea    0xdc8(%rip),%rdi
call   1050 <error@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_home_directory>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    0x2e9e(%rip),%r12
movl   $0x0,(%r12)
add    $0x1,%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11bd <make_home_directory+0x8d>
mov    %rax,%rbx
lea    0xe99(%rip),%r15
jmp    1194 <make_home_directory+0x64>
nopl   0x0(%rax)
mov    %r15,%rdi
call   1050 <error@plt>
movb   $0x2f,(%rbx)
add    $0x1,%rbx
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11bd <make_home_directory+0x8d>
movb   $0x0,(%rbx)
mov    %r14,%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
mov    (%r12),%eax
test   %eax,%eax
je     1178 <make_home_directory+0x48>
cmp    $0x80,%eax
jne    1170 <make_home_directory+0x40>
movl   $0x0,(%r12)
jmp    1178 <make_home_directory+0x48>
movl   $0x0,(%r12)
mov    %r14,%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
testl  $0xffffff7f,(%r12)
ff
je     11f3 <make_home_directory+0xc3>
lea    0xe1d(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1050 <error@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@errno = global i32 0
@.str = [34 x i8] c"Failed to create home directory.\0A\00"
define void @make_home_directory(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = getelementptr inbounds i8, i8* %4, i64 1
store i8* %5, i8** %3
store i32 0, i32* @errno
br label %6
6: ; preds = %1, %21
%7 = load i8*, i8** %3
%8 = call i8* @strchr(i8* %7, i8 signext 47)
store i8* %8, i8** %3
%9 = load i8*, i8** %3
%10 = icmp ne i8* %9, null
br i1 %10, label %12, label %11
11: ; preds = %6
br label %25
12: ; preds = %6
%13 = load i8*, i8** %3
store i8 0, i8* %13
%14 = load i8*, i8** %2
%15 = call i32 @mkdir(i8* %14, i32 493)
%16 = load i32, i32* @errno
switch i32 %16, label %19 [
i32 128, label %17
i32 0, label %18
]
17: ; preds = %12
store i32 0, i32* @errno
br label %21
18: ; preds = %12
br label %21
19: ; preds = %12
%20 = call i32 @error(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
br label %21
21: ; preds = %19, %18, %17
%22 = load i8*, i8** %3
store i8 47, i8* %22
%23 = load i8*, i8** %3
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %3
br label %6
25: ; preds = %11
store i32 0, i32* @errno
%26 = load i8*, i8** %2
%27 = call i32 @mkdir(i8* %26, i32 493)
%28 = load i32, i32* @errno
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %35
30: ; preds = %25
%31 = load i32, i32* @errno
%32 = icmp ne i32 %31, 128
br i1 %32, label %33, label %35
33: ; preds = %30
%34 = call i32 @error(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
br label %35
35: ; preds = %33, %30, %25
ret void
}

LLVM IR (-O2):
@errno = global i32 0
@.str = [34 x i8] c"Failed to create home directory.\0A\00"
define void @make_home_directory(i8* %0) {
store i32 0, i32* @errno
%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 %16, label %5
5: ; preds = %1, %12
%6 = phi i8* [ %14, %12 ], [ %3, %1 ]
store i8 0, i8* %6
%7 = tail call i32 @mkdir(i8* %0, i32 493)
%8 = load i32, i32* @errno
switch i32 %8, label %10 [
i32 128, label %9
i32 0, label %12
]
9: ; preds = %5
store i32 0, i32* @errno
br label %12
10: ; preds = %5
%11 = tail call i32 @error(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %5, %9
store i8 47, i8* %6
%13 = getelementptr inbounds i8, i8* %6, i64 1
%14 = tail call i8* @strchr(i8* %13, i8 signext 47)
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %5
16: ; preds = %12, %1
store i32 0, i32* @errno
%17 = tail call i32 @mkdir(i8* %0, i32 493)
%18 = load i32, i32* @errno
%19 = and i32 %18, -129
%20 = icmp eq i32 %19, 0
br i1 %20, label %23, label %21
21: ; preds = %16
%22 = tail call i32 @error(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
br label %23
23: ; preds = %21, %16
ret void
}