#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 */
int /*<<< orphan*/ chdir(char *);
int /*<<< orphan*/ mkdir(char *);
int /*<<< orphan*/ setdisk(scalar_t__);
int /*<<< orphan*/ sprintf(char *, char *, char *);
char *strchr(char *, char);
int strlen(char *);
scalar_t__ toupper(char);
void createdestpath(char *destdir) {
  char dirChar;
  char *p = strchr(destdir, '/');
  char envbuffer[260 + 7];
  while (p) {
    dirChar = *p;
    *p = '\0';
    mkdir(destdir);
    *p = dirChar;
    p = strchr(destdir, '/');
  }
  mkdir(destdir);
  if ((*p = destdir[strlen(destdir) - 1]) == dirChar)
    *p = '\0';
  sprintf(envbuffer, "DOSDIR=%s", destdir);
  if (destdir[1] == ':')
    setdisk(toupper(destdir[0]) - 'A');
  chdir(destdir);
}


x86 assembly (clang, -O0):
<createdestpath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1080 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11d5 <createdestpath+0x65>
mov    -0x18(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x9(%rbp)
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
call   1040 <mkdir@plt>
mov    -0x9(%rbp),%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1080 <strchr@plt>
mov    %rax,-0x18(%rbp)
jmp    1191 <createdestpath+0x21>
mov    -0x8(%rbp),%rdi
call   1040 <mkdir@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x138(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x138(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    -0x18(%rbp),%rcx
mov    %al,(%rcx)
movsbl %al,%eax
movsbl -0x9(%rbp),%ecx
cmp    %ecx,%eax
jne    1220 <createdestpath+0xb0>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x130(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xdce(%rip),%rsi
call   1090 <sprintf@plt>
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x3a,%eax
jne    1260 <createdestpath+0xf0>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1050 <toupper@plt>
mov    %rax,%rdi
sub    $0x41,%rdi
call   1030 <setdisk@plt>
mov    -0x8(%rbp),%rdi
call   1070 <chdir@plt>
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<createdestpath>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
mov    $0x2f,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     1176 <createdestpath+0x46>
mov    %rax,%rbx
nopl   0x0(%rax)
movzbl (%rbx),%ebp
movb   $0x0,(%rbx)
mov    %r14,%rdi
call   1030 <mkdir@plt>
mov    %bpl,(%rbx)
mov    %r14,%rdi
mov    $0x2f,%esi
call   1050 <strchr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1150 <createdestpath+0x20>
mov    %r14,%rdi
call   1030 <mkdir@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"DOSDIR=%s\00"
define void @createdestpath(i8* %0) {
%2 = alloca i8*
%3 = alloca i8
%4 = alloca i8*
%5 = alloca [267 x i8]
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i8* @strchr(i8* %6, i8 signext 47)
store i8* %7, i8** %4
br label %8
8: ; preds = %11, %1
%9 = load i8*, i8** %4
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %21
11: ; preds = %8
%12 = load i8*, i8** %4
%13 = load i8, i8* %12
store i8 %13, i8* %3
%14 = load i8*, i8** %4
store i8 0, i8* %14
%15 = load i8*, i8** %2
%16 = call i32 @mkdir(i8* %15)
%17 = load i8, i8* %3
%18 = load i8*, i8** %4
store i8 %17, i8* %18
%19 = load i8*, i8** %2
%20 = call i8* @strchr(i8* %19, i8 signext 47)
store i8* %20, i8** %4
br label %8
21: ; preds = %8
%22 = load i8*, i8** %2
%23 = call i32 @mkdir(i8* %22)
%24 = load i8*, i8** %2
%25 = load i8*, i8** %2
%26 = call i32 @strlen(i8* %25)
%27 = sub nsw i32 %26, 1
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %24, i64 %28
%30 = load i8, i8* %29
%31 = load i8*, i8** %4
store i8 %30, i8* %31
%32 = sext i8 %30 to i32
%33 = load i8, i8* %3
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %32, %34
br i1 %35, label %36, label %38
36: ; preds = %21
%37 = load i8*, i8** %4
store i8 0, i8* %37
br label %38
38: ; preds = %36, %21
%39 = getelementptr inbounds [267 x i8], [267 x i8]* %5, i64 0, i64 0
%40 = load i8*, i8** %2
%41 = call i32 @sprintf(i8* %39, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %40)
%42 = load i8*, i8** %2
%43 = getelementptr inbounds i8, i8* %42, i64 1
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = icmp eq i32 %45, 58
br i1 %46, label %47, label %54
47: ; preds = %38
%48 = load i8*, i8** %2
%49 = getelementptr inbounds i8, i8* %48, i64 0
%50 = load i8, i8* %49
%51 = call i64 @toupper(i8 signext %50)
%52 = sub nsw i64 %51, 65
%53 = call i32 @setdisk(i64 %52)
br label %54
54: ; preds = %47, %38
%55 = load i8*, i8** %2
%56 = call i32 @chdir(i8* %55)
ret void
}

LLVM IR (-O2):
define void @createdestpath(i8* %0) {
%2 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 47)
%3 = icmp eq i8* %2, null
br i1 %3, label %10, label %4
4: ; preds = %1, %4
%5 = phi i8* [ %8, %4 ], [ %2, %1 ]
%6 = load i8, i8* %5
store i8 0, i8* %5
%7 = tail call i32 @mkdir(i8* %0)
store i8 %6, i8* %5
%8 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 47)
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %4
10: ; preds = %4, %1
%11 = tail call i32 @mkdir(i8* %0)
%12 = tail call i32 @strlen(i8* %0)
unreachable
}