#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 */
struct stat {
  int dummy;
};
typedef int /*<<< orphan*/ st;

/* Variables and functions */
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWGRP;
int S_IWOTH;
int S_IWUSR;
int S_IXGRP;
int S_IXOTH;
int S_IXUSR;
scalar_t__ chmod(char const *, int);
int errno;
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, int,
                           char *);
int /*<<< orphan*/ memset(struct stat *, int /*<<< orphan*/, int);
scalar_t__ mkdir(char const *, int);
int stat(char const *, struct stat *);
int /*<<< orphan*/ stdout;
char *strerror(int);
int hubo_rt_make_directory_component(const char *subdirectory) {
  struct stat st;
  memset(&st, 0, sizeof(st));
  if (stat(subdirectory, &st) == -1) {
    if (mkdir(subdirectory, S_IRUSR | S_IXUSR | S_IWUSR | S_IRGRP | S_IXGRP |
                                S_IWGRP | S_IROTH | S_IXOTH | S_IWOTH) != 0) {
      fprintf(stdout, "Unable to create directory %s, code=%d (%s)\n",
              subdirectory, errno, strerror(errno));
      fflush(stdout);
      return -1;
    }
    if (chmod(subdirectory, S_IRUSR | S_IXUSR | S_IWUSR | S_IRGRP | S_IXGRP |
                                S_IWGRP | S_IROTH | S_IXOTH | S_IWOTH) != 0) {
      fprintf(stdout,
              "Unable to set universal permissions for directory %s, "
              "code=%d (%s)\n",
              subdirectory, errno, strerror(errno));
      fflush(stdout);
      return -2;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<hubo_rt_make_directory_component>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1060 <stat@plt>
cmp    $0xffffffff,%eax
jne    1331 <hubo_rt_make_directory_component+0x1c1>
mov    -0x10(%rbp),%rdi
mov    0x2df3(%rip),%rax
mov    (%rax),%esi
mov    0x2e2a(%rip),%rax
or     (%rax),%esi
mov    0x2e11(%rip),%rax
or     (%rax),%esi
mov    0x2de8(%rip),%rax
or     (%rax),%esi
mov    0x2df7(%rip),%rax
or     (%rax),%esi
mov    0x2dfe(%rip),%rax
or     (%rax),%esi
mov    0x2dc5(%rip),%rax
or     (%rax),%esi
mov    0x2dfc(%rip),%rax
or     (%rax),%esi
mov    0x2d93(%rip),%rax
or     (%rax),%esi
call   1030 <mkdir@plt>
cmp    $0x0,%rax
je     1267 <hubo_rt_make_directory_component+0xf7>
mov    0x2d8b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2d97(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2d8b(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
mov    %rax,%r8
lea    0xdb8(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2d44(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1338 <hubo_rt_make_directory_component+0x1c8>
mov    -0x10(%rbp),%rdi
mov    0x2d2e(%rip),%rax
mov    (%rax),%esi
mov    0x2d65(%rip),%rax
or     (%rax),%esi
mov    0x2d4c(%rip),%rax
or     (%rax),%esi
mov    0x2d23(%rip),%rax
or     (%rax),%esi
mov    0x2d32(%rip),%rax
or     (%rax),%esi
mov    0x2d39(%rip),%rax
or     (%rax),%esi
mov    0x2d00(%rip),%rax
or     (%rax),%esi
mov    0x2d37(%rip),%rax
or     (%rax),%esi
mov    0x2cce(%rip),%rax
or     (%rax),%esi
call   1080 <chmod@plt>
cmp    $0x0,%rax
je     132c <hubo_rt_make_directory_component+0x1bc>
mov    0x2cc6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    0x2cd2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0x2cc6(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rdx
mov    -0x30(%rbp),%ecx
mov    %rax,%r8
lea    0xd20(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2c7f(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1338 <hubo_rt_make_directory_component+0x1c8>
jmp    1331 <hubo_rt_make_directory_component+0x1c1>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hubo_rt_make_directory_component>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    %rsp,%rbp
xor    %r14d,%r14d
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1060 <stat@plt>
cmp    $0xffffffff,%eax
jne    12d1 <hubo_rt_make_directory_component+0x161>
mov    0x2df2(%rip),%rax
mov    0x2e2b(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e10(%rip),%rax
or     (%rax),%esi
mov    0x2de7(%rip),%rax
or     (%rax),%esi
mov    0x2df6(%rip),%rax
or     (%rax),%esi
mov    0x2dfd(%rip),%r12
or     (%r12),%esi
mov    0x2dc2(%rip),%r13
or     0x0(%r13),%esi
mov    0x2df7(%rip),%rbp
or     0x0(%rbp),%esi
mov    0x2d8d(%rip),%r15
or     (%r15),%esi
mov    %rbx,%rdi
call   1030 <mkdir@plt>
test   %rax,%rax
je     1244 <hubo_rt_make_directory_component+0xd4>
mov    0x2d86(%rip),%rax
mov    (%rax),%r14d
mov    0x2d9c(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1090 <strerror@plt>
lea    0xdd4(%rip),%rsi
mov    %r14d,%edi
mov    %rbx,%rdx
mov    %ebp,%ecx
mov    %rax,%r8
call   1050 <fprintf@plt>
mov    $0xffffffff,%r14d
jmp    12c3 <hubo_rt_make_directory_component+0x153>
mov    0x2d95(%rip),%rax
mov    (%rax),%esi
mov    0x2d4c(%rip),%rax
or     (%rax),%esi
mov    0x2d73(%rip),%rax
or     (%rax),%esi
mov    0x2d4a(%rip),%rax
or     (%rax),%esi
mov    0x2d59(%rip),%rax
or     (%rax),%esi
or     (%r12),%esi
or     0x0(%r13),%esi
or     0x0(%rbp),%esi
or     (%r15),%esi
mov    %rbx,%rdi
call   1080 <chmod@plt>
test   %rax,%rax
je     12d1 <hubo_rt_make_directory_component+0x161>
mov    0x2d05(%rip),%rax
mov    (%rax),%r14d
mov    0x2d1b(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1090 <strerror@plt>
lea    0xd80(%rip),%rsi
mov    %r14d,%edi
mov    %rbx,%rdx
mov    %ebp,%ecx
mov    %rax,%r8
call   1050 <fprintf@plt>
mov    $0xfffffffe,%r14d
mov    0x2cce(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@S_IRUSR = global i32 0
@S_IXUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IXGRP = global i32 0
@S_IWGRP = global i32 0
@S_IROTH = global i32 0
@S_IXOTH = global i32 0
@S_IWOTH = global i32 0
@stdout = global i32 0
@.str = [45 x i8] c"Unable to create directory %s, code=%d (%s)\0A\00"
@errno = global i32 0
@.str.1 = [68 x i8] c"Unable to set universal permissions for directory %s, code=%d (%s)\0A\00"
define i32 @hubo_rt_make_directory_component(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.stat
store i8* %0, i8** %3
%5 = call i32 @memset(%struct.stat* %4, i32 0, i32 4)
%6 = load i8*, i8** %3
%7 = call i32 @stat(i8* %6, %struct.stat* %4)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %70
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = load i32, i32* @S_IRUSR
%12 = load i32, i32* @S_IXUSR
%13 = or i32 %11, %12
%14 = load i32, i32* @S_IWUSR
%15 = or i32 %13, %14
%16 = load i32, i32* @S_IRGRP
%17 = or i32 %15, %16
%18 = load i32, i32* @S_IXGRP
%19 = or i32 %17, %18
%20 = load i32, i32* @S_IWGRP
%21 = or i32 %19, %20
%22 = load i32, i32* @S_IROTH
%23 = or i32 %21, %22
%24 = load i32, i32* @S_IXOTH
%25 = or i32 %23, %24
%26 = load i32, i32* @S_IWOTH
%27 = or i32 %25, %26
%28 = call i64 @mkdir(i8* %10, i32 %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %39
30: ; preds = %9
%31 = load i32, i32* @stdout
%32 = load i8*, i8** %3
%33 = load i32, i32* @errno
%34 = load i32, i32* @errno
%35 = call i8* @strerror(i32 %34)
%36 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %32, i32 %33, i8* %35)
%37 = load i32, i32* @stdout
%38 = call i32 @fflush(i32 %37)
store i32 -1, i32* %2
br label %71
39: ; preds = %9
%40 = load i8*, i8** %3
%41 = load i32, i32* @S_IRUSR
%42 = load i32, i32* @S_IXUSR
%43 = or i32 %41, %42
%44 = load i32, i32* @S_IWUSR
%45 = or i32 %43, %44
%46 = load i32, i32* @S_IRGRP
%47 = or i32 %45, %46
%48 = load i32, i32* @S_IXGRP
%49 = or i32 %47, %48
%50 = load i32, i32* @S_IWGRP
%51 = or i32 %49, %50
%52 = load i32, i32* @S_IROTH
%53 = or i32 %51, %52
%54 = load i32, i32* @S_IXOTH
%55 = or i32 %53, %54
%56 = load i32, i32* @S_IWOTH
%57 = or i32 %55, %56
%58 = call i64 @chmod(i8* %40, i32 %57)
%59 = icmp ne i64 %58, 0
br i1 %59, label %60, label %69
60: ; preds = %39
%61 = load i32, i32* @stdout
%62 = load i8*, i8** %3
%63 = load i32, i32* @errno
%64 = load i32, i32* @errno
%65 = call i8* @strerror(i32 %64)
%66 = call i32 @fprintf(i32 %61, i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.1, i64 0, i64 0), i8* %62, i32 %63, i8* %65)
%67 = load i32, i32* @stdout
%68 = call i32 @fflush(i32 %67)
store i32 -2, i32* %2
br label %71
69: ; preds = %39
br label %70
70: ; preds = %69, %1
store i32 0, i32* %2
br label %71
71: ; preds = %70, %60, %30
%72 = load i32, i32* %2
ret i32 %72
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@S_IRUSR = global i32 0
@S_IXUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IXGRP = global i32 0
@S_IWGRP = global i32 0
@S_IROTH = global i32 0
@S_IXOTH = global i32 0
@S_IWOTH = global i32 0
@stdout = global i32 0
@.str = [45 x i8] c"Unable to create directory %s, code=%d (%s)\0A\00"
@errno = global i32 0
@.str.1 = [68 x i8] c"Unable to set universal permissions for directory %s, code=%d (%s)\0A\00"
define i32 @hubo_rt_make_directory_component(i8* %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = call i32 @memset(%struct.stat* %2, i32 0, i32 4)
%5 = call i32 @stat(i8* %0, %struct.stat* %2)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %61
7: ; preds = %1
%8 = load i32, i32* @S_IRUSR
%9 = load i32, i32* @S_IXUSR
%10 = or i32 %9, %8
%11 = load i32, i32* @S_IWUSR
%12 = or i32 %10, %11
%13 = load i32, i32* @S_IRGRP
%14 = or i32 %12, %13
%15 = load i32, i32* @S_IXGRP
%16 = or i32 %14, %15
%17 = load i32, i32* @S_IWGRP
%18 = or i32 %16, %17
%19 = load i32, i32* @S_IROTH
%20 = or i32 %18, %19
%21 = load i32, i32* @S_IXOTH
%22 = or i32 %20, %21
%23 = load i32, i32* @S_IWOTH
%24 = or i32 %22, %23
%25 = call i64 @mkdir(i8* %0, i32 %24)
%26 = icmp eq i64 %25, 0
br i1 %26, label %32, label %27
27: ; preds = %7
%28 = load i32, i32* @stdout
%29 = load i32, i32* @errno
%30 = call i8* @strerror(i32 %29)
%31 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %29, i8* %30)
br label %57
32: ; preds = %7
%33 = load i32, i32* @S_IRUSR
%34 = load i32, i32* @S_IXUSR
%35 = or i32 %34, %33
%36 = load i32, i32* @S_IWUSR
%37 = or i32 %35, %36
%38 = load i32, i32* @S_IRGRP
%39 = or i32 %37, %38
%40 = load i32, i32* @S_IXGRP
%41 = or i32 %39, %40
%42 = load i32, i32* @S_IWGRP
%43 = or i32 %41, %42
%44 = load i32, i32* @S_IROTH
%45 = or i32 %43, %44
%46 = load i32, i32* @S_IXOTH
%47 = or i32 %45, %46
%48 = load i32, i32* @S_IWOTH
%49 = or i32 %47, %48
%50 = call i64 @chmod(i8* %0, i32 %49)
%51 = icmp eq i64 %50, 0
br i1 %51, label %61, label %52
52: ; preds = %32
%53 = load i32, i32* @stdout
%54 = load i32, i32* @errno
%55 = call i8* @strerror(i32 %54)
%56 = call i32 @fprintf(i32 %53, i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 %54, i8* %55)
br label %57
57: ; preds = %27, %52
%58 = phi i32 [ -2, %52 ], [ -1, %27 ]
%59 = load i32, i32* @stdout
%60 = call i32 @fflush(i32 %59)
br label %61
61: ; preds = %57, %1, %32
%62 = phi i32 [ 0, %32 ], [ 0, %1 ], [ %58, %57 ]
ret i32 %62
}