#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 mode_t;
typedef int /*<<< orphan*/ Dir;

/* Variables and functions */
scalar_t__ EEXIST;
int /*<<< orphan*/ FILENAME_MAX;
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int);
int /*<<< orphan*/ memset(char *, char, int);
int mkdir(char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
int umask(int);
int _RepMkDirs(char *Fname) {
  char Dir[FILENAME_MAX + 1];
  int i;
  int rc = 0;
  mode_t Mask;
  memset(Dir, '\0', sizeof(Dir));
  strcpy(Dir, Fname);
  for (i = 1; Dir[i] != '\0'; i++) {
    if (Dir[i] == '/') {
      Dir[i] = '\0';
      Mask = umask(0000);
      rc = mkdir(Dir, 0770);
      umask(Mask);
      if (rc && (errno == EEXIST))
        rc = 0;
      Dir[i] = '/';
      if (rc) {
        fprintf(stderr, "FATAL: 'mkdir %s' failed with rc=%d\n", Dir, rc);
        return (rc);
      }
    }
  }
  return (rc);
}


x86 assembly (clang, -O0):
<_RepMkDirs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e85(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x38(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x28(%rbp)
mov    %eax,%edx
xor    %esi,%esi
call   1050 <memset@plt>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
movl   $0x1,-0x24(%rbp)
mov    -0x38(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     128f <_RepMkDirs+0x13f>
mov    -0x38(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    127c <_RepMkDirs+0x12c>
mov    -0x38(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
xor    %edi,%edi
call   1070 <umask@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,-0x2c(%rbp)
mov    $0x1f8,%esi
call   1040 <mkdir@plt>
mov    %eax,-0x28(%rbp)
mov    -0x2c(%rbp),%edi
call   1070 <umask@plt>
cmpl   $0x0,-0x28(%rbp)
je     1233 <_RepMkDirs+0xe3>
mov    0x2daf(%rip),%rax
mov    (%rax),%rax
mov    0x2db5(%rip),%rcx
cmp    (%rcx),%rax
jne    1233 <_RepMkDirs+0xe3>
movl   $0x0,-0x28(%rbp)
mov    -0x38(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x2f,(%rax,%rcx,1)
cmpl   $0x0,-0x28(%rbp)
je     1277 <_RepMkDirs+0x127>
mov    -0x38(%rbp),%rdx
mov    0x2d7c(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%ecx
lea    0xda0(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x30(%rbp)
jmp    129c <_RepMkDirs+0x14c>
jmp    127c <_RepMkDirs+0x12c>
jmp    1281 <_RepMkDirs+0x131>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11af <_RepMkDirs+0x5f>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_RepMkDirs>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
mov    0x2e80(%rip),%rax
mov    (%rax),%edx
add    $0x1,%edx
mov    %rsp,%r12
lea    0xf(%rdx),%rbx
and    $0xfffffffffffffff0,%rbx
mov    %r12,%r14
sub    %rbx,%r14
mov    %r14,%rsp
mov    %r14,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
neg    %rbx
add    %r12,%rbx
add    $0x1,%rbx
mov    0x2e31(%rip),%r13
jmp    11b8 <_RepMkDirs+0x68>
nopl   0x0(%rax)
test   %al,%al
je     121c <_RepMkDirs+0xcc>
add    $0x1,%rbx
movzbl (%rbx),%eax
cmp    $0x2f,%al
jne    11b0 <_RepMkDirs+0x60>
movb   $0x0,(%rbx)
xor    %edi,%edi
call   1070 <umask@plt>
mov    %eax,%r12d
mov    %r14,%rdi
mov    $0x1f8,%esi
call   1040 <mkdir@plt>
mov    %eax,%r15d
mov    %r12d,%edi
call   1070 <umask@plt>
mov    0x2ddd(%rip),%rax
mov    (%rax),%rax
mov    0x0(%r13),%rcx
movb   $0x2f,(%rbx)
test   %r15d,%r15d
je     11b4 <_RepMkDirs+0x64>
cmp    %rcx,%rax
je     11b4 <_RepMkDirs+0x64>
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
lea    0xdf1(%rip),%rsi
mov    %r14,%rdx
mov    %r15d,%ecx
call   1060 <fprintf@plt>
jmp    121f <_RepMkDirs+0xcf>
xor    %r15d,%r15d
mov    %r15d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@FILENAME_MAX = global i32 0
@errno = global i64 0
@EEXIST = global i64 0
@stderr = global i32 0
@.str = [37 x i8] c"FATAL: 'mkdir %s' failed with rc=%d\0A\00"
define i32 @_RepMkDirs(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %3
%10 = load i32, i32* @FILENAME_MAX
%11 = add nsw i32 %10, 1
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %4
%14 = alloca i8, i64 %12
store i64 %12, i64* %5
store i32 0, i32* %7
%15 = trunc i64 %12 to i32
%16 = call i32 @memset(i8* %14, i8 signext 0, i32 %15)
%17 = load i8*, i8** %3
%18 = call i32 @strcpy(i8* %14, i8* %17)
store i32 1, i32* %6
br label %19
19: ; preds = %61, %1
%20 = load i32, i32* %6
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %14, i64 %21
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %64
26: ; preds = %19
%27 = load i32, i32* %6
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %14, i64 %28
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 47
br i1 %32, label %33, label %60
33: ; preds = %26
%34 = load i32, i32* %6
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %14, i64 %35
store i8 0, i8* %36
%37 = call i32 @umask(i32 0)
store i32 %37, i32* %8
%38 = call i32 @mkdir(i8* %14, i32 504)
store i32 %38, i32* %7
%39 = load i32, i32* %8
%40 = call i32 @umask(i32 %39)
%41 = load i32, i32* %7
%42 = icmp ne i32 %41, 0
br i1 %42, label %43, label %48
43: ; preds = %33
%44 = load i64, i64* @errno
%45 = load i64, i64* @EEXIST
%46 = icmp eq i64 %44, %45
br i1 %46, label %47, label %48
47: ; preds = %43
store i32 0, i32* %7
br label %48
48: ; preds = %47, %43, %33
%49 = load i32, i32* %6
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %14, i64 %50
store i8 47, i8* %51
%52 = load i32, i32* %7
%53 = icmp ne i32 %52, 0
br i1 %53, label %54, label %59
54: ; preds = %48
%55 = load i32, i32* @stderr
%56 = load i32, i32* %7
%57 = call i32 @fprintf(i32 %55, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %14, i32 %56)
%58 = load i32, i32* %7
store i32 %58, i32* %2
store i32 1, i32* %9
br label %66
59: ; preds = %48
br label %60
60: ; preds = %59, %26
br label %61
61: ; preds = %60
%62 = load i32, i32* %6
%63 = add nsw i32 %62, 1
store i32 %63, i32* %6
br label %19
64: ; preds = %19
%65 = load i32, i32* %7
store i32 %65, i32* %2
store i32 1, i32* %9
br label %66
66: ; preds = %64, %54
%67 = load i8*, i8** %4
%68 = load i32, i32* %2
ret i32 %68
}

LLVM IR (-O2):
@FILENAME_MAX = global i32 0
@errno = global i64 0
@EEXIST = global i64 0
@stderr = global i32 0
@.str = [37 x i8] c"FATAL: 'mkdir %s' failed with rc=%d\0A\00"
define i32 @_RepMkDirs(i8* %0) {
%2 = load i32, i32* @FILENAME_MAX
%3 = add nsw i32 %2, 1
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = call i32 @memset(i8* %5, i8 signext 0, i32 %3)
%7 = call i32 @strcpy(i8* %5, i8* %0)
br label %8
8: ; preds = %24, %1
%9 = phi i64 [ %25, %24 ], [ 1, %1 ]
%10 = getelementptr inbounds i8, i8* %5, i64 %9
%11 = load i8, i8* %10
switch i8 %11, label %24 [
i8 0, label %26
i8 47, label %12
]
12: ; preds = %8
store i8 0, i8* %10
%13 = call i32 @umask(i32 0)
%14 = call i32 @mkdir(i8* %5, i32 504)
%15 = call i32 @umask(i32 %13)
%16 = load i64, i64* @errno
%17 = load i64, i64* @EEXIST
%18 = icmp eq i64 %16, %17
store i8 47, i8* %10
%19 = icmp eq i32 %14, 0
%20 = select i1 %19, i1 true, i1 %18
br i1 %20, label %24, label %21
21: ; preds = %12
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %5, i32 %14)
br label %26
24: ; preds = %8, %12
%25 = add nuw i64 %9, 1
br label %8
26: ; preds = %8, %21
%27 = phi i32 [ %14, %21 ], [ 0, %8 ]
ret i32 %27
}