#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 */
scalar_t__ chdir(char *);
scalar_t__ file_IsDirectorySeparator(char const);
int /*<<< orphan*/ file_MakeSlashesNative(char *);
int /*<<< orphan*/ free(char *);
scalar_t__ strcasecmp(char const *, char *);
char *strdup(char const *);
int strlen(char const *);
int file_Cwd(const char *path) {
  while (path[0] == '.' && strlen(path) > 1 &&
         file_IsDirectorySeparator(path[1])) {
    path += 2;
  }
  if (strcasecmp(path, "") == 0 || strcasecmp(path, ".") == 0) {
    return 1;
  }
  char *pathcopy = strdup(path);
  if (!pathcopy) {
    return 0;
  }
  file_MakeSlashesNative(pathcopy);
  if (chdir(pathcopy) != 0) {
    free(pathcopy);
    return 0;
  }
  free(pathcopy);
  return 1;
}


x86 assembly (clang, -O0):
<file_Cwd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x2e,%ecx
mov    %al,-0x19(%rbp)
jne    11c1 <file_Cwd+0x51>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x1,%ecx
mov    %al,-0x19(%rbp)
jle    11c1 <file_Cwd+0x51>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1070 <file_IsDirectorySeparator@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    11d1 <file_Cwd+0x61>
jmp    11e2 <file_Cwd+0x72>
mov    -0x10(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x10(%rbp)
jmp    117c <file_Cwd+0xc>
mov    -0x10(%rbp),%rdi
lea    0xe14(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
je     1216 <file_Cwd+0xa6>
mov    -0x10(%rbp),%rdi
lea    0xdf9(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
jne    1222 <file_Cwd+0xb2>
movl   $0x1,-0x4(%rbp)
jmp    1287 <file_Cwd+0x117>
mov    -0x10(%rbp),%rdi
call   1090 <strdup@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1246 <file_Cwd+0xd6>
movl   $0x0,-0x4(%rbp)
jmp    1287 <file_Cwd+0x117>
mov    -0x18(%rbp),%rdi
call   1080 <file_MakeSlashesNative@plt>
mov    -0x18(%rbp),%rdi
call   1060 <chdir@plt>
cmp    $0x0,%rax
je     1277 <file_Cwd+0x107>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    1287 <file_Cwd+0x117>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_Cwd>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
cmpb   $0x2e,(%rdi)
jne    11aa <file_Cwd+0x3a>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1050 <strlen@plt>
cmp    $0x2,%eax
jl     11aa <file_Cwd+0x3a>
movsbl 0x1(%rbx),%edi
call   1070 <file_IsDirectorySeparator@plt>
test   %rax,%rax
je     11aa <file_Cwd+0x3a>
lea    0x2(%rbx),%rbp
cmpb   $0x2e,0x2(%rbx)
mov    %rbp,%rbx
je     1180 <file_Cwd+0x10>
jmp    11ad <file_Cwd+0x3d>
mov    %rbx,%rbp
lea    0xe4d(%rip),%rsi
mov    %rbp,%rdi
call   1040 <strcasecmp@plt>
mov    $0x1,%ebx
test   %rax,%rax
je     120e <file_Cwd+0x9e>
lea    0xe33(%rip),%rsi
mov    %rbp,%rdi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     120e <file_Cwd+0x9e>
mov    %rbp,%rdi
call   1090 <strdup@plt>
test   %rax,%rax
je     120c <file_Cwd+0x9c>
mov    %rax,%rbp
mov    %rax,%rdi
call   1080 <file_MakeSlashesNative@plt>
mov    %rbp,%rdi
call   1060 <chdir@plt>
xor    %ebx,%ebx
test   %rax,%rax
sete   %bl
mov    %rbp,%rdi
call   1030 <free@plt>
jmp    120e <file_Cwd+0x9e>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [2 x i8] c".\00"
define i32 @file_Cwd(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
br label %5
5: ; preds = %23, %1
%6 = load i8*, i8** %3
%7 = getelementptr inbounds i8, i8* %6, i64 0
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = icmp eq i32 %9, 46
br i1 %10, label %11, label %21
11: ; preds = %5
%12 = load i8*, i8** %3
%13 = call i32 @strlen(i8* %12)
%14 = icmp sgt i32 %13, 1
br i1 %14, label %15, label %21
15: ; preds = %11
%16 = load i8*, i8** %3
%17 = getelementptr inbounds i8, i8* %16, i64 1
%18 = load i8, i8* %17
%19 = call i64 @file_IsDirectorySeparator(i8 signext %18)
%20 = icmp ne i64 %19, 0
br label %21
21: ; preds = %15, %11, %5
%22 = phi i1 [ false, %11 ], [ false, %5 ], [ %20, %15 ]
br i1 %22, label %23, label %26
23: ; preds = %21
%24 = load i8*, i8** %3
%25 = getelementptr inbounds i8, i8* %24, i64 2
store i8* %25, i8** %3
br label %5
26: ; preds = %21
%27 = load i8*, i8** %3
%28 = call i64 @strcasecmp(i8* %27, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%29 = icmp eq i64 %28, 0
br i1 %29, label %34, label %30
30: ; preds = %26
%31 = load i8*, i8** %3
%32 = call i64 @strcasecmp(i8* %31, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %30, %26
store i32 1, i32* %2
br label %53
35: ; preds = %30
%36 = load i8*, i8** %3
%37 = call i8* @strdup(i8* %36)
store i8* %37, i8** %4
%38 = load i8*, i8** %4
%39 = icmp ne i8* %38, null
br i1 %39, label %41, label %40
40: ; preds = %35
store i32 0, i32* %2
br label %53
41: ; preds = %35
%42 = load i8*, i8** %4
%43 = call i32 @file_MakeSlashesNative(i8* %42)
%44 = load i8*, i8** %4
%45 = call i64 @chdir(i8* %44)
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %41
%48 = load i8*, i8** %4
%49 = call i32 @free(i8* %48)
store i32 0, i32* %2
br label %53
50: ; preds = %41
%51 = load i8*, i8** %4
%52 = call i32 @free(i8* %51)
store i32 1, i32* %2
br label %53
53: ; preds = %50, %47, %40, %34
%54 = load i32, i32* %2
ret i32 %54
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [2 x i8] c".\00"
define i32 @file_Cwd(i8* %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 46
br i1 %3, label %4, label %17
4: ; preds = %1, %13
%5 = phi i8* [ %14, %13 ], [ %0, %1 ]
%6 = tail call i32 @strlen(i8* %5)
%7 = icmp sgt i32 %6, 1
br i1 %7, label %8, label %17
8: ; preds = %4
%9 = getelementptr inbounds i8, i8* %5, i64 1
%10 = load i8, i8* %9
%11 = tail call i64 @file_IsDirectorySeparator(i8 signext %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %17, label %13
13: ; preds = %8
%14 = getelementptr inbounds i8, i8* %5, i64 2
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 46
br i1 %16, label %4, label %17
17: ; preds = %8, %4, %13, %1
%18 = phi i8* [ %0, %1 ], [ %14, %13 ], [ %5, %4 ], [ %5, %8 ]
%19 = tail call i64 @strcasecmp(i8* %18, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %33, label %21
21: ; preds = %17
%22 = tail call i64 @strcasecmp(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
br i1 %23, label %33, label %24
24: ; preds = %21
%25 = tail call i8* @strdup(i8* %18)
%26 = icmp eq i8* %25, null
br i1 %26, label %33, label %27
27: ; preds = %24
%28 = tail call i32 @file_MakeSlashesNative(i8* %25)
%29 = tail call i64 @chdir(i8* %25)
%30 = icmp eq i64 %29, 0
%31 = tail call i32 @free(i8* %25)
%32 = zext i1 %30 to i32
br label %33
33: ; preds = %27, %24, %17, %21
%34 = phi i32 [ 1, %21 ], [ 1, %17 ], [ 0, %24 ], [ %32, %27 ]
ret i32 %34
}