#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*/ getcwd(char *, int);
scalar_t__ mkdir(char *, int);
int /*<<< orphan*/ perror(char *);
int MakeDirectory(char *Directory) {
  char CurrentDirectory[1024];
  getcwd(CurrentDirectory, 1024);
  if (chdir(Directory) == 0) {
    chdir(CurrentDirectory);
    return 0;
  }
  if (mkdir(Directory, 0755) != 0) {
    perror("Failed to create directory");
    return 1;
  }
  if (chdir(Directory) != 0) {
    perror("Failed to change directory");
    return 1;
  }
  chdir(CurrentDirectory);
  return 0;
}


x86 assembly (clang, -O0):
<MakeDirectory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x410(%rbp),%rdi
mov    $0x400,%esi
call   1050 <getcwd@plt>
mov    -0x10(%rbp),%rdi
call   1040 <chdir@plt>
cmp    $0x0,%eax
jne    118a <MakeDirectory+0x4a>
lea    -0x410(%rbp),%rdi
call   1040 <chdir@plt>
movl   $0x0,-0x4(%rbp)
jmp    11f7 <MakeDirectory+0xb7>
mov    -0x10(%rbp),%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
cmp    $0x0,%rax
je     11ba <MakeDirectory+0x7a>
lea    0xe57(%rip),%rdi
call   1060 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    11f7 <MakeDirectory+0xb7>
mov    -0x10(%rbp),%rdi
call   1040 <chdir@plt>
cmp    $0x0,%eax
je     11e4 <MakeDirectory+0xa4>
lea    0xe48(%rip),%rdi
call   1060 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    11f7 <MakeDirectory+0xb7>
lea    -0x410(%rbp),%rdi
call   1040 <chdir@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MakeDirectory>:
push   %rbx
sub    $0x400,%rsp
mov    %rdi,%rbx
mov    %rsp,%rdi
mov    $0x400,%esi
call   1050 <getcwd@plt>
mov    %rbx,%rdi
call   1040 <chdir@plt>
test   %eax,%eax
je     1182 <MakeDirectory+0x42>
mov    %rbx,%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
test   %rax,%rax
jne    1195 <MakeDirectory+0x55>
mov    %rbx,%rdi
call   1040 <chdir@plt>
test   %eax,%eax
jne    119e <MakeDirectory+0x5e>
mov    %rsp,%rdi
call   1040 <chdir@plt>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbx
ret
lea    0xe64(%rip),%rdi
jmp    11a5 <MakeDirectory+0x65>
lea    0xe76(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%eax
jmp    118c <MakeDirectory+0x4c>

LLVM IR (-O0):
@.str = [27 x i8] c"Failed to create directory\00"
@.str.1 = [27 x i8] c"Failed to change directory\00"
define i32 @MakeDirectory(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [1024 x i8]
store i8* %0, i8** %3
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%6 = call i32 @getcwd(i8* %5, i32 1024)
%7 = load i8*, i8** %3
%8 = call i32 @chdir(i8* %7)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%12 = call i32 @chdir(i8* %11)
store i32 0, i32* %2
br label %28
13: ; preds = %1
%14 = load i8*, i8** %3
%15 = call i64 @mkdir(i8* %14, i32 493)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %2
br label %28
19: ; preds = %13
%20 = load i8*, i8** %3
%21 = call i32 @chdir(i8* %20)
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %19
%24 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %2
br label %28
25: ; preds = %19
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%27 = call i32 @chdir(i8* %26)
store i32 0, i32* %2
br label %28
28: ; preds = %25, %23, %17, %10
%29 = load i32, i32* %2
ret i32 %29
}

LLVM IR (-O2):
@.str = [27 x i8] c"Failed to create directory\00"
@.str.1 = [27 x i8] c"Failed to change directory\00"
define i32 @MakeDirectory(i8* %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = call i32 @getcwd(i8* %3, i32 1024)
%5 = call i32 @chdir(i8* %0)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = call i32 @chdir(i8* %3)
br label %21
9: ; preds = %1
%10 = call i64 @mkdir(i8* %0, i32 493)
%11 = icmp eq i64 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %9
%13 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %21
14: ; preds = %9
%15 = call i32 @chdir(i8* %0)
%16 = icmp eq i32 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %14
%18 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %21
19: ; preds = %14
%20 = call i32 @chdir(i8* %3)
br label %21
21: ; preds = %19, %17, %12, %7
%22 = phi i32 [ 0, %7 ], [ 1, %12 ], [ 1, %17 ], [ 0, %19 ]
ret i32 %22
}