#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*/ dn;

/* Variables and functions */
scalar_t__ lstat(char *, struct stat *);
int /*<<< orphan*/ mkdir(char *, int);
void mkd(const char *fn) {
  int i;
  char dn[1024];
  for (i = 0; i < sizeof(dn) && fn[i]; i++) {
    struct stat st;
    dn[i] = '\0';
    if (i && fn[i] == '/' && lstat(dn, &st))
      mkdir(dn, 0777);
    dn[i] = fn[i];
  }
}


x86 assembly (clang, -O0):
<mkd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movslq -0xc(%rbp),%rcx
xor    %eax,%eax
cmp    $0x400,%rcx
mov    %al,-0x419(%rbp)
jae    1167 <mkd+0x47>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x419(%rbp)
mov    -0x419(%rbp),%al
test   $0x1,%al
jne    117a <mkd+0x5a>
jmp    11f7 <mkd+0xd7>
movslq -0xc(%rbp),%rax
movb   $0x0,-0x410(%rbp,%rax,1)
cmpl   $0x0,-0xc(%rbp)
je     11d3 <mkd+0xb3>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    11d3 <mkd+0xb3>
lea    -0x410(%rbp),%rdi
lea    -0x418(%rbp),%rsi
call   1040 <lstat@plt>
cmp    $0x0,%rax
je     11d3 <mkd+0xb3>
lea    -0x410(%rbp),%rdi
mov    $0x1ff,%esi
call   1030 <mkdir@plt>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
movslq -0xc(%rbp),%rax
mov    %cl,-0x410(%rbp,%rax,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1136 <mkd+0x16>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mkd>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    %rdi,%r12
xor    %ebx,%ebx
lea    0x10(%rsp),%r14
lea    0x8(%rsp),%r15
jmp    1156 <mkd+0x36>
nop
movzbl (%r12,%rbx,1),%eax
mov    %al,0x10(%rsp,%rbx,1)
add    $0x1,%rbx
cmp    $0x400,%rbx
je     118c <mkd+0x6c>
movzbl (%r12,%rbx,1),%eax
test   %al,%al
je     118c <mkd+0x6c>
movb   $0x0,0x10(%rsp,%rbx,1)
test   %rbx,%rbx
je     1140 <mkd+0x20>
cmp    $0x2f,%al
jne    1140 <mkd+0x20>
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <lstat@plt>
test   %rax,%rax
je     1140 <mkd+0x20>
mov    %r14,%rdi
mov    $0x1ff,%esi
call   1030 <mkdir@plt>
jmp    1140 <mkd+0x20>
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
define void @mkd(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [1024 x i8]
%5 = alloca %struct.stat
store i8* %0, i8** %2
store i32 0, i32* %3
br label %6
6: ; preds = %50, %1
%7 = load i32, i32* %3
%8 = sext i32 %7 to i64
%9 = icmp ult i64 %8, 1024
br i1 %9, label %10, label %18
10: ; preds = %6
%11 = load i8*, i8** %2
%12 = load i32, i32* %3
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %11, i64 %13
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 0
br label %18
18: ; preds = %10, %6
%19 = phi i1 [ false, %6 ], [ %17, %10 ]
br i1 %19, label %20, label %53
20: ; preds = %18
%21 = load i32, i32* %3
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %22
store i8 0, i8* %23
%24 = load i32, i32* %3
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %41
26: ; preds = %20
%27 = load i8*, i8** %2
%28 = load i32, i32* %3
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 47
br i1 %33, label %34, label %41
34: ; preds = %26
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%36 = call i64 @lstat(i8* %35, %struct.stat* %5)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %34
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%40 = call i32 @mkdir(i8* %39, i32 511)
br label %41
41: ; preds = %38, %34, %26, %20
%42 = load i8*, i8** %2
%43 = load i32, i32* %3
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %42, i64 %44
%46 = load i8, i8* %45
%47 = load i32, i32* %3
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %48
store i8 %46, i8* %49
br label %50
50: ; preds = %41
%51 = load i32, i32* %3
%52 = add nsw i32 %51, 1
store i32 %52, i32* %3
br label %6
53: ; preds = %18
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
define void @mkd(i8* nocapture %0) {
%2 = alloca [1024 x i8]
%3 = alloca %struct.stat
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%5 = bitcast %struct.stat* %3 to i8*
br label %6
6: ; preds = %1, %21
%7 = phi i64 [ 0, %1 ], [ %23, %21 ]
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 0
br i1 %10, label %25, label %11
11: ; preds = %6
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %7
store i8 0, i8* %12
%13 = icmp ne i64 %7, 0
%14 = icmp eq i8 %9, 47
%15 = select i1 %13, i1 %14, i1 false
br i1 %15, label %16, label %21
16: ; preds = %11
%17 = call i64 @lstat(i8* %4, %struct.stat* %3)
%18 = icmp eq i64 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %16
%20 = call i32 @mkdir(i8* %4, i32 511)
br label %21
21: ; preds = %19, %16, %11
%22 = load i8, i8* %8
store i8 %22, i8* %12
%23 = add nuw nsw i64 %7, 1
%24 = icmp eq i64 %23, 1024
br i1 %24, label %25, label %6
25: ; preds = %21, %6
ret void
}