#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;
};
struct client_attr {
  int dummy;
};

/* Variables and functions */
scalar_t__ ENOENT;
scalar_t__ errno;
int mkdir(char *, int);
int stat(char *, struct stat *);
int /*<<< orphan*/ strcat(char *, char *);
char *strchr(char *, char);
int /*<<< orphan*/ strcpy(char *, char *);
void create_upload_dir(struct client_attr *attr, char *dirname) {
  char *p;
  char tmp[4096], dir[4096 + 255 + 1];
  struct stat sb;
  *tmp = 0;
  strcpy(dir, dirname);
  while ((p = strchr(dir, '/')) != NULL) {
    *p++ = 0;
    strcat(tmp, dir);
    strcat(tmp, "/");
    if (stat(tmp, &sb) == -1 && errno == ENOENT) {
      while (mkdir(tmp, 0700) == -1)
        ;
    }
    strcpy(dir, p);
  }
}


x86 assembly (clang, -O0):
<create_upload_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2130,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movb   $0x0,-0x1020(%rbp)
lea    -0x2120(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x2120(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1245 <create_upload_dir+0xf5>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x0,(%rax)
lea    -0x1020(%rbp),%rdi
lea    -0x2120(%rbp),%rsi
call   1070 <strcat@plt>
lea    -0x1020(%rbp),%rdi
lea    0xe34(%rip),%rsi
call   1070 <strcat@plt>
lea    -0x1020(%rbp),%rdi
lea    -0x2128(%rbp),%rsi
call   1060 <stat@plt>
cmp    $0xffffffff,%eax
jne    1230 <create_upload_dir+0xe0>
mov    0x2dec(%rip),%rax
mov    (%rax),%rax
mov    0x2dd2(%rip),%rcx
cmp    (%rcx),%rax
jne    1230 <create_upload_dir+0xe0>
jmp    120c <create_upload_dir+0xbc>
lea    -0x1020(%rbp),%rdi
mov    $0x1c0,%esi
call   1040 <mkdir@plt>
cmp    $0xffffffff,%eax
jne    122b <create_upload_dir+0xdb>
jmp    120c <create_upload_dir+0xbc>
jmp    1230 <create_upload_dir+0xe0>
lea    -0x2120(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    117a <create_upload_dir+0x2a>
add    $0x2130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_upload_dir>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2118,%rsp
movb   $0x0,0x10(%rsp)
lea    0x1010(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     1234 <create_upload_dir+0xe4>
mov    %rax,%rbx
lea    0x10(%rsp),%r12
lea    0x1010(%rsp),%r14
lea    0xe5d(%rip),%r15
lea    0x8(%rsp),%r13
mov    0x2e21(%rip),%rbp
jmp    11e0 <create_upload_dir+0x90>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %r14,%rdi
mov    $0x2f,%esi
call   1050 <strchr@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1234 <create_upload_dir+0xe4>
movb   $0x0,(%rbx)
add    $0x1,%rbx
mov    %r12,%rdi
mov    %r14,%rsi
call   1070 <strcat@plt>
mov    %r12,%rdi
mov    %r15,%rsi
call   1070 <strcat@plt>
mov    %r12,%rdi
mov    %r13,%rsi
call   1060 <stat@plt>
cmp    $0xffffffff,%eax
jne    11c0 <create_upload_dir+0x70>
mov    0x2dcc(%rip),%rax
mov    (%rax),%rax
cmp    0x0(%rbp),%rax
jne    11c0 <create_upload_dir+0x70>
nopl   (%rax)
mov    %r12,%rdi
mov    $0x1c0,%esi
call   1040 <mkdir@plt>
cmp    $0xffffffff,%eax
je     1220 <create_upload_dir+0xd0>
jmp    11c0 <create_upload_dir+0x70>
add    $0x2118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.client_attr = type { i32 }
%struct.stat = type { i32 }
@.str = [2 x i8] c"/\00"
@errno = global i64 0
@ENOENT = global i64 0
define void @create_upload_dir(%struct.client_attr* %0, i8* %1) {
%3 = alloca %struct.client_attr*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [4096 x i8]
%7 = alloca [4352 x i8]
%8 = alloca %struct.stat
store %struct.client_attr* %0, %struct.client_attr** %3
store i8* %1, i8** %4
%9 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
store i8 0, i8* %9
%10 = getelementptr inbounds [4352 x i8], [4352 x i8]* %7, i64 0, i64 0
%11 = load i8*, i8** %4
%12 = call i32 @strcpy(i8* %10, i8* %11)
br label %13
13: ; preds = %39, %2
%14 = getelementptr inbounds [4352 x i8], [4352 x i8]* %7, i64 0, i64 0
%15 = call i8* @strchr(i8* %14, i8 signext 47)
store i8* %15, i8** %5
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %43
17: ; preds = %13
%18 = load i8*, i8** %5
%19 = getelementptr inbounds i8, i8* %18, i32 1
store i8* %19, i8** %5
store i8 0, i8* %18
%20 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%21 = getelementptr inbounds [4352 x i8], [4352 x i8]* %7, i64 0, i64 0
%22 = call i32 @strcat(i8* %20, i8* %21)
%23 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%24 = call i32 @strcat(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%25 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%26 = call i32 @stat(i8* %25, %struct.stat* %8)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %39
28: ; preds = %17
%29 = load i64, i64* @errno
%30 = load i64, i64* @ENOENT
%31 = icmp eq i64 %29, %30
br i1 %31, label %32, label %39
32: ; preds = %28
br label %33
33: ; preds = %37, %32
%34 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%35 = call i32 @mkdir(i8* %34, i32 448)
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %38
37: ; preds = %33
br label %33
38: ; preds = %33
br label %39
39: ; preds = %38, %28, %17
%40 = getelementptr inbounds [4352 x i8], [4352 x i8]* %7, i64 0, i64 0
%41 = load i8*, i8** %5
%42 = call i32 @strcpy(i8* %40, i8* %41)
br label %13
43: ; preds = %13
ret void
}

LLVM IR (-O2):
%struct.client_attr = type { i32 }
%struct.stat = type { i32 }
@.str = [2 x i8] c"/\00"
@errno = global i64 0
@ENOENT = global i64 0
define void @create_upload_dir(%struct.client_attr* nocapture readnone %0, i8* %1) {
%3 = alloca [4096 x i8]
%4 = alloca [4352 x i8]
%5 = alloca %struct.stat
%6 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [4352 x i8], [4352 x i8]* %4, i64 0, i64 0
%8 = bitcast %struct.stat* %5 to i8*
store i8 0, i8* %6
%9 = call i32 @strcpy(i8* %7, i8* %1)
%10 = call i8* @strchr(i8* %7, i8 signext 47)
%11 = icmp eq i8* %10, null
br i1 %11, label %30, label %12
12: ; preds = %2, %26
%13 = phi i8* [ %28, %26 ], [ %10, %2 ]
%14 = getelementptr inbounds i8, i8* %13, i64 1
store i8 0, i8* %13
%15 = call i32 @strcat(i8* %6, i8* %7)
%16 = call i32 @strcat(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @stat(i8* %6, %struct.stat* %5)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %26
19: ; preds = %12
%20 = load i64, i64* @errno
%21 = load i64, i64* @ENOENT
%22 = icmp eq i64 %20, %21
br i1 %22, label %23, label %26
23: ; preds = %19, %23
%24 = call i32 @mkdir(i8* %6, i32 448)
%25 = icmp eq i32 %24, -1
br i1 %25, label %23, label %26
26: ; preds = %23, %19, %12
%27 = call i32 @strcpy(i8* %7, i8* %14)
%28 = call i8* @strchr(i8* %7, i8 signext 47)
%29 = icmp eq i8* %28, null
br i1 %29, label %30, label %12
30: ; preds = %26, %2
ret void
}